From c181831a37079939a5d1cfc4f2650eafe82b5779 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 5 Mar 2020 11:58:35 +0100 Subject: [PATCH] Fixed tests --- test/common/AsideMenu.test.js | 3 +-- test/servers/DeleteServerButton.test.js | 12 ++---------- test/servers/DeleteServerModal.test.js | 2 +- test/servers/reducers/selectedServer.test.js | 9 +++++---- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/test/common/AsideMenu.test.js b/test/common/AsideMenu.test.js index 4541b00d..b86b5650 100644 --- a/test/common/AsideMenu.test.js +++ b/test/common/AsideMenu.test.js @@ -1,6 +1,5 @@ import { shallow } from 'enzyme'; import React from 'react'; -import { NavLink } from 'react-router-dom'; import asideMenuCreator from '../../src/common/AsideMenu'; describe('', () => { @@ -15,7 +14,7 @@ describe('', () => { afterEach(() => wrapped.unmount()); it('contains links to different sections', () => { - const links = wrapped.find(NavLink); + const links = wrapped.find('[to]'); expect(links).toHaveLength(3); links.forEach((link) => expect(link.prop('to')).toContain('abc123')); diff --git a/test/servers/DeleteServerButton.test.js b/test/servers/DeleteServerButton.test.js index fbe11b09..a377cf83 100644 --- a/test/servers/DeleteServerButton.test.js +++ b/test/servers/DeleteServerButton.test.js @@ -21,16 +21,8 @@ describe('', () => { it('displays modal when button is clicked', () => { const btn = wrapper.find('.button'); - expect(wrapper.state('isModalOpen')).toEqual(false); + expect(wrapper.find(DeleteServerModal).prop('isOpen')).toEqual(false); btn.simulate('click'); - expect(wrapper.state('isModalOpen')).toEqual(true); - }); - - it('changes modal open state when toggled', () => { - const modal = wrapper.find(DeleteServerModal); - - expect(wrapper.state('isModalOpen')).toEqual(false); - modal.prop('toggle')(); - expect(wrapper.state('isModalOpen')).toEqual(true); + expect(wrapper.find(DeleteServerModal).prop('isOpen')).toEqual(true); }); }); diff --git a/test/servers/DeleteServerModal.test.js b/test/servers/DeleteServerModal.test.js index 21f938c7..6aca966b 100644 --- a/test/servers/DeleteServerModal.test.js +++ b/test/servers/DeleteServerModal.test.js @@ -38,7 +38,7 @@ describe('', () => { const modalBody = wrapper.find(ModalBody); expect(modalBody.find('p').first().text()).toEqual( - `Are you sure you want to delete server ${serverName}?` + `Are you sure you want to remove ${serverName}?` ); }); diff --git a/test/servers/reducers/selectedServer.test.js b/test/servers/reducers/selectedServer.test.js index 4d20fb5c..33728d9f 100644 --- a/test/servers/reducers/selectedServer.test.js +++ b/test/servers/reducers/selectedServer.test.js @@ -44,13 +44,14 @@ describe('selectedServerReducer', () => { afterEach(jest.clearAllMocks); it.each([ - [ version, version ], - [ 'latest', MAX_FALLBACK_VERSION ], - [ '%invalid_semver%', MIN_FALLBACK_VERSION ], - ])('dispatches proper actions', async (serverVersion, expectedVersion) => { + [ version, version, `v${version}` ], + [ 'latest', MAX_FALLBACK_VERSION, 'latest' ], + [ '%invalid_semver%', MIN_FALLBACK_VERSION, '%invalid_semver%' ], + ])('dispatches proper actions', async (serverVersion, expectedVersion, expectedPrintableVersion) => { const expectedSelectedServer = { ...selectedServer, version: expectedVersion, + printableVersion: expectedPrintableVersion, }; apiClientMock.health.mockResolvedValue({ version: serverVersion });