|
1 | 1 | import { render, screen } from "@testing-library/svelte"; |
| 2 | +import type HamburgerMenuComponent from "carbon-components-svelte/UIShell/HamburgerMenu.svelte"; |
| 3 | +import type HeaderComponent from "carbon-components-svelte/UIShell/Header.svelte"; |
| 4 | +import type HeaderActionLinkComponent from "carbon-components-svelte/UIShell/HeaderActionLink.svelte"; |
| 5 | +import type HeaderGlobalActionComponent from "carbon-components-svelte/UIShell/HeaderGlobalAction.svelte"; |
| 6 | +import type SideNavLinkComponent from "carbon-components-svelte/UIShell/SideNavLink.svelte"; |
| 7 | +import type SideNavMenuComponent from "carbon-components-svelte/UIShell/SideNavMenu.svelte"; |
| 8 | +import type { ComponentProps } from "svelte"; |
2 | 9 | import { user } from "../setup-tests"; |
3 | 10 | import HeaderSlot from "./Header.slot.test.svelte"; |
4 | 11 | import UiShell from "./UIShell.test.svelte"; |
@@ -674,4 +681,134 @@ describe("UIShell", () => { |
674 | 681 | }); |
675 | 682 | }); |
676 | 683 | }); |
| 684 | + |
| 685 | + describe("Generics", () => { |
| 686 | + describe("HamburgerMenu", () => { |
| 687 | + it("should support custom Icon types with generics", () => { |
| 688 | + type CustomIcon = new (...args: unknown[]) => unknown; |
| 689 | + |
| 690 | + type ComponentType = HamburgerMenuComponent<CustomIcon>; |
| 691 | + type Props = ComponentProps<ComponentType>; |
| 692 | + |
| 693 | + expectTypeOf<Props["iconMenu"]>().toEqualTypeOf< |
| 694 | + CustomIcon | undefined |
| 695 | + >(); |
| 696 | + expectTypeOf<Props["iconClose"]>().toEqualTypeOf< |
| 697 | + CustomIcon | undefined |
| 698 | + >(); |
| 699 | + }); |
| 700 | + |
| 701 | + it("should default to any type when generic is not specified", () => { |
| 702 | + type ComponentType = HamburgerMenuComponent; |
| 703 | + type Props = ComponentProps<ComponentType>; |
| 704 | + |
| 705 | + // biome-ignore lint/suspicious/noExplicitAny: Testing default any type |
| 706 | + expectTypeOf<Props["iconMenu"]>().toEqualTypeOf<any>(); |
| 707 | + // biome-ignore lint/suspicious/noExplicitAny: Testing default any type |
| 708 | + expectTypeOf<Props["iconClose"]>().toEqualTypeOf<any>(); |
| 709 | + }); |
| 710 | + }); |
| 711 | + |
| 712 | + describe("Header", () => { |
| 713 | + it("should support custom Icon types with generics", () => { |
| 714 | + type CustomIcon = new (...args: unknown[]) => unknown; |
| 715 | + |
| 716 | + type ComponentType = HeaderComponent<CustomIcon>; |
| 717 | + type Props = ComponentProps<ComponentType>; |
| 718 | + |
| 719 | + expectTypeOf<Props["iconMenu"]>().toEqualTypeOf< |
| 720 | + CustomIcon | undefined |
| 721 | + >(); |
| 722 | + expectTypeOf<Props["iconClose"]>().toEqualTypeOf< |
| 723 | + CustomIcon | undefined |
| 724 | + >(); |
| 725 | + }); |
| 726 | + |
| 727 | + it("should default to any type when generic is not specified", () => { |
| 728 | + type ComponentType = HeaderComponent; |
| 729 | + type Props = ComponentProps<ComponentType>; |
| 730 | + |
| 731 | + // biome-ignore lint/suspicious/noExplicitAny: Testing default any type |
| 732 | + expectTypeOf<Props["iconMenu"]>().toEqualTypeOf<any>(); |
| 733 | + // biome-ignore lint/suspicious/noExplicitAny: Testing default any type |
| 734 | + expectTypeOf<Props["iconClose"]>().toEqualTypeOf<any>(); |
| 735 | + }); |
| 736 | + }); |
| 737 | + |
| 738 | + describe("HeaderActionLink", () => { |
| 739 | + it("should support custom Icon types with generics", () => { |
| 740 | + type CustomIcon = new (...args: unknown[]) => unknown; |
| 741 | + |
| 742 | + type ComponentType = HeaderActionLinkComponent<CustomIcon>; |
| 743 | + type Props = ComponentProps<ComponentType>; |
| 744 | + |
| 745 | + expectTypeOf<Props["icon"]>().toEqualTypeOf<CustomIcon | undefined>(); |
| 746 | + }); |
| 747 | + |
| 748 | + it("should default to any type when generic is not specified", () => { |
| 749 | + type ComponentType = HeaderActionLinkComponent; |
| 750 | + type Props = ComponentProps<ComponentType>; |
| 751 | + |
| 752 | + // biome-ignore lint/suspicious/noExplicitAny: Testing default any type |
| 753 | + expectTypeOf<Props["icon"]>().toEqualTypeOf<any>(); |
| 754 | + }); |
| 755 | + }); |
| 756 | + |
| 757 | + describe("HeaderGlobalAction", () => { |
| 758 | + it("should support custom Icon types with generics", () => { |
| 759 | + type CustomIcon = new (...args: unknown[]) => unknown; |
| 760 | + |
| 761 | + type ComponentType = HeaderGlobalActionComponent<CustomIcon>; |
| 762 | + type Props = ComponentProps<ComponentType>; |
| 763 | + |
| 764 | + expectTypeOf<Props["icon"]>().toExtend<CustomIcon | undefined>(); |
| 765 | + }); |
| 766 | + |
| 767 | + it("should default to any type when generic is not specified", () => { |
| 768 | + type ComponentType = HeaderGlobalActionComponent; |
| 769 | + type Props = ComponentProps<ComponentType>; |
| 770 | + |
| 771 | + // biome-ignore lint/suspicious/noExplicitAny: Testing default any type |
| 772 | + expectTypeOf<Props["icon"]>().toEqualTypeOf<any>(); |
| 773 | + }); |
| 774 | + }); |
| 775 | + |
| 776 | + describe("SideNavLink", () => { |
| 777 | + it("should support custom Icon types with generics", () => { |
| 778 | + type CustomIcon = new (...args: unknown[]) => unknown; |
| 779 | + |
| 780 | + type ComponentType = SideNavLinkComponent<CustomIcon>; |
| 781 | + type Props = ComponentProps<ComponentType>; |
| 782 | + |
| 783 | + expectTypeOf<Props["icon"]>().toEqualTypeOf<CustomIcon | undefined>(); |
| 784 | + }); |
| 785 | + |
| 786 | + it("should default to any type when generic is not specified", () => { |
| 787 | + type ComponentType = SideNavLinkComponent; |
| 788 | + type Props = ComponentProps<ComponentType>; |
| 789 | + |
| 790 | + // biome-ignore lint/suspicious/noExplicitAny: Testing default any type |
| 791 | + expectTypeOf<Props["icon"]>().toEqualTypeOf<any>(); |
| 792 | + }); |
| 793 | + }); |
| 794 | + |
| 795 | + describe("SideNavMenu", () => { |
| 796 | + it("should support custom Icon types with generics", () => { |
| 797 | + type CustomIcon = new (...args: unknown[]) => unknown; |
| 798 | + |
| 799 | + type ComponentType = SideNavMenuComponent<CustomIcon>; |
| 800 | + type Props = ComponentProps<ComponentType>; |
| 801 | + |
| 802 | + expectTypeOf<Props["icon"]>().toEqualTypeOf<CustomIcon | undefined>(); |
| 803 | + }); |
| 804 | + |
| 805 | + it("should default to any type when generic is not specified", () => { |
| 806 | + type ComponentType = SideNavMenuComponent; |
| 807 | + type Props = ComponentProps<ComponentType>; |
| 808 | + |
| 809 | + // biome-ignore lint/suspicious/noExplicitAny: Testing default any type |
| 810 | + expectTypeOf<Props["icon"]>().toEqualTypeOf<any>(); |
| 811 | + }); |
| 812 | + }); |
| 813 | + }); |
677 | 814 | }); |
0 commit comments