refactor(ui): centralise themed dialogs

This commit is contained in:
cesnimda
2026-08-28 12:48:38 +02:00
parent 5805c1a621
commit 3b4adb8281
12 changed files with 113 additions and 335 deletions
+22
View File
@@ -2,6 +2,7 @@ import React from 'react';
import '@testing-library/jest-dom';
import { render, screen, fireEvent } from '@testing-library/react';
import { ConfirmProvider, useConfirm } from './confirm';
import { I18nProvider } from './i18n/I18nProvider';
function Demo() {
const { confirm } = useConfirm();
@@ -12,6 +13,11 @@ function Demo() {
);
}
function DefaultDemo() {
const { confirm } = useConfirm();
return <button onClick={() => void confirm({ message: 'Fortsett?' })}>Open localized confirm</button>;
}
test('renders app-owned confirmation dialog', async () => {
render(
<ConfirmProvider>
@@ -24,3 +30,19 @@ test('renders app-owned confirmation dialog', async () => {
expect(await screen.findByText(/are you sure/i)).toBeInTheDocument();
expect(screen.getByRole('button', { name: /delete/i })).toBeInTheDocument();
});
test('uses the selected language for shared dialog defaults', async () => {
window.localStorage.setItem('uiLanguage', 'nb');
render(
<I18nProvider>
<ConfirmProvider>
<DefaultDemo />
</ConfirmProvider>
</I18nProvider>,
);
fireEvent.click(screen.getByRole('button', { name: /open localized confirm/i }));
expect(await screen.findByRole('heading', { name: 'Bekreft handling' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Bekreft' })).toBeInTheDocument();
window.localStorage.removeItem('uiLanguage');
});