Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions apps/web/src/features/recipes/RecipeCreatePage.test.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) => {
Expand All @@ -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(() =>
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -664,20 +666,27 @@ 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(() => ({
data: { recipe: { ...apiRecipe, id: crypto.randomUUID() } },
}));
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'),
);
});
});

Expand Down