2
0
mirror of https://github.com/koreader/koreader synced 2024-11-10 01:10:34 +00:00
koreader/spec/unit/readerpaging_spec.lua
chrox 9ab005a1d3 fix unit test of readerlink and readerpaging
and have more confidence with the unit testing framework.

Now `make testfront` won't retry on failure and testing files are
ordered in each run so that it's possible to reproduce testing failure.

And this patch also fix flush settings not working before suspend issue:
at some point the `FlushSettings` event is sent to `UIManager` instead
of `ReaderUI`, but `UIManager` only delegated events to active widgets
and `ReaderUI` is actually not an active widgets thus will miss the event.

This patch also add a verbose debug mode with "-v" as a switch to turn
on this mode. With verbose mode on, event handling will be logged.
2016-08-12 17:05:07 +08:00

73 lines
2.5 KiB
Lua

describe("Readerpaging module", function()
local sample_pdf = "spec/front/unit/data/sample.pdf"
local readerui, UIManager, Event
local paging
setup(function()
require("commonrequire")
UIManager = require("ui/uimanager")
Event = require("ui/event")
end)
describe("Page mode", function()
setup(function()
readerui = require("apps/reader/readerui"):new{
document = require("document/documentregistry"):openDocument(sample_pdf),
}
paging = readerui.paging
end)
it("should emit EndOfBook event at the end", function()
UIManager:quit()
UIManager:show(readerui)
UIManager:scheduleIn(1, function() UIManager:close(readerui) end)
UIManager:run()
readerui:handleEvent(Event:new("SetScrollMode", false))
readerui.zooming:setZoomMode("pageheight")
paging:onGotoPage(readerui.document:getPageCount())
local called = false
readerui.onEndOfBook = function()
called = true
end
paging:onPagingRel(1)
assert.is.truthy(called)
readerui.onEndOfBook = nil
UIManager:quit()
end)
end)
describe("Scroll mode", function()
setup(function()
local purgeDir = require("ffi/util").purgeDir
local DocSettings = require("docsettings")
purgeDir(DocSettings:getSidecarDir(sample_pdf))
os.remove(DocSettings:getHistoryPath(sample_pdf))
readerui = require("apps/reader/readerui"):new{
document = require("document/documentregistry"):openDocument(sample_pdf),
}
paging = readerui.paging
end)
it("should emit EndOfBook event at the end", function()
UIManager:quit()
UIManager:show(readerui)
UIManager:scheduleIn(1, function() UIManager:close(readerui) end)
UIManager:run()
paging.page_positions = {}
readerui:handleEvent(Event:new("SetScrollMode", true))
paging:onGotoPage(readerui.document:getPageCount())
readerui.zooming:setZoomMode("pageheight")
local called = false
readerui.onEndOfBook = function()
called = true
end
paging:onPagingRel(1)
paging:onPagingRel(1)
assert.is.truthy(called)
readerui.onEndOfBook = nil
UIManager:quit()
end)
end)
end)