diff --git a/src/servers/helpers/DuplicatedServersModal.tsx b/src/servers/helpers/DuplicatedServersModal.tsx index 238d2f10..b2fb3d78 100644 --- a/src/servers/helpers/DuplicatedServersModal.tsx +++ b/src/servers/helpers/DuplicatedServersModal.tsx @@ -27,7 +27,9 @@ export const DuplicatedServersModal: FC = ( ) :
  • {url} - {apiKey}
  • )} - {hasMultipleServers ? 'Do you want to ignore duplicated servers?' : 'Do you want to save this server anyway?'} + + {hasMultipleServers ? 'Do you want to ignore duplicated servers' : 'Do you want to save this server anyway'}? + diff --git a/test/servers/helpers/DuplicatedServersModal.test.tsx b/test/servers/helpers/DuplicatedServersModal.test.tsx index 8810aac3..6e2b6731 100644 --- a/test/servers/helpers/DuplicatedServersModal.test.tsx +++ b/test/servers/helpers/DuplicatedServersModal.test.tsx @@ -1,6 +1,6 @@ import { shallow, ShallowWrapper } from 'enzyme'; import { Mock } from 'ts-mockery'; -import { Button } from 'reactstrap'; +import { Button, ModalHeader } from 'reactstrap'; import { DuplicatedServersModal } from '../../../src/servers/helpers/DuplicatedServersModal'; import { ServerData } from '../../../src/servers/data'; @@ -19,6 +19,51 @@ describe('', () => { beforeEach(jest.clearAllMocks); afterEach(() => wrapper?.unmount()); + it.each([ + [[], 0 ], + [[ Mock.all() ], 2 ], + [[ Mock.all(), Mock.all() ], 2 ], + [[ Mock.all(), Mock.all(), Mock.all() ], 3 ], + [[ Mock.all(), Mock.all(), Mock.all(), Mock.all() ], 4 ], + ])('renders expected amount of items', (duplicatedServers, expectedItems) => { + const wrapper = createWrapper(duplicatedServers); + const li = wrapper.find('li'); + + expect(li).toHaveLength(expectedItems); + }); + + it.each([ + [ + [ Mock.all() ], + { + header: 'Duplicated server', + firstParagraph: 'There is already a server with:', + lastParagraph: 'Do you want to save this server anyway?', + discardBtn: 'Discard', + }, + ], + [ + [ Mock.all(), Mock.all() ], + { + header: 'Duplicated servers', + firstParagraph: 'The next servers already exist:', + lastParagraph: 'Do you want to ignore duplicated servers?', + discardBtn: 'Ignore duplicated', + }, + ], + ])('renders expected texts based on amount of servers', (duplicatedServers, assertions) => { + const wrapper = createWrapper(duplicatedServers); + const header = wrapper.find(ModalHeader); + const p = wrapper.find('p'); + const span = wrapper.find('span'); + const discardBtn = wrapper.find(Button).first(); + + expect(header.html()).toContain(assertions.header); + expect(p.html()).toContain(assertions.firstParagraph); + expect(span.html()).toContain(assertions.lastParagraph); + expect(discardBtn.html()).toContain(assertions.discardBtn); + }); + it.each([ [[]], [[ Mock.of({ url: 'url', apiKey: 'apiKey' }) ]], @@ -28,9 +73,16 @@ describe('', () => { if (duplicatedServers.length === 0) { expect(li).toHaveLength(0); - } else { + } else if (duplicatedServers.length === 1) { expect(li.first().find('b').html()).toEqual(`${duplicatedServers[0].url}`); expect(li.last().find('b').html()).toEqual(`${duplicatedServers[0].apiKey}`); + } else { + expect.assertions(duplicatedServers.length); + li.forEach((item, index) => { + const server = duplicatedServers[index]; + + expect(item.html()).toContain(`${server.url} - ${server.apiKey}`); + }); } });