@@ -4,6 +4,7 @@ import Settings from "../../src/icons/Settings.svelte";
44import { user } from "../setup-tests" ;
55import Tab from "./Tab.test.svelte" ;
66import TabIcon from "./TabIcon.test.svelte" ;
7+ import TabIconContainer from "./TabIconContainer.test.svelte" ;
78import Tabs from "./Tabs.test.svelte" ;
89import TabsDynamic from "./TabsDynamic.test.svelte" ;
910import TabsSkeleton from "./TabsSkeleton.test.svelte" ;
@@ -442,6 +443,81 @@ describe("Tab icon", () => {
442443 } ) ;
443444} ) ;
444445
446+ describe ( "Container tabs with icon" , ( ) => {
447+ it ( "should render container type with icon" , ( ) => {
448+ const { container } = render ( TabIconContainer , {
449+ props : { icon : Calendar } ,
450+ } ) ;
451+
452+ const tabsContainer = screen . getByRole ( "navigation" ) ;
453+ expect ( tabsContainer ) . toHaveClass ( "bx--tabs--container" ) ;
454+
455+ const iconWrapper = container . querySelector ( ".bx--tabs__nav-item--icon" ) ;
456+ expect ( iconWrapper ) . toBeInTheDocument ( ) ;
457+
458+ const svg = iconWrapper ?. querySelector ( "svg" ) ;
459+ expect ( svg ) . toBeInTheDocument ( ) ;
460+ expect ( svg ) . toHaveAttribute ( "width" , "16" ) ;
461+ expect ( svg ) . toHaveAttribute ( "height" , "16" ) ;
462+ } ) ;
463+
464+ it ( "should not render icon wrapper on tab without icon in container" , ( ) => {
465+ const { container } = render ( TabIconContainer , {
466+ props : { icon : Calendar } ,
467+ } ) ;
468+
469+ const navItems = container . querySelectorAll ( ".bx--tabs__nav-item" ) ;
470+ const secondTab = navItems [ 1 ] ;
471+ const iconWrapper = secondTab ?. querySelector ( ".bx--tabs__nav-item--icon" ) ;
472+ expect ( iconWrapper ) . not . toBeInTheDocument ( ) ;
473+ } ) ;
474+
475+ it ( "should render icon inside nav link in container tabs" , ( ) => {
476+ const { container } = render ( TabIconContainer , {
477+ props : { icon : Calendar } ,
478+ } ) ;
479+
480+ const navLink = container . querySelector ( ".bx--tabs__nav-link" ) ;
481+ const iconWrapper = navLink ?. querySelector ( ".bx--tabs__nav-item--icon" ) ;
482+ expect ( iconWrapper ) . toBeInTheDocument ( ) ;
483+ } ) ;
484+
485+ it ( "should render label and icon together in container tabs" , ( ) => {
486+ render ( TabIconContainer , {
487+ props : { label : "Dashboard" , icon : Calendar } ,
488+ } ) ;
489+
490+ const tab = screen . getByRole ( "tab" , { name : / D a s h b o a r d / } ) ;
491+ expect ( tab ) . toBeInTheDocument ( ) ;
492+ expect ( tab . querySelector ( ".bx--tabs__nav-item--icon" ) ) . toBeInTheDocument ( ) ;
493+ } ) ;
494+
495+ it ( "should apply disabled styling when tab with icon is disabled in container" , ( ) => {
496+ const { container } = render ( TabIconContainer , {
497+ props : { icon : Settings , disabled : true } ,
498+ } ) ;
499+
500+ const disabledItem = container . querySelector (
501+ ".bx--tabs__nav-item--disabled" ,
502+ ) ;
503+ expect ( disabledItem ) . toBeInTheDocument ( ) ;
504+
505+ const iconWrapper = disabledItem ?. querySelector (
506+ ".bx--tabs__nav-item--icon" ,
507+ ) ;
508+ expect ( iconWrapper ) . toBeInTheDocument ( ) ;
509+ } ) ;
510+
511+ it ( "should be clickable with icon when enabled in container tabs" , async ( ) => {
512+ render ( TabIconContainer , { props : { icon : Calendar } } ) ;
513+
514+ const tab = screen . getByRole ( "tab" , { name : / T e s t T a b / } ) ;
515+ await user . click ( tab ) ;
516+
517+ expect ( tab ) . toHaveAttribute ( "aria-selected" , "true" ) ;
518+ } ) ;
519+ } ) ;
520+
445521describe ( "TabsSkeleton" , ( ) => {
446522 it ( "should render with default props" , ( ) => {
447523 const { container } = render ( TabsSkeleton ) ;
0 commit comments