From 7db222664d806c2524fbf3ee7aa13948d578b87d Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 15 Mar 2020 09:56:16 +0100 Subject: [PATCH] Fixed tests --- package-lock.json | 14 +++---- test/App.test.js | 5 ++- test/servers/helpers/ServerError.test.js | 42 +++++++++++++------- test/servers/reducers/selectedServer.test.js | 2 +- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7945df60..175f0e87 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5340,7 +5340,7 @@ }, "discontinuous-range": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/discontinuous-range/-/discontinuous-range-1.0.0.tgz", + "resolved": "https://registry.yarnpkg.com/discontinuous-range/-/discontinuous-range-1.0.0.tgz", "integrity": "sha1-44Mx8IRLukm5qctxx3FYWqsbxlo=", "dev": true }, @@ -9346,7 +9346,7 @@ }, "is-subset": { "version": "0.1.1", - "resolved": "https://registry.npmjs.org/is-subset/-/is-subset-0.1.1.tgz", + "resolved": "https://registry.yarnpkg.com/is-subset/-/is-subset-0.1.1.tgz", "integrity": "sha1-ilkRfZMt4d4A8kX83TnOQ/HpOaY=", "dev": true }, @@ -10557,13 +10557,13 @@ }, "lodash.escape": { "version": "4.0.1", - "resolved": "https://registry.npmjs.org/lodash.escape/-/lodash.escape-4.0.1.tgz", + "resolved": "https://registry.yarnpkg.com/lodash.escape/-/lodash.escape-4.0.1.tgz", "integrity": "sha1-yQRGkMIeBClL6qUXcS/e0fqI3pg=", "dev": true }, "lodash.flattendeep": { "version": "4.4.0", - "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", + "resolved": "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", "integrity": "sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI=", "dev": true }, @@ -10575,7 +10575,7 @@ }, "lodash.isequal": { "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", + "resolved": "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz", "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=", "dev": true }, @@ -13817,7 +13817,7 @@ }, "railroad-diagrams": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz", + "resolved": "https://registry.yarnpkg.com/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz", "integrity": "sha1-635iZ1SN3t+4mcG5Dlc3RVnN234=", "dev": true }, @@ -14977,7 +14977,7 @@ }, "rst-selector-parser": { "version": "2.2.3", - "resolved": "https://registry.npmjs.org/rst-selector-parser/-/rst-selector-parser-2.2.3.tgz", + "resolved": "https://registry.yarnpkg.com/rst-selector-parser/-/rst-selector-parser-2.2.3.tgz", "integrity": "sha1-gbIw6i/MYGbInjRy3nlChdmwPZE=", "dev": true, "requires": { diff --git a/test/App.test.js b/test/App.test.js index 428f3b1d..15208214 100644 --- a/test/App.test.js +++ b/test/App.test.js @@ -20,13 +20,14 @@ describe('', () => { it('renders app main routes', () => { const routes = wrapper.find(Route); const expectedPaths = [ - '/server/create', '/', + '/server/create', + '/server/:serverId/edit', '/server/:serverId', ]; expect.assertions(expectedPaths.length + 1); - expect(routes).toHaveLength(4); + expect(routes).toHaveLength(expectedPaths.length + 1); expectedPaths.forEach((path, index) => { expect(routes.at(index).prop('path')).toEqual(path); }); diff --git a/test/servers/helpers/ServerError.test.js b/test/servers/helpers/ServerError.test.js index 1e9d7417..32e1871c 100644 --- a/test/servers/helpers/ServerError.test.js +++ b/test/servers/helpers/ServerError.test.js @@ -1,35 +1,49 @@ import React from 'react'; import { shallow } from 'enzyme'; import { BrowserRouter } from 'react-router-dom'; -import { ServerError } from '../../../src/servers/helpers/ServerError'; +import { ServerError as createServerError } from '../../../src/servers/helpers/ServerError'; describe('', () => { let wrapper; + const selectedServer = { id: '' }; + const ServerError = createServerError(() => ''); afterEach(() => wrapper && wrapper.unmount()); it.each([ [ 'not-found', - [ 'Could not find this Shlink server.' ], - 'These are the Shlink servers', + { + 'Could not find this Shlink server.': true, + 'Oops! Could not connect to this Shlink server.': false, + 'Make sure you have internet connection, and the server is properly configured and on-line.': false, + 'Alternatively, if you think you may have miss-configured this server': false, + }, ], [ 'not-reachable', - [ - 'Oops! Could not connect to this Shlink server.', - 'Make sure you have internet connection, and the server is properly configured and on-line.', - ], - 'These are the other Shlink servers', + { + 'Could not find this Shlink server.': false, + 'Oops! Could not connect to this Shlink server.': true, + 'Make sure you have internet connection, and the server is properly configured and on-line.': true, + 'Alternatively, if you think you may have miss-configured this server': true, + }, ], - ])('renders expected information based on type', (type, expectedTitleParts, expectedBody) => { - wrapper = shallow(); + ])('renders expected information for type "%s"', (type, textsToFind) => { + wrapper = shallow( + + + + ); const wrapperText = wrapper.html(); - const textsToFind = [ ...expectedTitleParts, ...expectedBody ]; + const textPairs = Object.entries(textsToFind); - expect.assertions(textsToFind.length); - textsToFind.forEach((text) => { - expect(wrapperText).toContain(text); + textPairs.forEach(([ text, shouldBeFound ]) => { + if (shouldBeFound) { + expect(wrapperText).toContain(text); + } else { + expect(wrapperText).not.toContain(text); + } }); }); }); diff --git a/test/servers/reducers/selectedServer.test.js b/test/servers/reducers/selectedServer.test.js index 4cecf8cd..7c6ab7d0 100644 --- a/test/servers/reducers/selectedServer.test.js +++ b/test/servers/reducers/selectedServer.test.js @@ -72,7 +72,7 @@ describe('selectedServerReducer', () => { }); it('dispatches error when health endpoint fails', async () => { - const expectedSelectedServer = { serverNotReachable: true }; + const expectedSelectedServer = { ...selectedServer, serverNotReachable: true }; apiClientMock.health.mockRejectedValue({});