2016-02-22 01:46:19 +00:00
|
|
|
describe("Readerpaging module", function()
|
|
|
|
local sample_pdf = "spec/front/unit/data/sample.pdf"
|
2016-11-24 02:48:00 +00:00
|
|
|
local readerui, UIManager, Event, DocumentRegistry, ReaderUI
|
2016-02-22 01:46:19 +00:00
|
|
|
local paging
|
|
|
|
|
2016-08-12 06:05:18 +00:00
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
|
|
|
UIManager = require("ui/uimanager")
|
|
|
|
Event = require("ui/event")
|
2016-11-24 02:48:00 +00:00
|
|
|
DocumentRegistry = require("document/documentregistry")
|
|
|
|
ReaderUI = require("apps/reader/readerui")
|
2016-08-12 06:05:18 +00:00
|
|
|
end)
|
2016-02-22 01:46:19 +00:00
|
|
|
|
|
|
|
describe("Page mode", function()
|
|
|
|
setup(function()
|
2016-11-24 02:48:00 +00:00
|
|
|
readerui = ReaderUI:new{
|
|
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
2016-02-22 01:46:19 +00:00
|
|
|
}
|
|
|
|
paging = readerui.paging
|
|
|
|
end)
|
|
|
|
|
2016-08-12 06:05:18 +00:00
|
|
|
it("should emit EndOfBook event at the end", function()
|
|
|
|
UIManager:quit()
|
|
|
|
UIManager:show(readerui)
|
2017-05-16 09:11:11 +00:00
|
|
|
UIManager:nextTick(function() UIManager:close(readerui) end)
|
2016-08-12 06:05:18 +00:00
|
|
|
UIManager:run()
|
2016-07-18 06:12:53 +00:00
|
|
|
readerui:handleEvent(Event:new("SetScrollMode", false))
|
2016-02-22 01:46:19 +00:00
|
|
|
readerui.zooming:setZoomMode("pageheight")
|
2016-03-27 22:39:47 +00:00
|
|
|
paging:onGotoPage(readerui.document:getPageCount())
|
2016-02-22 01:46:19 +00:00
|
|
|
local called = false
|
|
|
|
readerui.onEndOfBook = function()
|
|
|
|
called = true
|
|
|
|
end
|
2019-03-01 15:05:03 +00:00
|
|
|
paging:onGotoViewRel(1)
|
2016-02-22 01:46:19 +00:00
|
|
|
assert.is.truthy(called)
|
|
|
|
readerui.onEndOfBook = nil
|
2016-08-12 06:05:18 +00:00
|
|
|
UIManager:quit()
|
2016-07-18 06:12:53 +00:00
|
|
|
end)
|
2016-02-22 01:46:19 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe("Scroll mode", function()
|
|
|
|
setup(function()
|
2016-04-19 06:50:36 +00:00
|
|
|
local purgeDir = require("ffi/util").purgeDir
|
|
|
|
local DocSettings = require("docsettings")
|
|
|
|
purgeDir(DocSettings:getSidecarDir(sample_pdf))
|
|
|
|
os.remove(DocSettings:getHistoryPath(sample_pdf))
|
|
|
|
|
2016-11-24 02:48:00 +00:00
|
|
|
readerui = ReaderUI:new{
|
|
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
2016-02-22 01:46:19 +00:00
|
|
|
}
|
|
|
|
paging = readerui.paging
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should emit EndOfBook event at the end", function()
|
2016-08-12 06:05:18 +00:00
|
|
|
UIManager:quit()
|
|
|
|
UIManager:show(readerui)
|
2017-05-16 09:11:11 +00:00
|
|
|
UIManager:nextTick(function() UIManager:close(readerui) end)
|
2016-08-12 06:05:18 +00:00
|
|
|
UIManager:run()
|
|
|
|
paging.page_positions = {}
|
|
|
|
readerui:handleEvent(Event:new("SetScrollMode", true))
|
2016-03-27 22:39:47 +00:00
|
|
|
paging:onGotoPage(readerui.document:getPageCount())
|
2016-02-22 01:46:19 +00:00
|
|
|
readerui.zooming:setZoomMode("pageheight")
|
|
|
|
local called = false
|
|
|
|
readerui.onEndOfBook = function()
|
|
|
|
called = true
|
|
|
|
end
|
2019-03-01 15:05:03 +00:00
|
|
|
paging:onGotoViewRel(1)
|
|
|
|
paging:onGotoViewRel(1)
|
2016-02-22 01:46:19 +00:00
|
|
|
assert.is.truthy(called)
|
|
|
|
readerui.onEndOfBook = nil
|
2016-08-12 06:05:18 +00:00
|
|
|
UIManager:quit()
|
2016-02-22 01:46:19 +00:00
|
|
|
end)
|
2016-11-24 02:48:00 +00:00
|
|
|
|
2017-05-16 09:11:11 +00:00
|
|
|
it("should scroll backward on the first page without crash", function()
|
2016-11-24 02:48:00 +00:00
|
|
|
local sample_djvu = "spec/front/unit/data/djvu3spec.djvu"
|
|
|
|
local tmp_readerui = ReaderUI:new{
|
|
|
|
document = DocumentRegistry:openDocument(sample_djvu),
|
|
|
|
}
|
|
|
|
tmp_readerui.paging:onScrollPanRel(-100)
|
|
|
|
end)
|
|
|
|
|
2017-05-16 09:11:11 +00:00
|
|
|
it("should scroll forward on the last page without crash", function()
|
2016-11-24 02:48:00 +00:00
|
|
|
local sample_djvu = "spec/front/unit/data/djvu3spec.djvu"
|
|
|
|
local tmp_readerui = ReaderUI:new{
|
|
|
|
document = DocumentRegistry:openDocument(sample_djvu),
|
|
|
|
}
|
2017-08-08 20:35:40 +00:00
|
|
|
paging = tmp_readerui.paging
|
2016-11-24 02:48:00 +00:00
|
|
|
paging:onGotoPage(tmp_readerui.document:getPageCount())
|
|
|
|
paging:onScrollPanRel(120)
|
|
|
|
paging:onScrollPanRel(-1)
|
|
|
|
paging:onScrollPanRel(120)
|
|
|
|
end)
|
2016-02-22 01:46:19 +00:00
|
|
|
end)
|
|
|
|
end)
|