richie-education 2.33.1-dev11 → 2.33.1-dev14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -10,14 +10,15 @@ describe('<SearchInput />', () => {
|
|
|
10
10
|
|
|
11
11
|
const inputProps = {};
|
|
12
12
|
|
|
13
|
-
it('renders with the input field and button', () => {
|
|
14
|
-
const { container,
|
|
13
|
+
it('renders with the input field, label and button', () => {
|
|
14
|
+
const { container, getByRole, getByLabelText } = render(
|
|
15
15
|
<IntlProvider locale="en">
|
|
16
16
|
<SearchInput context={contextProps} inputProps={inputProps} />
|
|
17
17
|
</IntlProvider>,
|
|
18
18
|
);
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
getByRole('button', { name: 'Search' });
|
|
21
|
+
getByLabelText('Search');
|
|
21
22
|
// NB: we're searching the DOM as labelling and a11y for this input are handled by `react-autosuggest`
|
|
22
23
|
expect(container.querySelector('input')).not.toBeNull();
|
|
23
24
|
expect(container.innerHTML).toContain('icon-magnifying-glass');
|
|
@@ -26,13 +27,13 @@ describe('<SearchInput />', () => {
|
|
|
26
27
|
it('triggers the passed callback on click', () => {
|
|
27
28
|
const callback = jest.fn();
|
|
28
29
|
|
|
29
|
-
const {
|
|
30
|
+
const { getByRole } = render(
|
|
30
31
|
<IntlProvider locale="en">
|
|
31
32
|
<SearchInput context={contextProps} inputProps={inputProps} onClick={callback} />
|
|
32
33
|
</IntlProvider>,
|
|
33
34
|
);
|
|
34
35
|
|
|
35
|
-
fireEvent.click(
|
|
36
|
+
fireEvent.click(getByRole('button', { name: 'Search' }));
|
|
36
37
|
expect(callback).toHaveBeenCalledTimes(1);
|
|
37
38
|
});
|
|
38
39
|
});
|
|
@@ -9,6 +9,11 @@ const messages = defineMessages({
|
|
|
9
9
|
description: 'Accessibility text for the search button inside the Search input.',
|
|
10
10
|
id: 'components.SearchInput.button',
|
|
11
11
|
},
|
|
12
|
+
label: {
|
|
13
|
+
defaultMessage: 'Search',
|
|
14
|
+
description: 'Accessibility text for the search input label.',
|
|
15
|
+
id: 'components.SearchInput.label',
|
|
16
|
+
},
|
|
12
17
|
});
|
|
13
18
|
|
|
14
19
|
/**
|
|
@@ -23,7 +28,10 @@ export const SearchInput = ({
|
|
|
23
28
|
onClick = () => {}, // by default, do nothing, this will just remove focus and close suggestions
|
|
24
29
|
}: { inputProps: any; onClick?: () => void } & CommonDataProps) => (
|
|
25
30
|
<div className="search-input">
|
|
26
|
-
<
|
|
31
|
+
<label className="offscreen" htmlFor="search-input-field">
|
|
32
|
+
<FormattedMessage {...messages.label} />
|
|
33
|
+
</label>
|
|
34
|
+
<input {...inputProps} id="search-input-field" />
|
|
27
35
|
<button className="search-input__btn" onClick={onClick}>
|
|
28
36
|
<Icon name={IconTypeEnum.MAGNIFYING_GLASS} className="search-input__btn__icon" />{' '}
|
|
29
37
|
<span className="offscreen">
|