shlink-web-client/test/utils/ExportBtn.test.tsx

37 lines
1.1 KiB
TypeScript
Raw Normal View History

import { render, screen } from '@testing-library/react';
import { ExportBtn } from '../../shlink-web-component/src/utils/components/ExportBtn';
2022-03-13 13:00:45 +03:00
describe('<ExportBtn />', () => {
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...'],
[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'],
])('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', () => {
setUp();
expect(screen.getByRole('img', { hidden: true })).toMatchSnapshot();
2022-03-13 13:00:45 +03:00
});
});