2022-05-14 12:11:50 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2022-03-13 13:00:45 +03:00
|
|
|
import { ExportBtn } from '../../src/utils/ExportBtn';
|
|
|
|
|
|
|
|
describe('<ExportBtn />', () => {
|
2022-05-14 12:11:50 +03:00
|
|
|
const setUp = (amount?: number, loading = false) => render(<ExportBtn amount={amount} loading={loading} />);
|
2022-03-13 13:00:45 +03:00
|
|
|
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
[true, 'Exporting...'],
|
2022-05-14 12:11:50 +03:00
|
|
|
[false, 'Export (0)'],
|
|
|
|
])('renders loading state when expected', async (loading, text) => {
|
|
|
|
setUp(undefined, loading);
|
|
|
|
const btn = await screen.findByRole('button');
|
|
|
|
|
|
|
|
expect(btn).toHaveTextContent(text);
|
|
|
|
if (loading) {
|
|
|
|
expect(btn).toHaveAttribute('disabled');
|
|
|
|
} else {
|
|
|
|
expect(btn).not.toHaveAttribute('disabled');
|
|
|
|
}
|
2022-03-13 13:00:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
[undefined, '0'],
|
|
|
|
[10, '10'],
|
|
|
|
[10_000, '10,000'],
|
|
|
|
[10_000_000, '10,000,000'],
|
2022-05-14 12:11:50 +03:00
|
|
|
])('renders expected amount', async (amount, expectedRenderedAmount) => {
|
|
|
|
setUp(amount);
|
|
|
|
expect(await screen.findByRole('button')).toHaveTextContent(`Export (${expectedRenderedAmount})`);
|
2022-03-13 13:00:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders expected icon', () => {
|
2022-05-14 12:11:50 +03:00
|
|
|
setUp();
|
|
|
|
expect(screen.getByRole('img', { hidden: true })).toMatchSnapshot();
|
2022-03-13 13:00:45 +03:00
|
|
|
});
|
|
|
|
});
|