Hero-admin: foto klikbaar voor de uitsnede, direct voorbeeld na Toepassen, Opslaan uitgegrijsd zonder wijzigingen

- De thumbnail is de knop 'Uitsnede aanpassen' (hint bij hover/focus, kleine crop-icoon altijd zichtbaar voor touch); losse focusknop vervalt
- Na Toepassen toont de thumbnail direct de nieuwe uitsnede (zelfde rekenlogica als de host) met 'Focus gewijzigd, nog niet opgeslagen'
- Opslaan is uitgeschakeld (aria-disabled) zolang er niets te bewaren is, bezig-indicator tijdens opslaan, weer uit na opslaan
- Test van de keten: Toepassen, Opslaan (imageFocus in de PUT), 'Nieuwe uitsnede wordt gemaakt', 'Verwerking afgerond'; backend: PUT-body bindt, status direct pending, renderer klaar
- Logregel 'recut superseded' als een nieuwere focus de lopende uitsnede overneemt

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 23:58:48 +01:00
co-authored by Claude Sonnet 5.5
parent 6999f5b2ba
commit 606af0aec2
7 changed files with 295 additions and 21 deletions
@@ -38,7 +38,7 @@ describe('Hero page', () => {
await openPage();
expect(await screen.findByTestId('hero-slide-0-processing', {}, T)).toBeInTheDocument();
expect(screen.getByTestId('hero-slide-0-focus')).toBeDisabled();
expect(screen.queryByTestId('hero-slide-0-focus')).not.toBeInTheDocument();
});
it('shows how many photos are ready, with an accessible progress bar, and hides it when all are ready', async () => {
@@ -134,6 +134,7 @@ describe('Hero page', () => {
it('does not save without a title and says why', async () => {
await openPage();
await userEvent.type(screen.getByTestId('hero-lead'), 'Alleen een lead');
await userEvent.click(screen.getByTestId('hero-save'));
@@ -339,6 +340,8 @@ describe('Focus dialog', () => {
it('sends no focus edits when nothing was changed', async () => {
await open();
await userEvent.click(screen.getByTestId('focus-cancel'));
// Something else changed, so there is something to save; the cancelled focus is not part of it.
await userEvent.type(screen.getByTestId('hero-tagline'), 'x');
await userEvent.click(screen.getByTestId('hero-save'));
@@ -886,7 +889,7 @@ describe('Each photo shows by itself when its processing is finished', () => {
await userEvent.upload(screen.getByTestId('hero-upload'), jpg('groot.jpg'));
expect(await screen.findByTestId('hero-slide-0-processing', {}, T)).toHaveClass('hero-shimmer');
expect(screen.getByTestId('hero-slide-0-focus')).toBeDisabled();
expect(screen.queryByTestId('hero-slide-0-focus')).not.toBeInTheDocument();
expect(screen.queryByTestId('hero-slide-0-done-text')).not.toBeInTheDocument();
// The server is done; nobody saves or reloads: the page asks again by itself.
@@ -934,7 +937,140 @@ describe('Each photo shows by itself when its processing is finished', () => {
expect(screen.getByTestId('hero-slide-0-focus')).toBeEnabled();
expect(screen.getByTestId('hero-slide-1-processing')).toBeInTheDocument();
expect(screen.getByTestId('hero-slide-1-focus')).toBeDisabled();
expect(screen.queryByTestId('hero-slide-1-focus')).not.toBeInTheDocument();
expect(screen.getByTestId('hero-processing-count')).toHaveTextContent(/1 van 2|1 of 2/);
}, 30000);
});
describe('The picture of a slide is the way to adjust its crop', () => {
beforeEach(() => {
resetMockHero();
});
it('is a real button named Adjust crop, with a hint that is there without hovering, and it opens the dialog', async () => {
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1)] });
await openPage();
const thumb = screen.getByTestId('hero-slide-0-focus');
expect(thumb.tagName).toBe('BUTTON');
expect(thumb).toHaveAccessibleName(/Uitsnede aanpassen|Adjust crop/);
expect(thumb.querySelector('svg')).not.toBeNull();
expect(within(thumb).getAllByText(/Uitsnede aanpassen|Adjust crop/).length).toBeGreaterThan(0);
expect(screen.queryByRole('button', { name: /Focus instellen|Set focus/ })).not.toBeInTheDocument();
thumb.focus();
await userEvent.keyboard('{Enter}');
expect(await screen.findByTestId('focus-dialog', {}, T)).toBeInTheDocument();
});
it('shows the new crop on the thumbnail right after Apply, with the not-saved note, and drops it when the change is undone', async () => {
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1)] });
await openPage();
expect(screen.queryByTestId('hero-slide-0-focus-local')).not.toBeInTheDocument();
await userEvent.click(screen.getByTestId('hero-slide-0-focus'));
fireEvent.change(await screen.findByTestId('focus-x', {}, T), { target: { value: '10' } });
await userEvent.click(screen.getByTestId('focus-save'));
await waitFor(() => expect(screen.queryByTestId('focus-dialog')).not.toBeInTheDocument());
const local = await screen.findByTestId('hero-slide-0-focus-local', {}, T);
expect(local.getAttribute('src')).toContain('full-1280.webp');
expect(local.style.left).toMatch(/^-?\d/);
expect(screen.getByTestId('hero-slide-0-focus-pending')).toHaveTextContent(/Focus gewijzigd, nog niet opgeslagen|Focus changed, not saved yet/);
});
it('follows the whole chain: Apply, Save sends the focus, the new crop is made (animation), then it is finished', async () => {
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1), slide(2)] });
await openPage();
await userEvent.click(screen.getByTestId('hero-slide-1-focus'));
fireEvent.change(await screen.findByTestId('focus-y', {}, T), { target: { value: '20' } });
await userEvent.click(screen.getByTestId('focus-save'));
await screen.findByTestId('hero-slide-1-focus-pending', {}, T);
await userEvent.click(screen.getByTestId('hero-save'));
await waitFor(() => expect(getSavedHeroRequests()).toHaveLength(1));
expect(getSavedHeroRequests()[0].imageFocus).toEqual([
expect.objectContaining({ imageId: '10000000-0000-0000-0000-000000000002', focus: { x: 0.5, y: 0.2, zoom: 1 } }),
]);
// Saved: the note of the unsaved change is gone and the new crop is being made, with the animation, on that photo only.
const recut = await screen.findByTestId('hero-slide-1-recut', {}, T);
expect(recut).toHaveClass('hero-shimmer');
expect(recut).toHaveTextContent(/Nieuwe uitsnede wordt gemaakt|Making the new crop/);
expect(screen.queryByTestId('hero-slide-1-focus-pending')).not.toBeInTheDocument();
expect(screen.queryByTestId('hero-slide-0-recut')).not.toBeInTheDocument();
finishMockRecut();
expect(await screen.findByTestId('hero-slide-1-done-text', {}, { timeout: 12000 })).toHaveTextContent(/Verwerking afgerond|Processing finished/);
expect(screen.queryByTestId('hero-slide-1-recut')).not.toBeInTheDocument();
expect(screen.getByTestId('hero-slide-1-focus').tagName).toBe('BUTTON');
}, 30000);
});
describe('The Save button', () => {
beforeEach(() => {
resetMockHero();
});
it('is greyed out while there is nothing to save, active after a change, busy while saving, and greyed out again after saving', async () => {
setMockHero({ ...emptyHero(), id: 'h1', title: 'Titel', slides: [slide(1)] });
let release: () => void = () => undefined;
const gate = new Promise<void>((resolve) => { release = resolve; });
server.use(
http.put(`${API_BASE}/api/v1/hero`, async ({ request }) => {
await gate;
const body = (await request.json()) as { title: string };
return HttpResponse.json({ ...emptyHero(), id: 'h1', title: body.title, slides: [slide(1)] });
}),
);
await openPage();
const save = screen.getByTestId('hero-save');
expect(save).toBeDisabled();
expect(save).toHaveAttribute('aria-disabled', 'true');
await userEvent.type(screen.getByTestId('hero-title-input'), '!');
await waitFor(() => expect(save).toBeEnabled());
expect(save).toHaveAttribute('aria-disabled', 'false');
await userEvent.click(save);
await waitFor(() => expect(save).toHaveAttribute('aria-busy', 'true'));
expect(save).toBeDisabled();
expect(save).toHaveTextContent(/Bezig met opslaan|Saving/);
release();
await waitFor(() => expect(save).toHaveAttribute('aria-busy', 'false'));
await waitFor(() => expect(save).toBeDisabled());
expect(screen.queryByTestId('hero-unsaved')).not.toBeInTheDocument();
});
it('is greyed out again when a change is undone, and active for a focus change that is applied', async () => {
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1)] });
await openPage();
const save = screen.getByTestId('hero-save');
await userEvent.type(screen.getByTestId('hero-title-input'), 'X');
await waitFor(() => expect(save).toBeEnabled());
await userEvent.type(screen.getByTestId('hero-title-input'), '{backspace}');
await waitFor(() => expect(save).toBeDisabled());
await userEvent.click(screen.getByTestId('hero-slide-0-focus'));
fireEvent.change(await screen.findByTestId('focus-x', {}, T), { target: { value: '15' } });
await userEvent.click(screen.getByTestId('focus-save'));
await waitFor(() => expect(save).toBeEnabled());
});
it('stays active when saving failed, so it can be tried again', async () => {
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1)] });
server.use(http.put(`${API_BASE}/api/v1/hero`, () => HttpResponse.json({ error: 'x', message: 'Het lukt niet.' }, { status: 500 })));
await openPage();
await userEvent.type(screen.getByTestId('hero-title-input'), 'X');
await userEvent.click(screen.getByTestId('hero-save'));
await waitFor(() => expect(screen.getByTestId('hero-save')).toHaveAttribute('aria-busy', 'false'));
expect(screen.getByTestId('hero-save')).toBeEnabled();
});
});