2014-10-07 09:09:37 +00:00
|
|
|
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
|
|
|
|
it("should get max toc depth", function()
|
|
|
|
toc_max_depth = toc:getMaxDepth()
|
|
|
|
assert.are.same(2, toc_max_depth)
|
|
|
|
end)
|
|
|
|
it("should get toc title from page", function()
|
2014-11-18 08:08:39 +00:00
|
|
|
local title = toc:getTocTitleByPage(54)
|
|
|
|
--DEBUG("toc", toc.toc)
|
2014-10-07 09:09:37 +00:00
|
|
|
assert(title == "Prologue")
|
2014-11-18 08:08:39 +00:00
|
|
|
local title = toc:getTocTitleByPage(162)
|
2014-10-07 09:09:37 +00:00
|
|
|
assert(title == "SCENE IV. Hall in Capulet's house.")
|
|
|
|
end)
|
|
|
|
describe("getTocTicks API", function()
|
|
|
|
local ticks_level_0 = nil
|
|
|
|
it("should get ticks of level 0", function()
|
|
|
|
ticks_level_0 = toc:getTocTicks(0)
|
2014-10-14 13:33:13 +00:00
|
|
|
--DEBUG("ticks", ticks_level_0)
|
2014-10-11 13:10:07 +00:00
|
|
|
assert.are.same(28, #ticks_level_0)
|
2014-10-07 09:09:37 +00:00
|
|
|
end)
|
|
|
|
local ticks_level_1 = nil
|
|
|
|
it("should get ticks of level 1", function()
|
|
|
|
ticks_level_1 = toc:getTocTicks(1)
|
|
|
|
assert.are.same(7, #ticks_level_1)
|
|
|
|
end)
|
2014-10-11 13:10:07 +00:00
|
|
|
local ticks_level_2 = nil
|
|
|
|
it("should get ticks of level 2", function()
|
|
|
|
ticks_level_2 = toc:getTocTicks(2)
|
|
|
|
assert.are.same(26, #ticks_level_2)
|
|
|
|
end)
|
2014-10-07 09:09:37 +00:00
|
|
|
local ticks_level_m1 = nil
|
|
|
|
it("should get ticks of level -1", function()
|
2014-10-11 13:10:07 +00:00
|
|
|
ticks_level_m1 = toc:getTocTicks(-1)
|
|
|
|
assert.are.same(26, #ticks_level_m1)
|
2014-10-07 09:09:37 +00:00
|
|
|
end)
|
2014-10-11 13:10:07 +00:00
|
|
|
it("should get the same ticks of level -1 and level 2", function()
|
2014-10-07 09:09:37 +00:00
|
|
|
if toc_max_depth == 2 then
|
2014-10-11 13:10:07 +00:00
|
|
|
assert.are.same(ticks_level_2, ticks_level_m1)
|
2014-10-07 09:09:37 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
it("should get page of next chapter", function()
|
2014-11-18 08:08:39 +00:00
|
|
|
assert.are.same(23, toc:getNextChapter(10, 0))
|
|
|
|
assert.are.same(112, toc:getNextChapter(100, 0))
|
2014-10-07 09:09:37 +00:00
|
|
|
assert.are.same(nil, toc:getNextChapter(200, 0))
|
|
|
|
end)
|
|
|
|
it("should get page of previous chapter", function()
|
2014-11-18 08:08:39 +00:00
|
|
|
assert.are.same(8, toc:getPreviousChapter(10, 0))
|
|
|
|
assert.are.same(99, toc:getPreviousChapter(100, 0))
|
|
|
|
assert.are.same(181, toc:getPreviousChapter(200, 0))
|
2014-10-07 09:09:37 +00:00
|
|
|
end)
|
|
|
|
it("should get page left of chapter", function()
|
2014-11-18 08:08:39 +00:00
|
|
|
assert.are.same(12, toc:getChapterPagesLeft(10, 0))
|
|
|
|
assert.are.same(11, toc:getChapterPagesLeft(100, 0))
|
2014-10-07 09:09:37 +00:00
|
|
|
assert.are.same(nil, toc:getChapterPagesLeft(200, 0))
|
|
|
|
end)
|
2014-10-07 09:43:48 +00:00
|
|
|
it("should get page done of chapter", function()
|
2014-11-18 08:08:39 +00:00
|
|
|
assert.are.same(2, toc:getChapterPagesDone(10, 0))
|
|
|
|
assert.are.same(1, toc:getChapterPagesDone(100, 0))
|
|
|
|
assert.are.same(19, toc:getChapterPagesDone(200, 0))
|
2014-10-07 09:43:48 +00:00
|
|
|
end)
|
2014-10-14 13:33:13 +00:00
|
|
|
describe("collasible TOC", function()
|
|
|
|
it("should collapse the secondary toc nodes by default", function()
|
|
|
|
toc:onShowToc()
|
|
|
|
assert.are.same(7, #toc.collapsed_toc)
|
|
|
|
end)
|
|
|
|
it("should not expand toc nodes that have no child nodes", function()
|
|
|
|
toc:expandToc(2)
|
|
|
|
assert.are.same(7, #toc.collapsed_toc)
|
|
|
|
end)
|
|
|
|
it("should expand toc nodes that have child nodes", function()
|
|
|
|
toc:expandToc(3)
|
|
|
|
assert.are.same(13, #toc.collapsed_toc)
|
|
|
|
toc:expandToc(18)
|
|
|
|
assert.are.same(18, #toc.collapsed_toc)
|
|
|
|
end)
|
|
|
|
it("should collapse toc nodes that have been expanded", function()
|
|
|
|
toc:collapseToc(3)
|
|
|
|
assert.are.same(12, #toc.collapsed_toc)
|
|
|
|
toc:collapseToc(18)
|
|
|
|
assert.are.same(7, #toc.collapsed_toc)
|
|
|
|
end)
|
|
|
|
end)
|
2014-10-07 09:09:37 +00:00
|
|
|
end)
|