Skip to content

Commit 524a137

Browse files
committed
add more test to the pagination related methods in woql.js
1 parent 036937d commit 524a137

File tree

1 file changed

+122
-11
lines changed

1 file changed

+122
-11
lines changed

test/woqlQuery.spec.js

Lines changed: 122 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,17 @@ describe('pre-roll queries', function () {
306306
const woqlObject=WOQL.limit(2).start(0);
307307
//console.log(JSON.stringify(woqlObject.getDocumentConnections("docid").json()));
308308
const jsonObj={ limit: [ 2, { start: [ 0, { "and": [
309+
{ "or": [
310+
{ "triple": [
311+
"doc:docid",
312+
"v:Outgoing",
313+
"v:Entid"
314+
] },
315+
{ "triple": [ "v:Entid",
316+
"v:Incoming",
317+
{ "@language": "en", "@value": "docid" },
318+
] },
319+
] },
309320
{ "isa": [ "v:Entid", "v:Enttype"] },
310321
{ "sub": [ "v:Enttype", "tcs:Document"] },
311322
{ "opt": [ { "triple": [
@@ -320,16 +331,7 @@ describe('pre-roll queries', function () {
320331
"db:schema"
321332
] } ] }
322333
],
323-
"or": [
324-
{ "triple": [
325-
"doc:docid",
326-
"v:Outgoing",
327-
"v:Entid"] },
328-
{ "triple": [
329-
"v:Entid",
330-
"v:Incoming",
331-
{ "@language": "en", "@value": "docid" }] },
332-
] } ] } ] };
334+
} ] } ] };
333335

334336
expect(woqlObject.getDocumentConnections("docid").json()).to.eql(jsonObj);
335337

@@ -467,11 +469,120 @@ describe('woql query object', function () {
467469

468470
const woqlObjectTrue=WOQL.limit(2).start(0);
469471
const woqlObjectFalse=WOQL.select("V1", WOQL.triple("a", "b", "c"));
470-
console.log(woqlObjectFalse.isPaged());
471472

472473
expect(woqlObjectTrue.isPaged()).to.eql(true);
473474
expect(woqlObjectFalse.isPaged()).to.eql(false);
474475

475476
})
476477

478+
it('check the getPaged method',function(){
479+
global.sandbox.stub(axios, "get").returns(Promise.resolve({status:200, data: {}}));
480+
481+
const woqlObject=WOQL.limit(2).start(0);
482+
const woqlObject2=WOQL.limit(3).start(10);
483+
const woqlObject3=WOQL.limit(2).start(10);
484+
485+
expect(woqlObject.getPage()).to.eql(1);
486+
expect(woqlObject2.getPage()).to.eql(4);
487+
expect(woqlObject3.getPage()).to.eql(6);
488+
489+
})
490+
491+
it('check the setPage method',function(){
492+
global.sandbox.stub(axios, "get").returns(Promise.resolve({status:200, data: {}}));
493+
494+
const woqlObject=WOQL.limit(2).start(0);
495+
496+
const jsonObj={ limit: [ 2, { start: [ 2, {} ] } ] };
497+
498+
expect(woqlObject.setPage(2).json()).to.eql(jsonObj);
499+
500+
})
501+
502+
it('check the nextPage method',function(){
503+
global.sandbox.stub(axios, "get").returns(Promise.resolve({status:200, data: {}}));
504+
505+
const woqlObject=WOQL.limit(2).start(0);
506+
507+
const jsonObj={ limit: [ 2, { start: [ 2, {} ] } ] };
508+
509+
expect(woqlObject.nextPage().json()).to.eql(jsonObj);
510+
511+
})
512+
513+
it('check the firstPage method',function(){
514+
global.sandbox.stub(axios, "get").returns(Promise.resolve({status:200, data: {}}));
515+
516+
const woqlObject=WOQL.limit(2).start(2);
517+
518+
const jsonObj={ limit: [ 2, { start: [ 0, {} ] } ] };
519+
520+
expect(woqlObject.firstPage().json()).to.eql(jsonObj);
521+
522+
})
523+
524+
it('check the previousPage method',function(){
525+
global.sandbox.stub(axios, "get").returns(Promise.resolve({status:200, data: {}}));
526+
527+
const woqlObject=WOQL.limit(2).start(4);
528+
529+
const jsonObj={ limit: [ 2, { start: [ 2, {} ] } ] };
530+
531+
expect(woqlObject.previousPage().json()).to.eql(jsonObj);
532+
533+
})
534+
535+
it('check the setPageSize method',function(){
536+
global.sandbox.stub(axios, "get").returns(Promise.resolve({status:200, data: {}}));
537+
538+
const woqlObject=WOQL.limit(2).start(0);
539+
540+
const jsonObj={ limit: [ 3, { start: [ 0, {} ] } ] };
541+
542+
expect(woqlObject.setPageSize(3).json()).to.eql(jsonObj);
543+
544+
})
545+
546+
it('check the setPageSize not first method',function(){
547+
global.sandbox.stub(axios, "get").returns(Promise.resolve({status:200, data: {}}));
548+
549+
const woqlObject=WOQL.limit(2).start(10);
550+
551+
const jsonObj={ limit: [ 3, { start: [ 10, {} ] } ] };
552+
553+
expect(woqlObject.setPageSize(3).json()).to.eql(jsonObj);
554+
555+
})
556+
557+
it('check the addStart method',function(){
558+
global.sandbox.stub(axios, "get").returns(Promise.resolve({status:200, data: {}}));
559+
560+
const woqlObject=WOQL.limit(2).start(10);
561+
562+
const jsonObj={ limit: [ 2, { start: [ 11, {} ] } ] };
563+
564+
expect(woqlObject.addStart(1).json()).to.eql(jsonObj);
565+
566+
})
567+
568+
it('check the hasStart method',function(){
569+
global.sandbox.stub(axios, "get").returns(Promise.resolve({status:200, data: {}}));
570+
571+
const woqlObjectTrue=WOQL.limit(2).start(10);
572+
const woqlObjectFalse=WOQL.limit(2);
573+
574+
expect(woqlObjectTrue.hasStart()).to.eql(true);
575+
expect(woqlObjectFalse.hasStart()).to.eql(false);
576+
577+
})
578+
579+
it('check the getStart method',function(){
580+
global.sandbox.stub(axios, "get").returns(Promise.resolve({status:200, data: {}}));
581+
582+
const woqlObject=WOQL.limit(2).start(10);
583+
584+
expect(woqlObject.getStart()).to.eql(10);
585+
586+
})
587+
477588
});

0 commit comments

Comments
 (0)