X-Git-Url: http://jaekl.net/gitweb/?p=quanweb.git;a=blobdiff_plain;f=js%2Ftest%2FBooksModelTest.js;fp=js%2Ftest%2FBooksModelTest.js;h=38997e4b2ef27f9503ea13c904e963db0a702a3b;hp=0000000000000000000000000000000000000000;hb=13efcb823cde095d5562ac061ef5a859d91c0f70;hpb=222a53b5def154dcc59dbaad98404ea2930e8434 diff --git a/js/test/BooksModelTest.js b/js/test/BooksModelTest.js new file mode 100644 index 0000000..38997e4 --- /dev/null +++ b/js/test/BooksModelTest.js @@ -0,0 +1,49 @@ +'use strict'; + +describe('Scroll forward should not advance beyond end', function() { + var bm = BooksModel; + var calledRefreshData; + + // [first, last, pageSize, count, setting, expectFirst, expectLast, expectRefresh] + data = [ [ 0, 19 , 20, 100, 20, 20 , 39 , true ], + [ 0, 19 , 20, 100, 100, 80 , 99 , true ], + [ 0, 19 , 20, 100, 80, 80 , 99 , true ], + [ 0, 19 , 20, 100, 79, 79 , 98 , true ], + [ 79, 99 , 20, 100, 50, 50 , 69 , true ], + [ 0, 11 , 20, 12, 19, 0 , 11 , false ], + [ 0, (-1), 20, 0, 20, 0 , (-1), false ] + ]; + + function doTest(datum) { + bm.first = datum[0]; + bm.last = datum[1]; + bm.pageSize = datum[2]; + bm.count = datum[3]; + + var oldFunc = bm.refreshData; + calledRefreshData = false; + try { + bm.refreshData = function() { + calledRefreshData = true; + }; + + bm.adjustPos(datum[4]); + } + finally { + bm.refreshData = oldFunc; + } + } + + it('should stay within valid range, and call refreshData() if bm.first changes', function() { + var i = 4; + for (i = 0; i < data.length; i += 1) { + datum = data[i]; + doTest(datum); + expect(bm.first).toBe(datum[5]); + expect(bm.last).toBe(datum[6]); + expect(calledRefreshData).toBe(datum[7]); + } + }); +}); + +