import { render, screen } from '@testing-library/react';
import * as React from 'react';
import { Tabs, TabItem } from '../Tabs';
import { Text } from '../../Text';
import { ComponentClassNames } from '../../shared';
describe('Tabs', () => {
it('can render custom classnames', async () => {
render(
Tab 1
);
const tabs = await screen.findByTestId('tabsId');
expect(tabs.className).toContain('custom-classname');
expect(tabs.className).toContain(ComponentClassNames.Tabs);
});
it('can render any arbitrary data-* attribute', async () => {
render(
Tab 1
Tab 2
);
const tabs = await screen.findByTestId('tabsTest');
expect(tabs.dataset['demo']).toBe('true');
});
it('should forward ref to Tabs DOM element', async () => {
const ref = React.createRef();
render(
Tab 1
);
await screen.findByTestId('tabsId');
expect(ref.current?.nodeName).toBe('DIV');
});
it('should skip over null children', async () => {
render(
Tab 1
{null}
);
const tabs = await screen.findByTestId('tabsTest');
const panels = await screen.findAllByRole('tabpanel');
expect(tabs.children).toHaveLength(1);
expect(panels).toHaveLength(1);
});
it('should work with defaultIndex and null children', async () => {
render(
Tab 1
{null}
{undefined}
Tab 2
);
const tabs = await screen.findAllByRole('tab');
expect(tabs).toHaveLength(2);
expect(tabs[1]).toHaveAttribute('aria-selected', 'true');
});
describe('TabItem', () => {
it('can render custom classnames', async () => {
render(
Tab 1
);
const tab = await screen.findByRole('tab');
expect(tab.className).toContain('custom-classname');
expect(tab.className).toContain(ComponentClassNames.TabItems);
});
it('should handle React nodes in the title', async () => {
render(
Test1234}>Tab 1
);
const tab = await screen.findByTestId('test');
expect(tab.innerHTML).toContain('Test1234');
});
it('should render disabled button when disabled', async () => {
render(
Tab 1
);
const tab = await screen.findByRole('tab');
expect(tab).toHaveAttribute('disabled');
});
it('should forward ref to TabItem Button DOM element', async () => {
const ref = React.createRef();
render(
Tab 1
);
await screen.findByRole('tab');
expect(ref.current?.nodeName).toBe('BUTTON');
});
});
});