/* eslint-disable react/prop-types */ 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: () =>
, ModalConfirm: ({ onConfirm, isOpen }) => isOpen ? (
) : null, Modal: ({ isOpen, children }) => isOpen &&
{children}
, ModalHeader: ({ children }) =>
{children}
, ModalSection: ({ children }) =>
{children}
, ModalFooter: ({ children }) =>
{children}
, })); jest.mock('../../../utils', () => ({ getTrad: x => x, })); jest.mock('react-intl', () => ({ useIntl: () => ({ formatMessage: ({ id }) => id, }), })); describe('i18n settings page', () => { afterEach(() => { jest.resetAllMocks(); }); describe('initial state', () => { it('shows default EN locale with edit button but no delete button', async () => { render( ); 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( ); 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( ); const row = await waitFor(() => screen.getByText('French').closest('tr')); const rowUtils = within(row); fireEvent.click(rowUtils.getByLabelText('Delete locale')); fireEvent.click(screen.getByText('Confirm')); await waitFor(() => expect(strapi.notification.success).toBeCalledWith('Settings.locales.modal.delete.success') ); }); }); describe('edit', () => { it('shows the default edit modal layout', async () => { render( ); 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(); }); }); });