Skip to content

Commit a82feae

Browse files
committed
test(tabs): make reusable test work
1 parent feae634 commit a82feae

File tree

2 files changed

+62
-75
lines changed

2 files changed

+62
-75
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"]
66
],
77
"editor.codeActionsOnSave": {
8-
"source.removeUnusedImports": true
8+
"source.removeUnusedImports": "explicit"
99
}
1010
}

packages/kit-headless/src/components/tabs/tabs.spec.tsx

Lines changed: 61 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { $, component$, useSignal, useStore } from '@builder.io/qwik';
1+
import { $, Slot, component$, useSignal, useStore } from '@builder.io/qwik';
22
import { Tabs } from './tabs';
3-
import { TabList } from './tabs-list';
4-
import { Tab } from './tab';
5-
import { TabPanel } from './tab-panel';
3+
import { TabList, TabListProps } from './tabs-list';
4+
import { Tab, TabProps } from './tab';
5+
import { TabPanel, TabPanelProps } from './tab-panel';
66

77
describe('Tabs', () => {
88
it('INIT', () => {
@@ -769,74 +769,61 @@ describe('Tabs', () => {
769769
});
770770
});
771771

772-
// TODO: add test for Custom tabs
773-
774-
// Couldn't write the test because of the following error:
775-
/**
776-
* The following error originated from your test code, not from Cypress.
777-
> Captured variable in the closure can not be serialized because it's a function named "CustomTabs". You might need to convert it to a QRL using $(fn):
778-
*/
779-
780-
// const CustomTabs = (props: TabsProps) => (
781-
// <Tabs {...props} TabList={CustomTabList} Tab={CustomTab} TabPanel={CustomTabPanel} />
782-
// );
783-
784-
// const CustomTabList = component$<TabListProps>(() => {
785-
// return (
786-
// <TabList>
787-
// <Slot />
788-
// </TabList>
789-
// );
790-
// });
791-
792-
// const CustomTab = component$<TabProps>(({ ...props }) => {
793-
// return (
794-
// <Tab {...props}>
795-
// <Slot />
796-
// </Tab>
797-
// );
798-
// });
799-
800-
// const CustomTabPanel = component$<TabPanelProps>(({ ...props }) => {
801-
// return (
802-
// <TabPanel {...props}>
803-
// <Slot />
804-
// </TabPanel>
805-
// );
806-
// });
807-
808-
// const CustomThreeTabsComponent = component$(() => {
809-
// return (
810-
// <>
811-
// <CustomTabs>
812-
// <CustomTabList>
813-
// <CustomTab>Tab 1</CustomTab>
814-
// <CustomTab>Tab 2</CustomTab>
815-
// <CustomTab>Tab 3</CustomTab>
816-
// </CustomTabList>
817-
// <CustomTabPanel>Panel 1</CustomTabPanel>
818-
// <CustomTabPanel>Panel 2</CustomTabPanel>
819-
// <CustomTabPanel>Panel 3</CustomTabPanel>
820-
// </CustomTabs>
821-
// </>
822-
// );
823-
// });
824-
825-
// describe('User-defined TabList', () => {
826-
// it(`GIVEN a user-defined TabList to Tabs
827-
// WHEN clicking the middle Tab
828-
// THEN render the middle panel`, () => {
829-
// cy.mount(<CustomThreeTabsComponent />);
830-
831-
// cy.get('[role="tab"]').should('have.length', 3);
832-
833-
// cy.findByRole('tabpanel').should('contain', 'Panel 3');
834-
835-
// cy.findByRole('tab', { name: /Tab 2/i }).click();
836-
837-
// cy.findByRole('tabpanel').should('contain', 'Panel 2');
838-
839-
// cy.findByRole('tablist').should('exist');
840-
// });
841-
// });
772+
describe('User-defined reusable TabList/Tab/TabPanel components', () => {
773+
const CustomTabList = component$<TabListProps>(() => {
774+
return (
775+
<TabList>
776+
<Slot />
777+
</TabList>
778+
);
779+
});
780+
781+
const CustomTab = component$<TabProps>(({ ...props }) => {
782+
return (
783+
<Tab {...props}>
784+
<Slot />
785+
</Tab>
786+
);
787+
});
788+
789+
const CustomTabPanel = component$<TabPanelProps>(({ ...props }) => {
790+
return (
791+
<TabPanel {...props}>
792+
<Slot />
793+
</TabPanel>
794+
);
795+
});
796+
797+
const CustomThreeTabsComponent = component$(() => {
798+
return (
799+
<>
800+
<Tabs TabList={CustomTabList} Tab={CustomTab} TabPanel={CustomTabPanel}>
801+
<CustomTabList>
802+
<CustomTab>Tab 1</CustomTab>
803+
<CustomTab>Tab 2</CustomTab>
804+
<CustomTab>Tab 3</CustomTab>
805+
</CustomTabList>
806+
<CustomTabPanel>Panel 1</CustomTabPanel>
807+
<CustomTabPanel>Panel 2</CustomTabPanel>
808+
<CustomTabPanel>Panel 3</CustomTabPanel>
809+
</Tabs>
810+
</>
811+
);
812+
});
813+
it(`GIVEN a user-defined TabList to Tabs
814+
WHEN clicking the middle Tab
815+
THEN render the middle panel`, () => {
816+
cy.mount(<CustomThreeTabsComponent />);
817+
818+
cy.get('[role="tab"]').should('have.length', 3);
819+
820+
cy.findByRole('tabpanel').should('contain', 'Panel 1');
821+
822+
cy.findByRole('tab', { name: /Tab 2/i }).click();
823+
824+
cy.findByRole('tabpanel').should('contain', 'Panel 2');
825+
826+
cy.findByRole('tablist').should('exist');
827+
});
828+
});
842829
});

0 commit comments

Comments
 (0)