Hero-admin: schakelaar Actief, destructieve knoppen rood, slide-kopjes, juiste voorvertoning in het focusvenster, status per foto
- Schakelaar (role=switch) Actief / Niet actief bij de knoppen, gedimde rij; 'Verberg voor schermlezers'; veld 'Beschrijving' binnen een groep 'Slide N'
- Alle foto's zonder complete set tonen 'Wordt verwerkt' (voortgang bij de foto die bezig is, 'in de wachtrij' bij de rest); totaal bovenaan telt ook nog niet opgeslagen foto's
- Per foto 'Verwerking afgerond' (zelfde weergave voor een hergebruikte foto), foto direct bruikbaar; niet-opgeslagen foto's worden zelf ververst (GET /hero/images/{id}), ook in een achtergrondtab
- Focusvenster toont de hele foto (full-preview in elke set, achtergrond-aanvulling voor oude sets) in plaats van de uitgesneden wide-variant (vervorming)
- Prullenbak en 'Wijzigingen weggooien' in de destructieve stijl
- upload-respons: reused (intern)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { fireEvent, screen, waitFor, within } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
@@ -634,14 +634,15 @@ describe('Order by dragging, wording and calm waiting', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('speaks plain language: no alt text, decoration with an explanation, and a short guide per part', async () => {
|
||||
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1)] });
|
||||
it('speaks plain language: a plain Description field inside a titled slide, no alt text, and a short guide per part', async () => {
|
||||
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1), slide(2)] });
|
||||
await openPage();
|
||||
|
||||
expect(screen.getByLabelText(/Beschrijving afbeelding 1$|Description of image 1$/)).toBeInTheDocument();
|
||||
const row = within(screen.getByTestId('hero-slide-0'));
|
||||
expect(row.getByText(/Alleen versiering|Decoration only/)).toBeInTheDocument();
|
||||
expect(row.getByText(/niets toevoegt aan de inhoud|adds nothing to the content/)).toBeInTheDocument();
|
||||
const first = screen.getByRole('group', { name: /^Slide 1$/ });
|
||||
expect(within(first).getByLabelText(/^(Beschrijving|Description)$/)).toBeInTheDocument();
|
||||
expect(within(first).getByText(/Verberg voor schermlezers|Hide from screen readers/)).toBeInTheDocument();
|
||||
expect(within(first).queryByText(/niets toevoegt aan de inhoud|adds nothing to the content/)).not.toBeInTheDocument();
|
||||
expect(screen.getByRole('group', { name: /^Slide 2$/ })).toBeInTheDocument();
|
||||
expect(screen.queryByText(/alt-tekst|alt text/i)).not.toBeInTheDocument();
|
||||
const help = screen.getByTestId('hero-help');
|
||||
expect(help).toHaveTextContent(/#contact/);
|
||||
@@ -649,6 +650,55 @@ describe('Order by dragging, wording and calm waiting', () => {
|
||||
expect(help).toHaveTextContent(/Planning|Schedule/);
|
||||
});
|
||||
|
||||
it('numbers the slides by their current order, also after the order changed', async () => {
|
||||
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1), slide(2)] });
|
||||
await openPage();
|
||||
|
||||
await userEvent.click(screen.getByTestId('hero-slide-1-up'));
|
||||
|
||||
expect(within(screen.getByRole('group', { name: /^Slide 1$/ })).getByTestId('hero-slide-0-alt')).toHaveValue('Foto 2');
|
||||
});
|
||||
|
||||
it('has a switch per slide: role switch, Active or Not active, keyboard, and a dimmed row when off', async () => {
|
||||
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1), slide(2)] });
|
||||
await openPage();
|
||||
const toggle = screen.getByTestId('hero-slide-0-active');
|
||||
expect(toggle).toHaveAttribute('role', 'switch');
|
||||
expect(toggle).toBeChecked();
|
||||
expect(toggle).toHaveTextContent(/^(Actief|Active)/);
|
||||
expect(screen.getByTestId('hero-slide-0')).not.toHaveAttribute('data-inactive');
|
||||
|
||||
toggle.focus();
|
||||
await userEvent.keyboard('{Enter}');
|
||||
|
||||
expect(toggle).not.toBeChecked();
|
||||
expect(toggle).toHaveTextContent(/^(Niet actief|Not active)/);
|
||||
expect(screen.getByTestId('hero-slide-0')).toHaveAttribute('data-inactive', 'true');
|
||||
expect(screen.getByTestId('hero-slide-1')).not.toHaveAttribute('data-inactive');
|
||||
await userEvent.click(screen.getByTestId('hero-save'));
|
||||
await waitFor(() => expect(getSavedHeroRequests()).toHaveLength(1));
|
||||
expect(getSavedHeroRequests()[0].slides.map((x) => x.isActive)).toEqual([false, true]);
|
||||
});
|
||||
|
||||
it('marks every photo without a complete set as being processed, the one being cut with its step and the rest as queued', async () => {
|
||||
const waiting = (n: number, step?: [number, number]) => ({
|
||||
...slide(n),
|
||||
image: { ...slide(n).image, variants: [], src: '', processing: true, renderDone: step?.[0] ?? null, renderTotal: step?.[1] ?? null },
|
||||
});
|
||||
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [waiting(1, [3, 16]), waiting(2), waiting(3)] });
|
||||
await openPage();
|
||||
|
||||
for (const i of [0, 1, 2]) {
|
||||
const box = await screen.findByTestId(`hero-slide-${i}-processing`, {}, T);
|
||||
expect(box).toHaveClass('hero-shimmer');
|
||||
expect(box).toHaveTextContent(/Wordt verwerkt|Processing/);
|
||||
}
|
||||
expect(screen.getByTestId('hero-slide-0-processing-step')).toHaveTextContent('3/16');
|
||||
expect(screen.getByTestId('hero-slide-1-processing-queued')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('hero-slide-2-processing-queued')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('hero-processing-count')).toHaveTextContent(/0 van 3|0 of 3/);
|
||||
});
|
||||
|
||||
it('keeps the waiting placeholder mounted through the background refresh, so its animation keeps running', async () => {
|
||||
const waiting = { ...slide(1), image: { ...slide(1).image, variants: [], src: '', processing: true } };
|
||||
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [waiting, slide(2)] });
|
||||
@@ -736,3 +786,155 @@ describe('A changed focus point makes a new crop in the background', () => {
|
||||
await waitFor(() => expect(getRetriedImages()).toEqual([waiting.imageId]), T);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('Focus dialog shows the whole picture', () => {
|
||||
beforeEach(() => {
|
||||
resetMockHero();
|
||||
});
|
||||
|
||||
const portraitSlide = () => {
|
||||
const base = slide(1);
|
||||
// A portrait photo of 2000x3000: the published crops are wide/tall, but the dialog needs the whole picture.
|
||||
return { ...base, image: { ...base.image, width: 2000, height: 3000, src: '/media/hero/0123456789abcdef/wide-1600.webp', previewSrc: '/media/hero/0123456789abcdef/full-1280.webp' } };
|
||||
};
|
||||
|
||||
it('uses the full-frame preview at the shape of the original, not the wide crop', async () => {
|
||||
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [portraitSlide()] });
|
||||
await openPage();
|
||||
|
||||
await userEvent.click(screen.getByTestId('hero-slide-0-focus'));
|
||||
|
||||
const area = await screen.findByTestId('focus-area', {}, T);
|
||||
expect(area.style.aspectRatio.replace(/\s/g, '')).toBe('2000/3000');
|
||||
const picture = area.querySelector('img')!;
|
||||
expect(picture.getAttribute('src')).toContain('full-1280.webp');
|
||||
expect(picture.getAttribute('src')).not.toContain('wide-1600');
|
||||
expect(picture).toHaveClass('object-cover');
|
||||
for (const ratio of ['wide', 'tall']) {
|
||||
expect(screen.getByTestId(`focus-preview-${ratio}`).querySelector('img')!.getAttribute('src')).toContain('full-1280.webp');
|
||||
}
|
||||
});
|
||||
|
||||
it('says the preview is being prepared when the server has none yet, instead of showing a wrong picture', async () => {
|
||||
const base = portraitSlide();
|
||||
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [{ ...base, image: { ...base.image, previewSrc: null } }] });
|
||||
await openPage();
|
||||
|
||||
await userEvent.click(screen.getByTestId('hero-slide-0-focus'));
|
||||
|
||||
expect(await screen.findByTestId('focus-preview-pending', {}, T)).toBeInTheDocument();
|
||||
expect(screen.getByTestId('focus-area').querySelector('img')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Destructive actions are red', () => {
|
||||
beforeEach(() => {
|
||||
resetMockHero();
|
||||
});
|
||||
|
||||
it('shows the remove button of every slide in the destructive style, with a name', async () => {
|
||||
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1), slide(2)] });
|
||||
await openPage();
|
||||
|
||||
for (const i of [0, 1]) {
|
||||
const remove = screen.getByTestId(`hero-slide-${i}-remove`);
|
||||
expect(remove).toHaveClass('bg-destructive');
|
||||
expect(remove).toHaveAccessibleName(/Slide verwijderen|Remove slide/);
|
||||
}
|
||||
});
|
||||
|
||||
it('shows Discard changes in the destructive style', async () => {
|
||||
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1)] });
|
||||
await openPage();
|
||||
await userEvent.type(screen.getByTestId('hero-title-input'), 'X');
|
||||
await screen.findByTestId('hero-unsaved');
|
||||
|
||||
await userEvent.click(screen.getByTestId('nav-dashboard'));
|
||||
|
||||
expect(await screen.findByTestId('hero-leave-discard', {}, T)).toHaveClass('bg-destructive');
|
||||
expect(screen.getByTestId('hero-leave-stay')).not.toHaveClass('bg-destructive');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('Each photo shows by itself when its processing is finished', () => {
|
||||
beforeEach(() => {
|
||||
resetMockHero();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
const jpg = (name: string) => new File(['x'], name, { type: 'image/jpeg' });
|
||||
const cutting = (id: string) => ({
|
||||
id, width: 5757, height: 3838, focus: { x: 0.5, y: 0.5, zoom: 1 }, wideFocus: null, tallFocus: null,
|
||||
src: '', variants: [], processing: true, failed: false, previewSrc: null,
|
||||
});
|
||||
const ready = (id: string) => ({
|
||||
...cutting(id), src: '/media/hero/0123456789abcdef/wide-1600.webp', processing: false,
|
||||
variants: [{ ratio: 'wide', width: 960, height: 640, type: 'image/webp', url: '/media/hero/0123456789abcdef/wide-960.webp' }],
|
||||
previewSrc: '/media/hero/0123456789abcdef/full-1280.webp',
|
||||
});
|
||||
|
||||
it('turns the placeholder of a photo that was not saved yet into a finished note on that photo, by itself, and the photo can be worked on at once', async () => {
|
||||
const id = '70000000-0000-0000-0000-000000000001';
|
||||
let finished = false;
|
||||
server.use(
|
||||
http.post(`${API_BASE}/api/v1/hero/images`, () => HttpResponse.json(cutting(id), { status: 201 })),
|
||||
http.get(`${API_BASE}/api/v1/hero/images/${id}`, () => HttpResponse.json(finished ? ready(id) : cutting(id))),
|
||||
);
|
||||
await openPage();
|
||||
|
||||
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-done-text')).not.toBeInTheDocument();
|
||||
|
||||
// The server is done; nobody saves or reloads: the page asks again by itself.
|
||||
finished = true;
|
||||
const note = await screen.findByTestId('hero-slide-0-done-text', {}, { timeout: 12000 });
|
||||
expect(note).toHaveTextContent(/Verwerking afgerond|Processing finished/);
|
||||
expect(screen.getByTestId('hero-slide-0-done')).toHaveAttribute('role', 'status');
|
||||
expect(screen.getByTestId('hero-slide-0-done')).toHaveAttribute('aria-live', 'polite');
|
||||
expect(screen.queryByTestId('hero-slide-0-processing')).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId('hero-slide-0-focus')).toBeEnabled();
|
||||
// The note names the slide for a screen reader, and goes away by itself after a few seconds.
|
||||
expect(note.textContent).toMatch(/Slide 1: (verwerking afgerond|processing finished)/);
|
||||
await waitFor(() => expect(screen.queryByTestId('hero-slide-0-done-text')).not.toBeInTheDocument(), { timeout: 8000 });
|
||||
}, 30000);
|
||||
|
||||
it('shows the same finished note, at once and without a placeholder, for a photo that was already in the CMS', async () => {
|
||||
const id = '70000000-0000-0000-0000-000000000002';
|
||||
server.use(http.post(`${API_BASE}/api/v1/hero/images`, () => HttpResponse.json({ ...ready(id), reused: true }, { status: 201 })));
|
||||
await openPage();
|
||||
|
||||
await userEvent.upload(screen.getByTestId('hero-upload'), jpg('zelfde.jpg'));
|
||||
|
||||
expect(await screen.findByTestId('hero-slide-0-done-text', {}, T)).toHaveTextContent(/Verwerking afgerond|Processing finished/);
|
||||
expect(screen.queryByTestId('hero-slide-0-processing')).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId('hero-slide-0-focus')).toBeEnabled();
|
||||
expect(screen.queryByText(/stond al|already/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('finishes photo by photo: the first one can be worked on while the second is still busy, and the total at the top follows', async () => {
|
||||
const ids = ['70000000-0000-0000-0000-000000000011', '70000000-0000-0000-0000-000000000012'];
|
||||
let n = 0;
|
||||
const finished = new Set<string>();
|
||||
server.use(
|
||||
http.post(`${API_BASE}/api/v1/hero/images`, () => HttpResponse.json(cutting(ids[n++]), { status: 201 })),
|
||||
http.get(`${API_BASE}/api/v1/hero/images/${ids[0]}`, () => HttpResponse.json(finished.has(ids[0]) ? ready(ids[0]) : cutting(ids[0]))),
|
||||
http.get(`${API_BASE}/api/v1/hero/images/${ids[1]}`, () => HttpResponse.json(finished.has(ids[1]) ? ready(ids[1]) : cutting(ids[1]))),
|
||||
);
|
||||
await openPage();
|
||||
await userEvent.upload(screen.getByTestId('hero-upload'), [jpg('a.jpg'), jpg('b.jpg')]);
|
||||
await screen.findByTestId('hero-slide-1-processing', {}, T);
|
||||
expect(screen.getByTestId('hero-processing-count')).toHaveTextContent(/0 van 2|0 of 2/);
|
||||
|
||||
finished.add(ids[0]);
|
||||
await screen.findByTestId('hero-slide-0-done-text', {}, { timeout: 12000 });
|
||||
|
||||
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.getByTestId('hero-processing-count')).toHaveTextContent(/1 van 2|1 of 2/);
|
||||
}, 30000);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user