|
1 | 1 | import { describe, it, expect } from 'vitest'; |
2 | 2 | import { render, screen, fireEvent, waitFor } from '@testing-library/preact'; |
3 | | -import { within } from '@testing-library/preact'; |
4 | 3 | import { http, HttpResponse } from 'msw'; |
5 | 4 | import { server, buildFeedResponse } from './mocks/server'; |
6 | 5 | import { App } from '../components/App'; |
@@ -30,31 +29,37 @@ describe('App contract', () => { |
30 | 29 | }) |
31 | 30 | ); |
32 | 31 | }), |
33 | | - http.get('/api/v1/feeds/generated-token', () => |
34 | | - HttpResponse.text( |
35 | | - `<?xml version="1.0"?><rss><channel><title>Contract Feed</title><item><title>Contract Item</title></item></channel></rss>` |
36 | | - ) |
37 | | - ) |
| 32 | + http.get('/api/v1/feeds/generated-token', ({ request }) => { |
| 33 | + expect(request.headers.get('accept')).toBe('application/feed+json'); |
| 34 | + |
| 35 | + return HttpResponse.json( |
| 36 | + { |
| 37 | + items: [{ title: 'Contract Item' }], |
| 38 | + }, |
| 39 | + { |
| 40 | + headers: { 'content-type': 'application/feed+json' }, |
| 41 | + } |
| 42 | + ); |
| 43 | + }) |
38 | 44 | ); |
39 | 45 |
|
40 | 46 | render(<App />); |
41 | 47 |
|
42 | | - await screen.findByText('Create a feed URL.'); |
| 48 | + await screen.findByLabelText('Page URL'); |
43 | 49 |
|
44 | | - const urlInput = screen.getByLabelText('Source URL') as HTMLInputElement; |
| 50 | + const urlInput = screen.getByLabelText('Page URL') as HTMLInputElement; |
45 | 51 | fireEvent.input(urlInput, { target: { value: 'https://example.com/articles' } }); |
46 | 52 |
|
47 | 53 | fireEvent.click(screen.getByRole('button', { name: 'Generate feed URL' })); |
48 | 54 |
|
49 | 55 | await waitFor(() => { |
50 | | - const resultRegion = document.getElementById('feed-result'); |
51 | | - expect(resultRegion).not.toBeNull(); |
52 | | - const resultQueries = within(resultRegion!); |
53 | | - |
54 | | - expect(screen.getByText('Result')).toBeInTheDocument(); |
55 | 56 | expect(screen.getByText('Example Feed')).toBeInTheDocument(); |
56 | | - expect(resultQueries.getByRole('button', { name: 'Copy feed URL' })).toBeInTheDocument(); |
57 | | - expect(resultQueries.getByRole('link', { name: 'Open feed' })).toBeInTheDocument(); |
| 57 | + expect(screen.getByLabelText('Feed URL')).toBeInTheDocument(); |
| 58 | + expect(screen.getByRole('button', { name: 'Copy feed URL' })).toBeInTheDocument(); |
| 59 | + expect(screen.getByRole('link', { name: 'Open feed' })).toBeInTheDocument(); |
| 60 | + expect(screen.getByRole('button', { name: 'Create another feed' })).toBeInTheDocument(); |
| 61 | + expect(screen.getByText('Feed preview')).toBeInTheDocument(); |
| 62 | + expect(screen.getByText('Contract Item')).toBeInTheDocument(); |
58 | 63 | }); |
59 | 64 | }); |
60 | 65 | }); |
0 commit comments