Skip to content

Commit

Permalink
test: clear search filters in between tests
Browse files Browse the repository at this point in the history
Since search filters are now stored in the URL, they can leak between tests.
  • Loading branch information
pomegranited committed Jan 1, 2025
1 parent ced360e commit d060113
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/search-modal/SearchUI.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,16 @@ describe('<SearchUI />', () => {
expect(getByText(mockResultDisplayName)).toBeInTheDocument();
});

afterEach(async () => {
// Clear any search filters applied by the previous test.
// We need to do this because search filters are stored in the URL, and so they can leak between tests.
const { queryByRole } = rendered;
const clearFilters = await queryByRole('button', { name: /clear filters/i });
if (clearFilters) {
fireEvent.click(clearFilters);
}
});

it('can filter results by component/XBlock type', async () => {
const { getByRole, getByText } = rendered;
// Now open the filters menu:
Expand Down Expand Up @@ -409,8 +419,8 @@ describe('<SearchUI />', () => {
await waitFor(() => { expect(getByLabelText(checkboxLabel)).toBeInTheDocument(); });
// In addition to the checkbox, there is another button to show the child tags:
expect(getByLabelText(/Expand to show child tags of "ESDC Skills and Competencies"/i)).toBeInTheDocument();
const competentciesCheckbox = getByLabelText(checkboxLabel);
fireEvent.click(competentciesCheckbox, {});
const competenciesCheckbox = getByLabelText(checkboxLabel);
fireEvent.click(competenciesCheckbox, {});
// Now wait for the filter to be applied and the new results to be fetched.
await waitFor(() => { expect(fetchMock).toHaveFetchedTimes(2, searchEndpoint, 'post'); });
// Because we're mocking the results, there's no actual changes to the mock results,
Expand Down

0 comments on commit d060113

Please sign in to comment.