mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
tests: factorize UI related helpers
This commit is contained in:
committed by
Frans de Jonge
parent
480eb7e142
commit
f1b522acb9
@@ -30,6 +30,8 @@ files["spec/unit/*"].globals = {
|
||||
"package",
|
||||
"disable_plugins",
|
||||
"load_plugin",
|
||||
"fastforward_ui_events",
|
||||
"screenshot",
|
||||
}
|
||||
|
||||
-- TODO: clean up and enforce max line width (631)
|
||||
|
||||
@@ -75,3 +75,17 @@ function load_plugin(name)
|
||||
end
|
||||
assert(false)
|
||||
end
|
||||
|
||||
function fastforward_ui_events()
|
||||
local UIManager = require("ui/uimanager")
|
||||
-- Fast forward all scheduled tasks.
|
||||
UIManager:shiftScheduledTasksBy(-1e9)
|
||||
-- Fix hang when running tests with our docker base image SDL.
|
||||
UIManager:setInputTimeout(0)
|
||||
-- And run the UI manager's input loop once.
|
||||
UIManager:handleInput()
|
||||
end
|
||||
|
||||
function screenshot(screen, filename)
|
||||
screen:shot(DataStorage:getDataDir() .. "/screenshots/" .. filename)
|
||||
end
|
||||
|
||||
@@ -20,10 +20,6 @@ describe("ReaderBookmark module", function()
|
||||
Util.copyFile("spec/front/unit/data/sample.pdf", sample_pdf)
|
||||
end)
|
||||
|
||||
local function screenshot(filename)
|
||||
Screen:shot(DataStorage:getDataDir() .. "/screenshots/" .. filename)
|
||||
end
|
||||
|
||||
local function highlight_text(readerui, pos0, pos1)
|
||||
readerui.highlight:onHold(nil, { pos = pos0 })
|
||||
readerui.highlight:onHoldPan(nil, { pos = pos1 })
|
||||
@@ -79,13 +75,13 @@ describe("ReaderBookmark module", function()
|
||||
it("should show dogear after toggling non-bookmarked page", function()
|
||||
assert.falsy(readerui.view.dogear_visible)
|
||||
toggler_dogear(readerui)
|
||||
screenshot("reader_bookmark_dogear_epub.png")
|
||||
screenshot(Screen, "reader_bookmark_dogear_epub.png")
|
||||
assert.truthy(readerui.view.dogear_visible)
|
||||
end)
|
||||
it("should not show dogear after toggling bookmarked page", function()
|
||||
assert.truthy(readerui.view.dogear_visible)
|
||||
toggler_dogear(readerui)
|
||||
screenshot("reader_bookmark_nodogear_epub.png")
|
||||
screenshot(Screen, "reader_bookmark_nodogear_epub.png")
|
||||
assert.falsy(readerui.view.dogear_visible)
|
||||
end)
|
||||
it("should sort bookmarks with ascending page numbers", function()
|
||||
@@ -96,7 +92,7 @@ describe("ReaderBookmark module", function()
|
||||
end
|
||||
readerui.bookmark:onShowBookmark()
|
||||
show_bookmark_menu(readerui)
|
||||
screenshot("reader_bookmark_10marks_epub.png")
|
||||
screenshot(Screen, "reader_bookmark_10marks_epub.png")
|
||||
assert.are.same(10, #readerui.annotation.annotations)
|
||||
assert.are.same(15, readerui.document:getPageFromXPointer(readerui.annotation.annotations[4].page))
|
||||
end)
|
||||
@@ -108,7 +104,7 @@ describe("ReaderBookmark module", function()
|
||||
end
|
||||
readerui.bookmark:onShowBookmark()
|
||||
show_bookmark_menu(readerui)
|
||||
screenshot("reader_bookmark_5marks_epub.png")
|
||||
screenshot(Screen, "reader_bookmark_5marks_epub.png")
|
||||
assert.are.same(5, #readerui.annotation.annotations)
|
||||
end)
|
||||
it("should add bookmark by highlighting", function()
|
||||
@@ -117,7 +113,7 @@ describe("ReaderBookmark module", function()
|
||||
Geom:new{ x = 260, y = 90 })
|
||||
readerui.bookmark:onShowBookmark()
|
||||
show_bookmark_menu(readerui)
|
||||
screenshot("reader_bookmark_6marks_epub.png")
|
||||
screenshot(Screen, "reader_bookmark_6marks_epub.png")
|
||||
assert.are.same(6, #readerui.annotation.annotations)
|
||||
end)
|
||||
it("should get previous bookmark for certain page", function()
|
||||
@@ -154,12 +150,12 @@ describe("ReaderBookmark module", function()
|
||||
end)
|
||||
it("should show dogear after toggling non-bookmarked page", function()
|
||||
toggler_dogear(readerui)
|
||||
screenshot("reader_bookmark_dogear_pdf.png")
|
||||
screenshot(Screen, "reader_bookmark_dogear_pdf.png")
|
||||
assert.truthy(readerui.view.dogear_visible)
|
||||
end)
|
||||
it("should not show dogear after toggling bookmarked page", function()
|
||||
toggler_dogear(readerui)
|
||||
screenshot("reader_bookmark_nodogear_pdf.png")
|
||||
screenshot(Screen, "reader_bookmark_nodogear_pdf.png")
|
||||
assert.truthy(not readerui.view.dogear_visible)
|
||||
end)
|
||||
it("should sort bookmarks with ascending page numbers", function()
|
||||
@@ -170,7 +166,7 @@ describe("ReaderBookmark module", function()
|
||||
end
|
||||
readerui.bookmark:onShowBookmark()
|
||||
show_bookmark_menu(readerui)
|
||||
screenshot("reader_bookmark_10marks_pdf.png")
|
||||
screenshot(Screen, "reader_bookmark_10marks_pdf.png")
|
||||
assert.are.same(10, #readerui.annotation.annotations)
|
||||
assert.are.same(15, readerui.annotation.annotations[4].page)
|
||||
end)
|
||||
@@ -182,14 +178,14 @@ describe("ReaderBookmark module", function()
|
||||
end
|
||||
readerui.bookmark:onShowBookmark()
|
||||
show_bookmark_menu(readerui)
|
||||
screenshot("reader_bookmark_5marks_pdf.png")
|
||||
screenshot(Screen, "reader_bookmark_5marks_pdf.png")
|
||||
assert.are.same(5, #readerui.annotation.annotations)
|
||||
end)
|
||||
it("should add bookmark by highlighting", function()
|
||||
highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 })
|
||||
readerui.bookmark:onShowBookmark()
|
||||
show_bookmark_menu(readerui)
|
||||
screenshot("reader_bookmark_6marks_pdf.png")
|
||||
screenshot(Screen, "reader_bookmark_6marks_pdf.png")
|
||||
assert.are.same(6, #readerui.annotation.annotations)
|
||||
end)
|
||||
it("should get previous bookmark for certain page", function()
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
describe("Readerdictionary module", function()
|
||||
local DataStorage, DocumentRegistry, ReaderUI, UIManager, Screen
|
||||
local DocumentRegistry, ReaderUI, UIManager, Screen
|
||||
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
disable_plugins()
|
||||
load_plugin("japanese.koplugin")
|
||||
DataStorage = require("datastorage")
|
||||
DocumentRegistry = require("document/documentregistry")
|
||||
ReaderUI = require("apps/reader/readerui")
|
||||
UIManager = require("ui/uimanager")
|
||||
Screen = require("device").screen
|
||||
end)
|
||||
|
||||
local function screenshot(filename)
|
||||
Screen:shot(DataStorage:getDataDir() .. "/screenshots/" .. filename)
|
||||
end
|
||||
|
||||
local readerui, rolling, dictionary
|
||||
setup(function()
|
||||
local sample_epub = "spec/front/unit/data/leaves.epub"
|
||||
@@ -42,7 +37,7 @@ describe("Readerdictionary module", function()
|
||||
ReaderUI.instance = readerui
|
||||
end)
|
||||
UIManager:run()
|
||||
screenshot("screenshots/reader_dictionary.png")
|
||||
screenshot(Screen, "reader_dictionary.png")
|
||||
end)
|
||||
it("should attempt to deinflect (Japanese) word on lookup", function()
|
||||
UIManager:quit()
|
||||
@@ -72,6 +67,6 @@ describe("Readerdictionary module", function()
|
||||
ReaderUI.instance = readerui
|
||||
end)
|
||||
UIManager:run()
|
||||
screenshot("screenshots/reader_dictionary_japanese.png")
|
||||
screenshot(Screen, "reader_dictionary_japanese.png")
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -18,10 +18,6 @@ describe("Readerhighlight module", function()
|
||||
require("ffi/util").copyFile("spec/front/unit/data/sample.pdf", sample_pdf)
|
||||
end)
|
||||
|
||||
local function screenshot(filename)
|
||||
Screen:shot(DataStorage:getDataDir() .. "/screenshots/" .. filename)
|
||||
end
|
||||
|
||||
local function highlight_single_word(readerui, pos0)
|
||||
local s = spy.on(readerui.languagesupport, "improveWordSelection")
|
||||
|
||||
@@ -112,7 +108,7 @@ describe("Readerhighlight module", function()
|
||||
end)
|
||||
it("should highlight single word", function()
|
||||
highlight_single_word(readerui, Geom:new{ x = 400, y = 70 })
|
||||
screenshot("reader_highlight_single_word_epub.png")
|
||||
screenshot(Screen, "reader_highlight_single_word_epub.png")
|
||||
assert.spy(selection_spy).was_called()
|
||||
assert.truthy(#readerui.annotation.annotations == 1)
|
||||
end)
|
||||
@@ -120,7 +116,7 @@ describe("Readerhighlight module", function()
|
||||
highlight_text(readerui,
|
||||
Geom:new{ x = 400, y = 110 },
|
||||
Geom:new{ x = 400, y = 170 })
|
||||
screenshot("reader_highlight_text_epub.png")
|
||||
screenshot(Screen, "reader_highlight_text_epub.png")
|
||||
assert.spy(selection_spy).was_called()
|
||||
assert.truthy(#readerui.annotation.annotations == 1)
|
||||
end)
|
||||
@@ -129,7 +125,7 @@ describe("Readerhighlight module", function()
|
||||
Geom:new{ x = 130, y = 100 },
|
||||
Geom:new{ x = 350, y = 395 },
|
||||
Geom:new{ x = 80, y = 265 })
|
||||
screenshot("reader_tap_highlight_text_epub.png")
|
||||
screenshot(Screen, "reader_tap_highlight_text_epub.png")
|
||||
assert.spy(selection_spy).was_called()
|
||||
end)
|
||||
end)
|
||||
@@ -163,16 +159,16 @@ describe("Readerhighlight module", function()
|
||||
Geom:new{ x = 260, y = 70 },
|
||||
Geom:new{ x = 260, y = 150 },
|
||||
Geom:new{ x = 280, y = 110 })
|
||||
screenshot("reader_tap_highlight_text_pdf.png")
|
||||
screenshot(Screen, "reader_tap_highlight_text_pdf.png")
|
||||
end)
|
||||
it("should highlight single word", function()
|
||||
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
|
||||
screenshot("reader_highlight_single_word_pdf.png")
|
||||
screenshot(Screen, "reader_highlight_single_word_pdf.png")
|
||||
assert.truthy(#readerui.annotation.annotations == 1)
|
||||
end)
|
||||
it("should highlight text", function()
|
||||
highlight_text(readerui, Geom:new{ x = 260, y = 170 }, Geom:new{ x = 260, y = 250 })
|
||||
screenshot("reader_highlight_text_pdf.png")
|
||||
screenshot(Screen, "reader_highlight_text_pdf.png")
|
||||
assert.truthy(#readerui.annotation.annotations == 1)
|
||||
end)
|
||||
end)
|
||||
@@ -188,16 +184,16 @@ describe("Readerhighlight module", function()
|
||||
end)
|
||||
it("should respond to 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 })
|
||||
screenshot("reader_tap_highlight_text_pdf_scanned.png")
|
||||
screenshot(Screen, "reader_tap_highlight_text_pdf_scanned.png")
|
||||
end)
|
||||
it("should highlight single word", function()
|
||||
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
|
||||
screenshot("reader_highlight_single_word_pdf_scanned.png")
|
||||
screenshot(Screen, "reader_highlight_single_word_pdf_scanned.png")
|
||||
assert.truthy(#readerui.annotation.annotations == 1)
|
||||
end)
|
||||
it("should highlight text", function()
|
||||
highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 })
|
||||
screenshot("reader_highlight_text_pdf_scanned.png")
|
||||
screenshot(Screen, "reader_highlight_text_pdf_scanned.png")
|
||||
assert.truthy(#readerui.annotation.annotations == 1)
|
||||
end)
|
||||
end)
|
||||
@@ -218,16 +214,16 @@ describe("Readerhighlight module", function()
|
||||
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 })
|
||||
screenshot("reader_tap_highlight_text_pdf_reflowed.png")
|
||||
screenshot(Screen, "reader_tap_highlight_text_pdf_reflowed.png")
|
||||
end)
|
||||
it("should highlight single word", function()
|
||||
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
|
||||
screenshot("reader_highlight_single_word_pdf_reflowed.png")
|
||||
screenshot(Screen, "reader_highlight_single_word_pdf_reflowed.png")
|
||||
assert.truthy(#readerui.annotation.annotations == 1)
|
||||
end)
|
||||
it("should highlight text", function()
|
||||
highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 })
|
||||
screenshot("reader_highlight_text_pdf_reflowed.png")
|
||||
screenshot(Screen, "reader_highlight_text_pdf_reflowed.png")
|
||||
assert.truthy(#readerui.annotation.annotations == 1)
|
||||
end)
|
||||
end)
|
||||
@@ -261,11 +257,11 @@ describe("Readerhighlight module", function()
|
||||
end)
|
||||
it("should highlight single word", function()
|
||||
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
|
||||
screenshot("reader_highlight_single_word_pdf_scroll.png")
|
||||
screenshot(Screen, "reader_highlight_single_word_pdf_scroll.png")
|
||||
end)
|
||||
it("should highlight text", function()
|
||||
highlight_text(readerui, Geom:new{ x = 260, y = 170 }, Geom:new{ x = 260, y = 250 })
|
||||
screenshot("reader_highlight_text_pdf_scroll.png")
|
||||
screenshot(Screen, "reader_highlight_text_pdf_scroll.png")
|
||||
assert.truthy(#readerui.annotation.annotations == 1)
|
||||
end)
|
||||
it("should response on tap gesture", function()
|
||||
@@ -273,7 +269,7 @@ describe("Readerhighlight module", function()
|
||||
Geom:new{ x = 260, y = 70 },
|
||||
Geom:new{ x = 260, y = 150 },
|
||||
Geom:new{ x = 280, y = 110 })
|
||||
screenshot("reader_tap_highlight_text_pdf_scroll.png")
|
||||
screenshot(Screen, "reader_tap_highlight_text_pdf_scroll.png")
|
||||
assert.truthy(#readerui.annotation.annotations == 1)
|
||||
end)
|
||||
end)
|
||||
@@ -290,17 +286,17 @@ describe("Readerhighlight module", function()
|
||||
end)
|
||||
it("should highlight single word", function()
|
||||
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
|
||||
screenshot("reader_highlight_single_word_pdf_scanned_scroll.png")
|
||||
screenshot(Screen, "reader_highlight_single_word_pdf_scanned_scroll.png")
|
||||
assert.truthy(#readerui.annotation.annotations == 1)
|
||||
end)
|
||||
it("should highlight text", function()
|
||||
highlight_text(readerui, Geom:new{x = 192, y = 186}, Geom:new{x = 280, y = 186})
|
||||
screenshot("reader_highlight_text_pdf_scanned_scroll.png")
|
||||
screenshot(Screen, "reader_highlight_text_pdf_scanned_scroll.png")
|
||||
assert.truthy(#readerui.annotation.annotations == 1)
|
||||
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 })
|
||||
screenshot("reader_tap_highlight_text_pdf_scanned_scroll.png")
|
||||
screenshot(Screen, "reader_tap_highlight_text_pdf_scanned_scroll.png")
|
||||
end)
|
||||
end)
|
||||
describe("for reflowed page", function()
|
||||
@@ -320,17 +316,17 @@ describe("Readerhighlight module", function()
|
||||
end)
|
||||
it("should highlight single word", function()
|
||||
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
|
||||
screenshot("reader_highlight_single_word_pdf_reflowed_scroll.png")
|
||||
screenshot(Screen, "reader_highlight_single_word_pdf_reflowed_scroll.png")
|
||||
assert.truthy(#readerui.annotation.annotations == 1)
|
||||
end)
|
||||
it("should highlight text", function()
|
||||
highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 })
|
||||
screenshot("reader_highlight_text_pdf_reflowed_scroll.png")
|
||||
screenshot(Screen, "reader_highlight_text_pdf_reflowed_scroll.png")
|
||||
assert.truthy(#readerui.annotation.annotations == 1)
|
||||
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 })
|
||||
screenshot("reader_tap_highlight_text_pdf_reflowed_scroll.png")
|
||||
screenshot(Screen, "reader_tap_highlight_text_pdf_reflowed_scroll.png")
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
describe("ReaderLink module", function()
|
||||
local DocumentRegistry, ReaderUI, UIManager, sample_epub, sample_pdf, Event, Screen
|
||||
local DocumentRegistry, ReaderUI, sample_epub, sample_pdf, Event, Screen
|
||||
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
@@ -8,7 +8,6 @@ describe("ReaderLink module", function()
|
||||
DocumentRegistry = require("document/documentregistry")
|
||||
Event = require("ui/event")
|
||||
ReaderUI = require("apps/reader/readerui")
|
||||
UIManager = require("ui/uimanager")
|
||||
Screen = require("device").screen
|
||||
sample_epub = "spec/front/unit/data/leaves.epub"
|
||||
sample_pdf = "spec/front/unit/data/paper.pdf"
|
||||
@@ -16,18 +15,10 @@ describe("ReaderLink module", function()
|
||||
|
||||
local readerui
|
||||
|
||||
local function fastforward_ui_events()
|
||||
-- Fast forward all scheduled tasks.
|
||||
UIManager:shiftScheduledTasksBy(-1e9)
|
||||
UIManager:run()
|
||||
end
|
||||
|
||||
after_each(function()
|
||||
readerui:closeDocument()
|
||||
readerui:onClose()
|
||||
readerui = nil
|
||||
UIManager:quit()
|
||||
UIManager._exit_code = nil
|
||||
end)
|
||||
|
||||
describe("with epub", function()
|
||||
|
||||
Reference in New Issue
Block a user