Skip to content

Commit

Permalink
feat: update homecontainer test
Browse files Browse the repository at this point in the history
  • Loading branch information
Poojesh Shetty authored and Poojesh Shetty committed Jul 17, 2022
1 parent 8164292 commit 11f86ff
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions app/containers/HomeContainer/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -205,12 +205,12 @@ 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 () => {
Expand All @@ -221,31 +221,21 @@ describe('<HomeContainer /> tests', () => {

it('should sort the launches by date in ASC', async () => {
history.location.search = '?order=unknown';
const { getByText, getByRole, rerender } = renderProvider(
const { getByText, getByRole } = renderProvider(
<HomeContainer {...defaultProps} launchData={launchData} loading={false} />
);
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(() => expect(history.location.search).toContain('order=asc'));
});

it('should sort the launches by date in DESC', async () => {
const { getByText, getByRole, rerender } = renderProvider(
const { getByText, getByRole } = renderProvider(
<HomeContainer {...defaultProps} launchData={launchData} loading={false} />
);
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(() => expect(history.location.search).toContain('order=desc'));
});

it('should push to first page if no data found in the current page', async () => {
Expand Down Expand Up @@ -273,13 +263,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

0 comments on commit 11f86ff

Please sign in to comment.