From 65e196292e551f3b239aee718e30fde50241ad3b Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 9 Jun 2026 16:46:06 +0200 Subject: [PATCH] refactor(journey-editor): fix fragile ordering assertion with compareDocumentPosition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous check used document.body.textContent which includes ARIA labels and hidden elements — a match in those could misfire the indexOf comparison. compareDocumentPosition(DOCUMENT_POSITION_FOLLOWING) checks DOM tree position directly and is not affected by non-visible text. Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/lib/geschichte/JourneyEditor.svelte.spec.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/frontend/src/lib/geschichte/JourneyEditor.svelte.spec.ts b/frontend/src/lib/geschichte/JourneyEditor.svelte.spec.ts index 01c121d7..4eed135c 100644 --- a/frontend/src/lib/geschichte/JourneyEditor.svelte.spec.ts +++ b/frontend/src/lib/geschichte/JourneyEditor.svelte.spec.ts @@ -70,11 +70,10 @@ describe('JourneyEditor — items in position order', () => { ]; render(JourneyEditor, defaultProps({ geschichte: makeGeschichte({ items }) })); - const titles = await page.getByText(/Brief [AB]/).all(); - expect(titles.length).toBeGreaterThanOrEqual(2); - // Brief A should appear before Brief B (position 0 first) - const textContent = document.body.textContent ?? ''; - expect(textContent.indexOf('Brief A')).toBeLessThan(textContent.indexOf('Brief B')); + // Brief A (position 0) must appear before Brief B (position 1) in DOM order + const briefA = page.getByText('Brief A').element(); + const briefB = page.getByText('Brief B').element(); + expect(briefA.compareDocumentPosition(briefB) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy(); }); });