Skip to content

Commit a63a7be

Browse files
committed
Add a few more tests
Explicitly test the case where the slice is oversized/undersized on the left/right.
1 parent 8f0fc3b commit a63a7be

File tree

1 file changed

+128
-4
lines changed

1 file changed

+128
-4
lines changed

src/connection/__tests__/arrayconnection.js

Lines changed: 128 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,67 @@ describe('connectionFromArraySlice()', () => {
688688
});
689689
});
690690

691-
it('works with an oversized array slice', () => {
691+
it('works with an oversized array slice ("left" side)', () => {
692+
var c = connectionFromArraySlice(
693+
letters.slice(0, 3),
694+
{
695+
first: 2,
696+
after: 'YXJyYXljb25uZWN0aW9uOjA=',
697+
},
698+
{
699+
sliceStart: 0,
700+
arrayLength: 5,
701+
}
702+
);
703+
return expect(c).to.deep.equal({
704+
edges: [
705+
{
706+
node: 'B',
707+
cursor: 'YXJyYXljb25uZWN0aW9uOjE=',
708+
},
709+
{
710+
node: 'C',
711+
cursor: 'YXJyYXljb25uZWN0aW9uOjI=',
712+
},
713+
],
714+
pageInfo: {
715+
startCursor: 'YXJyYXljb25uZWN0aW9uOjE=',
716+
endCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
717+
hasPreviousPage: false,
718+
hasNextPage: true,
719+
}
720+
});
721+
});
722+
723+
it('works with an oversized array slice ("right" side)', () => {
724+
var c = connectionFromArraySlice(
725+
letters.slice(2, 4),
726+
{
727+
first: 1,
728+
after: 'YXJyYXljb25uZWN0aW9uOjE=',
729+
},
730+
{
731+
sliceStart: 2,
732+
arrayLength: 5,
733+
}
734+
);
735+
return expect(c).to.deep.equal({
736+
edges: [
737+
{
738+
node: 'C',
739+
cursor: 'YXJyYXljb25uZWN0aW9uOjI=',
740+
},
741+
],
742+
pageInfo: {
743+
startCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
744+
endCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
745+
hasPreviousPage: false,
746+
hasNextPage: true,
747+
}
748+
});
749+
});
750+
751+
it('works with an oversized array slice (both sides)', () => {
692752
var c = connectionFromArraySlice(
693753
letters.slice(1, 4),
694754
{
@@ -716,9 +776,41 @@ describe('connectionFromArraySlice()', () => {
716776
});
717777
});
718778

719-
it('works with an undersized array slice', () => {
779+
it('works with an undersized array slice ("left" side)', () => {
720780
var c = connectionFromArraySlice(
721-
letters.slice(2, 3),
781+
letters.slice(3, 5),
782+
{
783+
first: 3,
784+
after: 'YXJyYXljb25uZWN0aW9uOjE=',
785+
},
786+
{
787+
sliceStart: 3,
788+
arrayLength: 5,
789+
}
790+
);
791+
return expect(c).to.deep.equal({
792+
edges: [
793+
{
794+
node: 'D',
795+
cursor: 'YXJyYXljb25uZWN0aW9uOjM=',
796+
},
797+
{
798+
node: 'E',
799+
cursor: 'YXJyYXljb25uZWN0aW9uOjQ=',
800+
},
801+
],
802+
pageInfo: {
803+
startCursor: 'YXJyYXljb25uZWN0aW9uOjM=',
804+
endCursor: 'YXJyYXljb25uZWN0aW9uOjQ=',
805+
hasPreviousPage: false,
806+
hasNextPage: false,
807+
}
808+
});
809+
});
810+
811+
it('works with an undersized array slice ("right" side)', () => {
812+
var c = connectionFromArraySlice(
813+
letters.slice(2, 4),
722814
{
723815
first: 3,
724816
after: 'YXJyYXljb25uZWN0aW9uOjE=',
@@ -734,10 +826,42 @@ describe('connectionFromArraySlice()', () => {
734826
node: 'C',
735827
cursor: 'YXJyYXljb25uZWN0aW9uOjI=',
736828
},
829+
{
830+
node: 'D',
831+
cursor: 'YXJyYXljb25uZWN0aW9uOjM=',
832+
},
737833
],
738834
pageInfo: {
739835
startCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
740-
endCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
836+
endCursor: 'YXJyYXljb25uZWN0aW9uOjM=',
837+
hasPreviousPage: false,
838+
hasNextPage: true,
839+
}
840+
});
841+
});
842+
843+
it('works with an undersized array slice (both sides)', () => {
844+
var c = connectionFromArraySlice(
845+
letters.slice(3, 4),
846+
{
847+
first: 3,
848+
after: 'YXJyYXljb25uZWN0aW9uOjE=',
849+
},
850+
{
851+
sliceStart: 3,
852+
arrayLength: 5,
853+
}
854+
);
855+
return expect(c).to.deep.equal({
856+
edges: [
857+
{
858+
node: 'D',
859+
cursor: 'YXJyYXljb25uZWN0aW9uOjM=',
860+
},
861+
],
862+
pageInfo: {
863+
startCursor: 'YXJyYXljb25uZWN0aW9uOjM=',
864+
endCursor: 'YXJyYXljb25uZWN0aW9uOjM=',
741865
hasPreviousPage: false,
742866
hasNextPage: true,
743867
}

0 commit comments

Comments
 (0)