2016-03-27 22:39:47 +00:00
|
|
|
describe("ReaderLink module", function()
|
2020-07-01 20:17:41 +00:00
|
|
|
local DocumentRegistry, ReaderUI, UIManager, sample_epub, sample_pdf, Event, Screen
|
2016-03-27 22:39:47 +00:00
|
|
|
|
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
2017-06-23 17:04:11 +00:00
|
|
|
package.unloadAll()
|
2019-02-18 16:01:00 +00:00
|
|
|
require("document/canvascontext"):init(require("device"))
|
2016-03-27 22:39:47 +00:00
|
|
|
DocumentRegistry = require("document/documentregistry")
|
2016-07-18 06:12:53 +00:00
|
|
|
Event = require("ui/event")
|
2016-03-27 22:39:47 +00:00
|
|
|
ReaderUI = require("apps/reader/readerui")
|
|
|
|
UIManager = require("ui/uimanager")
|
2020-07-01 20:17:41 +00:00
|
|
|
Screen = require("device").screen
|
2016-03-27 22:39:47 +00:00
|
|
|
sample_epub = "spec/front/unit/data/leaves.epub"
|
2016-08-14 16:32:23 +00:00
|
|
|
sample_pdf = "spec/front/unit/data/paper.pdf"
|
2016-03-27 22:39:47 +00:00
|
|
|
end)
|
|
|
|
|
2017-08-16 15:44:16 +00:00
|
|
|
it("should jump to links in epub #nocov", function()
|
2016-03-27 22:39:47 +00:00
|
|
|
local readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2016-03-27 22:39:47 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_epub),
|
|
|
|
}
|
2020-04-19 11:53:01 +00:00
|
|
|
readerui.rolling:onGotoPage(5)
|
|
|
|
readerui.link:onTap(nil, {pos = {x = 320, y = 190}})
|
|
|
|
assert.is.same(37, readerui.rolling.current_page)
|
2020-12-19 04:32:23 +00:00
|
|
|
readerui:closeDocument()
|
|
|
|
readerui:onClose()
|
2016-03-27 22:39:47 +00:00
|
|
|
end)
|
|
|
|
|
2016-07-18 06:12:53 +00:00
|
|
|
it("should jump to links in pdf page mode", function()
|
2016-03-27 22:39:47 +00:00
|
|
|
UIManager:quit()
|
|
|
|
local readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2016-03-27 22:39:47 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
|
|
|
}
|
2016-07-18 06:12:53 +00:00
|
|
|
readerui:handleEvent(Event:new("SetScrollMode", false))
|
2019-08-05 16:38:10 +00:00
|
|
|
readerui:handleEvent(Event:new("SetZoomMode", "page"))
|
2016-03-27 22:39:47 +00:00
|
|
|
readerui.paging:onGotoPage(1)
|
2019-11-21 09:05:40 +00:00
|
|
|
readerui.link:onTap(nil, {pos = {x = 363, y = 565}})
|
2016-03-27 22:39:47 +00:00
|
|
|
UIManager:run()
|
|
|
|
assert.is.same(22, readerui.paging.current_page)
|
2020-12-19 04:32:23 +00:00
|
|
|
readerui:closeDocument()
|
|
|
|
readerui:onClose()
|
2016-03-27 22:39:47 +00:00
|
|
|
end)
|
|
|
|
|
2016-07-18 06:51:58 +00:00
|
|
|
it("should jump to links in pdf scroll mode", function()
|
|
|
|
UIManager:quit()
|
|
|
|
local readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2016-07-18 06:51:58 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
|
|
|
}
|
|
|
|
readerui:handleEvent(Event:new("SetScrollMode", true))
|
2019-08-05 16:38:10 +00:00
|
|
|
readerui:handleEvent(Event:new("SetZoomMode", "page"))
|
2016-07-18 06:51:58 +00:00
|
|
|
readerui.paging:onGotoPage(1)
|
2016-10-04 17:38:32 +00:00
|
|
|
assert.is.same(1, readerui.paging.current_page)
|
2020-02-20 22:00:32 +00:00
|
|
|
readerui.link:onTap(nil, {pos = {x = 228, y = 534}})
|
2016-07-18 06:51:58 +00:00
|
|
|
UIManager:run()
|
2016-08-12 06:05:18 +00:00
|
|
|
-- its really hard to get the exact page number in scroll mode
|
|
|
|
-- page positions may have unexpected impact on page number
|
|
|
|
assert.truthy(readerui.paging.current_page == 21
|
|
|
|
or readerui.paging.current_page == 20)
|
2020-12-19 04:32:23 +00:00
|
|
|
readerui:closeDocument()
|
|
|
|
readerui:onClose()
|
2016-07-18 06:51:58 +00:00
|
|
|
end)
|
|
|
|
|
2017-08-16 15:44:16 +00:00
|
|
|
it("should be able to go back after link jump in epub #nocov", function()
|
2016-03-27 22:39:47 +00:00
|
|
|
local readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2016-03-27 22:39:47 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_epub),
|
|
|
|
}
|
2020-04-19 11:53:01 +00:00
|
|
|
readerui.rolling:onGotoPage(5)
|
|
|
|
readerui.link:onTap(nil, {pos = {x = 320, y = 190}})
|
|
|
|
assert.is.same(37, readerui.rolling.current_page)
|
2016-03-27 22:39:47 +00:00
|
|
|
readerui.link:onGoBackLink()
|
2020-04-19 11:53:01 +00:00
|
|
|
assert.is.same(5, readerui.rolling.current_page)
|
2020-12-19 04:32:23 +00:00
|
|
|
readerui:closeDocument()
|
|
|
|
readerui:onClose()
|
2016-03-27 22:39:47 +00:00
|
|
|
end)
|
|
|
|
|
2016-07-18 06:12:53 +00:00
|
|
|
it("should be able to go back after link jump in pdf page mode", function()
|
2016-03-27 22:39:47 +00:00
|
|
|
UIManager:quit()
|
|
|
|
local readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2016-03-27 22:39:47 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
|
|
|
}
|
2016-07-18 06:12:53 +00:00
|
|
|
readerui:handleEvent(Event:new("SetScrollMode", false))
|
2019-08-05 16:38:10 +00:00
|
|
|
readerui:handleEvent(Event:new("SetZoomMode", "page"))
|
2016-03-27 22:39:47 +00:00
|
|
|
readerui.paging:onGotoPage(1)
|
2019-11-21 09:05:40 +00:00
|
|
|
readerui.link:onTap(nil, {pos = {x = 363, y = 565}})
|
2016-03-27 22:39:47 +00:00
|
|
|
UIManager:run()
|
|
|
|
assert.is.same(22, readerui.paging.current_page)
|
|
|
|
readerui.link:onGoBackLink()
|
|
|
|
assert.is.same(1, readerui.paging.current_page)
|
2020-12-19 04:32:23 +00:00
|
|
|
readerui:closeDocument()
|
|
|
|
readerui:onClose()
|
2016-03-27 22:39:47 +00:00
|
|
|
end)
|
|
|
|
|
2016-07-18 06:51:58 +00:00
|
|
|
it("should be able to go back after link jump in pdf scroll mode", function()
|
|
|
|
UIManager:quit()
|
|
|
|
local readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2016-07-18 06:51:58 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
|
|
|
}
|
|
|
|
readerui:handleEvent(Event:new("SetScrollMode", true))
|
2019-08-05 16:38:10 +00:00
|
|
|
readerui:handleEvent(Event:new("SetZoomMode", "page"))
|
2016-07-18 06:51:58 +00:00
|
|
|
readerui.paging:onGotoPage(1)
|
2016-10-04 17:38:32 +00:00
|
|
|
assert.is.same(1, readerui.paging.current_page)
|
2020-02-20 22:00:32 +00:00
|
|
|
readerui.link:onTap(nil, {pos = {x = 228, y = 534}})
|
2016-07-18 06:51:58 +00:00
|
|
|
UIManager:run()
|
2016-08-12 06:05:18 +00:00
|
|
|
assert.truthy(readerui.paging.current_page == 21
|
|
|
|
or readerui.paging.current_page == 20)
|
2016-07-18 06:51:58 +00:00
|
|
|
readerui.link:onGoBackLink()
|
|
|
|
assert.is.same(1, readerui.paging.current_page)
|
2020-12-19 04:32:23 +00:00
|
|
|
readerui:closeDocument()
|
|
|
|
readerui:onClose()
|
2016-07-18 06:51:58 +00:00
|
|
|
end)
|
|
|
|
|
2016-10-04 17:38:32 +00:00
|
|
|
it("should be able to go back to the same position after link jump in pdf scroll mode", function()
|
2016-03-27 22:39:47 +00:00
|
|
|
UIManager:quit()
|
|
|
|
local expected_page_states = {
|
|
|
|
{
|
|
|
|
gamma = 1,
|
2020-02-20 22:00:32 +00:00
|
|
|
offset = {x = 0, y = 0},
|
2016-03-27 22:39:47 +00:00
|
|
|
page = 3,
|
|
|
|
page_area = {
|
|
|
|
x = 0, y = 0,
|
|
|
|
h = 800, w = 566,
|
|
|
|
},
|
|
|
|
rotation = 0,
|
|
|
|
visible_area = {
|
|
|
|
x = 0, y = 694,
|
|
|
|
h = 106, w = 566,
|
|
|
|
},
|
|
|
|
zoom = 0.9501187648456056456,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
gamma = 1,
|
2020-02-20 22:00:32 +00:00
|
|
|
offset = {x = 0, y = 0},
|
2016-03-27 22:39:47 +00:00
|
|
|
page = 4,
|
|
|
|
page_area = {
|
|
|
|
h = 800, w = 566,
|
|
|
|
x = 0, y = 0,
|
|
|
|
},
|
|
|
|
rotation = 0,
|
|
|
|
visible_area = {
|
|
|
|
h = 686, w = 566,
|
|
|
|
x = 0, y = 0,
|
|
|
|
},
|
|
|
|
zoom = 0.9501187648456056456,
|
|
|
|
},
|
|
|
|
}
|
2016-04-29 03:31:17 +00:00
|
|
|
-- disable footer
|
|
|
|
G_reader_settings:saveSetting("reader_footer_mode", 0)
|
2016-10-04 17:38:32 +00:00
|
|
|
require("docsettings"):open(sample_pdf):purge()
|
2016-03-27 22:39:47 +00:00
|
|
|
local readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2016-03-27 22:39:47 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
|
|
|
}
|
2019-08-05 16:38:10 +00:00
|
|
|
readerui:handleEvent(Event:new("SetZoomMode", "page"))
|
2016-11-02 08:38:52 +00:00
|
|
|
assert.is.falsy(readerui.view.footer_visible)
|
2016-04-19 06:50:36 +00:00
|
|
|
readerui.paging:onGotoPage(1)
|
|
|
|
assert.is.same(1, readerui.paging.current_page)
|
2016-03-27 22:39:47 +00:00
|
|
|
readerui.view:onSetScrollMode(true)
|
|
|
|
assert.is.same(true, readerui.view.page_scroll)
|
2016-11-02 08:38:52 +00:00
|
|
|
assert.is.same(1, readerui.paging.current_page)
|
2019-03-01 15:05:03 +00:00
|
|
|
|
|
|
|
readerui.paging:onGotoViewRel(1)
|
2016-11-02 08:38:52 +00:00
|
|
|
assert.is.same(2, readerui.paging.current_page)
|
2019-03-01 15:05:03 +00:00
|
|
|
|
|
|
|
readerui.paging:onGotoViewRel(-1)
|
|
|
|
assert.is.same(1, readerui.paging.current_page)
|
|
|
|
|
|
|
|
readerui.paging:onGotoViewRel(1)
|
|
|
|
readerui.paging:onGotoViewRel(1)
|
2016-11-02 08:38:52 +00:00
|
|
|
assert.is.same(3, readerui.paging.current_page)
|
2019-03-01 15:05:03 +00:00
|
|
|
|
|
|
|
readerui.paging:onGotoViewRel(-1)
|
|
|
|
assert.is.same(2, readerui.paging.current_page)
|
|
|
|
|
|
|
|
readerui.paging:onGotoViewRel(1)
|
|
|
|
readerui.paging:onGotoViewRel(1)
|
2016-03-27 22:39:47 +00:00
|
|
|
assert.is.same(4, readerui.paging.current_page)
|
|
|
|
assert.are.same(expected_page_states, readerui.view.page_states)
|
2019-03-01 15:05:03 +00:00
|
|
|
|
2020-02-20 22:00:32 +00:00
|
|
|
readerui.link:onTap(nil, {pos = {x = 164, y = 366}})
|
2016-03-27 22:39:47 +00:00
|
|
|
UIManager:run()
|
|
|
|
assert.is.same(22, readerui.paging.current_page)
|
|
|
|
readerui.link:onGoBackLink()
|
2016-07-18 06:51:58 +00:00
|
|
|
assert.is.same(3, readerui.paging.current_page)
|
2016-03-27 22:39:47 +00:00
|
|
|
assert.are.same(expected_page_states, readerui.view.page_states)
|
2020-12-19 04:32:23 +00:00
|
|
|
readerui:closeDocument()
|
|
|
|
readerui:onClose()
|
2016-03-27 22:39:47 +00:00
|
|
|
end)
|
|
|
|
end)
|