@@ -347,41 +347,87 @@ describe('connectionResolver', () => {
347
347
348
348
describe ( '"Relay Cursor Connections Specification (PageInfo)":' , ( ) => {
349
349
describe ( 'HasPreviousPage' , ( ) => {
350
- it ( 'If last was not set (but first is present ), return false.' , ( ) => {
351
- expect ( preparePageInfo ( fiveEdges , { first : 2 } , 5 , 2 ) . hasPreviousPage ) . toBe ( false ) ;
350
+ it ( 'If first is set (and after is empty ), return false.' , ( ) => {
351
+ expect ( preparePageInfo ( fiveEdges , { first : 4 } , 4 , 0 ) . hasPreviousPage ) . toBe ( false ) ;
352
352
} ) ;
353
- it ( 'If last was not set (and first is empty), return true.' , ( ) => {
354
- expect ( preparePageInfo ( fiveEdges , { } , 5 , 2 ) . hasPreviousPage ) . toBe ( true ) ;
353
+ it ( 'If first is set (and after is present), return true.' , ( ) => {
354
+ expect ( preparePageInfo ( fiveEdges , { first : 4 , after : 'abc' } , 4 , 0 ) . hasPreviousPage ) . toBe (
355
+ true
356
+ ) ;
355
357
} ) ;
356
- it ( 'If last was not set (but after is present), return true.' , ( ) => {
357
- expect ( preparePageInfo ( fiveEdges , { after : 'abc' } , 5 , 0 ) . hasPreviousPage ) . toBe ( true ) ;
358
+ it ( 'If last is set (and before is empty), and edges contains more than last elements, return true.' , ( ) => {
359
+ // if `first` is empty and `last` is set, `first` will be assigned according to count of edges targeted
360
+ expect ( preparePageInfo ( fiveEdges , { first : 10 , last : 5 } , 5 , 5 ) . hasPreviousPage ) . toBe (
361
+ true
362
+ ) ;
358
363
} ) ;
359
- it ( 'If edges contains more than last elements, return true.' , ( ) => {
360
- expect ( preparePageInfo ( fiveEdges , { last : 3 } , 3 , 2 ) . hasPreviousPage ) . toBe ( true ) ;
364
+ it ( 'If last is set (and before is empty), and edges contains no more than last elements, return false.' , ( ) => {
365
+ expect ( preparePageInfo ( fiveEdges , { first : 5 , last : 5 } , 5 , 0 ) . hasPreviousPage ) . toBe (
366
+ false
367
+ ) ;
361
368
} ) ;
362
- it ( 'Return false' , ( ) => {
363
- expect ( preparePageInfo ( fiveEdges , { last : 5 } , 5 , 0 ) . hasPreviousPage ) . toBe ( false ) ;
369
+ it ( 'If last is set (and before is present), and edges contains more than last elements, return true.' , ( ) => {
370
+ expect (
371
+ preparePageInfo ( fiveEdges , { first : 10 , last : 4 , before : 'abc' } , 4 , 6 ) . hasPreviousPage
372
+ ) . toBe ( true ) ;
373
+ } ) ;
374
+ it ( 'If last is set (and before is present), and edges contains no more than last elements, return false.' , ( ) => {
375
+ expect (
376
+ preparePageInfo ( fiveEdges , { first : 4 , last : 4 , before : 'abc' } , 4 , 0 ) . hasPreviousPage
377
+ ) . toBe ( false ) ;
378
+ } ) ;
379
+ it ( 'If both first and last are set, and edges contains more than last elements, return true.' , ( ) => {
380
+ expect ( preparePageInfo ( fiveEdges , { first : 10 , last : 4 } , 4 , 6 ) . hasPreviousPage ) . toBe (
381
+ true
382
+ ) ;
383
+ } ) ;
384
+ it ( 'If both first and last are set, and edges contains no more than last elements, return true.' , ( ) => {
385
+ expect ( preparePageInfo ( fiveEdges , { first : 4 , last : 4 } , 4 , 0 ) . hasPreviousPage ) . toBe (
386
+ false
387
+ ) ;
364
388
} ) ;
365
389
} ) ;
366
390
367
391
describe ( 'HasNextPage' , ( ) => {
368
- it ( 'If first was not set (and last is empty), return true.' , ( ) => {
392
+ it ( 'If first was not set (and last is empty), and there is more edges, return true.' , ( ) => {
369
393
// By current Relay Cursor Connections Specification
370
394
// if `first` and `last` are empty `hasNextPage` should be false.
371
395
// This rule is deviation from specification for better dev experience:
372
396
// when first and last args are empty
373
397
// we should check if exist more edges and provide correct `hasNextPage` value.
374
398
expect ( preparePageInfo ( fiveEdges , { } , 4 , 0 ) . hasNextPage ) . toBe ( true ) ;
375
399
} ) ;
376
- it ( 'If first was not set (but last is present), return false.' , ( ) => {
377
- expect ( preparePageInfo ( fiveEdges , { last : 200 } , 4 , 0 ) . hasNextPage ) . toBe ( false ) ;
400
+ it ( 'If last is set (and before is empty), return false.' , ( ) => {
401
+ // if `first` is empty and `last` is set, `first` will be assigned according to count of edges targeted
402
+ expect ( preparePageInfo ( fiveEdges , { first : 10 , last : 5 } , 5 , 5 ) . hasNextPage ) . toBe ( false ) ;
403
+ } ) ;
404
+ it ( 'If last is set (and before is present), return true.' , ( ) => {
405
+ expect (
406
+ preparePageInfo ( fiveEdges , { first : 10 , last : 4 , before : 'abc' } , 4 , 6 ) . hasNextPage
407
+ ) . toBe ( true ) ;
378
408
} ) ;
379
- it ( 'If edges contains more than first elements, return true.' , ( ) => {
409
+ it ( 'If first is set (and after is empty), and edges contains more than first elements, return true.' , ( ) => {
380
410
expect ( preparePageInfo ( fiveEdges , { first : 4 } , 4 , 0 ) . hasNextPage ) . toBe ( true ) ;
381
411
} ) ;
382
- it ( 'Return false' , ( ) => {
412
+ it ( 'If first is set (and after is empty), and edges contains no more than first elements, return false. ' , ( ) => {
383
413
expect ( preparePageInfo ( fiveEdges , { first : 5 } , 5 , 0 ) . hasNextPage ) . toBe ( false ) ;
384
414
} ) ;
415
+ it ( 'If first is set (and after is present), and edges contains more than first elements, return true.' , ( ) => {
416
+ expect ( preparePageInfo ( fiveEdges , { first : 4 , after : 'abc' } , 4 , 0 ) . hasNextPage ) . toBe (
417
+ true
418
+ ) ;
419
+ } ) ;
420
+ it ( 'If first is set (and after is present), and edges contains no more than first elements, return false.' , ( ) => {
421
+ expect ( preparePageInfo ( fiveEdges , { first : 5 , after : 'abc' } , 5 , 0 ) . hasNextPage ) . toBe (
422
+ false
423
+ ) ;
424
+ } ) ;
425
+ it ( 'If both first and last are set, and edges contains more than first elements, return true.' , ( ) => {
426
+ expect ( preparePageInfo ( fiveEdges , { first : 10 , last : 4 } , 4 , 6 ) . hasNextPage ) . toBe ( true ) ;
427
+ } ) ;
428
+ it ( 'If both first and last are set, and edges contains no more than first elements, return false.' , ( ) => {
429
+ expect ( preparePageInfo ( fiveEdges , { first : 10 , last : 6 } , 6 , 4 ) . hasNextPage ) . toBe ( false ) ;
430
+ } ) ;
385
431
} ) ;
386
432
387
433
it ( 'should return startCursor' , ( ) => {
0 commit comments