test(routes): expand home page coverage for ?? fallback branches
Adds minimal-data render (default ?? fallbacks), reader-only minimal data, isReader+canBlogWrite drafts module, full data shape populated. 4 new tests covering ~10 branches. Refs #496. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -168,4 +168,64 @@ describe('home page (/)', () => {
|
|||||||
// The page mounts and computes greeting with empty name without throwing
|
// The page mounts and computes greeting with empty name without throwing
|
||||||
expect(document.querySelector('main')).not.toBeNull();
|
expect(document.querySelector('main')).not.toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('renders without throwing when data props are undefined (uses ?? fallbacks)', async () => {
|
||||||
|
const minimalData = {
|
||||||
|
isReader: false,
|
||||||
|
user: { firstName: 'Anna' },
|
||||||
|
canWrite: false,
|
||||||
|
canBlogWrite: false
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(() => render(HomePage, { props: { data: minimalData } })).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders without throwing when reader data has all undefined fields', async () => {
|
||||||
|
const readerData = {
|
||||||
|
isReader: true,
|
||||||
|
user: { firstName: 'Anna' },
|
||||||
|
canBlogWrite: false
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(() => render(HomePage, { props: { data: readerData } })).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders without throwing when isReader and canBlogWrite are both true (drafts module)', async () => {
|
||||||
|
render(HomePage, {
|
||||||
|
props: {
|
||||||
|
data: baseData({
|
||||||
|
isReader: true,
|
||||||
|
canBlogWrite: true,
|
||||||
|
user: { firstName: 'Anna' },
|
||||||
|
readerStats: { totalDocuments: 100, totalPersons: 25, totalStories: 5 },
|
||||||
|
drafts: [
|
||||||
|
{
|
||||||
|
id: 'd1',
|
||||||
|
title: 'Reise nach Berlin',
|
||||||
|
updatedAt: '2026-04-15T10:00:00Z'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const main = document.querySelector('main');
|
||||||
|
expect(main).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders writer dashboard without throwing with weeklyStats + pulse populated', async () => {
|
||||||
|
// Stub-shaped objects that satisfy whichever child components expect them
|
||||||
|
expect(() =>
|
||||||
|
render(HomePage, {
|
||||||
|
props: {
|
||||||
|
data: baseData({
|
||||||
|
isReader: false,
|
||||||
|
user: { firstName: 'Anna' },
|
||||||
|
canWrite: true,
|
||||||
|
incompleteTotal: 25
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
).not.toThrow();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user