mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
test(fix): update tests for default scroll mode
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
describe("Readerhighlight module", function()
|
||||
local DocumentRegistry, ReaderUI, UIManager, Screen, Geom, dbg
|
||||
local DocumentRegistry, ReaderUI, UIManager, Screen, Geom, dbg, Event
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
DocumentRegistry = require("document/documentregistry")
|
||||
@@ -8,6 +8,7 @@ describe("Readerhighlight module", function()
|
||||
Screen = require("device").screen
|
||||
Geom = require("ui/geometry")
|
||||
dbg = require("dbg")
|
||||
Event = require("ui/event")
|
||||
end)
|
||||
|
||||
local function highlight_single_word(readerui, pos0)
|
||||
@@ -23,12 +24,24 @@ describe("Readerhighlight module", function()
|
||||
local function highlight_text(readerui, pos0, pos1)
|
||||
readerui.highlight:onHold(nil, { pos = pos0 })
|
||||
readerui.highlight:onHoldPan(nil, { pos = pos1 })
|
||||
local next_slot
|
||||
for i = #UIManager._window_stack, 0, -1 do
|
||||
local top_window = UIManager._window_stack[i]
|
||||
-- skip modal window
|
||||
if not top_window or not top_window.widget.modal then
|
||||
next_slot = i + 1
|
||||
break
|
||||
end
|
||||
end
|
||||
readerui.highlight:onHoldRelease()
|
||||
assert.truthy(readerui.highlight.highlight_dialog)
|
||||
assert.truthy(UIManager._window_stack[next_slot].widget
|
||||
== readerui.highlight.highlight_dialog)
|
||||
readerui.highlight:onHighlight()
|
||||
UIManager:scheduleIn(1, function()
|
||||
UIManager:close(readerui.highlight.highlight_dialog)
|
||||
UIManager:close(readerui)
|
||||
UIManager:quit()
|
||||
end)
|
||||
UIManager:run()
|
||||
end
|
||||
@@ -90,13 +103,14 @@ describe("Readerhighlight module", function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("highlight for PDF documents", function()
|
||||
describe("highlight for PDF documents in page mode", function()
|
||||
local readerui
|
||||
setup(function()
|
||||
local sample_pdf = "spec/front/unit/data/sample.pdf"
|
||||
readerui = ReaderUI:new{
|
||||
document = DocumentRegistry:openDocument(sample_pdf),
|
||||
}
|
||||
readerui:handleEvent(Event:new("SetScrollMode", false))
|
||||
end)
|
||||
describe("for scanned page with text layer", function()
|
||||
before_each(function()
|
||||
@@ -170,4 +184,89 @@ describe("Readerhighlight module", function()
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("highlight for PDF documents in scroll mode", function()
|
||||
local readerui
|
||||
setup(function()
|
||||
local sample_pdf = "spec/front/unit/data/sample.pdf"
|
||||
readerui = ReaderUI:new{
|
||||
document = DocumentRegistry:openDocument(sample_pdf),
|
||||
}
|
||||
readerui:handleEvent(Event:new("SetScrollMode", true))
|
||||
end)
|
||||
describe("for scanned page with text layer", function()
|
||||
before_each(function()
|
||||
UIManager:quit()
|
||||
UIManager:show(readerui)
|
||||
readerui.paging:onGotoPage(10)
|
||||
readerui.zooming:setZoomMode("contentwidth")
|
||||
end)
|
||||
after_each(function()
|
||||
readerui.highlight:clear()
|
||||
end)
|
||||
it("should highlight single word", function()
|
||||
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
|
||||
Screen:shot("screenshots/reader_highlight_single_word_pdf_scroll.png")
|
||||
end)
|
||||
it("should highlight text", function()
|
||||
highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 })
|
||||
Screen:shot("screenshots/reader_highlight_text_pdf_scroll.png")
|
||||
end)
|
||||
it("should response on tap gesture", function()
|
||||
tap_highlight_text(readerui,
|
||||
Geom:new{ x = 260, y = 70 },
|
||||
Geom:new{ x = 260, y = 150 },
|
||||
Geom:new{ x = 280, y = 110 })
|
||||
Screen:shot("screenshots/reader_tap_highlight_text_pdf_scroll.png")
|
||||
end)
|
||||
end)
|
||||
describe("for scanned page without text layer", function()
|
||||
before_each(function()
|
||||
UIManager:quit()
|
||||
UIManager:show(readerui)
|
||||
readerui.paging:onGotoPage(28)
|
||||
readerui.zooming:setZoomMode("contentwidth")
|
||||
end)
|
||||
after_each(function()
|
||||
readerui.highlight:clear()
|
||||
end)
|
||||
it("should highlight single word", function()
|
||||
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
|
||||
Screen:shot("screenshots/reader_highlight_single_word_pdf_scanned_scroll.png")
|
||||
end)
|
||||
it("should highlight text", function()
|
||||
highlight_text(readerui, Geom:new{x = 192, y = 186}, Geom:new{x = 280, y = 186})
|
||||
Screen:shot("screenshots/reader_highlight_text_pdf_scanned_scroll.png")
|
||||
end)
|
||||
it("should response on tap gesture", function()
|
||||
tap_highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 }, Geom:new{ x = 280, y = 110 })
|
||||
Screen:shot("screenshots/reader_tap_highlight_text_pdf_scanned_scroll.png")
|
||||
end)
|
||||
end)
|
||||
describe("for reflowed page", function()
|
||||
before_each(function()
|
||||
UIManager:quit()
|
||||
readerui.document.configurable.text_wrap = 1
|
||||
UIManager:show(readerui)
|
||||
readerui.paging:onGotoPage(31)
|
||||
end)
|
||||
after_each(function()
|
||||
readerui.highlight:clear()
|
||||
readerui.document.configurable.text_wrap = 0
|
||||
end)
|
||||
it("should highlight single word", function()
|
||||
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
|
||||
Screen:shot("screenshots/reader_highlight_single_word_pdf_reflowed_scroll.png")
|
||||
end)
|
||||
it("should highlight text", function()
|
||||
highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 })
|
||||
Screen:shot("screenshots/reader_highlight_text_pdf_reflowed_scroll.png")
|
||||
end)
|
||||
it("should response on tap gesture", function()
|
||||
tap_highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 }, Geom:new{ x = 280, y = 110 })
|
||||
Screen:shot("screenshots/reader_tap_highlight_text_pdf_reflowed_scroll.png")
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
describe("ReaderLink module", function()
|
||||
local DocumentRegistry, ReaderUI, UIManager, sample_epub, sample_pdf
|
||||
local DocumentRegistry, ReaderUI, UIManager, sample_epub, sample_pdf, Event
|
||||
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
DocumentRegistry = require("document/documentregistry")
|
||||
Event = require("ui/event")
|
||||
ReaderUI = require("apps/reader/readerui")
|
||||
UIManager = require("ui/uimanager")
|
||||
sample_epub = "spec/front/unit/data/leaves.epub"
|
||||
@@ -19,11 +20,12 @@ describe("ReaderLink module", function()
|
||||
assert.is.same(36, readerui.rolling.current_page)
|
||||
end)
|
||||
|
||||
it("should jump to links in pdf", function()
|
||||
it("should jump to links in pdf page mode", function()
|
||||
UIManager:quit()
|
||||
local readerui = ReaderUI:new{
|
||||
document = DocumentRegistry:openDocument(sample_pdf),
|
||||
}
|
||||
readerui:handleEvent(Event:new("SetScrollMode", false))
|
||||
readerui.paging:onGotoPage(1)
|
||||
readerui.link:onTap(nil, {pos = {x = 363, y = 585}})
|
||||
UIManager:run()
|
||||
@@ -41,11 +43,12 @@ describe("ReaderLink module", function()
|
||||
assert.is.same(4, readerui.rolling.current_page)
|
||||
end)
|
||||
|
||||
it("should be able to go back after link jump in pdf", function()
|
||||
it("should be able to go back after link jump in pdf page mode", function()
|
||||
UIManager:quit()
|
||||
local readerui = ReaderUI:new{
|
||||
document = DocumentRegistry:openDocument(sample_pdf),
|
||||
}
|
||||
readerui:handleEvent(Event:new("SetScrollMode", false))
|
||||
readerui.paging:onGotoPage(1)
|
||||
readerui.link:onTap(nil, {pos = {x = 363, y = 585}})
|
||||
UIManager:run()
|
||||
|
||||
@@ -6,14 +6,18 @@ describe("Readerpaging module", function()
|
||||
setup(function() require("commonrequire") end)
|
||||
|
||||
describe("Page mode", function()
|
||||
local Event
|
||||
|
||||
setup(function()
|
||||
Event = require("ui/event")
|
||||
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()
|
||||
it("should emit EndOfBook event at the end in page mode", function()
|
||||
readerui:handleEvent(Event:new("SetScrollMode", false))
|
||||
readerui.zooming:setZoomMode("pageheight")
|
||||
paging:onGotoPage(readerui.document:getPageCount())
|
||||
local called = false
|
||||
@@ -24,6 +28,19 @@ describe("Readerpaging module", function()
|
||||
assert.is.truthy(called)
|
||||
readerui.onEndOfBook = nil
|
||||
end)
|
||||
|
||||
it("should emit EndOfBook event at the end in scroll mode", function()
|
||||
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)
|
||||
assert.is.truthy(called)
|
||||
readerui.onEndOfBook = nil
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("Scroll mode", function()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
describe("Readerview module", function()
|
||||
local DocumentRegistry, Blitbuffer, ReaderUI, UIManager
|
||||
local DocumentRegistry, Blitbuffer, ReaderUI, UIManager, Event
|
||||
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
@@ -7,6 +7,7 @@ describe("Readerview module", function()
|
||||
Blitbuffer = require("ffi/blitbuffer")
|
||||
ReaderUI = require("apps/reader/readerui")
|
||||
UIManager = require("ui/uimanager")
|
||||
Event = require("ui/event")
|
||||
end)
|
||||
|
||||
it("should stop hinting on document close event", function()
|
||||
@@ -44,11 +45,12 @@ describe("Readerview module", function()
|
||||
end
|
||||
end)
|
||||
|
||||
it("should return and restore view context", function()
|
||||
it("should return and restore view context in page mode", function()
|
||||
local sample_pdf = "spec/front/unit/data/2col.pdf"
|
||||
local readerui = ReaderUI:new{
|
||||
document = DocumentRegistry:openDocument(sample_pdf),
|
||||
}
|
||||
readerui:handleEvent(Event:new("SetScrollMode", false))
|
||||
local view = readerui.view
|
||||
local ctx = view:getViewContext()
|
||||
local zoom = ctx[1].zoom
|
||||
@@ -75,7 +77,7 @@ describe("Readerview module", function()
|
||||
h = 800, w = 566,
|
||||
},
|
||||
}
|
||||
assert.are.same(ctx, saved_ctx)
|
||||
assert.are.same(saved_ctx, ctx)
|
||||
assertAlmostEquals(zoom, 0.95011876484561, 0.0001)
|
||||
|
||||
assert.is.same(view.state.page, 1)
|
||||
@@ -89,4 +91,51 @@ describe("Readerview module", function()
|
||||
assert.is.same(view.visible_area.x, 0)
|
||||
assert.is.same(view.visible_area.y, 10)
|
||||
end)
|
||||
|
||||
it("should return and restore view context in scroll mode", function()
|
||||
local sample_pdf = "spec/front/unit/data/2col.pdf"
|
||||
local readerui = ReaderUI:new{
|
||||
document = DocumentRegistry:openDocument(sample_pdf),
|
||||
}
|
||||
readerui:handleEvent(Event:new("SetScrollMode", true))
|
||||
local view = readerui.view
|
||||
local ctx = view:getViewContext()
|
||||
local zoom = ctx[1].zoom
|
||||
ctx[1].zoom = nil
|
||||
local saved_ctx = {
|
||||
{
|
||||
gamma = 1,
|
||||
offset = {x = 17, y = 0},
|
||||
page = 1,
|
||||
page_area = {
|
||||
h = 800,
|
||||
w = 566,
|
||||
x = 0,
|
||||
y = 0,
|
||||
},
|
||||
rotation = 0,
|
||||
visible_area = {
|
||||
h = 800,
|
||||
w = 566,
|
||||
x = 0,
|
||||
y = 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
assert.are.same(saved_ctx, ctx)
|
||||
assertAlmostEquals(zoom, 0.95011876484561, 0.0001)
|
||||
|
||||
assert.is.same(view.state.page, 1)
|
||||
assert.is.same(view.visible_area.x, 0)
|
||||
assert.is.same(view.visible_area.y, 0)
|
||||
saved_ctx[1].page = 2
|
||||
saved_ctx[1].zoom = zoom
|
||||
saved_ctx[1].visible_area.y = 10
|
||||
view:restoreViewContext(saved_ctx)
|
||||
assert.is.same(#view.page_states, 1)
|
||||
assert.is.same(view.page_states[1].page, 2)
|
||||
assert.is.same(view.page_states[1].visible_area.x, 0)
|
||||
assert.is.same(view.page_states[1].visible_area.y, 10)
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user