test(briefwechsel): expand CorrespondenzPersonBar coverage
Adds receiver-focus triggers correspondents fetch, advanced-filter chevron rotation in both states. 3 new tests covering ~6 branches. Refs #496. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -92,4 +92,53 @@ describe('CorrespondenzPersonBar', () => {
|
|||||||
|
|
||||||
expect(onswapPersons).toHaveBeenCalledOnce();
|
expect(onswapPersons).toHaveBeenCalledOnce();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('opens the suggestions dropdown on receiver focus when a senderId is set', async () => {
|
||||||
|
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
|
||||||
|
new Response(JSON.stringify([{ id: 'p3', firstName: 'Carl', lastName: 'Brandt' }]), {
|
||||||
|
status: 200,
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
})
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
render(CorrespondenzPersonBar, {
|
||||||
|
props: baseProps({ senderId: 'p1', receiverId: '' })
|
||||||
|
});
|
||||||
|
|
||||||
|
// Find the second PersonTypeahead input (Korrespondent) and trigger focus event
|
||||||
|
const inputs = document.querySelectorAll('input[type="text"]');
|
||||||
|
const corrInput = inputs[inputs.length - 1] as HTMLInputElement;
|
||||||
|
corrInput.dispatchEvent(new Event('focus', { bubbles: true }));
|
||||||
|
|
||||||
|
await new Promise((r) => setTimeout(r, 100));
|
||||||
|
// No assertion on the suggestions dropdown UI (component-internal),
|
||||||
|
// just confirm the fetch was made
|
||||||
|
expect(fetchSpy).toHaveBeenCalled();
|
||||||
|
} finally {
|
||||||
|
fetchSpy.mockRestore();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not show advanced filter chevron rotation when showAdvanced is false', async () => {
|
||||||
|
render(CorrespondenzPersonBar, { props: baseProps({ showAdvanced: false }) });
|
||||||
|
|
||||||
|
// The filter toggle button has a chevron — should NOT be rotated
|
||||||
|
const buttons = document.querySelectorAll('button');
|
||||||
|
const filterBtn = Array.from(buttons).find((b) =>
|
||||||
|
b.textContent?.toLowerCase().includes('filter')
|
||||||
|
);
|
||||||
|
const chevron = filterBtn?.querySelector('img');
|
||||||
|
expect(chevron?.getAttribute('class')).not.toContain('rotate-180');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rotates the filter chevron when showAdvanced is true', async () => {
|
||||||
|
render(CorrespondenzPersonBar, { props: baseProps({ showAdvanced: true }) });
|
||||||
|
|
||||||
|
const buttons = document.querySelectorAll('button');
|
||||||
|
const filterBtn = Array.from(buttons).find((b) =>
|
||||||
|
b.textContent?.toLowerCase().includes('filter')
|
||||||
|
);
|
||||||
|
const chevron = filterBtn?.querySelector('img');
|
||||||
|
expect(chevron?.getAttribute('class')).toContain('rotate-180');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user