From 23a48e1d498680be769e931f46ddb1fd44f38d1a Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Fri, 13 Feb 2026 07:46:58 -0800 Subject: Implement Tag View and fix tests --- frontend/src/components/FeedList.test.tsx | 39 ++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'frontend/src/components/FeedList.test.tsx') diff --git a/frontend/src/components/FeedList.test.tsx b/frontend/src/components/FeedList.test.tsx index 92ff345..eba9b88 100644 --- a/frontend/src/components/FeedList.test.tsx +++ b/frontend/src/components/FeedList.test.tsx @@ -28,9 +28,20 @@ describe('FeedList Component', () => { { _id: 2, title: 'Feed Two', url: 'http://test.com/rss', web_url: 'http://test.com', category: 'News' }, ]; - (global.fetch as any).mockResolvedValueOnce({ - ok: true, - json: async () => mockFeeds, + (global.fetch as any).mockImplementation((url: string) => { + if (url.includes('/api/feed/')) { + return Promise.resolve({ + ok: true, + json: async () => mockFeeds, + }); + } + if (url.includes('/api/tag')) { + return Promise.resolve({ + ok: true, + json: async () => [{ title: 'Tech' }], + }); + } + return Promise.reject(new Error(`Unknown URL: ${url}`)); }); render( @@ -42,12 +53,13 @@ describe('FeedList Component', () => { await waitFor(() => { expect(screen.getByText('Feed One')).toBeInTheDocument(); expect(screen.getByText('Feed Two')).toBeInTheDocument(); - expect(screen.getByText('Tech')).toBeInTheDocument(); + const techElements = screen.getAllByText('Tech'); + expect(techElements.length).toBeGreaterThan(0); }); }); it('handles fetch error', async () => { - (global.fetch as any).mockRejectedValueOnce(new Error('API Error')); + (global.fetch as any).mockImplementation(() => Promise.reject(new Error('API Error'))); render( @@ -61,9 +73,20 @@ describe('FeedList Component', () => { }); it('handles empty feed list', async () => { - (global.fetch as any).mockResolvedValueOnce({ - ok: true, - json: async () => [], + (global.fetch as any).mockImplementation((url: string) => { + if (url.includes('/api/feed/')) { + return Promise.resolve({ + ok: true, + json: async () => [], + }); + } + if (url.includes('/api/tag')) { + return Promise.resolve({ + ok: true, + json: async () => [], + }); + } + return Promise.reject(new Error(`Unknown URL: ${url}`)); }); render( -- cgit v1.2.3