Skip to content

Commit

Permalink
issue test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
flacoman91 committed Nov 6, 2024
1 parent 30003b4 commit dc63ad6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/components/Filters/Issue/Issue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,43 @@ import {
screen,
waitFor,
} from '../../../testUtils/test-utils';
import fetchMock from 'jest-fetch-mock';
import userEvent from '@testing-library/user-event';
import { merge } from '../../../testUtils/functionHelpers';
import { aggsState } from '../../reducers/aggs/aggsSlice';
import { Issue } from './Issue';
import { listOfIssues } from '../../../testUtils/aggsConstants';
import * as filterActions from '../../../reducers/filters/filtersSlice';
import { filtersState } from '../../../reducers/filters/filtersSlice';
import { aggResponse } from './fixture';

describe('Issue', () => {
const user = userEvent.setup({ delay: null });
const renderComponent = () => {
const newAggsState = { issue: listOfIssues };
const newFiltersState = { issue: ['Incorrect information on your report'] };
merge(newAggsState, aggsState);
merge(newFiltersState, filtersState);
const data = {
aggs: newAggsState,
filters: newFiltersState,
routes: { queryString: '?foo=bar' },
};

render(<Issue />, {
preloadedState: data,
});
};

beforeEach(() => {
fetchMock.resetMocks();
});

test('Options appear when user types and dispatches filtersReplaced on selection', async () => {
const filtersReplacedSpy = jest
.spyOn(filterActions, 'filtersReplaced')
.mockImplementation(() => jest.fn());

fetchMock.mockResponseOnce(JSON.stringify(aggResponse));
renderComponent();
await screen.findByRole('button', {
name: /Incorrect information on your report/,
});
const input = screen.getByPlaceholderText('Enter name of issue');
await user.type(input, 'Improper');
const option = await screen.findByRole('option', {
Expand All @@ -50,15 +56,25 @@ describe('Issue', () => {
});

test('No matches found appears if user types non-existing option', async () => {
fetchMock.mockResponseOnce(JSON.stringify(aggResponse));
renderComponent();
await screen.findByRole('button', {
name: /Incorrect information on your report/,
});

const input = screen.getByPlaceholderText('Enter name of issue');
await user.type(input, 'Apples');

expect(await screen.findByText('No matches found.')).toBeInTheDocument();
});

test('Option list disappears when user removes text', async () => {
fetchMock.mockResponseOnce(JSON.stringify(aggResponse));
renderComponent();
await screen.findByRole('button', {
name: /Incorrect information on your report/,
});

const input = screen.getByPlaceholderText('Enter name of issue');
await user.type(input, 'Improper');
const option = await screen.findByRole('option', {
Expand Down
Loading

0 comments on commit dc63ad6

Please sign in to comment.