From 669f8f8f881b948ae02f939581af4dc156e5a478 Mon Sep 17 00:00:00 2001 From: Poojesh Shetty Date: Thu, 14 Jul 2022 21:09:17 +0530 Subject: [PATCH 1/5] feat: bump up react-helmet --- package.json | 2 +- yarn.lock | 35 ++++++++++++++--------------------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 61a021f..97d68e7 100644 --- a/package.json +++ b/package.json @@ -112,7 +112,7 @@ "prop-types": "15.7.2", "react": "18.2.0", "react-dom": "18.2.0", - "react-helmet": "6.0.0-beta", + "react-helmet": "^6.1.0", "react-intl": "5.20.3", "react-redux": "7.0.2", "react-router-dom": "^5.1.2", diff --git a/yarn.lock b/yarn.lock index da5b8d2..ea344d4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15306,7 +15306,7 @@ prompts@^2.0.1: kleur "^3.0.3" sisteransi "^1.0.5" -prop-types@15.7.2, prop-types@^15.5.0, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2: +prop-types@15.7.2, prop-types@^15.5.0, prop-types@^15.5.10, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2: version "15.7.2" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5" integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ== @@ -15998,12 +15998,7 @@ react-error-overlay@^6.0.3: resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.9.tgz#3c743010c9359608c375ecd6bc76f35d93995b0a" integrity sha512-nQTTcUu+ATDbrSD1BZHr5kgSD4oF8OFjxun8uAaL8RwPBacGBNPf/yAuVVdx17N8XNzRDMrZ9XcKZHCjPW+9ew== -react-fast-compare@^2.0.2: - version "2.0.4" - resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-2.0.4.tgz#e84b4d455b0fec113e0402c329352715196f81f9" - integrity sha512-suNP+J1VU1MWFKcyt7RtjiSWUjvidmQSlqu+eHslq+342xCbGTYmC0mEhPCOHxlW0CywylOC1u2DFAT+bv4dBw== - -react-fast-compare@^3.2.0: +react-fast-compare@^3.1.1, react-fast-compare@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.0.tgz#641a9da81b6a6320f270e89724fb45a0b39e43bb" integrity sha512-rtGImPZ0YyLrscKI9xTpV8psd6I8VAtjKCzQDlzyDvqJA8XOW78TXYQwNRNd8g8JZnDu8q9Fu/1v4HPAVwVdHA== @@ -16063,15 +16058,15 @@ react-helmet-async@^1.0.2: react-fast-compare "^3.2.0" shallowequal "^1.1.0" -react-helmet@6.0.0-beta: - version "6.0.0-beta" - resolved "https://registry.yarnpkg.com/react-helmet/-/react-helmet-6.0.0-beta.tgz#1f2ac04521951486e4fce3296d0c88aae8cabd5c" - integrity sha512-GnNWsokebTe7fe8MH2I/a2dl4THYWhthLBoMaQSRYqW5XbPo881WAJGi+lqRBjyOFryW6zpQluEkBy70zh+h9w== +react-helmet@^6.1.0: + version "6.1.0" + resolved "https://registry.yarnpkg.com/react-helmet/-/react-helmet-6.1.0.tgz#a750d5165cb13cf213e44747502652e794468726" + integrity sha512-4uMzEY9nlDlgxr61NL3XbKRy1hEkXmKNXhjbAIOVw5vcFrsdYbH2FEwcNyWvWinl103nXgzYNlns9ca+8kFiWw== dependencies: object-assign "^4.1.1" - prop-types "^15.5.4" - react-fast-compare "^2.0.2" - react-side-effect "^1.1.0" + prop-types "^15.7.2" + react-fast-compare "^3.1.1" + react-side-effect "^2.1.0" react-hotkeys@2.0.0: version "2.0.0" @@ -16236,12 +16231,10 @@ react-select@^3.0.8: react-input-autosize "^3.0.0" react-transition-group "^4.3.0" -react-side-effect@^1.1.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/react-side-effect/-/react-side-effect-1.2.0.tgz#0e940c78faba0c73b9b0eba9cd3dda8dfb7e7dae" - integrity sha512-v1ht1aHg5k/thv56DRcjw+WtojuuDHFUgGfc+bFHOWsF4ZK6C2V57DO0Or0GPsg6+LSTE0M6Ry/gfzhzSwbc5w== - dependencies: - shallowequal "^1.0.1" +react-side-effect@^2.1.0: + version "2.1.2" + resolved "https://registry.yarnpkg.com/react-side-effect/-/react-side-effect-2.1.2.tgz#dc6345b9e8f9906dc2eeb68700b615e0b4fe752a" + integrity sha512-PVjOcvVOyIILrYoyGEpDN3vmYNLdy1CajSFNt4TDsVQC5KpTijDvWVoR+/7Rz2xT978D8/ZtFceXxzsPwZEDvw== react-sizeme@^2.6.7: version "2.6.12" @@ -17272,7 +17265,7 @@ shallow-equal@^1.1.0: resolved "https://registry.yarnpkg.com/shallow-equal/-/shallow-equal-1.2.1.tgz#4c16abfa56043aa20d050324efa68940b0da79da" integrity sha512-S4vJDjHHMBaiZuT9NPb616CSmLf618jawtv3sufLl6ivK8WocjAo58cXwbRV1cgqxH0Qbv+iUt6m05eqEa2IRA== -shallowequal@^1.0.1, shallowequal@^1.1.0: +shallowequal@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/shallowequal/-/shallowequal-1.1.0.tgz#188d521de95b9087404fd4dcb68b13df0ae4e7f8" integrity sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ== From 780c45939bd47033b7b47424f918c90e6f0c4240 Mon Sep 17 00:00:00 2001 From: Poojesh Shetty Date: Fri, 15 Jul 2022 09:34:31 +0530 Subject: [PATCH 2/5] feat: update homecontainer test --- .../HomeContainer/tests/index.test.tsx | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/app/containers/HomeContainer/tests/index.test.tsx b/app/containers/HomeContainer/tests/index.test.tsx index edfba83..686512c 100644 --- a/app/containers/HomeContainer/tests/index.test.tsx +++ b/app/containers/HomeContainer/tests/index.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { timeout, renderProvider } from '@utils/testUtils'; import { HomeContainerTest as HomeContainer, mapDispatchToProps } from '../index'; import { HomeContainerProps, LaunchData } from '../types'; -import { fireEvent } from '@testing-library/react'; +import { fireEvent, waitFor } from '@testing-library/react'; import { createIntl } from 'react-intl'; import { translationMessages } from '@app/i18n'; import history from '@app/utils/history'; @@ -227,11 +227,13 @@ describe(' tests', () => { fireEvent.mouseDown(getByRole('combobox')!); fireEvent.click(getByText('ASC')); expect(history.location.search).toContain('order=asc'); - renderProvider( - , - undefined, - rerender as any - ); + await waitFor(() => { + renderProvider( + , + undefined, + rerender as any + ); + }); }); it('should sort the launches by date in DESC', async () => { @@ -241,11 +243,13 @@ describe(' tests', () => { fireEvent.mouseDown(getByRole('combobox')!); fireEvent.click(getByText('DESC')); expect(history.location.search).toContain('order=desc'); - renderProvider( - , - undefined, - rerender as any - ); + await waitFor(() => { + renderProvider( + , + undefined, + rerender as any + ); + }); }); it('should push to first page if no data found in the current page', async () => { @@ -273,13 +277,15 @@ describe(' tests', () => { expect(history.location.search).toContain('page=1'); }); - it('should clear sort when clicked on clear sort button', () => { + it('should clear sort when clicked on clear sort button', async () => { const { getByText, getByRole, getByTestId, rerender } = renderProvider( ); fireEvent.mouseDown(getByRole('combobox')!); fireEvent.click(getByText('DESC')); - renderProvider(, {}, rerender as any); + await waitFor(() => { + renderProvider(, {}, rerender as any); + }); fireEvent.click(getByTestId('clear-sort')); expect(history.location.search).not.toContain('order=desc'); }); From e1c57ffea4947fec4789f1df8e6e36532f6851b2 Mon Sep 17 00:00:00 2001 From: Poojesh Shetty Date: Fri, 15 Jul 2022 11:17:38 +0530 Subject: [PATCH 3/5] feat: update homecontainer test --- .../HomeContainer/tests/index.test.tsx | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/app/containers/HomeContainer/tests/index.test.tsx b/app/containers/HomeContainer/tests/index.test.tsx index 686512c..4c980ae 100644 --- a/app/containers/HomeContainer/tests/index.test.tsx +++ b/app/containers/HomeContainer/tests/index.test.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { timeout, renderProvider } from '@utils/testUtils'; +import { renderProvider } from '@utils/testUtils'; import { HomeContainerTest as HomeContainer, mapDispatchToProps } from '../index'; import { HomeContainerProps, LaunchData } from '../types'; import { fireEvent, waitFor } from '@testing-library/react'; @@ -143,8 +143,7 @@ describe(' tests', () => { it('should call dispatchLaunchList on page reload', async () => { renderProvider(); - await timeout(500); - expect(submitSpy).toBeCalled(); + await waitFor(() => expect(submitSpy).toBeCalled()); }); it('should validate mapDispatchToProps actions', () => { @@ -199,24 +198,22 @@ describe(' tests', () => { }); it('should delete mission_name query param from search on empty change', async () => { - const { getByTestId } = renderProvider( + const { findByTestId } = renderProvider( ); - fireEvent.change(getByTestId('search-bar'), { + fireEvent.change(await findByTestId('search-bar'), { target: { value: 'a' } }); - await timeout(500); - expect(history.location.search).toContain('mission_name=a'); - fireEvent.change(getByTestId('search-bar'), { + await waitFor(() => expect(history.location.search).toContain('mission_name=a')); + fireEvent.change(await findByTestId('search-bar'), { target: { value: '' } }); - await timeout(500); - expect(history.location.search).not.toContain('mission='); + await waitFor(() => expect(history.location.search).not.toContain('mission=')); }); + it('should dispatchLaunchList on update on mount if there is no launchQuery and no data already persisted', async () => { renderProvider(); - await timeout(500); - expect(submitSpy).toBeCalled(); + await waitFor(() => expect(submitSpy).toBeCalled()); }); it('should sort the launches by date in ASC', async () => { @@ -257,10 +254,9 @@ describe(' tests', () => { const { rerender } = renderProvider( ); - expect(history.location.search).toContain('page=1'); + await waitFor(() => expect(history.location.search).toContain('page=1')); renderProvider(, {}, rerender as any); - await timeout(500); - expect(history.location.search).toContain('page=1'); + await waitFor(() => expect(history.location.search).toContain('page=1')); }); it('should push the user to next page when clicked on NEXT button', () => { From e73a693a15034ad7a9476bd4bc243061d6ab2f88 Mon Sep 17 00:00:00 2001 From: Poojesh Shetty Date: Fri, 15 Jul 2022 11:18:30 +0530 Subject: [PATCH 4/5] feat: update app container test --- .../tests/__snapshots__/index.test.tsx.snap | 148 +++++++++++++++++- app/containers/App/tests/index.test.tsx | 6 +- 2 files changed, 151 insertions(+), 3 deletions(-) diff --git a/app/containers/App/tests/__snapshots__/index.test.tsx.snap b/app/containers/App/tests/__snapshots__/index.test.tsx.snap index 1aace03..8fc5e74 100644 --- a/app/containers/App/tests/__snapshots__/index.test.tsx.snap +++ b/app/containers/App/tests/__snapshots__/index.test.tsx.snap @@ -47,7 +47,153 @@ exports[` container tests should render and match the snapshot 1`] = `
+ > +
+
+ + + + + + + + +
+ +
+
+ + + + + SORT BY DATE + +
+ +
+
+
+
+
+

+ No results found for the search term. +

+
+
+

+

+ + +
+
+
`; diff --git a/app/containers/App/tests/index.test.tsx b/app/containers/App/tests/index.test.tsx index a9f774e..5817797 100644 --- a/app/containers/App/tests/index.test.tsx +++ b/app/containers/App/tests/index.test.tsx @@ -2,14 +2,16 @@ import React from 'react'; import { renderProvider } from '@utils/testUtils'; import App from '@containers/App'; import { BrowserRouter } from 'react-router-dom'; +import { waitFor } from '@testing-library/react'; describe(' container tests', () => { - it('should render and match the snapshot', () => { + it('should render and match the snapshot', async () => { const { container } = renderProvider( ); - expect(container).toMatchSnapshot(); + await waitFor(() => expect(container.textContent).toContain('SORT BY')); + await waitFor(() => expect(container).toMatchSnapshot()); }); }); From cd6b29cc1bc0533db41d18f1c1da445af94bd97a Mon Sep 17 00:00:00 2001 From: Poojesh Shetty Date: Fri, 15 Jul 2022 14:48:16 +0530 Subject: [PATCH 5/5] feat: update homecontainer test to cover emptysearch function call --- app/containers/HomeContainer/tests/index.test.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/containers/HomeContainer/tests/index.test.tsx b/app/containers/HomeContainer/tests/index.test.tsx index 4c980ae..164799d 100644 --- a/app/containers/HomeContainer/tests/index.test.tsx +++ b/app/containers/HomeContainer/tests/index.test.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { renderProvider } from '@utils/testUtils'; +import { renderProvider, timeout } from '@utils/testUtils'; import { HomeContainerTest as HomeContainer, mapDispatchToProps } from '../index'; import { HomeContainerProps, LaunchData } from '../types'; import { fireEvent, waitFor } from '@testing-library/react'; @@ -198,17 +198,19 @@ describe(' tests', () => { }); it('should delete mission_name query param from search on empty change', async () => { - const { findByTestId } = renderProvider( + const { getByTestId } = renderProvider( ); - fireEvent.change(await findByTestId('search-bar'), { + fireEvent.change(getByTestId('search-bar'), { target: { value: 'a' } }); - await waitFor(() => expect(history.location.search).toContain('mission_name=a')); - fireEvent.change(await findByTestId('search-bar'), { + await waitFor(() => timeout(500)); + expect(history.location.search).toContain('mission_name=a'); + fireEvent.change(getByTestId('search-bar'), { target: { value: '' } }); - await waitFor(() => expect(history.location.search).not.toContain('mission=')); + await waitFor(() => timeout(500)); + expect(history.location.search).not.toContain('mission='); }); it('should dispatchLaunchList on update on mount if there is no launchQuery and no data already persisted', async () => {