@@ -192,7 +192,7 @@ describe('useStacSearch', () => {
192192 expect ( postPayload ) . toEqual ( response . links [ 0 ] . body ) ;
193193 } ) ;
194194
195- it ( 'includes nextPage callback' , async ( ) => {
195+ it ( 'includes previousPage callback' , async ( ) => {
196196 const response = {
197197 links : [ {
198198 rel : 'prev' ,
@@ -225,4 +225,38 @@ describe('useStacSearch', () => {
225225 expect ( result . current . results ) . toEqual ( { data : '12345' } ) ;
226226 expect ( postPayload ) . toEqual ( response . links [ 0 ] . body ) ;
227227 } ) ;
228+
229+ it ( 'includes previousPage callback (previous edition)' , async ( ) => {
230+ const response = {
231+ links : [ {
232+ rel : 'previous' ,
233+ type : 'application/geo+json' ,
234+ method : 'POST' ,
235+ href : 'https://example.com/stac/search' ,
236+ body : {
237+ limit : 25 ,
238+ token : 'prev:abc123'
239+ }
240+ } ]
241+ } ;
242+ fetch . mockResponseOnce ( JSON . stringify ( response ) ) ;
243+
244+ const { result, waitForNextUpdate } = renderHook (
245+ ( ) => useStacSearch ( stacApi )
246+ ) ;
247+
248+ act ( ( ) => result . current . setDateRangeTo ( '2022-05-17' ) ) ;
249+ act ( ( ) => result . current . submit ( ) ) ;
250+ await waitForNextUpdate ( ) ; // wait to set results
251+ expect ( result . current . results ) . toEqual ( response ) ;
252+ expect ( result . current . previousPage ) . toBeDefined ( ) ;
253+
254+ fetch . mockResponseOnce ( JSON . stringify ( { data : '12345' } ) ) ;
255+ act ( ( ) => result . current . previousPage && result . current . previousPage ( ) ) ;
256+ await waitForNextUpdate ( ) ;
257+
258+ const postPayload = parseRequestPayload ( fetch . mock . calls [ 1 ] [ 1 ] ) ;
259+ expect ( result . current . results ) . toEqual ( { data : '12345' } ) ;
260+ expect ( postPayload ) . toEqual ( response . links [ 0 ] . body ) ;
261+ } ) ;
228262} ) ;
0 commit comments