/
githubmirror
/
strapi
Обзор
Документация
Войти
/
githubmirror
/
strapi
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/plugins/i18n/admin/src/components/tests/DeleteLocale.test.tsx
69 строк
2 KB
Andrei L
chore(deps): migrate msw 1.x → 2.13.4 across admin test suites (#26065)
11 май 2026, 11:45
Не верифицирован
11 май 2026, 11:45
6d83054
Код
Авторство
О чём код?
import { errors } from '@strapi/utils'; import { render, screen, server } from '@tests/utils'; import { http, HttpResponse } from 'msw'; import { DeleteLocale } from '../DeleteLocale'; import type { Locale } from '../../../../shared/contracts/locales'; const LOCALE: Locale = { id: 1, code: 'en', isDefault: false, name: 'English', createdAt: '', updatedAt: '', }; describe('DeleteLocale', () => { it('should render an icon button by default', () => { render(<DeleteLocale {...LOCALE} />); expect(screen.getByRole('button', { name: 'Delete English locale' })).toBeInTheDocument(); }); it('should render a confirmation alertdialog when the icon button is clicked', async () => { const { user } = render(<DeleteLocale {...LOCALE} />); expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument(); await user.click(screen.getByRole('button', { name: 'Delete English locale' })); expect(screen.getByRole('alertdialog', { name: 'Confirmation' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: 'Confirm' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: 'Cancel' })).toBeInTheDocument(); await user.click(screen.getByRole('button', { name: 'Cancel' })); expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument(); }); it('should allow you to delete a locale', async () => { const { user } = render(<DeleteLocale {...LOCALE} />); await user.click(screen.getByRole('button', { name: 'Delete English locale' })); await user.click(screen.getByRole('button', { name: 'Confirm' })); await screen.findByText('Deleted locale'); }); it('show an error if the deletion failed', async () => { server.use( http.delete('/i18n/locales/:id', () => { return HttpResponse.json( { error: new errors.ApplicationError('Could not delete locale'), }, { status: 500 } ); }) ); const { user } = render(<DeleteLocale {...LOCALE} />); await user.click(screen.getByRole('button', { name: 'Delete English locale' })); await user.click(screen.getByRole('button', { name: 'Confirm' })); expect(await screen.findByText('Could not delete locale')).toBeInTheDocument(); }); });