2014-10-10 10:12:25 +00:00
|
|
|
describe("Readerrolling module", function()
|
2020-07-01 20:17:41 +00:00
|
|
|
local DocumentRegistry, ReaderUI, Event, Screen
|
2016-04-19 06:50:36 +00:00
|
|
|
local readerui, rolling
|
|
|
|
|
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
|
|
|
DocumentRegistry = require("document/documentregistry")
|
|
|
|
ReaderUI = require("apps/reader/readerui")
|
|
|
|
Event = require("ui/event")
|
2020-07-01 20:17:41 +00:00
|
|
|
Screen = require("device").screen
|
2016-04-19 06:50:36 +00:00
|
|
|
|
|
|
|
local sample_epub = "spec/front/unit/data/juliet.epub"
|
|
|
|
readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2016-04-19 06:50:36 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_epub),
|
|
|
|
}
|
|
|
|
rolling = readerui.rolling
|
|
|
|
end)
|
|
|
|
|
2014-10-10 10:12:25 +00:00
|
|
|
describe("test in portrait screen mode", function()
|
|
|
|
it("should goto portrait screen mode", function()
|
2020-07-01 20:17:41 +00:00
|
|
|
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_PORTRAIT))
|
2014-10-10 10:12:25 +00:00
|
|
|
end)
|
2016-04-21 06:16:40 +00:00
|
|
|
|
2014-10-10 10:12:25 +00:00
|
|
|
it("should goto certain page", function()
|
|
|
|
for i = 1, 10, 5 do
|
2016-03-27 22:39:47 +00:00
|
|
|
rolling:onGotoPage(i)
|
2014-10-10 10:12:25 +00:00
|
|
|
assert.are.same(i, rolling.current_page)
|
|
|
|
end
|
|
|
|
end)
|
2016-04-21 06:16:40 +00:00
|
|
|
|
2014-10-10 10:12:25 +00:00
|
|
|
it("should goto relative page", function()
|
|
|
|
for i = 20, 40, 5 do
|
2016-03-27 22:39:47 +00:00
|
|
|
rolling:onGotoPage(i)
|
2014-10-10 10:12:25 +00:00
|
|
|
rolling:onGotoViewRel(1)
|
|
|
|
assert.are.same(i + 1, rolling.current_page)
|
|
|
|
rolling:onGotoViewRel(-1)
|
|
|
|
assert.are.same(i, rolling.current_page)
|
|
|
|
end
|
|
|
|
end)
|
2016-04-21 06:16:40 +00:00
|
|
|
|
2014-10-10 10:12:25 +00:00
|
|
|
it("should goto next chapter", function()
|
|
|
|
local toc = readerui.toc
|
|
|
|
for i = 30, 50, 5 do
|
2016-03-27 22:39:47 +00:00
|
|
|
rolling:onGotoPage(i)
|
2019-03-01 14:56:05 +00:00
|
|
|
rolling:onGotoNextChapter()
|
2014-10-10 10:12:25 +00:00
|
|
|
assert.are.same(toc:getNextChapter(i, 0), rolling.current_page)
|
|
|
|
end
|
|
|
|
end)
|
2016-04-21 06:16:40 +00:00
|
|
|
|
2014-10-10 10:12:25 +00:00
|
|
|
it("should goto previous chapter", function()
|
|
|
|
local toc = readerui.toc
|
|
|
|
for i = 60, 80, 5 do
|
2016-03-27 22:39:47 +00:00
|
|
|
rolling:onGotoPage(i)
|
2019-03-01 14:56:05 +00:00
|
|
|
rolling:onGotoPrevChapter()
|
2014-10-10 10:12:25 +00:00
|
|
|
assert.are.same(toc:getPreviousChapter(i, 0), rolling.current_page)
|
|
|
|
end
|
|
|
|
end)
|
2016-04-21 06:16:40 +00:00
|
|
|
|
2016-04-21 04:41:34 +00:00
|
|
|
it("should emit EndOfBook event at the end of sample epub", function()
|
2016-02-22 01:46:19 +00:00
|
|
|
local called = false
|
|
|
|
readerui.onEndOfBook = function()
|
|
|
|
called = true
|
|
|
|
end
|
2016-04-21 04:41:34 +00:00
|
|
|
-- check beginning of the book
|
|
|
|
rolling:onGotoPage(1)
|
|
|
|
assert.is.falsy(called)
|
|
|
|
rolling:onGotoViewRel(-1)
|
|
|
|
rolling:onGotoViewRel(-1)
|
|
|
|
assert.is.falsy(called)
|
|
|
|
-- check end of the book
|
|
|
|
rolling:onGotoPage(readerui.document:getPageCount())
|
|
|
|
assert.is.falsy(called)
|
2016-02-22 01:46:19 +00:00
|
|
|
rolling:onGotoViewRel(1)
|
2016-04-21 04:41:34 +00:00
|
|
|
assert.is.truthy(called)
|
2016-02-22 01:46:19 +00:00
|
|
|
rolling:onGotoViewRel(1)
|
|
|
|
assert.is.truthy(called)
|
|
|
|
readerui.onEndOfBook = nil
|
|
|
|
end)
|
2016-04-21 04:41:34 +00:00
|
|
|
|
|
|
|
it("should emit EndOfBook event at the end sample txt", function()
|
|
|
|
local sample_txt = "spec/front/unit/data/sample.txt"
|
2021-05-18 18:54:54 +00:00
|
|
|
-- Unsafe second // ReaderUI instance!
|
2016-04-21 04:41:34 +00:00
|
|
|
local txt_readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2016-04-21 04:41:34 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_txt),
|
|
|
|
}
|
|
|
|
local called = false
|
|
|
|
txt_readerui.onEndOfBook = function()
|
|
|
|
called = true
|
|
|
|
end
|
|
|
|
local txt_rolling = txt_readerui.rolling
|
|
|
|
-- check beginning of the book
|
|
|
|
txt_rolling:onGotoPage(1)
|
|
|
|
assert.is.falsy(called)
|
|
|
|
txt_rolling:onGotoViewRel(-1)
|
|
|
|
txt_rolling:onGotoViewRel(-1)
|
|
|
|
assert.is.falsy(called)
|
|
|
|
-- not at the end of the book
|
|
|
|
txt_rolling:onGotoPage(3)
|
|
|
|
assert.is.falsy(called)
|
|
|
|
txt_rolling:onGotoViewRel(1)
|
|
|
|
assert.is.falsy(called)
|
|
|
|
-- at the end of the book
|
|
|
|
txt_rolling:onGotoPage(txt_readerui.document:getPageCount())
|
|
|
|
assert.is.falsy(called)
|
|
|
|
txt_rolling:onGotoViewRel(1)
|
|
|
|
assert.is.truthy(called)
|
|
|
|
readerui.onEndOfBook = nil
|
2020-12-19 04:32:23 +00:00
|
|
|
txt_readerui:closeDocument()
|
|
|
|
txt_readerui:onClose()
|
2021-05-18 18:54:54 +00:00
|
|
|
-- Restore the ref to the original ReaderUI instance
|
|
|
|
ReaderUI.instance = readerui
|
2016-04-21 04:41:34 +00:00
|
|
|
end)
|
2014-10-10 10:12:25 +00:00
|
|
|
end)
|
2016-04-21 04:41:34 +00:00
|
|
|
|
2014-10-10 10:12:25 +00:00
|
|
|
describe("test in landscape screen mode", function()
|
|
|
|
it("should go to landscape screen mode", function()
|
2020-07-01 20:17:41 +00:00
|
|
|
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_LANDSCAPE))
|
2014-10-10 10:12:25 +00:00
|
|
|
end)
|
|
|
|
it("should goto certain page", function()
|
|
|
|
for i = 1, 10, 5 do
|
2016-03-27 22:39:47 +00:00
|
|
|
rolling:onGotoPage(i)
|
2014-10-10 10:12:25 +00:00
|
|
|
assert.are.same(i, rolling.current_page)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
it("should goto relative page", function()
|
|
|
|
for i = 20, 40, 5 do
|
2016-03-27 22:39:47 +00:00
|
|
|
rolling:onGotoPage(i)
|
2014-10-10 10:12:25 +00:00
|
|
|
rolling:onGotoViewRel(1)
|
|
|
|
assert.are.same(i + 1, rolling.current_page)
|
|
|
|
rolling:onGotoViewRel(-1)
|
|
|
|
assert.are.same(i, rolling.current_page)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
it("should goto next chapter", function()
|
|
|
|
local toc = readerui.toc
|
|
|
|
for i = 30, 50, 5 do
|
2016-03-27 22:39:47 +00:00
|
|
|
rolling:onGotoPage(i)
|
2019-03-01 14:56:05 +00:00
|
|
|
rolling:onGotoNextChapter()
|
2014-10-10 10:12:25 +00:00
|
|
|
assert.are.same(toc:getNextChapter(i, 0), rolling.current_page)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
it("should goto previous chapter", function()
|
|
|
|
local toc = readerui.toc
|
|
|
|
for i = 60, 80, 5 do
|
2016-03-27 22:39:47 +00:00
|
|
|
rolling:onGotoPage(i)
|
2019-03-01 14:56:05 +00:00
|
|
|
rolling:onGotoPrevChapter()
|
2014-10-10 10:12:25 +00:00
|
|
|
assert.are.same(toc:getPreviousChapter(i, 0), rolling.current_page)
|
|
|
|
end
|
|
|
|
end)
|
2016-02-22 01:46:19 +00:00
|
|
|
it("should emit EndOfBook event at the end", function()
|
2016-03-27 22:39:47 +00:00
|
|
|
rolling:onGotoPage(readerui.document:getPageCount())
|
2016-02-22 01:46:19 +00:00
|
|
|
local called = false
|
|
|
|
readerui.onEndOfBook = function()
|
|
|
|
called = true
|
|
|
|
end
|
|
|
|
rolling:onGotoViewRel(1)
|
|
|
|
rolling:onGotoViewRel(1)
|
|
|
|
assert.is.truthy(called)
|
|
|
|
readerui.onEndOfBook = nil
|
|
|
|
end)
|
2014-10-10 10:12:25 +00:00
|
|
|
end)
|
2016-04-21 04:41:34 +00:00
|
|
|
|
2014-10-10 10:12:25 +00:00
|
|
|
describe("switching screen mode should not change current page number", function()
|
2016-08-11 09:12:55 +00:00
|
|
|
teardown(function()
|
2020-07-01 20:17:41 +00:00
|
|
|
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_PORTRAIT))
|
2016-08-11 09:12:55 +00:00
|
|
|
end)
|
2014-10-10 10:12:25 +00:00
|
|
|
it("for portrait-landscape-portrait switching", function()
|
|
|
|
for i = 80, 100, 10 do
|
2020-07-01 20:17:41 +00:00
|
|
|
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_PORTRAIT))
|
2014-10-10 10:12:25 +00:00
|
|
|
rolling:onGotoPage(i)
|
|
|
|
assert.are.same(i, rolling.current_page)
|
2020-07-01 20:17:41 +00:00
|
|
|
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_LANDSCAPE))
|
2014-10-10 10:12:25 +00:00
|
|
|
assert.are_not.same(i, rolling.current_page)
|
2020-07-01 20:17:41 +00:00
|
|
|
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_PORTRAIT))
|
2014-10-10 10:12:25 +00:00
|
|
|
assert.are.same(i, rolling.current_page)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
it("for landscape-portrait-landscape switching", function()
|
|
|
|
for i = 110, 130, 10 do
|
2020-07-01 20:17:41 +00:00
|
|
|
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_LANDSCAPE))
|
2014-10-10 10:12:25 +00:00
|
|
|
rolling:onGotoPage(i)
|
|
|
|
assert.are.same(i, rolling.current_page)
|
2020-07-01 20:17:41 +00:00
|
|
|
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_PORTRAIT))
|
2014-10-10 10:12:25 +00:00
|
|
|
assert.are_not.same(i, rolling.current_page)
|
2020-07-01 20:17:41 +00:00
|
|
|
readerui:handleEvent(Event:new("SetRotationMode", Screen.ORIENTATION_LANDSCAPE))
|
2014-10-10 10:12:25 +00:00
|
|
|
assert.are.same(i, rolling.current_page)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end)
|
2016-10-04 17:38:32 +00:00
|
|
|
|
2018-06-30 18:49:01 +00:00
|
|
|
describe("test changing word gap - space condensing", function()
|
|
|
|
it("should show pages for different word gap", function()
|
2020-07-01 20:17:41 +00:00
|
|
|
readerui:handleEvent(Event:new("SetWordSpacing", {100, 90}))
|
2019-11-22 22:54:34 +00:00
|
|
|
assert.are.same(252, readerui.document:getPageCount())
|
2020-07-01 20:17:41 +00:00
|
|
|
readerui:handleEvent(Event:new("SetWordSpacing", {95, 75}))
|
2019-11-28 21:39:06 +00:00
|
|
|
assert.are.same(241, readerui.document:getPageCount())
|
2020-07-01 20:17:41 +00:00
|
|
|
readerui:handleEvent(Event:new("SetWordSpacing", {75, 50}))
|
2019-11-28 21:39:06 +00:00
|
|
|
assert.are.same(231, readerui.document:getPageCount())
|
2018-06-30 18:49:01 +00:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2016-10-04 17:38:32 +00:00
|
|
|
describe("test initialization", function()
|
|
|
|
it("should emit PageUpdate event after book is rendered", function()
|
|
|
|
local ReaderView = require("apps/reader/modules/readerview")
|
|
|
|
local saved_handler = ReaderView.onPageUpdate
|
2022-06-11 17:06:06 +00:00
|
|
|
ReaderView.onPageUpdate = function(this)
|
|
|
|
assert.are.same(6, this.ui.document:getPageCount())
|
2016-10-04 17:38:32 +00:00
|
|
|
end
|
|
|
|
local test_book = "spec/front/unit/data/sample.txt"
|
|
|
|
require("docsettings"):open(test_book):purge()
|
2021-05-18 18:54:54 +00:00
|
|
|
readerui:closeDocument()
|
|
|
|
readerui:onClose()
|
2020-12-19 04:32:23 +00:00
|
|
|
local tmp_readerui = ReaderUI:new{
|
2016-10-04 17:38:32 +00:00
|
|
|
document = DocumentRegistry:openDocument(test_book),
|
|
|
|
}
|
|
|
|
ReaderView.onPageUpdate = saved_handler
|
2020-12-19 04:32:23 +00:00
|
|
|
tmp_readerui:closeDocument()
|
|
|
|
tmp_readerui:onClose()
|
2016-10-04 17:38:32 +00:00
|
|
|
end)
|
|
|
|
end)
|
2014-10-10 10:12:25 +00:00
|
|
|
end)
|