test(person): replace 7 setTimeout sleeps in AddRelationshipForm with vi.waitFor

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-11 17:34:19 +02:00
committed by marcel
parent 910f890c75
commit 1035527278
2 changed files with 38 additions and 44 deletions

View File

@@ -79,7 +79,6 @@ describe('StammbaumSidePanel', () => {
props: { node: baseNode(), onClose: () => {} }
});
// no years line visible — should not see the question-mark fallback
expect(document.body.textContent).not.toMatch(/\?\?/);
});
@@ -128,20 +127,19 @@ describe('StammbaumSidePanel', () => {
props: { node: baseNode(), onClose: () => {} }
});
await new Promise((r) => setTimeout(r, 100));
await expect.element(page.getByText(/keine beziehungen bekannt/i)).toBeVisible();
});
it('shows the error banner when both fetch calls fail', async () => {
fetchSpy.mockResolvedValue(new Response('error', { status: 500 }));
fetchSpy.mockImplementation(async () => new Response('error', { status: 500 }));
render(StammbaumSidePanel, {
props: { node: baseNode(), onClose: () => {} }
});
await new Promise((r) => setTimeout(r, 100));
const alert = document.querySelector('[role="alert"]');
expect(alert).not.toBeNull();
await vi.waitFor(() => {
expect(document.querySelector('[role="alert"]')).not.toBeNull();
});
});
it('shows the AddRelationshipForm only when canWrite is true', async () => {
@@ -149,12 +147,12 @@ describe('StammbaumSidePanel', () => {
props: { node: baseNode(), onClose: () => {}, canWrite: true }
});
await new Promise((r) => setTimeout(r, 100));
// AddRelationshipForm exposes a "Beziehung hinzufügen" toggle button
const addButtons = Array.from(document.querySelectorAll('button')).filter((b) =>
b.textContent?.toLowerCase().includes('hinzufügen')
);
expect(addButtons.length).toBeGreaterThan(0);
await vi.waitFor(() => {
const addButtons = Array.from(document.querySelectorAll('button')).filter((b) =>
b.textContent?.toLowerCase().includes('hinzufügen')
);
expect(addButtons.length).toBeGreaterThan(0);
});
});
it('hides the AddRelationshipForm when canWrite is false', async () => {
@@ -162,7 +160,7 @@ describe('StammbaumSidePanel', () => {
props: { node: baseNode(), onClose: () => {}, canWrite: false }
});
await new Promise((r) => setTimeout(r, 100));
// canWrite=false hides the form — assert the toggle button is absent in the rendered DOM.
const addButtons = Array.from(document.querySelectorAll('button')).filter((b) =>
b.textContent?.toLowerCase().includes('hinzufügen')
);