Skip to content

Commit 8d11289

Browse files
committed
test(tabs): add test template since not working
1 parent 3a73752 commit 8d11289

File tree

2 files changed

+131
-2
lines changed

2 files changed

+131
-2
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { Slot, component$ } from '@builder.io/qwik';
2+
import {
3+
Tab,
4+
TabList,
5+
TabListProps,
6+
TabPanel,
7+
TabPanelProps,
8+
TabProps,
9+
Tabs,
10+
TabsProps,
11+
} from '@qwik-ui/headless';
12+
13+
const CustomTabs = (props: TabsProps) => (
14+
<Tabs {...props} TabList={CustomTabList} Tab={CustomTab} TabPanel={CustomTabPanel} />
15+
);
16+
17+
const CustomTabList = component$<TabListProps>(() => {
18+
return (
19+
<TabList>
20+
<Slot />
21+
</TabList>
22+
);
23+
});
24+
25+
const CustomTab = component$<TabProps>(({ ...props }) => {
26+
return (
27+
<Tab {...props}>
28+
<Slot />
29+
</Tab>
30+
);
31+
});
32+
33+
const CustomTabPanel = component$<TabPanelProps>(({ ...props }) => {
34+
return (
35+
<TabPanel {...props}>
36+
<Slot />
37+
</TabPanel>
38+
);
39+
});
40+
41+
const CustomThreeTabsComponent = component$(() => {
42+
return (
43+
<CustomTabs>
44+
<CustomTabList>
45+
<CustomTab>Tab 1</CustomTab>
46+
<CustomTab>Tab 2</CustomTab>
47+
<CustomTab>Tab 3</CustomTab>
48+
</CustomTabList>
49+
<CustomTabPanel>Panel 1</CustomTabPanel>
50+
<CustomTabPanel>Panel 2</CustomTabPanel>
51+
<CustomTabPanel>Panel 3</CustomTabPanel>
52+
</CustomTabs>
53+
);
54+
});
55+
56+
export default component$(() => {
57+
return <CustomThreeTabsComponent />;
58+
});

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

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { $, component$, useSignal, useStore } from '@builder.io/qwik';
2-
import { Tab } from './tab';
3-
import { TabPanel } from './tab-panel';
42
import { Tabs } from './tabs';
53
import { TabList } from './tabs-list';
4+
import { Tab } from './tab';
5+
import { TabPanel } from './tab-panel';
66

77
describe('Tabs', () => {
88
it('INIT', () => {
@@ -768,4 +768,75 @@ describe('Tabs', () => {
768768
cy.findByRole('tablist').should('exist');
769769
});
770770
});
771+
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+
// });
771842
});

0 commit comments

Comments
 (0)