Skip to content

Commit 3439bd0

Browse files
committed
Update frontend contract test for new flow
1 parent e8bd90c commit 3439bd0

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

frontend/src/__tests__/App.contract.test.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { describe, it, expect } from 'vitest';
22
import { render, screen, fireEvent, waitFor } from '@testing-library/preact';
3-
import { within } from '@testing-library/preact';
43
import { http, HttpResponse } from 'msw';
54
import { server, buildFeedResponse } from './mocks/server';
65
import { App } from '../components/App';
@@ -30,31 +29,37 @@ describe('App contract', () => {
3029
})
3130
);
3231
}),
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+
})
3844
);
3945

4046
render(<App />);
4147

42-
await screen.findByText('Create a feed URL.');
48+
await screen.findByLabelText('Page URL');
4349

44-
const urlInput = screen.getByLabelText('Source URL') as HTMLInputElement;
50+
const urlInput = screen.getByLabelText('Page URL') as HTMLInputElement;
4551
fireEvent.input(urlInput, { target: { value: 'https://example.com/articles' } });
4652

4753
fireEvent.click(screen.getByRole('button', { name: 'Generate feed URL' }));
4854

4955
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();
5556
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();
5863
});
5964
});
6065
});

0 commit comments

Comments
 (0)