mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-10 18:27:25 +03:00
Created ShortUrlCreation test
This commit is contained in:
parent
c3ebb0d10f
commit
5afd3869dd
1 changed files with 54 additions and 0 deletions
54
test/settings/ShortUrlCreation.test.tsx
Normal file
54
test/settings/ShortUrlCreation.test.tsx
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
import { shallow, ShallowWrapper } from 'enzyme';
|
||||||
|
import { Mock } from 'ts-mockery';
|
||||||
|
import { ShortUrlCreationSettings, Settings } from '../../src/settings/reducers/settings';
|
||||||
|
import { ShortUrlCreation } from '../../src/settings/ShortUrlCreation';
|
||||||
|
import ToggleSwitch from '../../src/utils/ToggleSwitch';
|
||||||
|
|
||||||
|
describe('<ShortUrlCreation />', () => {
|
||||||
|
let wrapper: ShallowWrapper;
|
||||||
|
const setShortUrlCreationSettings = jest.fn();
|
||||||
|
const createWrapper = (shortUrlCreation?: ShortUrlCreationSettings) => {
|
||||||
|
wrapper = shallow(
|
||||||
|
<ShortUrlCreation
|
||||||
|
settings={Mock.of<Settings>({ shortUrlCreation })}
|
||||||
|
setShortUrlCreationSettings={setShortUrlCreationSettings}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
return wrapper;
|
||||||
|
};
|
||||||
|
|
||||||
|
afterEach(() => wrapper?.unmount());
|
||||||
|
afterEach(jest.clearAllMocks);
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
[{ validateUrls: true }, true ],
|
||||||
|
[{ validateUrls: false }, false ],
|
||||||
|
[ undefined, false ],
|
||||||
|
])('switch is toggled if option is tru', (shortUrlCreation, expectedChecked) => {
|
||||||
|
const wrapper = createWrapper(shortUrlCreation);
|
||||||
|
const toggle = wrapper.find(ToggleSwitch);
|
||||||
|
|
||||||
|
expect(toggle.prop('checked')).toEqual(expectedChecked);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([[ true ], [ false ]])('invokes setShortUrlCreationSettings when toggle value changes', (validateUrls) => {
|
||||||
|
const wrapper = createWrapper();
|
||||||
|
const toggle = wrapper.find(ToggleSwitch);
|
||||||
|
|
||||||
|
expect(setShortUrlCreationSettings).not.toHaveBeenCalled();
|
||||||
|
toggle.simulate('change', validateUrls);
|
||||||
|
expect(setShortUrlCreationSettings).toHaveBeenCalledWith({ validateUrls });
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
[{ validateUrls: true }, 'checkbox will be checked' ],
|
||||||
|
[{ validateUrls: false }, 'checkbox will be unchecked' ],
|
||||||
|
[ undefined, 'checkbox will be unchecked' ],
|
||||||
|
])('shows expected helper text', (shortUrlCreation, expectedText) => {
|
||||||
|
const wrapper = createWrapper(shortUrlCreation);
|
||||||
|
const text = wrapper.find('.form-text');
|
||||||
|
|
||||||
|
expect(text.text()).toContain(expectedText);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue