@@ -6,39 +6,41 @@ import { ResultDisplay } from '../components/ResultDisplay';
66describe ( 'ResultDisplay' , ( ) => {
77 const mockOnCreateAnother = vi . fn ( ) ;
88 const mockResult = {
9- id : 'test-id' ,
10- name : 'Test Feed' ,
11- url : 'https://example.com' ,
12- strategy : 'faraday' ,
13- feed_token : 'test-feed-token' ,
14- public_url : 'https://example.com/feed.xml' ,
15- json_public_url : 'https://example.com/feed.json' ,
9+ feed : {
10+ id : 'test-id' ,
11+ name : 'Test Feed' ,
12+ url : 'https://example.com' ,
13+ strategy : 'faraday' ,
14+ feed_token : 'test-feed-token' ,
15+ public_url : 'https://example.com/feed.xml' ,
16+ json_public_url : 'https://example.com/feed.json' ,
17+ } ,
18+ preview : {
19+ items : [
20+ {
21+ title : 'Item One' ,
22+ excerpt : 'First preview item with markup.' ,
23+ url : 'https://example.com/item-one' ,
24+ publishedLabel : 'Jan 1, 2024' ,
25+ } ,
26+ {
27+ title : '56 points by canpan 1 hour ago | hide | 18 comments' ,
28+ excerpt : '' ,
29+ publishedLabel : 'Jan 2, 2024' ,
30+ } ,
31+ {
32+ title : 'Item Two' ,
33+ excerpt : '' ,
34+ url : 'https://example.com/item-two' ,
35+ publishedLabel : 'Jan 3, 2024' ,
36+ } ,
37+ ] ,
38+ error : null ,
39+ } ,
1640 } ;
1741
1842 beforeEach ( ( ) => {
1943 vi . clearAllMocks ( ) ;
20- vi . spyOn ( window , 'fetch' ) . mockResolvedValue ( {
21- ok : true ,
22- json : async ( ) => ( {
23- items : [
24- {
25- title : 'Item One' ,
26- content_text : '<p>First preview item with <strong>markup</strong>.</p>' ,
27- url : 'https://example.com/item-one' ,
28- date_published : '2024-01-01T00:00:00Z' ,
29- } ,
30- {
31- content_text : '56 points by canpan 1 hour ago | hide | 18 comments' ,
32- date_published : '2024-01-02T00:00:00Z' ,
33- } ,
34- {
35- content_text : '2. Item Two ( example.com )' ,
36- url : 'https://example.com/item-two' ,
37- date_published : '2024-01-03T00:00:00Z' ,
38- } ,
39- ] ,
40- } ) ,
41- } as Response ) ;
4244 } ) ;
4345
4446 it ( 'renders the success state actions and richer preview cards' , async ( ) => {
@@ -60,18 +62,15 @@ describe('ResultDisplay', () => {
6062 expect ( screen . getByText ( 'Item Two' ) ) . toBeInTheDocument ( ) ;
6163 expect ( screen . getByText ( 'Latest items from this feed' ) ) . toBeInTheDocument ( ) ;
6264 } ) ;
63- expect ( window . fetch ) . toHaveBeenCalledWith ( 'https://example.com/feed.xml' , {
64- headers : { Accept : 'application/feed+json' } ,
65- } ) ;
6665 } ) ;
6766
68- it ( 'surfaces preview fetch failures as a result-state message' , async ( ) => {
69- vi . mocked ( window . fetch ) . mockResolvedValueOnce ( {
70- ok : false ,
71- json : async ( ) => ( { } ) ,
72- } as Response ) ;
73-
74- render ( < ResultDisplay result = { mockResult } onCreateAnother = { mockOnCreateAnother } /> ) ;
67+ it ( 'surfaces preview failures as a result-state message' , async ( ) => {
68+ render (
69+ < ResultDisplay
70+ result = { { ... mockResult , preview : { items : [ ] , error : 'Preview unavailable right now.' } } }
71+ onCreateAnother = { mockOnCreateAnother }
72+ />
73+ ) ;
7574
7675 await waitFor ( ( ) => {
7776 expect ( screen . getByText ( 'Preview unavailable right now.' ) ) . toBeInTheDocument ( ) ;
0 commit comments