diff --git a/apps/web/src/features/recipes/RecipeCreatePage.test.tsx b/apps/web/src/features/recipes/RecipeCreatePage.test.tsx index 25a8633..719634c 100644 --- a/apps/web/src/features/recipes/RecipeCreatePage.test.tsx +++ b/apps/web/src/features/recipes/RecipeCreatePage.test.tsx @@ -1,5 +1,5 @@ import '@testing-library/jest-dom/vitest'; -import { fireEvent, render, screen } from '@testing-library/react'; +import { fireEvent, render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { useAppStore } from '../../store'; @@ -239,6 +239,7 @@ async function fillRecipe() { await user.type(screen.getByLabelText('Step 1'), 'Mix.'); return user; } +// Full form interactions can exceed 5 s on the shared CI runner. it('creates a recipe with explicit times and difficulty, then opens its detail route', async () => { let input: unknown; mockRecipeFetch((_operation, variables) => { @@ -258,7 +259,7 @@ it('creates a recipe with explicit times and difficulty, then opens its detail r imageUrl: null, category: 'soup', }); -}); +}, 15_000); it('preserves input after a failed save and allows retry', async () => { let fail = true; mockRecipeFetch(() => @@ -380,11 +381,12 @@ it('opens recipes with legacy Norwegian units as English and saves English', asy ingredients: [expect.objectContaining({ unit: 'tbsp' })], }); }); +// Keep the complete keyboard/focus scenario within one test, with CI headroom. it('reorders ingredients and steps with the keyboard, keeping focus and announcing the position', async () => { const user = userEvent.setup(); mount(); - // Fill fields directly: this test is about moving rows, not typing, and - // per-keystroke typing made it too slow for the CI runner's 5 s limit. + // Fill fields directly so setup does not spend time on individual keystrokes; + // the keyboard interactions below exercise moving rows and retaining focus. const fill = (label: string, value: string) => fireEvent.change(screen.getByLabelText(label), { target: { value } }); fill('Ingredient 1', 'Flour'); @@ -428,7 +430,7 @@ it('reorders ingredients and steps with the keyboard, keeping focus and announci expect(screen.getByRole('status')).toHaveTextContent( 'Step moved to position 1 of 2.', ); -}); +}, 15_000); describe('recipe drafts', () => { beforeEach(() => localStorage.clear()); @@ -664,7 +666,10 @@ describe('edit page titles', () => { })); const owned = mount('/recipes/' + apiRecipe.id + '/edit'); await screen.findByRole('heading', { name: 'Edit Recipe' }); - expect(document.title).toBe(`Edit ${apiRecipe.title} – Recipe Platform`); + // The heading can render before usePageTitle's effect updates the tab. + await waitFor(() => + expect(document.title).toBe(`Edit ${apiRecipe.title} – Recipe Platform`), + ); owned.unmount(); mockRecipeFetch(() => ({ @@ -672,12 +677,16 @@ describe('edit page titles', () => { })); const other = mount('/recipes/' + crypto.randomUUID() + '/edit'); await screen.findByRole('heading', { name: 'Cannot edit recipe' }); - expect(document.title).toBe('Cannot edit recipe – Recipe Platform'); + await waitFor(() => + expect(document.title).toBe('Cannot edit recipe – Recipe Platform'), + ); other.unmount(); mount('/recipes/abc/edit'); await screen.findByRole('heading', { name: 'Recipe unavailable' }); - expect(document.title).toBe('Recipe unavailable – Recipe Platform'); + await waitFor(() => + expect(document.title).toBe('Recipe unavailable – Recipe Platform'), + ); }); });