Skip to content

Instantly share code, notes, and snippets.

@giulianovarriale
Created November 8, 2019 14:11
Show Gist options
  • Save giulianovarriale/0aaf7c835677286b791f3d27d8232922 to your computer and use it in GitHub Desktop.
Save giulianovarriale/0aaf7c835677286b791f3d27d8232922 to your computer and use it in GitHub Desktop.
import { fireEvent } from '@testing-library/react';
import { sampleSize } from 'lodash';
import * as React from 'react';
import { AGREEMENT_CATEGORY_SUGGESTIONS } from '../../../../domainSubsequentAgreement/constants/agreement-form-value-constants';
import renderWithRedux from '../../../../testUtils/renderWithRedux';
import CategoryFilterContainer from '../CategoryFilterContainer';
describe('CategoryFilterContainer', () => {
it('updates the store category filter value when user interacts with', () => {
const [category1, category2] = sampleSize(AGREEMENT_CATEGORY_SUGGESTIONS, 2);
const { getByText, getAllByRole, store } = renderWithRedux(<CategoryFilterContainer />);
fireEvent.click(getByText('Category'));
fireEvent.click(getByText(category1.textKey));
expect(store.getState().filtersState.categoryFilter).toEqual([category1.valueKey.id]);
fireEvent.click(getByText(category2.textKey));
expect(store.getState().filtersState.categoryFilter).toEqual([
category1.valueKey.id,
category2.valueKey.id,
]);
fireEvent.click(getByText(category1.textKey));
fireEvent.click(getAllByRole('option').find(el => el.textContent === category2.textKey));
expect(store.getState().filtersState.categoryFilter).toEqual([]);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment