A four-layer proven method for testing software
// Should not have basic accessibility issues
// Should not show the dropdown of places when a postcode as been entered
// Should show the dropdown of match when a place as been entered
// Should not show the dropdown if less than 3 character have been entered
// Should show a error message if there are no matches for a place
// Should include the search term in the suggestation
// Should trigger error message if user submits without entering a value
// Should trigger error message if user enters an invalid postcode
// FreeTextGroupSearch > __tests__ > FreeTextGroupSearch.spec.js
import 'jest-dom/extend-expect';
import React from 'react';
describe('FreeTextGroupSearch', () => {
afterEach(cleanup);
it('The component mounts', async () => {
const { container } = render(
<FreeTextGroupSearch />
);
});
});
import { render, fireEvent, cleanup } from '@testing-library/react';
import 'jest-dom/extend-expect';
import React from 'react';
import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';
import mockTowns from './towns-mock.json';
const mockStore = configureStore();
const townStore = mockStore(() => nearestGroupState);
const nearestGroupState = {
async: {
actionTypes: {},
},
view: {
nearestGroup: {
allTowns: mockTowns.towns,
},
},
};
describe('FreeTextGroupSearch', () => {
afterEach(cleanup);
it('The component mounts', async () => {
const { container } = render(
<Provider store={townStore}>
<FreeTextGroupSearch />
</Provider>,
);
});
});
jest FreeTextGroupSearch.spec.js --watch
import MarshalContext from 'common/src/app/util/testing/MarshalContext';
import nearestGroupGeoLocationLocale from 'components/molecules/NearestGroupGeoLocation/locale/nearest-group-geo-location.en-GB.json';
import validationLocale from 'common/src/app/locale/validation.en-GB.json';
import nearestGroupSearchBarLocale from
'../../../../locale/nearest-group-search-bar.en-GB.json';
const contextMessages = {
...nearestGroupSearchBarLocale,
...nearestGroupGeoLocationLocale,
...validationLocale,
};
describe('FreeTextGroupSearch', () => {
afterEach(cleanup);
it('The component mounts', async () => {
const { container } = render(
<Provider store={townStore}>
<MarshalContext messages={contextMessages}>
<FreeTextGroupSearch / >
</MarshalContext>
</Provider>,
);
});
});
jest.mock('../../../src/app/config/market/market.configdefinitions', () => ({
// the value to mock
}));
it('Should show the dropdown of match when a place as been entered', () => {
const { getByTestId } = render(
<Provider store={townStore}>
<MarshalContext messages={contextMessages}>
<FreeTextGroupSearch />
</MarshalContext>
</Provider>,
);
fireEvent.change(getByTestId('free-text-group-search-input'), { target: { value: 'Der' } });
expect(getByTestId('dropdown-results-list')).toBeVisible();
});
import { axe, toHaveNoViolations } from 'jest-axe';
expect.extend(toHaveNoViolations);
describe('FreeTextGroupSearch', () => {
it('Should not have basic accessibility issues', async () => {
const { container } = render(
<Provider store={townStore}>
<MarshalContext messages={contextMessages}>
<FreeTextGroupSearch />
</MarshalContext>
</Provider>,
);
const results = await axe(container);
expect(results).toHaveNoViolations();
});
}
