Skip to content

Commit

Permalink
Merge pull request #33 from poojesh-ws/feat/18
Browse files Browse the repository at this point in the history
Feat/18 updated tests to rectify warnings
  • Loading branch information
alichherawalla authored Jul 18, 2022
2 parents 556caa1 + cd6b29c commit 7de91b7
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 48 deletions.
148 changes: 147 additions & 1 deletion app/containers/App/tests/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,153 @@ exports[`<App /> container tests should render and match the snapshot 1`] = `
</div>
<main
class="ant-layout-content"
/>
>
<div
class="HomeContainer__Container-wd79o1-0 gPuIaC"
>
<div
class="HomeContainer__CustomHeader-wd79o1-1 dpKNJS"
>
<span
class="ant-input-affix-wrapper ant-input-affix-wrapper-focused HomeContainer__CustomSearch-wd79o1-2 jUUWQt"
>
<span
class="ant-input-prefix"
>
<span
aria-label="search"
class="anticon anticon-search"
role="img"
style="font-size: 22px; color: black;"
>
<svg
aria-hidden="true"
data-icon="search"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M909.6 854.5L649.9 594.8C690.2 542.7 712 479 712 412c0-80.2-31.3-155.4-87.9-212.1-56.6-56.7-132-87.9-212.1-87.9s-155.5 31.3-212.1 87.9C143.2 256.5 112 331.8 112 412c0 80.1 31.3 155.5 87.9 212.1C256.5 680.8 331.8 712 412 712c67 0 130.6-21.8 182.7-62l259.7 259.6a8.2 8.2 0 0011.6 0l43.6-43.5a8.2 8.2 0 000-11.6zM570.4 570.4C528 612.7 471.8 636 412 636s-116-23.3-158.4-65.6C211.3 528 188 471.8 188 412s23.3-116.1 65.6-158.4C296 211.3 352.2 188 412 188s116.1 23.2 158.4 65.6S636 352.2 636 412s-23.3 116.1-65.6 158.4z"
/>
</svg>
</span>
</span>
<input
class="ant-input"
data-testid="search-bar"
placeholder="SEARCH BY MISSION NAME"
type="text"
value=""
/>
</span>
<div
class="HomeContainer__ButtonBox-wd79o1-3 jIUvfd"
>
<button
class="ant-btn"
data-testid="clear-sort"
disabled=""
type="button"
>
<span>
CLEAR SORT
</span>
</button>
<div
class="ant-select HomeContainer__SortSelect-wd79o1-4 SiddR ant-select-single ant-select-show-arrow"
data-testid="sort-select"
>
<div
class="ant-select-selector"
>
<span
class="ant-select-selection-search"
>
<input
aria-activedescendant="sort-select_list_0"
aria-autocomplete="list"
aria-controls="sort-select_list"
aria-haspopup="listbox"
aria-owns="sort-select_list"
autocomplete="off"
class="ant-select-selection-search-input"
id="sort-select"
readonly=""
role="combobox"
style="opacity: 0;"
type="search"
unselectable="on"
value=""
/>
</span>
<span
class="ant-select-selection-item"
title="SORT BY DATE"
>
SORT BY DATE
</span>
</div>
<span
aria-hidden="true"
class="ant-select-arrow"
style="user-select: none;"
unselectable="on"
>
<img
alt="chevron-up-down"
src="IMAGE_MOCK"
/>
</span>
</div>
</div>
</div>
<div
class="ant-card ant-card-bordered LaunchList__CustomErrorCard-sc-1l6drbj-0 ldMApU"
>
<div
class="ant-card-body"
>
<p
class="T__StyledText-gcrjip-0 gIxZML"
data-testid="default-message"
>
No results found for the search term.
</p>
</div>
</div>
<p
class="T__StyledText-gcrjip-0 gIxZML"
data-testid="default-message"
/>
<div
class="HomeContainer__CustomFooter-wd79o1-5 frgUSq"
>
<button
class="ant-btn ant-btn-primary"
data-testid="prev-btn"
disabled=""
type="button"
>
<span>
PREV
</span>
</button>
<button
class="ant-btn ant-btn-primary"
data-testid="next-btn"
disabled=""
type="button"
>
<span>
NEXT
</span>
</button>
</div>
</div>
</main>
</section>
</div>
`;
6 changes: 4 additions & 2 deletions app/containers/App/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('<App /> container tests', () => {
it('should render and match the snapshot', () => {
it('should render and match the snapshot', async () => {
const { container } = renderProvider(
<BrowserRouter>
<App />
</BrowserRouter>
);
expect(container).toMatchSnapshot();
await waitFor(() => expect(container.textContent).toContain('SORT BY'));
await waitFor(() => expect(container).toMatchSnapshot());
});
});
50 changes: 27 additions & 23 deletions app/containers/HomeContainer/tests/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { timeout, renderProvider } from '@utils/testUtils';
import { renderProvider, timeout } 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';
Expand Down Expand Up @@ -143,8 +143,7 @@ describe('<HomeContainer /> tests', () => {

it('should call dispatchLaunchList on page reload', async () => {
renderProvider(<HomeContainer {...defaultProps} />);
await timeout(500);
expect(submitSpy).toBeCalled();
await waitFor(() => expect(submitSpy).toBeCalled());
});

it('should validate mapDispatchToProps actions', () => {
Expand Down Expand Up @@ -205,18 +204,18 @@ describe('<HomeContainer /> tests', () => {
fireEvent.change(getByTestId('search-bar'), {
target: { value: 'a' }
});
await timeout(500);
await waitFor(() => timeout(500));
expect(history.location.search).toContain('mission_name=a');
fireEvent.change(getByTestId('search-bar'), {
target: { value: '' }
});
await timeout(500);
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 () => {
renderProvider(<HomeContainer {...defaultProps} launchData={{}} />);
await timeout(500);
expect(submitSpy).toBeCalled();
await waitFor(() => expect(submitSpy).toBeCalled());
});

it('should sort the launches by date in ASC', async () => {
Expand All @@ -227,11 +226,13 @@ describe('<HomeContainer /> tests', () => {
fireEvent.mouseDown(getByRole('combobox')!);
fireEvent.click(getByText('ASC'));
expect(history.location.search).toContain('order=asc');
renderProvider(
<HomeContainer {...defaultProps} launchData={launchData} loading={false} />,
undefined,
rerender as any
);
await waitFor(() => {
renderProvider(
<HomeContainer {...defaultProps} launchData={launchData} loading={false} />,
undefined,
rerender as any
);
});
});

it('should sort the launches by date in DESC', async () => {
Expand All @@ -241,22 +242,23 @@ describe('<HomeContainer /> tests', () => {
fireEvent.mouseDown(getByRole('combobox')!);
fireEvent.click(getByText('DESC'));
expect(history.location.search).toContain('order=desc');
renderProvider(
<HomeContainer {...defaultProps} launchData={launchData} loading={false} />,
undefined,
rerender as any
);
await waitFor(() => {
renderProvider(
<HomeContainer {...defaultProps} launchData={launchData} loading={false} />,
undefined,
rerender as any
);
});
});

it('should push to first page if no data found in the current page', async () => {
history.location.search = '?page=3';
const { rerender } = renderProvider(
<HomeContainer {...defaultProps} launchData={{ launches: [] }} loading={false} />
);
expect(history.location.search).toContain('page=1');
await waitFor(() => expect(history.location.search).toContain('page=1'));
renderProvider(<HomeContainer {...defaultProps} launchData={launchData} loading={false} />, {}, 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', () => {
Expand All @@ -273,13 +275,15 @@ describe('<HomeContainer /> 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(
<HomeContainer {...defaultProps} launchData={launchData} loading={false} />
);
fireEvent.mouseDown(getByRole('combobox')!);
fireEvent.click(getByText('DESC'));
renderProvider(<HomeContainer {...defaultProps} launchData={launchData} loading={false} />, {}, rerender as any);
await waitFor(() => {
renderProvider(<HomeContainer {...defaultProps} launchData={launchData} loading={false} />, {}, rerender as any);
});
fireEvent.click(getByTestId('clear-sort'));
expect(history.location.search).not.toContain('order=desc');
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
35 changes: 14 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15306,7 +15306,7 @@ prompts@^2.0.1:
kleur "^3.0.3"
sisteransi "^1.0.5"

[email protected], 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:
[email protected], 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==
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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"

[email protected]:
version "2.0.0"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down

0 comments on commit 7de91b7

Please sign in to comment.