-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathResultDisplay.test.tsx
More file actions
98 lines (86 loc) · 3.41 KB
/
ResultDisplay.test.tsx
File metadata and controls
98 lines (86 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { render, screen, fireEvent, waitFor } from '@testing-library/preact';
import { h } from 'preact';
import { ResultDisplay } from '../components/ResultDisplay';
describe('ResultDisplay', () => {
const mockOnCreateAnother = vi.fn();
const mockResult = {
feed: {
id: 'test-id',
name: 'Test Feed',
url: 'https://example.com',
strategy: 'faraday',
feed_token: 'test-feed-token',
public_url: 'https://example.com/feed.xml',
json_public_url: 'https://example.com/feed.json',
},
preview: {
items: [
{
title: 'Item One',
excerpt: 'First preview item with markup.',
url: 'https://example.com/item-one',
publishedLabel: 'Jan 1, 2024',
},
{
title: '56 points by canpan 1 hour ago | hide | 18 comments',
excerpt: '',
publishedLabel: 'Jan 2, 2024',
},
{
title: 'Item Two',
excerpt: '',
url: 'https://example.com/item-two',
publishedLabel: 'Jan 3, 2024',
},
],
error: null,
},
};
beforeEach(() => {
vi.clearAllMocks();
});
it('renders the success state actions and richer preview cards', async () => {
render(<ResultDisplay result={mockResult} onCreateAnother={mockOnCreateAnother} />);
expect(screen.getByText('Your feed is ready')).toBeInTheDocument();
expect(screen.getByText('Test Feed')).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Copy feed URL' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Open feed' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Open JSON Feed' })).toHaveAttribute(
'href',
'https://example.com/feed.json'
);
await waitFor(() => {
expect(screen.getByText('Item One')).toBeInTheDocument();
expect(screen.getByText('First preview item with markup.')).toBeInTheDocument();
expect(screen.getAllByText('Open original')).toHaveLength(2);
expect(screen.getByText(/points by canpan/i)).toBeInTheDocument();
expect(screen.getByText('Item Two')).toBeInTheDocument();
expect(screen.getByText('Latest items from this feed')).toBeInTheDocument();
});
});
it('surfaces preview failures as a result-state message', async () => {
render(
<ResultDisplay
result={{ ...mockResult, preview: { items: [], error: 'Preview unavailable right now.' } }}
onCreateAnother={mockOnCreateAnother}
/>
);
await waitFor(() => {
expect(screen.getByText('Preview unavailable right now.')).toBeInTheDocument();
expect(screen.getByText('Latest items from this feed')).toBeInTheDocument();
});
});
it('calls onCreateAnother when the reset button is clicked', () => {
render(<ResultDisplay result={mockResult} onCreateAnother={mockOnCreateAnother} />);
fireEvent.click(screen.getByRole('button', { name: 'Create another feed' }));
expect(mockOnCreateAnother).toHaveBeenCalled();
});
it('copies feed URL to clipboard when copy button is clicked', async () => {
render(<ResultDisplay result={mockResult} onCreateAnother={mockOnCreateAnother} />);
fireEvent.click(screen.getByRole('button', { name: 'Copy feed URL' }));
await waitFor(() => {
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('https://example.com/feed.xml');
});
});
});