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 }) }));
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user