From 053b38bee3dafb506748a4cd0f908574d5b467af Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 30 Dec 2021 21:40:08 +0100 Subject: [PATCH] Created DuplicatedServerModal test --- .../helpers/DuplicatedServerModal.test.tsx | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/servers/helpers/DuplicatedServerModal.test.tsx diff --git a/test/servers/helpers/DuplicatedServerModal.test.tsx b/test/servers/helpers/DuplicatedServerModal.test.tsx new file mode 100644 index 00000000..4eaa5737 --- /dev/null +++ b/test/servers/helpers/DuplicatedServerModal.test.tsx @@ -0,0 +1,56 @@ +import { shallow, ShallowWrapper } from 'enzyme'; +import { Mock } from 'ts-mockery'; +import { Button } from 'reactstrap'; +import { DuplicatedServerModal } from '../../../src/servers/helpers/DuplicatedServerModal'; +import { ServerData } from '../../../src/servers/data'; + +describe('', () => { + const onDiscard = jest.fn(); + const onSave = jest.fn(); + let wrapper: ShallowWrapper; + const createWrapper = (serverData?: ServerData) => { + wrapper = shallow( + , + ); + + return wrapper; + }; + + beforeEach(jest.clearAllMocks); + afterEach(() => wrapper?.unmount()); + + it.each([ + [ undefined ], + [ Mock.of({ url: 'url', apiKey: 'apiKey' }) ], + ])('displays provided server data', (serverData) => { + const wrapper = createWrapper(serverData); + const li = wrapper.find('li'); + + expect(li.first().find('b').html()).toEqual(`${serverData?.url ?? ''}`); + expect(li.last().find('b').html()).toEqual(`${serverData?.apiKey ?? ''}`); + }); + + 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(); + }); +});