An open source design system that's fully customizable and agent ready
TypeScript
test(PowerSearch, Tokenizer): the sheet warm-ups load their modules before any test, not inside a 15 s wait (#9968)
Christopher Chedeau3b44b43d97a2
diff --git a/packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsx b/packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsxindex f136c07ac0..f0052e4bd3 100644--- a/packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsx+++ b/packages/core/src/PowerSearch/PowerSearchBottomSheet.test.tsx@@ -64,6 +64,13 @@ import {} from './powerSearchSheetUtils';import {renderHook} from '@testing-library/react';+// PowerSearch and Tokenizer load their sheets on demand, and a first load+// under the test transform can take seconds on a busy machine. The file loads+// both sheet modules before any test runs, so neither load counts against a+// wait or a time limit.+await import('./PowerSearchBottomSheet');+await import('../Tokenizer/TokenizerBottomSheet');+// =============================================================================// Environment// =============================================================================@@ -542,19 +549,21 @@ function expectBleedRowsOnBodyInset(list: HTMLElement): void {}// The sheet flow is loaded with React.lazy, so the first flow renders a tick-// after it opens. Open one up front so the module is cached and every later-// flow renders synchronously.+// after it opens. Open one up front so every later flow renders synchronously.+// `act` renders the flow once its loaded module resolves, with no wait.beforeAll(async () => {stubEnvironment();try {setup({filters: [openFilter]});- openSheet();- await screen.findByRole('heading', {name: 'Filters'}, {timeout: 15000});+ await act(async () => {+ openSheet();+ });+ expect(screen.getByRole('heading', {name: 'Filters'})).toBeInTheDocument();} finally {cleanup();vi.unstubAllGlobals();}-}, 20000);+});// A list value's Tokenizer sheet is loaded with React.lazy too. Open one up// front, so every later Tokenizer sheet renders synchronously inside its press.@@ -564,13 +573,15 @@ beforeAll(async () => {setup({config: valueTypesConfig});openAddFlow();tapRow('ID');- fireEvent.click(within(sheet()).getByRole('button', {name: 'ID'}));- await screen.findByRole('dialog', {name: 'ID'}, {timeout: 15000});+ await act(async () => {+ fireEvent.click(within(sheet()).getByRole('button', {name: 'ID'}));+ });+ expect(screen.getByRole('dialog', {name: 'ID'})).toBeInTheDocument();} finally {cleanup();vi.unstubAllGlobals();}-}, 20000);+});beforeEach(() => {__resetLiveRegionsForTest();diff --git a/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx b/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsxindex 997a237701..c7d7ee1d7d 100644--- a/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx+++ b/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx@@ -46,6 +46,12 @@ import {} from '../BottomSheet/bottomSheetStack';import {getActiveModalOutlet} from '../Layer/modalOutlet';+// Tokenizer loads its sheet on demand, and a first load under the test+// transform can take seconds on a busy machine. The file loads the sheet+// module before any test runs, so that load counts against no wait or time+// limit.+await import('./TokenizerBottomSheet');+const ITEMS: SearchableItem[] = [{id: 'design', label: 'Design'},{id: 'eng', label: 'Eng'},@@ -143,19 +149,22 @@ const openTrigger = () => screen.getByRole('button', {name: 'Tags'});const list = () => document.querySelector<HTMLElement>('[data-total-count]')!;// The sheet surface is loaded with React.lazy, so the first sheet renders a-// tick after it opens. Open one up front so the module is cached and every-// later sheet renders synchronously.+// tick after it opens. Open one up front so every later sheet renders+// synchronously. `act` renders the sheet once its loaded module resolves,+// with no wait.beforeAll(async () => {stubEnvironment();try {render(<Harness />);- fireEvent.click(openTrigger());- await screen.findByLabelText('Search Tags', undefined, {timeout: 15000});+ await act(async () => {+ fireEvent.click(openTrigger());+ });+ expect(screen.getByLabelText('Search Tags')).toBeInTheDocument();} finally {cleanup();vi.unstubAllGlobals();}-}, 20000);+});beforeEach(() => {__resetLiveRegionsForTest();