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/TagView.test.tsx | 81 ++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 frontend/src/components/TagView.test.tsx (limited to 'frontend/src/components/TagView.test.tsx') diff --git a/frontend/src/components/TagView.test.tsx b/frontend/src/components/TagView.test.tsx new file mode 100644 index 0000000..8a724cd --- /dev/null +++ b/frontend/src/components/TagView.test.tsx @@ -0,0 +1,81 @@ +import React from 'react'; +import { render, screen, waitFor } from '@testing-library/react'; +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { MemoryRouter, Route, Routes } from 'react-router-dom'; +import FeedList from './FeedList'; +import FeedItems from './FeedItems'; + +describe('Tag View Integration', () => { + beforeEach(() => { + vi.resetAllMocks(); + global.fetch = vi.fn(); + }); + + it('renders tags in FeedList and navigates to tag view', async () => { + const mockFeeds = [{ _id: 1, title: 'Feed 1', url: 'http://example.com/rss', category: 'Tech' }]; + const mockTags = [{ title: 'Tech' }, { title: 'News' }]; + + (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 () => mockTags, + }); + } + return Promise.reject(new Error(`Unknown URL: ${url}`)); + }); + + render( + + + + ); + + await waitFor(() => { + const techTags = screen.getAllByText('Tech'); + expect(techTags.length).toBeGreaterThan(0); + expect(screen.getByText('News')).toBeInTheDocument(); + }); + + // Verify structure + const techTag = screen.getByText('News').closest('a'); + expect(techTag).toHaveAttribute('href', '/tag/News'); + }); + + it('fetches items by tag in FeedItems', async () => { + const mockItems = [ + { _id: 101, title: 'Tag Item 1', url: 'http://example.com/1', feed_title: 'Feed 1' } + ]; + + (global.fetch as any).mockImplementation((url: string) => { + if (url.includes('/api/stream')) { + return Promise.resolve({ + ok: true, + json: async () => mockItems, + }); + } + return Promise.reject(new Error(`Unknown URL: ${url}`)); + }); + + render( + + + } /> + + + ); + + await waitFor(() => { + expect(screen.getByText('Tag: Tech')).toBeInTheDocument(); + expect(screen.getByText('Tag Item 1')).toBeInTheDocument(); + }); + + expect(global.fetch).toHaveBeenCalledWith('/api/stream?tag=Tech'); + }); +}); -- cgit v1.2.3