tests/readerlink: reorganize

Group tests by file type (EPUB or PDF).
reviewable/pr11781/r2
Benoit Pierre 1 month ago committed by Frans de Jonge
parent b67c6147d5
commit d0ca04c48d

@ -14,185 +14,193 @@ describe("ReaderLink module", function()
sample_pdf = "spec/front/unit/data/paper.pdf" sample_pdf = "spec/front/unit/data/paper.pdf"
end) end)
it("should jump to links in epub #nocov", function() describe("with epub", function()
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
readerui.rolling:onGotoPage(5)
readerui.link:onTap(nil, {pos = {x = 320, y = 190}})
assert.is.same(37, readerui.rolling.current_page)
readerui:closeDocument()
readerui:onClose()
end)
it("should jump to links in pdf page mode", function() it("should jump to links #nocov", function()
UIManager:quit() local readerui = ReaderUI:new{
UIManager._exit_code = nil dimen = Screen:getSize(),
local readerui = ReaderUI:new{ document = DocumentRegistry:openDocument(sample_epub),
dimen = Screen:getSize(), }
document = DocumentRegistry:openDocument(sample_pdf), readerui.rolling:onGotoPage(5)
} readerui.link:onTap(nil, {pos = {x = 320, y = 190}})
readerui:handleEvent(Event:new("SetScrollMode", false)) assert.is.same(37, readerui.rolling.current_page)
readerui:handleEvent(Event:new("SetZoomMode", "page")) readerui:closeDocument()
readerui.paging:onGotoPage(1) readerui:onClose()
readerui.link:onTap(nil, {pos = {x = 363, y = 565}}) end)
UIManager:run()
assert.is.same(22, readerui.paging.current_page)
readerui:closeDocument()
readerui:onClose()
end)
it("should jump to links in pdf scroll mode", function() it("should be able to go back after link jump #nocov", function()
UIManager:quit() local readerui = ReaderUI:new{
UIManager._exit_code = nil dimen = Screen:getSize(),
local readerui = ReaderUI:new{ document = DocumentRegistry:openDocument(sample_epub),
dimen = Screen:getSize(), }
document = DocumentRegistry:openDocument(sample_pdf), readerui.rolling:onGotoPage(5)
} readerui.link:onTap(nil, {pos = {x = 320, y = 190}})
readerui:handleEvent(Event:new("SetScrollMode", true)) assert.is.same(37, readerui.rolling.current_page)
readerui:handleEvent(Event:new("SetZoomMode", "page")) readerui.link:onGoBackLink()
readerui.paging:onGotoPage(1) assert.is.same(5, readerui.rolling.current_page)
assert.is.same(1, readerui.paging.current_page) readerui:closeDocument()
readerui.link:onTap(nil, {pos = {x = 228, y = 534}}) readerui:onClose()
UIManager:run() end)
-- 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)
readerui:closeDocument()
readerui:onClose()
end)
it("should be able to go back after link jump in epub #nocov", function()
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
readerui.rolling:onGotoPage(5)
readerui.link:onTap(nil, {pos = {x = 320, y = 190}})
assert.is.same(37, readerui.rolling.current_page)
readerui.link:onGoBackLink()
assert.is.same(5, readerui.rolling.current_page)
readerui:closeDocument()
readerui:onClose()
end) end)
it("should be able to go back after link jump in pdf page mode", function() describe("with pdf", function()
UIManager:quit()
UIManager._exit_code = nil
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
readerui:handleEvent(Event:new("SetScrollMode", false))
readerui:handleEvent(Event:new("SetZoomMode", "page"))
readerui.paging:onGotoPage(1)
readerui.link:onTap(nil, {pos = {x = 363, y = 565}})
UIManager:run()
assert.is.same(22, readerui.paging.current_page)
readerui.link:onGoBackLink()
assert.is.same(1, readerui.paging.current_page)
readerui:closeDocument()
readerui:onClose()
end)
it("should be able to go back after link jump in pdf scroll mode", function() it("should jump to links in page mode", function()
UIManager:quit() UIManager:quit()
UIManager._exit_code = nil UIManager._exit_code = nil
local readerui = ReaderUI:new{ local readerui = ReaderUI:new{
dimen = Screen:getSize(), dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf), document = DocumentRegistry:openDocument(sample_pdf),
} }
readerui:handleEvent(Event:new("SetScrollMode", true)) readerui:handleEvent(Event:new("SetScrollMode", false))
readerui:handleEvent(Event:new("SetZoomMode", "page")) readerui:handleEvent(Event:new("SetZoomMode", "page"))
readerui.paging:onGotoPage(1) readerui.paging:onGotoPage(1)
assert.is.same(1, readerui.paging.current_page) readerui.link:onTap(nil, {pos = {x = 363, y = 565}})
readerui.link:onTap(nil, {pos = {x = 228, y = 534}}) UIManager:run()
UIManager:run() assert.is.same(22, readerui.paging.current_page)
assert.truthy(readerui.paging.current_page == 21 readerui:closeDocument()
or readerui.paging.current_page == 20) readerui:onClose()
readerui.link:onGoBackLink() end)
assert.is.same(1, readerui.paging.current_page)
readerui:closeDocument()
readerui:onClose()
end)
it("should be able to go back to the same position after link jump in pdf scroll mode", function() it("should jump to links in scroll mode", function()
UIManager:quit() UIManager:quit()
UIManager._exit_code = nil UIManager._exit_code = nil
local expected_page_states = { local readerui = ReaderUI:new{
{ dimen = Screen:getSize(),
gamma = 1, document = DocumentRegistry:openDocument(sample_pdf),
offset = {x = 17, y = 0}, }
page = 3, readerui:handleEvent(Event:new("SetScrollMode", true))
page_area = { readerui:handleEvent(Event:new("SetZoomMode", "page"))
x = 0, y = 0, readerui.paging:onGotoPage(1)
h = 800, w = 566, assert.is.same(1, readerui.paging.current_page)
}, readerui.link:onTap(nil, {pos = {x = 228, y = 534}})
rotation = 0, UIManager:run()
visible_area = { -- its really hard to get the exact page number in scroll mode
x = 0, y = 694, -- page positions may have unexpected impact on page number
h = 106, w = 566, assert.truthy(readerui.paging.current_page == 21
}, or readerui.paging.current_page == 20)
zoom = 0.95032191328269044472, readerui:closeDocument()
}, readerui:onClose()
{ end)
gamma = 1,
offset = {x = 17, y = 0}, it("should be able to go back after link jump in page mode", function()
page = 4, UIManager:quit()
page_area = { UIManager._exit_code = nil
h = 800, w = 566, local readerui = ReaderUI:new{
x = 0, y = 0, dimen = Screen:getSize(),
}, document = DocumentRegistry:openDocument(sample_pdf),
rotation = 0, }
visible_area = { readerui:handleEvent(Event:new("SetScrollMode", false))
h = 686, w = 566, readerui:handleEvent(Event:new("SetZoomMode", "page"))
x = 0, y = 0, readerui.paging:onGotoPage(1)
readerui.link:onTap(nil, {pos = {x = 363, y = 565}})
UIManager:run()
assert.is.same(22, readerui.paging.current_page)
readerui.link:onGoBackLink()
assert.is.same(1, readerui.paging.current_page)
readerui:closeDocument()
readerui:onClose()
end)
it("should be able to go back after link jump in scroll mode", function()
UIManager:quit()
UIManager._exit_code = nil
local readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_pdf),
}
readerui:handleEvent(Event:new("SetScrollMode", true))
readerui:handleEvent(Event:new("SetZoomMode", "page"))
readerui.paging:onGotoPage(1)
assert.is.same(1, readerui.paging.current_page)
readerui.link:onTap(nil, {pos = {x = 228, y = 534}})
UIManager:run()
assert.truthy(readerui.paging.current_page == 21
or readerui.paging.current_page == 20)
readerui.link:onGoBackLink()
assert.is.same(1, readerui.paging.current_page)
readerui:closeDocument()
readerui:onClose()
end)
it("should be able to go back to the same position after link jump in scroll mode", function()
UIManager:quit()
UIManager._exit_code = nil
local expected_page_states = {
{
gamma = 1,
offset = {x = 17, y = 0},
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.95032191328269044472,
},
{
gamma = 1,
offset = {x = 17, y = 0},
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.95032191328269044472,
}, },
zoom = 0.95032191328269044472, }
}, -- disable footer
} G_reader_settings:saveSetting("reader_footer_mode", 0)
-- disable footer require("docsettings"):open(sample_pdf):purge()
G_reader_settings:saveSetting("reader_footer_mode", 0) local readerui = ReaderUI:new{
require("docsettings"):open(sample_pdf):purge() dimen = Screen:getSize(),
local readerui = ReaderUI:new{ document = DocumentRegistry:openDocument(sample_pdf),
dimen = Screen:getSize(), }
document = DocumentRegistry:openDocument(sample_pdf), readerui:handleEvent(Event:new("SetZoomMode", "page"))
} assert.is.falsy(readerui.view.footer_visible)
readerui:handleEvent(Event:new("SetZoomMode", "page")) readerui.paging:onGotoPage(1)
assert.is.falsy(readerui.view.footer_visible) assert.is.same(1, readerui.paging.current_page)
readerui.paging:onGotoPage(1) readerui.view:onSetScrollMode(true)
assert.is.same(1, readerui.paging.current_page) assert.is.same(true, readerui.view.page_scroll)
readerui.view:onSetScrollMode(true) assert.is.same(1, readerui.paging.current_page)
assert.is.same(true, readerui.view.page_scroll)
assert.is.same(1, readerui.paging.current_page) readerui.paging:onGotoViewRel(1)
assert.is.same(2, readerui.paging.current_page)
readerui.paging:onGotoViewRel(1)
assert.is.same(2, readerui.paging.current_page) readerui.paging:onGotoViewRel(-1)
assert.is.same(1, readerui.paging.current_page)
readerui.paging:onGotoViewRel(-1)
assert.is.same(1, readerui.paging.current_page) readerui.paging:onGotoViewRel(1)
readerui.paging:onGotoViewRel(1)
readerui.paging:onGotoViewRel(1) assert.is.same(3, readerui.paging.current_page)
readerui.paging:onGotoViewRel(1)
assert.is.same(3, readerui.paging.current_page) readerui.paging:onGotoViewRel(-1)
assert.is.same(2, readerui.paging.current_page)
readerui.paging:onGotoViewRel(-1)
assert.is.same(2, readerui.paging.current_page) readerui.paging:onGotoViewRel(1)
readerui.paging:onGotoViewRel(1)
readerui.paging:onGotoViewRel(1) assert.is.same(4, readerui.paging.current_page)
readerui.paging:onGotoViewRel(1) assert.are.same(expected_page_states, readerui.view.page_states)
assert.is.same(4, readerui.paging.current_page)
assert.are.same(expected_page_states, readerui.view.page_states) readerui.link:onTap(nil, {pos = {x = 164, y = 366}})
UIManager:run()
readerui.link:onTap(nil, {pos = {x = 164, y = 366}}) assert.is.same(22, readerui.paging.current_page)
UIManager:run() readerui.link:onGoBackLink()
assert.is.same(22, readerui.paging.current_page) assert.is.same(3, readerui.paging.current_page)
readerui.link:onGoBackLink() assert.are.same(expected_page_states, readerui.view.page_states)
assert.is.same(3, readerui.paging.current_page) readerui:closeDocument()
assert.are.same(expected_page_states, readerui.view.page_states) readerui:onClose()
readerui:closeDocument() end)
readerui:onClose()
end) end)
end) end)

Loading…
Cancel
Save