|
1 |
| -import { $, component$, useSignal, useStore } from '@builder.io/qwik'; |
| 1 | +import { $, Slot, component$, useSignal, useStore } from '@builder.io/qwik'; |
2 | 2 | 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'; |
6 | 6 |
|
7 | 7 | describe('Tabs', () => {
|
8 | 8 | it('INIT', () => {
|
@@ -769,74 +769,61 @@ describe('Tabs', () => {
|
769 | 769 | });
|
770 | 770 | });
|
771 | 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 |
| - // }); |
| 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 | + }); |
842 | 829 | });
|
0 commit comments