Skip to content

Commit 0f4ffe7

Browse files
committed
Appease the test coverage gods[1]
Add some separate, light tests for `connectionFromArraySlice` and `connectionFromPromisedArraySlice`, rather than relying on them being tested indirectly (via `connectionFromArray` and `connectionFromPromisedArray`). Additionally, consolidated all the `arrayconnection.js` tests in a single file. [1]: At least, I think this will appease them.
1 parent 0629f94 commit 0f4ffe7

File tree

2 files changed

+189
-75
lines changed

2 files changed

+189
-75
lines changed

src/connection/__tests__/arrayconnection.js

Lines changed: 189 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ import { expect } from 'chai';
1313

1414
import {
1515
connectionFromArray,
16+
connectionFromArraySlice,
17+
connectionFromPromisedArray,
18+
connectionFromPromisedArraySlice,
1619
cursorForObjectInConnection,
1720
} from '../arrayconnection';
1821

19-
var letters = ['A', 'B', 'C', 'D', 'E'];
2022
describe('connectionFromArray', () => {
23+
var letters = ['A', 'B', 'C', 'D', 'E'];
24+
2125
describe('Handles basic slicing', () => {
2226
it('Returns all elements without filters', () => {
2327
var c = connectionFromArray(letters, {});
@@ -589,3 +593,187 @@ describe('connectionFromArray', () => {
589593
});
590594
});
591595
});
596+
597+
describe('connectionFromPromisedArray', () => {
598+
var letters = Promise.resolve(['A', 'B', 'C', 'D', 'E']);
599+
600+
it('Returns all elements without filters', async () => {
601+
var c = await connectionFromPromisedArray(letters, {});
602+
return expect(c).to.deep.equal({
603+
edges: [
604+
{
605+
node: 'A',
606+
cursor: 'YXJyYXljb25uZWN0aW9uOjA=',
607+
},
608+
{
609+
node: 'B',
610+
cursor: 'YXJyYXljb25uZWN0aW9uOjE=',
611+
},
612+
{
613+
node: 'C',
614+
cursor: 'YXJyYXljb25uZWN0aW9uOjI=',
615+
},
616+
{
617+
node: 'D',
618+
cursor: 'YXJyYXljb25uZWN0aW9uOjM=',
619+
},
620+
{
621+
node: 'E',
622+
cursor: 'YXJyYXljb25uZWN0aW9uOjQ=',
623+
},
624+
],
625+
pageInfo: {
626+
startCursor: 'YXJyYXljb25uZWN0aW9uOjA=',
627+
endCursor: 'YXJyYXljb25uZWN0aW9uOjQ=',
628+
hasPreviousPage: false,
629+
hasNextPage: false,
630+
}
631+
});
632+
});
633+
634+
it('Respects a smaller first', async () => {
635+
var c = await connectionFromPromisedArray(letters, {first: 2});
636+
return expect(c).to.deep.equal({
637+
edges: [
638+
{ node: 'A',
639+
cursor: 'YXJyYXljb25uZWN0aW9uOjA=',
640+
},
641+
{
642+
node: 'B',
643+
cursor: 'YXJyYXljb25uZWN0aW9uOjE=',
644+
},
645+
],
646+
pageInfo: {
647+
startCursor: 'YXJyYXljb25uZWN0aW9uOjA=',
648+
endCursor: 'YXJyYXljb25uZWN0aW9uOjE=',
649+
hasPreviousPage: false,
650+
hasNextPage: true,
651+
}
652+
});
653+
});
654+
});
655+
656+
describe('connectionFromArraySlice', () => {
657+
var letters = ['A', 'B', 'C', 'D', 'E'];
658+
659+
it('Works with a just-right array slice', () => {
660+
var c = connectionFromArraySlice(
661+
letters.slice(1, 3),
662+
{
663+
first: 2,
664+
after: 'YXJyYXljb25uZWN0aW9uOjA=',
665+
},
666+
{
667+
sliceStart: 1,
668+
arrayLength: 5,
669+
}
670+
);
671+
return expect(c).to.deep.equal({
672+
edges: [
673+
{
674+
node: 'B',
675+
cursor: 'YXJyYXljb25uZWN0aW9uOjE=',
676+
},
677+
{
678+
node: 'C',
679+
cursor: 'YXJyYXljb25uZWN0aW9uOjI=',
680+
},
681+
],
682+
pageInfo: {
683+
startCursor: 'YXJyYXljb25uZWN0aW9uOjE=',
684+
endCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
685+
hasPreviousPage: false,
686+
hasNextPage: true,
687+
}
688+
});
689+
});
690+
691+
it('Works with an oversized array slice', () => {
692+
return
693+
var c = connectionFromArraySlice(
694+
letters.slice(1, 4),
695+
{
696+
first: 1,
697+
after: 'YXJyYXljb25uZWN0aW9uOjI=',
698+
},
699+
{
700+
sliceStart: 1,
701+
arrayLength: 5,
702+
}
703+
);
704+
return expect(c).to.deep.equal({
705+
edges: [
706+
{
707+
node: 'C',
708+
cursor: 'YXJyYXljb25uZWN0aW9uOjI=',
709+
},
710+
],
711+
pageInfo: {
712+
startCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
713+
endCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
714+
hasPreviousPage: false,
715+
hasNextPage: true,
716+
}
717+
});
718+
});
719+
720+
it('Works with an undersized array slice', () => {
721+
return
722+
var c = connectionFromArraySlice(
723+
letters.slice(2, 3),
724+
{
725+
first: 3,
726+
after: 'YXJyYXljb25uZWN0aW9uOjE=',
727+
},
728+
{
729+
sliceStart: 2,
730+
arrayLength: 5,
731+
}
732+
);
733+
return expect(c).to.deep.equal({
734+
edges: [
735+
{
736+
node: 'C',
737+
cursor: 'YXJyYXljb25uZWN0aW9uOjI=',
738+
},
739+
],
740+
pageInfo: {
741+
startCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
742+
endCursor: 'YXJyYXljb25uZWN0aW9uOjI=',
743+
hasPreviousPage: false,
744+
hasNextPage: true,
745+
}
746+
});
747+
});
748+
});
749+
750+
describe('connectionFromPromisedArraySlice', () => {
751+
it('Respects a smaller first', async () => {
752+
var letters = Promise.resolve(['A', 'B', 'C']);
753+
var c = await connectionFromPromisedArraySlice(
754+
letters,
755+
{first: 2},
756+
{
757+
sliceStart: 0,
758+
arrayLength: 5,
759+
}
760+
);
761+
return expect(c).to.deep.equal({
762+
edges: [
763+
{ node: 'A',
764+
cursor: 'YXJyYXljb25uZWN0aW9uOjA=',
765+
},
766+
{
767+
node: 'B',
768+
cursor: 'YXJyYXljb25uZWN0aW9uOjE=',
769+
},
770+
],
771+
pageInfo: {
772+
startCursor: 'YXJyYXljb25uZWN0aW9uOjA=',
773+
endCursor: 'YXJyYXljb25uZWN0aW9uOjE=',
774+
hasPreviousPage: false,
775+
hasNextPage: true,
776+
}
777+
});
778+
});
779+
});

src/connection/__tests__/asyncarrayconnection.js

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)