refactor(journey-editor): fix fragile ordering assertion with compareDocumentPosition
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 <noreply@anthropic.com>
This commit is contained in:
@@ -70,11 +70,10 @@ describe('JourneyEditor — items in position order', () => {
|
|||||||
];
|
];
|
||||||
render(JourneyEditor, defaultProps({ geschichte: makeGeschichte({ items }) }));
|
render(JourneyEditor, defaultProps({ geschichte: makeGeschichte({ items }) }));
|
||||||
|
|
||||||
const titles = await page.getByText(/Brief [AB]/).all();
|
// Brief A (position 0) must appear before Brief B (position 1) in DOM order
|
||||||
expect(titles.length).toBeGreaterThanOrEqual(2);
|
const briefA = page.getByText('Brief A').element();
|
||||||
// Brief A should appear before Brief B (position 0 first)
|
const briefB = page.getByText('Brief B').element();
|
||||||
const textContent = document.body.textContent ?? '';
|
expect(briefA.compareDocumentPosition(briefB) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||||
expect(textContent.indexOf('Brief A')).toBeLessThan(textContent.indexOf('Brief B'));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user