import React from 'react'; import { render, screen } from '@testing-library/react'; import { Tabs } from '../Tabs'; import { Tab } from '../Tab'; import { TabTitleText } from '../TabTitleText'; import { TabTitleIcon } from '../TabTitleIcon'; import { TabContent } from '../TabContent'; import { TabContentBody } from '../TabContentBody'; test('should render simple tabs', () => { const { asFragment } = render( "Tab item 1"}> Tab 1 section "Tab item 2"}> Tab 2 section "Tab item 3"}> Tab 3 section 4 {' '} Users{' '} } > Tab 4 section ); expect(asFragment()).toMatchSnapshot(); }); test('should render closeable tabs', () => { const view = render( "Tab item 1"} closeButtonAriaLabel="close-label"> Tab 1 section ); expect(screen.getByLabelText('close-label')).toBeTruthy(); }); test('should render add button', () => { const view = render( "Tab item 1"} closeButtonAriaLabel="close-label"> Tab 1 section ); expect(screen.getByLabelText('add-label')).toBeTruthy(); }); test('should render uncontrolled tabs', () => { const { asFragment } = render( "Tab item 1"}> Tab 1 section "Tab item 2"}> Tab 2 section "Tab item 3"}> Tab 3 section 4 {' '} Users{' '} } > Tab 4 section ); expect(asFragment()).toMatchSnapshot(); }); test('should render vertical tabs', () => { const { asFragment } = render( "Tab item 1"}> Tab 1 section "Tab item 2"}> Tab 2 section "Tab item 3"}> Tab 3 section 4 {' '} Users{' '} } > Tab 4 section ); expect(asFragment()).toMatchSnapshot(); }); test('should render expandable vertical tabs', () => { const { asFragment } = render( "Tab item 1"}> Tab 1 section "Tab item 2"}> Tab 2 section "Tab item 3"}> Tab 3 section 4 {' '} Users{' '} } > Tab 4 section ); expect(asFragment()).toMatchSnapshot(); }); test('should log error when there is no aria-label or toggleText for expandable vertical tabs', () => { const consoleErrorMock = jest.fn(); global.console = { error: consoleErrorMock } as any; const { asFragment } = render( "Tab item 1"}> Tab 1 section "Tab item 2"}> Tab 2 section "Tab item 3"}> Tab 3 section 4 {' '} Users{' '} } > Tab 4 section ); expect(consoleErrorMock).toHaveBeenCalled(); }); test('should render box tabs', () => { const { asFragment } = render( "Tab item 1"}> Tab 1 section "Tab item 2"}> Tab 2 section "Tab item 3"}> Tab 3 section 4 {' '} Users{' '} } > Tab 4 section ); expect(asFragment()).toMatchSnapshot(); }); test('should render accessible tabs', () => { const { asFragment } = render( "Tab item 1"} href="#/items/1"> Tab 1 section "Tab item 2"} href="#/items/2"> Tab 2 section "Tab item 3"} href="#/items/3"> Tab 3 section ); expect(asFragment()).toMatchSnapshot(); }); test('should render filled tabs', () => { const { asFragment } = render( "Tab item 1"}> Tab 1 section "Tab item 2"}> Tab 2 section "Tab item 3"}> Tab 3 section ); expect(asFragment()).toMatchSnapshot(); }); test('should render secondary tabs', () => { const { asFragment } = render( "Tab item 1"}> "Secondary Tab item 1"}> Secondary Tab 1 section "Secondary Tab item 2"}> Secondary Tab 2 section "Secondary Tab item 3"}> Secondary Tab 3 section "Tab item 2"}> Tab 2 section "Tab item 3"}> Tab 3 section ); expect(asFragment()).toMatchSnapshot(); }); test('should render tabs with eventKey Strings', () => { const { asFragment } = render( "Secondary Tab item 1"}> Tab 1 section "Secondary Tab item 2"}> Tab 2 section "Secondary Tab item 3"}> Tab 3 section ); expect(asFragment()).toMatchSnapshot(); }); test('should render tabs with separate content', () => { const contentRef1: React.RefObject = null; const contentRef2: React.RefObject = null; const contentRef3: React.RefObject = null; const { asFragment } = render( <> Tab item 1} tabContentId="refTab1Section" tabContentRef={contentRef1} /> Tab item 2} tabContentId="refTab2Section" tabContentRef={contentRef2} /> Tab item 3} tabContentId="refTab3Section" tabContentRef={contentRef3} />
Tab 1 section
); expect(asFragment()).toMatchSnapshot(); }); test('should render box tabs of light variant', () => { const { asFragment } = render( "Tab item 1"}> Tab 1 section "Tab item 2"}> Tab 2 section "Tab item 3"}> Tab 3 section ); expect(asFragment()).toMatchSnapshot(); }); test('should render tabs with no bottom border', () => { const { asFragment } = render( "Tab item 1"}> Tab 1 section "Tab item 2"}> Tab 2 section "Tab item 3"}> Tab 3 section ); expect(asFragment()).toMatchSnapshot(); }); test('should render secondary tabs with no bottom border when passed hasNoBorderBottom', () => { render( "Tab item 1"}> Tab 1 section "Tab item 2"}> Tab 2 section "Tab item 3"}> Tab 3 section ); const tabsContainer = screen.queryByLabelText('Secondary bottom border'); expect(tabsContainer).toHaveClass('pf-m-no-border-bottom'); }); test('should render secondary tabs with border bottom', () => { render( "Tab item 1"}> Tab 1 section "Tab item 2"}> Tab 2 section "Tab item 3"}> Tab 3 section ); const tabsContainer = screen.queryByLabelText('Secondary bottom border'); expect(tabsContainer).not.toHaveClass('pf-m-no-border-bottom'); }); test('should not render scroll buttons by default', () => { render( "Tab item 1"}> Tab 1 section "Tab item 2"}> Tab 2 section "Tab item 3"}> Tab 3 section ); expect(screen.queryByLabelText('Scroll left')).not.toBeInTheDocument(); expect(screen.queryByLabelText('Scroll right')).not.toBeInTheDocument(); }) test('should not render scroll buttons when isVertical is true', () => { render( "Tab item 1"}> Tab 1 section "Tab item 2"}> Tab 2 section "Tab item 3"}> Tab 3 section ); expect(screen.queryByLabelText('Scroll left')).not.toBeInTheDocument(); expect(screen.queryByLabelText('Scroll right')).not.toBeInTheDocument(); })