fix all the tests

This commit is contained in:
Qingping Hou
2016-04-18 23:50:36 -07:00
parent a049eddcbc
commit c22a3747d8
24 changed files with 230 additions and 138 deletions

View File

@@ -1,15 +1,20 @@
require("commonrequire")
local DocumentRegistry = require("document/documentregistry")
local ReaderUI = require("apps/reader/readerui")
local DEBUG = require("dbg")
describe("Readertoc module", function()
local sample_epub = "spec/front/unit/data/juliet.epub"
local readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_epub),
}
local toc = readerui.toc
local toc_max_depth = nil
local DocumentRegistry, ReaderUI, DEBUG
local readerui, toc, toc_max_depth
setup(function()
require("commonrequire")
DocumentRegistry = require("document/documentregistry")
ReaderUI = require("apps/reader/readerui")
DEBUG = require("dbg")
local sample_epub = "spec/front/unit/data/juliet.epub"
readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_epub),
}
toc = readerui.toc
end)
it("should get max toc depth", function()
toc_max_depth = toc:getMaxDepth()
assert.are.same(2, toc_max_depth)
@@ -50,24 +55,24 @@ describe("Readertoc module", function()
end)
end)
it("should get page of next chapter", function()
assert.are.same(24, toc:getNextChapter(10, 0))
assert.are.same(113, toc:getNextChapter(100, 0))
assert.are.same(26, toc:getNextChapter(10, 0))
assert.are.same(102, toc:getNextChapter(100, 0))
assert.are.same(nil, toc:getNextChapter(200, 0))
end)
it("should get page of previous chapter", function()
assert.are.same(8, toc:getPreviousChapter(10, 0))
assert.are.same(97, toc:getPreviousChapter(100, 0))
assert.are.same(182, toc:getPreviousChapter(200, 0))
assert.are.same(9, toc:getPreviousChapter(10, 0))
assert.are.same(99, toc:getPreviousChapter(100, 0))
assert.are.same(186, toc:getPreviousChapter(200, 0))
end)
it("should get page left of chapter", function()
assert.are.same(13, toc:getChapterPagesLeft(10, 0))
assert.are.same(12, toc:getChapterPagesLeft(100, 0))
assert.are.same(15, toc:getChapterPagesLeft(10, 0))
assert.are.same(12, toc:getChapterPagesLeft(102, 0))
assert.are.same(nil, toc:getChapterPagesLeft(200, 0))
end)
it("should get page done of chapter", function()
assert.are.same(2, toc:getChapterPagesDone(10, 0))
assert.are.same(0, toc:getChapterPagesDone(100, 0))
assert.are.same(18, toc:getChapterPagesDone(200, 0))
assert.are.same(2, toc:getChapterPagesDone(12, 0))
assert.are.same(0, toc:getChapterPagesDone(99, 0))
assert.are.same(18, toc:getChapterPagesDone(204, 0))
end)
describe("collasible TOC", function()
it("should collapse the secondary toc nodes by default", function()