2014-10-07 17:09:37 +08:00
|
|
|
describe("Readertoc module", function()
|
2020-07-01 16:17:41 -04:00
|
|
|
local DocumentRegistry, ReaderUI, Screen, DEBUG
|
2017-08-08 22:35:40 +02:00
|
|
|
local readerui, toc, toc_max_depth, title
|
2016-04-18 23:50:36 -07:00
|
|
|
|
|
|
|
|
setup(function()
|
|
|
|
|
require("commonrequire")
|
|
|
|
|
DocumentRegistry = require("document/documentregistry")
|
|
|
|
|
ReaderUI = require("apps/reader/readerui")
|
2020-07-01 16:17:41 -04:00
|
|
|
Screen = require("device").screen
|
2016-04-18 23:50:36 -07:00
|
|
|
DEBUG = require("dbg")
|
|
|
|
|
|
|
|
|
|
local sample_epub = "spec/front/unit/data/juliet.epub"
|
2020-12-19 05:32:23 +01:00
|
|
|
-- Clear settings from previous tests
|
|
|
|
|
local DocSettings = require("docsettings")
|
|
|
|
|
local doc_settings = DocSettings:open(sample_epub)
|
|
|
|
|
doc_settings:close()
|
|
|
|
|
doc_settings:purge()
|
|
|
|
|
|
2016-04-18 23:50:36 -07:00
|
|
|
readerui = ReaderUI:new{
|
2020-07-01 16:17:41 -04:00
|
|
|
dimen = Screen:getSize(),
|
2016-04-18 23:50:36 -07:00
|
|
|
document = DocumentRegistry:openDocument(sample_epub),
|
|
|
|
|
}
|
2017-05-16 02:11:11 -07:00
|
|
|
-- reset book to first page
|
|
|
|
|
readerui.rolling:onGotoPage(0)
|
2016-04-18 23:50:36 -07:00
|
|
|
toc = readerui.toc
|
|
|
|
|
end)
|
|
|
|
|
|
2014-10-07 17:09:37 +08:00
|
|
|
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()
|
2018-12-05 13:01:49 +01:00
|
|
|
title = toc:getTocTitleByPage(60)
|
2015-09-05 11:32:34 +02:00
|
|
|
DEBUG("toc", toc.toc)
|
2019-04-25 23:33:47 +02:00
|
|
|
assert.is.equal("SCENE V. A hall in Capulet's house.", title)
|
2019-11-22 23:54:34 +01:00
|
|
|
title = toc:getTocTitleByPage(187)
|
2019-04-25 23:33:47 +02:00
|
|
|
assert.is.equal("SCENE I. Friar Laurence's cell.", title)
|
2014-10-07 17:09:37 +08:00
|
|
|
end)
|
|
|
|
|
describe("getTocTicks API", function()
|
|
|
|
|
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 21:10:07 +08: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 17:09:37 +08:00
|
|
|
local ticks_level_m1 = nil
|
|
|
|
|
it("should get ticks of level -1", function()
|
2014-10-11 21:10:07 +08:00
|
|
|
ticks_level_m1 = toc:getTocTicks(-1)
|
|
|
|
|
assert.are.same(26, #ticks_level_m1)
|
2014-10-07 17:09:37 +08:00
|
|
|
end)
|
2014-10-11 21:10:07 +08:00
|
|
|
it("should get the same ticks of level -1 and level 2", function()
|
2014-10-07 17:09:37 +08:00
|
|
|
if toc_max_depth == 2 then
|
2014-10-11 21:10:07 +08:00
|
|
|
assert.are.same(ticks_level_2, ticks_level_m1)
|
2014-10-07 17:09:37 +08:00
|
|
|
end
|
|
|
|
|
end)
|
2020-09-27 22:25:16 +02:00
|
|
|
local ticks_level_flat = nil
|
|
|
|
|
it("should get all ticks (flattened)", function()
|
|
|
|
|
ticks_level_flat = toc:getTocTicksFlattened()
|
|
|
|
|
assert.are.same(28, #ticks_level_flat)
|
|
|
|
|
end)
|
2014-10-07 17:09:37 +08:00
|
|
|
end)
|
|
|
|
|
it("should get page of next chapter", function()
|
2020-09-27 22:25:16 +02:00
|
|
|
assert.truthy(toc:getNextChapter(10) > 10)
|
|
|
|
|
assert.truthy(toc:getNextChapter(100) > 100)
|
|
|
|
|
assert.are.same(nil, toc:getNextChapter(290))
|
2014-10-07 17:09:37 +08:00
|
|
|
end)
|
|
|
|
|
it("should get page of previous chapter", function()
|
2020-09-27 22:25:16 +02:00
|
|
|
assert.truthy(toc:getPreviousChapter(10) < 10)
|
|
|
|
|
assert.truthy(toc:getPreviousChapter(100) < 100)
|
|
|
|
|
assert.truthy(toc:getPreviousChapter(200) < 200)
|
2014-10-07 17:09:37 +08:00
|
|
|
end)
|
|
|
|
|
it("should get page left of chapter", function()
|
2020-09-27 22:25:16 +02:00
|
|
|
assert.truthy(toc:getChapterPagesLeft(10) > 10)
|
|
|
|
|
assert.truthy(toc:getChapterPagesLeft(95) > 10)
|
|
|
|
|
assert.are.same(nil, toc:getChapterPagesLeft(290))
|
2014-10-07 17:09:37 +08:00
|
|
|
end)
|
2014-10-07 17:43:48 +08:00
|
|
|
it("should get page done of chapter", function()
|
2020-09-27 22:25:16 +02:00
|
|
|
assert.truthy(toc:getChapterPagesDone(11) < 5)
|
|
|
|
|
assert.truthy(toc:getChapterPagesDone(88) < 5)
|
|
|
|
|
assert.truthy(toc:getChapterPagesDone(290) > 10)
|
2014-10-07 17:43:48 +08:00
|
|
|
end)
|
2014-10-14 21:33:13 +08: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)
|
2020-12-19 05:32:23 +01:00
|
|
|
|
|
|
|
|
--- @note: Delay the teardown 'til the last test, because of course the tests rely on incremental state changes across tests...
|
|
|
|
|
readerui:closeDocument()
|
|
|
|
|
readerui:onClose()
|
2014-10-14 21:33:13 +08:00
|
|
|
end)
|
|
|
|
|
end)
|
2014-10-07 17:09:37 +08:00
|
|
|
end)
|