2021-02-02 16:08:16 +01:00
|
|
|
/* eslint-disable react/prop-types */
|
|
|
|
|
2021-02-01 16:02:47 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { fireEvent, render, screen, within, waitFor } from '@testing-library/react';
|
|
|
|
import { ThemeProvider } from 'styled-components';
|
|
|
|
import LocaleSettingsPage from '..';
|
|
|
|
import themes from '../../../../../../strapi-admin/admin/src/themes';
|
|
|
|
|
|
|
|
// TODO: we should not be forced to mock this module
|
|
|
|
// but it bugs somehow when run with jest
|
|
|
|
jest.mock('strapi-helper-plugin', () => ({
|
|
|
|
BaselineAlignment: () => <div />,
|
|
|
|
ModalConfirm: ({ onConfirm, isOpen }) =>
|
|
|
|
isOpen ? (
|
|
|
|
<div role="dialog">
|
|
|
|
<button onClick={onConfirm} type="button">
|
|
|
|
Confirm
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
) : null,
|
2021-02-02 16:08:16 +01:00
|
|
|
|
|
|
|
Modal: ({ isOpen, children }) => isOpen && <div role="dialog">{children}</div>,
|
|
|
|
ModalHeader: ({ children }) => <div>{children}</div>,
|
|
|
|
ModalSection: ({ children }) => <div>{children}</div>,
|
|
|
|
ModalFooter: ({ children }) => <div>{children}</div>,
|
2021-02-01 16:02:47 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock('../../../utils', () => ({
|
|
|
|
getTrad: x => x,
|
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock('react-intl', () => ({
|
|
|
|
useIntl: () => ({
|
|
|
|
formatMessage: ({ id }) => id,
|
|
|
|
}),
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('i18n settings page', () => {
|
2021-02-02 16:08:16 +01:00
|
|
|
afterEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
});
|
|
|
|
|
2021-02-01 16:02:47 +01:00
|
|
|
describe('initial state', () => {
|
|
|
|
it('shows default EN locale with edit button but no delete button', async () => {
|
|
|
|
render(
|
|
|
|
<ThemeProvider theme={themes}>
|
|
|
|
<LocaleSettingsPage />
|
|
|
|
</ThemeProvider>
|
|
|
|
);
|
|
|
|
|
|
|
|
const row = await waitFor(() => screen.getByText('English').closest('tr'));
|
|
|
|
const rowUtils = within(row);
|
|
|
|
|
|
|
|
expect(rowUtils.queryByLabelText('Delete locale')).toBeFalsy();
|
|
|
|
expect(rowUtils.getByLabelText('Edit locale')).toBeVisible();
|
|
|
|
expect(rowUtils.getByText('Settings.locales.row.default-locale')).toBeVisible();
|
|
|
|
expect(rowUtils.getByText('en-US')).toBeVisible();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows FR locale with edit button and delete button', async () => {
|
|
|
|
render(
|
|
|
|
<ThemeProvider theme={themes}>
|
|
|
|
<LocaleSettingsPage />
|
|
|
|
</ThemeProvider>
|
|
|
|
);
|
|
|
|
|
|
|
|
const row = await waitFor(() => screen.getByText('French').closest('tr'));
|
|
|
|
const rowUtils = within(row);
|
|
|
|
|
|
|
|
expect(rowUtils.getByLabelText('Delete locale')).toBeVisible();
|
|
|
|
expect(rowUtils.getByLabelText('Edit locale')).toBeVisible();
|
|
|
|
expect(rowUtils.getByText('fr-FR')).toBeVisible();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('delete', () => {
|
|
|
|
it('removes the locale when clicking the confirmation button', async () => {
|
|
|
|
render(
|
|
|
|
<ThemeProvider theme={themes}>
|
|
|
|
<LocaleSettingsPage />
|
|
|
|
</ThemeProvider>
|
|
|
|
);
|
|
|
|
|
|
|
|
const row = await waitFor(() => screen.getByText('French').closest('tr'));
|
|
|
|
const rowUtils = within(row);
|
|
|
|
|
|
|
|
fireEvent.click(rowUtils.getByLabelText('Delete locale'));
|
2021-02-02 16:08:16 +01:00
|
|
|
fireEvent.click(screen.getByText('Confirm'));
|
2021-02-01 16:02:47 +01:00
|
|
|
|
2021-02-02 16:08:16 +01:00
|
|
|
await waitFor(() =>
|
|
|
|
expect(strapi.notification.success).toBeCalledWith('Settings.locales.modal.delete.success')
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2021-02-01 16:02:47 +01:00
|
|
|
|
2021-02-02 16:08:16 +01:00
|
|
|
describe('edit', () => {
|
|
|
|
it('shows the default edit modal layout', async () => {
|
|
|
|
render(
|
|
|
|
<ThemeProvider theme={themes}>
|
|
|
|
<LocaleSettingsPage />
|
|
|
|
</ThemeProvider>
|
|
|
|
);
|
|
|
|
|
|
|
|
const row = await waitFor(() => screen.getByText('English').closest('tr'));
|
|
|
|
const rowUtils = within(row);
|
|
|
|
|
|
|
|
fireEvent.click(rowUtils.getByLabelText('Edit locale'));
|
|
|
|
|
|
|
|
expect(screen.getByText(`Settings.locales.modal.edit.confirmation`)).toBeVisible();
|
2021-02-01 16:02:47 +01:00
|
|
|
});
|
2021-02-02 17:20:04 +01:00
|
|
|
|
|
|
|
it('closes the edit modal when clicking on cancel', async () => {
|
|
|
|
render(
|
|
|
|
<ThemeProvider theme={themes}>
|
|
|
|
<LocaleSettingsPage />
|
|
|
|
</ThemeProvider>
|
|
|
|
);
|
|
|
|
|
|
|
|
const row = await waitFor(() => screen.getByText('English').closest('tr'));
|
|
|
|
const rowUtils = within(row);
|
|
|
|
|
|
|
|
fireEvent.click(rowUtils.getByLabelText('Edit locale'));
|
|
|
|
fireEvent.click(screen.getByText('app.components.Button.cancel'));
|
|
|
|
|
|
|
|
expect(screen.queryByText(`Edit locale`)).toBeFalsy();
|
|
|
|
});
|
2021-02-01 16:02:47 +01:00
|
|
|
});
|
|
|
|
});
|