2022-03-13 13:00:45 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
import { faFileDownload } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { ExportBtn } from '../../src/utils/ExportBtn';
|
|
|
|
|
|
|
|
describe('<ExportBtn />', () => {
|
|
|
|
let wrapper: ShallowWrapper;
|
2022-03-13 20:56:42 +03:00
|
|
|
const createWrapper = (amount?: number, loading = false) => {
|
|
|
|
wrapper = shallow(<ExportBtn amount={amount} loading={loading} />);
|
2022-03-13 13:00:45 +03:00
|
|
|
|
|
|
|
return wrapper;
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(jest.clearAllMocks);
|
|
|
|
afterEach(() => wrapper?.unmount());
|
|
|
|
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
[true, 'Exporting...'],
|
|
|
|
[false, 'Export ('],
|
2022-03-13 20:56:42 +03:00
|
|
|
])('renders a button', (loading, text) => {
|
|
|
|
const wrapper = createWrapper(undefined, loading);
|
2022-03-13 13:00:45 +03:00
|
|
|
|
|
|
|
expect(wrapper.prop('outline')).toEqual(true);
|
|
|
|
expect(wrapper.prop('color')).toEqual('primary');
|
2022-03-13 20:56:42 +03:00
|
|
|
expect(wrapper.prop('disabled')).toEqual(loading);
|
|
|
|
expect(wrapper.html()).toContain(text);
|
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-03-13 13:00:45 +03:00
|
|
|
])('renders expected amount', (amount, expectedRenderedAmount) => {
|
2022-03-13 20:56:42 +03:00
|
|
|
const wrapper = createWrapper(amount);
|
2022-03-13 13:00:45 +03:00
|
|
|
|
|
|
|
expect(wrapper.html()).toContain(`Export (${expectedRenderedAmount})`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders expected icon', () => {
|
|
|
|
const wrapper = createWrapper();
|
|
|
|
const icon = wrapper.find(FontAwesomeIcon);
|
|
|
|
|
|
|
|
expect(icon).toHaveLength(1);
|
|
|
|
expect(icon.prop('icon')).toEqual(faFileDownload);
|
|
|
|
});
|
|
|
|
});
|