fix: pages feature now works properly

This commit is contained in:
2026-02-16 08:15:02 +01:00
parent 9440c5e543
commit 9bab8ac89c
4 changed files with 139 additions and 10 deletions

View File

@@ -2175,6 +2175,19 @@ Published content`);
const result = await postEngine.searchPosts('nonexistent');
expect(result).toEqual([]);
});
it('should cap search results at 500', async () => {
mockLocalClient.execute.mockResolvedValueOnce({ rows: [] });
await postEngine.searchPosts('term');
expect(mockLocalClient.execute).toHaveBeenCalled();
const call = vi.mocked(mockLocalClient.execute).mock.calls[0]?.[0] as { sql?: string } | undefined;
expect(call?.sql).toBeDefined();
const sql = call?.sql?.toLowerCase() ?? '';
expect(sql).toContain('limit 500');
expect(sql).not.toMatch(/\blimit\s+50\b/);
});
});
describe('getTagsWithCounts', () => {

View File

@@ -77,6 +77,9 @@ describe('Pages shortcut UI', () => {
it('shows only page-category posts when pages view is active', async () => {
useAppStore.setState({ activeView: 'pages', sidebarVisible: true });
window.electronAPI.posts.filter = vi.fn().mockResolvedValue([
createMockPost({ id: 'post-page', title: 'About Page', categories: ['page'] }),
]);
render(<Sidebar />);
@@ -87,4 +90,70 @@ describe('Pages shortcut UI', () => {
expect(within(pagesPanel as HTMLElement).getByText('About Page')).toBeInTheDocument();
expect(within(pagesPanel as HTMLElement).queryByText('Regular Article')).not.toBeInTheDocument();
});
it('loads pages subset from full table and does not require load-more pagination', async () => {
useAppStore.setState({
activeView: 'pages',
sidebarVisible: true,
posts: [
createMockPost({
id: 'post-article-only',
title: 'Loaded Article',
categories: ['article'],
}),
],
hasMorePosts: true,
totalPosts: 1200,
});
window.electronAPI.posts.filter = vi.fn().mockResolvedValue([
createMockPost({ id: 'post-page-remote', title: 'Remote Page', categories: ['page'] }),
]);
render(<Sidebar />);
const pagesHeader = await screen.findByText('PAGES');
const pagesPanel = pagesHeader.closest('.sidebar-content') as HTMLElement;
expect(within(pagesPanel).getByText('Remote Page')).toBeInTheDocument();
expect(within(pagesPanel).queryByText('Loaded Article')).not.toBeInTheDocument();
expect(within(pagesPanel).queryByText(/Load more/i)).not.toBeInTheDocument();
expect(window.electronAPI.posts.filter).toHaveBeenCalledWith({ categories: ['page'] });
});
it('does not prefetch pages subset while posts view is active', async () => {
useAppStore.setState({
activeView: 'posts',
sidebarVisible: true,
posts: [
createMockPost({ id: 'post-1', title: 'Loaded Post', categories: ['article'] }),
],
hasMorePosts: true,
totalPosts: 1200,
});
window.electronAPI.posts.filter = vi.fn().mockResolvedValue([
createMockPost({ id: 'post-page-remote', title: 'Remote Page', categories: ['page'] }),
]);
render(<Sidebar />);
expect(await screen.findByText('POSTS')).toBeInTheDocument();
expect(window.electronAPI.posts.filter).not.toHaveBeenCalledWith({ categories: ['page'] });
});
it('uses a flex-height wrapper for active posts/pages sidebar view', async () => {
useAppStore.setState({
activeView: 'posts',
sidebarVisible: true,
posts: [createMockPost({ id: 'post-1', title: 'Loaded Post', categories: ['article'] })],
});
const { container } = render(<Sidebar />);
expect(await screen.findByText('POSTS')).toBeInTheDocument();
const wrappers = container.querySelectorAll('.sidebar > div');
expect(wrappers.length).toBeGreaterThanOrEqual(2);
expect((wrappers[0] as HTMLElement).style.display).toBe('flex');
});
});