2019-01-03 16:00:55 +03:00
|
|
|
import React from 'react';
|
2021-10-22 07:18:03 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
import userEvent from '@testing-library/user-event';
|
2019-01-03 16:00:55 +03:00
|
|
|
import { Tabs } from '../src';
|
2020-09-02 20:30:47 +03:00
|
|
|
import { tabs, simple10Tabs } from '../src/Tabs/data';
|
2019-01-03 16:00:55 +03:00
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
describe('Tabs', function () {
|
2019-01-03 16:00:55 +03:00
|
|
|
it('renders correctly', () => {
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(
|
2020-09-09 17:35:22 +03:00
|
|
|
<Tabs
|
|
|
|
tabs={tabs}
|
|
|
|
onClick={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
2023-07-12 21:03:20 +03:00
|
|
|
/>,
|
2020-09-09 17:35:22 +03:00
|
|
|
);
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders with props', () => {
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(
|
2020-09-09 17:35:22 +03:00
|
|
|
<Tabs
|
|
|
|
tabs={tabs}
|
|
|
|
onClick={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
|
|
|
selected="Tab2"
|
2023-07-12 21:03:20 +03:00
|
|
|
/>,
|
2019-01-03 16:00:55 +03:00
|
|
|
);
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tabs without inner components', () => {
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(
|
2020-09-09 17:35:22 +03:00
|
|
|
<Tabs
|
|
|
|
tabs={simple10Tabs}
|
|
|
|
onClick={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
|
|
|
selected="5"
|
2023-07-12 21:03:20 +03:00
|
|
|
/>,
|
2019-01-03 16:00:55 +03:00
|
|
|
);
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
|
2022-06-06 19:22:05 +03:00
|
|
|
it('should select tab', async () => {
|
2019-01-03 16:00:55 +03:00
|
|
|
const onClick = jest.fn();
|
2021-10-22 07:18:03 +03:00
|
|
|
render(<Tabs tabs={tabs} onClick={onClick} />);
|
2019-01-03 16:00:55 +03:00
|
|
|
|
2022-06-06 19:22:05 +03:00
|
|
|
await userEvent.click(screen.getByRole('button', { name: 'Tab1' }));
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(onClick).toHaveBeenCalled();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
});
|