2021-12-30 23:40:08 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
|
|
|
import { Mock } from 'ts-mockery';
|
|
|
|
import { Button } from 'reactstrap';
|
2022-01-01 14:20:09 +03:00
|
|
|
import { DuplicatedServersModal } from '../../../src/servers/helpers/DuplicatedServersModal';
|
2021-12-30 23:40:08 +03:00
|
|
|
import { ServerData } from '../../../src/servers/data';
|
|
|
|
|
2022-01-01 14:20:09 +03:00
|
|
|
describe('<DuplicatedServersModal />', () => {
|
2021-12-30 23:40:08 +03:00
|
|
|
const onDiscard = jest.fn();
|
|
|
|
const onSave = jest.fn();
|
|
|
|
let wrapper: ShallowWrapper;
|
2022-01-01 14:20:09 +03:00
|
|
|
const createWrapper = (duplicatedServers: ServerData[] = []) => {
|
2021-12-30 23:40:08 +03:00
|
|
|
wrapper = shallow(
|
2022-01-01 14:20:09 +03:00
|
|
|
<DuplicatedServersModal isOpen duplicatedServers={duplicatedServers} onDiscard={onDiscard} onSave={onSave} />,
|
2021-12-30 23:40:08 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
return wrapper;
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(jest.clearAllMocks);
|
|
|
|
afterEach(() => wrapper?.unmount());
|
|
|
|
|
|
|
|
it.each([
|
2022-01-01 14:20:09 +03:00
|
|
|
[[]],
|
|
|
|
[[ Mock.of<ServerData>({ url: 'url', apiKey: 'apiKey' }) ]],
|
|
|
|
])('displays provided server data', (duplicatedServers) => {
|
|
|
|
const wrapper = createWrapper(duplicatedServers);
|
2021-12-30 23:40:08 +03:00
|
|
|
const li = wrapper.find('li');
|
|
|
|
|
2022-01-01 14:20:09 +03:00
|
|
|
if (duplicatedServers.length === 0) {
|
|
|
|
expect(li).toHaveLength(0);
|
|
|
|
} else {
|
|
|
|
expect(li.first().find('b').html()).toEqual(`<b>${duplicatedServers[0].url}</b>`);
|
|
|
|
expect(li.last().find('b').html()).toEqual(`<b>${duplicatedServers[0].apiKey}</b>`);
|
|
|
|
}
|
2021-12-30 23:40:08 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('invokes onDiscard when appropriate button is clicked', () => {
|
|
|
|
const wrapper = createWrapper();
|
|
|
|
const btn = wrapper.find(Button).first();
|
|
|
|
|
|
|
|
btn.simulate('click');
|
|
|
|
|
|
|
|
expect(onDiscard).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('invokes onSave when appropriate button is clicked', () => {
|
|
|
|
const wrapper = createWrapper();
|
|
|
|
const btn = wrapper.find(Button).last();
|
|
|
|
|
|
|
|
btn.simulate('click');
|
|
|
|
|
|
|
|
expect(onSave).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|