aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/src/components/FeedList.test.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/components/FeedList.test.tsx')
-rw-r--r--frontend/src/components/FeedList.test.tsx39
1 files changed, 31 insertions, 8 deletions
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(
<BrowserRouter>
@@ -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(