2021-09-10 06:43:06 +02:00
|
|
|
import React from 'react';
|
2021-10-27 10:36:00 +02:00
|
|
|
import { ThemeProvider, lightTheme } from '@strapi/design-system';
|
2021-09-30 17:07:43 +02:00
|
|
|
import { render as renderTL } from '@testing-library/react';
|
2021-09-10 06:43:06 +02:00
|
|
|
import { QueryClientProvider, QueryClient } from 'react-query';
|
|
|
|
|
import { Provider } from 'react-redux';
|
|
|
|
|
import { combineReducers, createStore } from 'redux';
|
|
|
|
|
import en from '../../../translations/en.json';
|
|
|
|
|
import server from './server';
|
|
|
|
|
import reducers from '../../../hooks/reducers';
|
|
|
|
|
import LocaleSelect from '..';
|
|
|
|
|
|
|
|
|
|
jest.mock('../../../utils', () => ({
|
2022-08-08 23:33:39 +02:00
|
|
|
getTrad: (x) => x,
|
2021-09-10 06:43:06 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
jest.mock('react-intl', () => ({
|
|
|
|
|
FormattedMessage: ({ id }) => id,
|
|
|
|
|
useIntl: () => ({ formatMessage: jest.fn(({ id }) => en[id]) }),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
jest.mock('@strapi/helper-plugin', () => ({
|
|
|
|
|
...jest.requireActual('@strapi/helper-plugin'),
|
|
|
|
|
useNotification: jest.fn(),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const queryClient = new QueryClient({
|
|
|
|
|
defaultOptions: {
|
|
|
|
|
queries: {
|
|
|
|
|
refetchOnWindowFocus: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const store = createStore(combineReducers(reducers));
|
|
|
|
|
|
2022-08-08 23:33:39 +02:00
|
|
|
const render = (props) =>
|
2021-09-10 06:43:06 +02:00
|
|
|
renderTL(
|
|
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
|
<Provider store={store}>
|
|
|
|
|
<ThemeProvider theme={lightTheme}>
|
|
|
|
|
<LocaleSelect {...props} />
|
|
|
|
|
</ThemeProvider>
|
|
|
|
|
</Provider>
|
|
|
|
|
</QueryClientProvider>,
|
|
|
|
|
{ container: document.body }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
describe('LocaleSelect', () => {
|
|
|
|
|
beforeAll(() => server.listen());
|
|
|
|
|
afterEach(() => server.resetHandlers());
|
|
|
|
|
afterAll(() => server.close());
|
|
|
|
|
|
2021-09-27 15:34:11 +02:00
|
|
|
it('shows an aria-busy element when loading the data', async () => {
|
2021-09-10 06:43:06 +02:00
|
|
|
const { container } = render();
|
|
|
|
|
|
|
|
|
|
expect(container.firstChild).toMatchInlineSnapshot(`
|
2022-04-26 15:09:11 +02:00
|
|
|
.c9 {
|
2021-09-10 06:43:06 +02:00
|
|
|
padding-left: 12px;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-26 15:09:11 +02:00
|
|
|
.c1 {
|
|
|
|
|
-webkit-align-items: stretch;
|
|
|
|
|
-webkit-box-align: stretch;
|
|
|
|
|
-ms-flex-align: stretch;
|
|
|
|
|
align-items: stretch;
|
2021-09-10 06:43:06 +02:00
|
|
|
display: -webkit-box;
|
|
|
|
|
display: -webkit-flex;
|
|
|
|
|
display: -ms-flexbox;
|
|
|
|
|
display: flex;
|
2022-04-26 15:09:11 +02:00
|
|
|
-webkit-flex-direction: column;
|
|
|
|
|
-ms-flex-direction: column;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.c4 {
|
2021-09-10 06:43:06 +02:00
|
|
|
-webkit-align-items: center;
|
|
|
|
|
-webkit-box-align: center;
|
|
|
|
|
-ms-flex-align: center;
|
|
|
|
|
align-items: center;
|
2021-09-30 17:07:43 +02:00
|
|
|
display: -webkit-box;
|
|
|
|
|
display: -webkit-flex;
|
|
|
|
|
display: -ms-flexbox;
|
|
|
|
|
display: flex;
|
|
|
|
|
-webkit-flex-direction: row;
|
|
|
|
|
-ms-flex-direction: row;
|
|
|
|
|
flex-direction: row;
|
2022-04-26 15:09:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.c6 {
|
2021-09-30 17:07:43 +02:00
|
|
|
-webkit-align-items: center;
|
|
|
|
|
-webkit-box-align: center;
|
|
|
|
|
-ms-flex-align: center;
|
|
|
|
|
align-items: center;
|
2022-04-26 15:09:11 +02:00
|
|
|
display: -webkit-box;
|
|
|
|
|
display: -webkit-flex;
|
|
|
|
|
display: -ms-flexbox;
|
|
|
|
|
display: flex;
|
|
|
|
|
-webkit-flex-direction: row;
|
|
|
|
|
-ms-flex-direction: row;
|
|
|
|
|
flex-direction: row;
|
2021-11-02 09:24:02 +01:00
|
|
|
-webkit-flex-wrap: wrap;
|
|
|
|
|
-ms-flex-wrap: wrap;
|
|
|
|
|
flex-wrap: wrap;
|
2021-09-27 15:34:11 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-26 15:09:11 +02:00
|
|
|
.c10 {
|
2021-11-02 09:24:02 +01:00
|
|
|
background: transparent;
|
|
|
|
|
border: none;
|
|
|
|
|
position: relative;
|
|
|
|
|
z-index: 1;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-26 15:09:11 +02:00
|
|
|
.c10 svg {
|
2021-11-02 09:24:02 +01:00
|
|
|
height: 0.6875rem;
|
|
|
|
|
width: 0.6875rem;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-26 15:09:11 +02:00
|
|
|
.c10 svg path {
|
2021-11-02 09:24:02 +01:00
|
|
|
fill: #666687;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-26 15:09:11 +02:00
|
|
|
.c11 {
|
2021-09-10 06:43:06 +02:00
|
|
|
display: -webkit-box;
|
|
|
|
|
display: -webkit-flex;
|
|
|
|
|
display: -ms-flexbox;
|
|
|
|
|
display: flex;
|
2021-11-02 09:24:02 +01:00
|
|
|
background: none;
|
|
|
|
|
border: none;
|
2021-09-10 06:43:06 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-26 15:09:11 +02:00
|
|
|
.c11 svg {
|
2021-11-02 09:24:02 +01:00
|
|
|
width: 0.375rem;
|
2021-09-10 06:43:06 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-26 15:09:11 +02:00
|
|
|
.c3 {
|
2021-11-08 12:17:38 +01:00
|
|
|
font-weight: 600;
|
|
|
|
|
color: #32324d;
|
2021-11-02 09:24:02 +01:00
|
|
|
font-size: 0.75rem;
|
|
|
|
|
line-height: 1.33;
|
2021-09-10 06:43:06 +02:00
|
|
|
}
|
|
|
|
|
|
2021-11-02 09:24:02 +01:00
|
|
|
.c0 {
|
|
|
|
|
border: 0;
|
|
|
|
|
-webkit-clip: rect(0 0 0 0);
|
|
|
|
|
clip: rect(0 0 0 0);
|
|
|
|
|
height: 1px;
|
|
|
|
|
margin: -1px;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
padding: 0;
|
|
|
|
|
position: absolute;
|
|
|
|
|
width: 1px;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-26 15:09:11 +02:00
|
|
|
.c5 {
|
2021-09-10 06:43:06 +02:00
|
|
|
position: relative;
|
|
|
|
|
border: 1px solid #dcdce4;
|
|
|
|
|
padding-right: 12px;
|
2021-11-02 09:24:02 +01:00
|
|
|
padding-left: 12px;
|
2021-09-10 06:43:06 +02:00
|
|
|
border-radius: 4px;
|
|
|
|
|
background: #ffffff;
|
2021-10-05 11:51:09 +02:00
|
|
|
outline: none;
|
|
|
|
|
box-shadow: 0;
|
|
|
|
|
-webkit-transition-property: border-color,box-shadow,fill;
|
|
|
|
|
transition-property: border-color,box-shadow,fill;
|
|
|
|
|
-webkit-transition-duration: 0.2s;
|
|
|
|
|
transition-duration: 0.2s;
|
2021-09-10 06:43:06 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-26 15:09:11 +02:00
|
|
|
.c5:focus-within {
|
2021-09-30 17:07:43 +02:00
|
|
|
border: 1px solid #4945ff;
|
2021-10-05 11:51:09 +02:00
|
|
|
box-shadow: #4945ff 0px 0px 0px 2px;
|
2021-09-10 06:43:06 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-26 15:09:11 +02:00
|
|
|
.c7 {
|
2021-11-02 09:24:02 +01:00
|
|
|
display: grid;
|
|
|
|
|
-webkit-flex: 1 1 0%;
|
|
|
|
|
-ms-flex: 1 1 0%;
|
|
|
|
|
flex: 1 1 0%;
|
|
|
|
|
position: relative;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-26 15:09:11 +02:00
|
|
|
.c8 {
|
2021-11-02 09:24:02 +01:00
|
|
|
display: inline-grid;
|
|
|
|
|
grid-area: 1 / 1 / 2 / 3;
|
|
|
|
|
grid-template-columns: 0px min-content;
|
2021-09-30 17:07:43 +02:00
|
|
|
background: transparent;
|
2021-11-02 09:24:02 +01:00
|
|
|
min-height: 2.5rem;
|
2021-09-10 06:43:06 +02:00
|
|
|
border: none;
|
2021-11-02 09:24:02 +01:00
|
|
|
-webkit-flex: 1;
|
|
|
|
|
-ms-flex: 1;
|
|
|
|
|
flex: 1;
|
|
|
|
|
font-size: 0.875rem;
|
|
|
|
|
color: #32324d;
|
|
|
|
|
outline: none;
|
2021-09-10 06:43:06 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-26 15:09:11 +02:00
|
|
|
.c8:focus-visible {
|
2021-11-02 09:24:02 +01:00
|
|
|
outline: none;
|
|
|
|
|
box-shadow: none;
|
|
|
|
|
outline-offset: 0;
|
2021-09-10 06:43:06 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-26 15:09:11 +02:00
|
|
|
.c8[aria-disabled='true'] {
|
2021-11-02 09:24:02 +01:00
|
|
|
background: inherit;
|
|
|
|
|
color: inherit;
|
|
|
|
|
cursor: not-allowed;
|
2021-09-10 06:43:06 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-26 15:09:11 +02:00
|
|
|
.c2 > * {
|
2021-11-02 09:24:02 +01:00
|
|
|
margin-top: 0;
|
|
|
|
|
margin-bottom: 0;
|
2021-09-10 06:43:06 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-26 15:09:11 +02:00
|
|
|
.c2 > * + * {
|
2021-11-02 09:24:02 +01:00
|
|
|
margin-top: 4px;
|
2021-09-10 06:43:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<div
|
2021-11-02 09:24:02 +01:00
|
|
|
aria-atomic="false"
|
|
|
|
|
aria-live="polite"
|
|
|
|
|
aria-relevant="additions text"
|
2021-09-10 06:43:06 +02:00
|
|
|
class="c0"
|
2021-11-02 09:24:02 +01:00
|
|
|
/>
|
|
|
|
|
<div
|
2022-04-26 15:09:11 +02:00
|
|
|
class="c1 c2"
|
2022-03-10 14:45:19 +01:00
|
|
|
spacing="1"
|
2021-09-10 06:43:06 +02:00
|
|
|
>
|
2021-11-02 09:24:02 +01:00
|
|
|
<label
|
2022-04-26 15:09:11 +02:00
|
|
|
class="c3"
|
2021-11-02 09:24:02 +01:00
|
|
|
for="combobox-1"
|
|
|
|
|
id="combobox-1-label"
|
2021-09-10 06:43:06 +02:00
|
|
|
>
|
2022-03-10 14:45:19 +01:00
|
|
|
<div
|
2022-04-26 15:09:11 +02:00
|
|
|
class="c4"
|
2022-03-10 14:45:19 +01:00
|
|
|
>
|
|
|
|
|
Locales
|
|
|
|
|
</div>
|
2021-11-02 09:24:02 +01:00
|
|
|
</label>
|
2021-09-10 06:43:06 +02:00
|
|
|
<div
|
2022-04-26 15:09:11 +02:00
|
|
|
class="c4 c5"
|
2021-09-10 06:43:06 +02:00
|
|
|
>
|
|
|
|
|
<div
|
2022-04-26 15:09:11 +02:00
|
|
|
class="c6 c7"
|
2021-11-02 09:24:02 +01:00
|
|
|
wrap="wrap"
|
2021-09-10 06:43:06 +02:00
|
|
|
>
|
2021-11-02 09:24:02 +01:00
|
|
|
|
|
|
|
|
<input
|
|
|
|
|
aria-activedescendant=""
|
|
|
|
|
aria-autocomplete="list"
|
|
|
|
|
aria-controls="combobox-1-listbox"
|
|
|
|
|
aria-disabled="false"
|
|
|
|
|
aria-expanded="false"
|
|
|
|
|
aria-haspopup="listbox"
|
|
|
|
|
aria-labelledby="combobox-1-label"
|
|
|
|
|
autocomplete="off"
|
|
|
|
|
autocorrect="off"
|
2022-04-26 15:09:11 +02:00
|
|
|
class="c8"
|
2021-11-02 09:24:02 +01:00
|
|
|
id="combobox-1"
|
|
|
|
|
placeholder="Select or enter a value"
|
|
|
|
|
role="combobox"
|
|
|
|
|
spellcheck="off"
|
|
|
|
|
type="text"
|
|
|
|
|
value=""
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
2022-04-26 15:09:11 +02:00
|
|
|
class="c4"
|
2021-11-02 09:24:02 +01:00
|
|
|
>
|
|
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
aria-hidden="true"
|
2022-04-26 15:09:11 +02:00
|
|
|
class="c9 c10 c11"
|
2021-11-02 09:24:02 +01:00
|
|
|
tabindex="-1"
|
|
|
|
|
type="button"
|
2021-09-10 06:43:06 +02:00
|
|
|
>
|
2021-11-02 09:24:02 +01:00
|
|
|
<svg
|
|
|
|
|
fill="none"
|
|
|
|
|
height="1em"
|
|
|
|
|
viewBox="0 0 14 8"
|
|
|
|
|
width="1em"
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
2021-09-10 06:43:06 +02:00
|
|
|
>
|
2021-11-02 09:24:02 +01:00
|
|
|
<path
|
|
|
|
|
clip-rule="evenodd"
|
|
|
|
|
d="M14 .889a.86.86 0 01-.26.625L7.615 7.736A.834.834 0 017 8a.834.834 0 01-.615-.264L.26 1.514A.861.861 0 010 .889c0-.24.087-.45.26-.625A.834.834 0 01.875 0h12.25c.237 0 .442.088.615.264a.86.86 0 01.26.625z"
|
|
|
|
|
fill="#32324D"
|
|
|
|
|
fill-rule="evenodd"
|
|
|
|
|
/>
|
|
|
|
|
</svg>
|
|
|
|
|
</button>
|
2021-09-10 06:43:06 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
`);
|
|
|
|
|
});
|
|
|
|
|
|
2021-09-30 17:07:43 +02:00
|
|
|
// it('only shows the locales that have not already been used', async () => {
|
|
|
|
|
// render();
|
2021-09-10 06:43:06 +02:00
|
|
|
|
2021-09-30 17:07:43 +02:00
|
|
|
// await waitFor(() =>
|
|
|
|
|
// expect(screen.queryByText('Loading the available locales...')).not.toBeInTheDocument()
|
|
|
|
|
// );
|
|
|
|
|
// fireEvent.click(screen.getByLabelText('Locales'));
|
|
|
|
|
// await waitFor(() => screen.getByText('Afrikaans (af)'));
|
2021-09-10 06:43:06 +02:00
|
|
|
|
2021-09-30 17:07:43 +02:00
|
|
|
// expect(screen.getByText('Afrikaans (af)')).toBeVisible();
|
|
|
|
|
// expect(screen.getByText('French (fr)')).toBeVisible();
|
|
|
|
|
// expect(screen.queryByText('English (en)')).toBeFalsy();
|
|
|
|
|
// });
|
2021-09-10 06:43:06 +02:00
|
|
|
|
2021-09-30 17:07:43 +02:00
|
|
|
// it('brings back an object of code and displayName keys when changing', async () => {
|
|
|
|
|
// const onLocaleChangeSpy = jest.fn();
|
|
|
|
|
// render({ onLocaleChange: onLocaleChangeSpy });
|
2021-09-10 06:43:06 +02:00
|
|
|
|
2021-09-30 17:07:43 +02:00
|
|
|
// await waitFor(() =>
|
|
|
|
|
// expect(screen.queryByText('Loading the available locales...')).not.toBeInTheDocument()
|
|
|
|
|
// );
|
|
|
|
|
// fireEvent.click(screen.getByLabelText('Locales'));
|
|
|
|
|
// await waitFor(() => screen.getByText('Afrikaans (af)'));
|
|
|
|
|
// fireEvent.click(screen.getByText('French (fr)'));
|
2021-09-10 06:43:06 +02:00
|
|
|
|
2021-09-30 17:07:43 +02:00
|
|
|
// expect(onLocaleChangeSpy).toBeCalledWith({ code: 'fr', displayName: 'French (fr)' });
|
|
|
|
|
// });
|
2021-09-10 06:43:06 +02:00
|
|
|
});
|