From 2c3cad528a247c771bca136466337877f76f280f Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Thu, 12 Feb 2026 21:59:55 -0800 Subject: Implement Frontend Feed List with tests --- frontend/src/components/FeedList.test.tsx | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 frontend/src/components/FeedList.test.tsx (limited to 'frontend/src/components/FeedList.test.tsx') diff --git a/frontend/src/components/FeedList.test.tsx b/frontend/src/components/FeedList.test.tsx new file mode 100644 index 0000000..578e3c2 --- /dev/null +++ b/frontend/src/components/FeedList.test.tsx @@ -0,0 +1,61 @@ +import React from 'react'; +import '@testing-library/jest-dom'; +import { render, screen, waitFor } from '@testing-library/react'; +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import FeedList from './FeedList'; + +describe('FeedList Component', () => { + beforeEach(() => { + vi.resetAllMocks(); + global.fetch = vi.fn(); + }); + + it('renders loading state initially', () => { + (global.fetch as any).mockImplementation(() => new Promise(() => { })); + render(); + expect(screen.getByText(/loading feeds/i)).toBeInTheDocument(); + }); + + it('renders list of feeds', async () => { + const mockFeeds = [ + { _id: 1, title: 'Feed One', url: 'http://example.com/rss', web_url: 'http://example.com', category: 'Tech' }, + { _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, + }); + + render(); + + await waitFor(() => { + expect(screen.getByText('Feed One')).toBeInTheDocument(); + expect(screen.getByText('Feed Two')).toBeInTheDocument(); + expect(screen.getByText('Tech')).toBeInTheDocument(); + }); + }); + + it('handles fetch error', async () => { + (global.fetch as any).mockRejectedValueOnce(new Error('API Error')); + + render(); + + await waitFor(() => { + expect(screen.getByText(/error: api error/i)).toBeInTheDocument(); + }); + }); + + it('handles empty feed list', async () => { + (global.fetch as any).mockResolvedValueOnce({ + ok: true, + json: async () => [], + }); + + render(); + + await waitFor(() => { + expect(screen.getByText(/no feeds found/i)).toBeInTheDocument(); + }); + }); +}); -- cgit v1.2.3