test(briefwechsel): convert 3 .not.toThrow to localStorage / container assertions
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -114,41 +114,50 @@ describe('briefwechsel/+ page', () => {
|
||||
expect(document.body.textContent).toContain('Brief 1');
|
||||
});
|
||||
|
||||
it('persists the recent person when senderName is set after navigation', async () => {
|
||||
// localStorage mock — confirm no throw on parsing/writing path
|
||||
it('writes the senderName to localStorage when sender filter is set on mount', async () => {
|
||||
localStorage.removeItem('korrespondenz_recent_persons');
|
||||
expect(() =>
|
||||
render(BriefwechselPage, {
|
||||
props: {
|
||||
data: baseData({
|
||||
filters: { senderId: 'p1', receiverId: '', from: '', to: '', dir: 'DESC' },
|
||||
initialValues: { senderName: 'Anna Schmidt', receiverName: '' }
|
||||
})
|
||||
}
|
||||
})
|
||||
).not.toThrow();
|
||||
render(BriefwechselPage, {
|
||||
props: {
|
||||
data: baseData({
|
||||
filters: { senderId: 'p1', receiverId: '', from: '', to: '', dir: 'DESC' },
|
||||
initialValues: { senderName: 'Anna Schmidt', receiverName: '' }
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
// persistRecentPerson runs in onMount — the persisted entry must include the name.
|
||||
await vi.waitFor(() => {
|
||||
const stored = localStorage.getItem('korrespondenz_recent_persons');
|
||||
expect(stored).toContain('Anna Schmidt');
|
||||
});
|
||||
});
|
||||
|
||||
it('handles malformed localStorage data gracefully on mount', async () => {
|
||||
it('falls back to an empty recent-persons list when localStorage is malformed', async () => {
|
||||
localStorage.setItem('korrespondenz_recent_persons', 'not-json');
|
||||
expect(() =>
|
||||
render(BriefwechselPage, {
|
||||
props: { data: baseData() }
|
||||
})
|
||||
).not.toThrow();
|
||||
render(BriefwechselPage, {
|
||||
props: { data: baseData() }
|
||||
});
|
||||
|
||||
// Page still mounts; the malformed entry must not break rendering. The page renders
|
||||
// a max-w-7xl container at the root.
|
||||
expect(document.querySelector('.max-w-7xl')).not.toBeNull();
|
||||
localStorage.removeItem('korrespondenz_recent_persons');
|
||||
});
|
||||
|
||||
it('renders without throwing when senderName is set (persistRecentPerson path)', async () => {
|
||||
expect(() =>
|
||||
render(BriefwechselPage, {
|
||||
props: {
|
||||
data: baseData({
|
||||
filters: { senderId: 'p-test', receiverId: '', from: '', to: '', dir: 'DESC' },
|
||||
initialValues: { senderName: 'Test Person', receiverName: '' }
|
||||
})
|
||||
}
|
||||
})
|
||||
).not.toThrow();
|
||||
it('appends the senderName when only sender is set on mount (persistRecentPerson path)', async () => {
|
||||
localStorage.removeItem('korrespondenz_recent_persons');
|
||||
render(BriefwechselPage, {
|
||||
props: {
|
||||
data: baseData({
|
||||
filters: { senderId: 'p-test', receiverId: '', from: '', to: '', dir: 'DESC' },
|
||||
initialValues: { senderName: 'Test Person', receiverName: '' }
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
const stored = localStorage.getItem('korrespondenz_recent_persons');
|
||||
expect(stored).toContain('Test Person');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user