|
23 | 23 | */ |
24 | 24 | import { describe, it, expect, vi, beforeAll, afterEach } from 'vitest'; |
25 | 25 | import React from 'react'; |
26 | | -import { render, screen, cleanup, fireEvent } from '@testing-library/react'; |
| 26 | +import { render, screen, cleanup, fireEvent, waitFor } from '@testing-library/react'; |
27 | 27 | import '@testing-library/jest-dom'; |
28 | 28 | import { I18nProvider, LocalizationProvider } from '@object-ui/i18n'; |
29 | 29 | import type { BulkActionDef, BulkActionParam } from '@object-ui/types'; |
@@ -100,16 +100,31 @@ function openDialog(tenantLocale: string | undefined) { |
100 | 100 | ); |
101 | 101 | } |
102 | 102 |
|
| 103 | +/** |
| 104 | + * The confirm step's sentence, read as the dialog's description `textContent`. |
| 105 | + * Not `findByText`: its default normalizer turns the no-break space `Intl` |
| 106 | + * writes before a de-DE `€` into a plain space in the node text, while the |
| 107 | + * matcher string keeps it, so the right sentence would not match. |
| 108 | + */ |
| 109 | +async function confirmSentence(): Promise<string | null> { |
| 110 | + fireEvent.click(await screen.findByRole('button', { name: 'Next' })); |
| 111 | + const dialog = await screen.findByRole('dialog'); |
| 112 | + const description = await waitFor(() => { |
| 113 | + const el = document.getElementById(dialog.getAttribute('aria-describedby') ?? ''); |
| 114 | + expect(el?.textContent).toMatch(/^Set the amount to /); |
| 115 | + return el; |
| 116 | + }); |
| 117 | + return description?.textContent ?? null; |
| 118 | +} |
| 119 | + |
103 | 120 | describe('BulkActionDialog formats its confirm sentence in the display locale (objectstack#26307)', () => { |
104 | 121 | it('formats a currency hole in the tenant display locale', async () => { |
105 | 122 | openDialog('de-DE'); |
106 | | - fireEvent.click(await screen.findByRole('button', { name: 'Next' })); |
107 | | - expect(await screen.findByText(`Set the amount to ${money('de-DE')} on 2 records?`)).toBeInTheDocument(); |
| 123 | + expect(await confirmSentence()).toBe(`Set the amount to ${money('de-DE')} on 2 records?`); |
108 | 124 | }); |
109 | 125 |
|
110 | 126 | it('formats in the UI language when no tenant locale is set', async () => { |
111 | 127 | openDialog(undefined); |
112 | | - fireEvent.click(await screen.findByRole('button', { name: 'Next' })); |
113 | | - expect(await screen.findByText(`Set the amount to ${money('en')} on 2 records?`)).toBeInTheDocument(); |
| 128 | + expect(await confirmSentence()).toBe(`Set the amount to ${money('en')} on 2 records?`); |
114 | 129 | }); |
115 | 130 | }); |
0 commit comments