tests: improve frontend testsuite isolation

This commit is contained in:
Benoit Pierre
2024-11-24 23:05:35 +01:00
committed by Frans de Jonge
parent 8005275388
commit 8c839d9ead
10 changed files with 89 additions and 69 deletions

View File

@@ -54,6 +54,7 @@ G_defaults = require("luadefaults"):open(DataStorage:getDataDir() .. "/defaults.
os.remove(DataStorage:getDataDir() .. "/settings.tests.lua") os.remove(DataStorage:getDataDir() .. "/settings.tests.lua")
os.remove(DataStorage:getDataDir() .. "/settings.tests.lua.old") os.remove(DataStorage:getDataDir() .. "/settings.tests.lua.old")
G_reader_settings = require("luasettings"):open(DataStorage:getDataDir() .. "/settings.tests.lua") G_reader_settings = require("luasettings"):open(DataStorage:getDataDir() .. "/settings.tests.lua")
G_reader_settings:saveSetting("document_metadata_folder", "dir")
-- global einkfb for Screen (do not show SDL window) -- global einkfb for Screen (do not show SDL window)
einkfb = require("ffi/framebuffer") --luacheck: ignore einkfb = require("ffi/framebuffer") --luacheck: ignore

View File

@@ -49,7 +49,7 @@ describe("docsettings module", function()
it("should read legacy history file", function() it("should read legacy history file", function()
G_reader_settings:delSetting("document_metadata_folder") G_reader_settings:delSetting("document_metadata_folder")
local file = "file.pdf" local file = DataStorage:getDataDir() .. "/file.pdf"
local d = docsettings:open(file) local d = docsettings:open(file)
d:saveSetting("a", "b") d:saveSetting("a", "b")
d:saveSetting("c", "d") d:saveSetting("c", "d")
@@ -59,7 +59,7 @@ describe("docsettings module", function()
local legacy_files = { local legacy_files = {
docsettings:getHistoryPath(file), docsettings:getHistoryPath(file),
d.doc_sidecar_dir .. "/file.pdf.lua", d.doc_sidecar_dir .. "/file.pdf.lua",
"file.pdf.kpdfview.lua", file .. ".kpdfview.lua",
} }
for _, f in ipairs(legacy_files) do for _, f in ipairs(legacy_files) do
@@ -83,13 +83,13 @@ describe("docsettings module", function()
end) end)
it("should respect newest history file", function() it("should respect newest history file", function()
local file = "file.pdf" local file = DataStorage:getDataDir() .. "/file.pdf"
local d = docsettings:open(file) local d = docsettings:open(file)
local legacy_files = { local legacy_files = {
docsettings:getHistoryPath(file), docsettings:getHistoryPath(file),
d.doc_sidecar_dir .. "/file.pdf.lua", d.doc_sidecar_dir .. "/file.pdf.lua",
"file.pdf.kpdfview.lua", file .. ".kpdfview.lua",
} }
-- docsettings:flush will remove legacy files. -- docsettings:flush will remove legacy files.
@@ -120,7 +120,7 @@ describe("docsettings module", function()
it("should reserve last good file", function() it("should reserve last good file", function()
G_reader_settings:delSetting("document_metadata_folder") G_reader_settings:delSetting("document_metadata_folder")
local file = "file.pdf" local file = DataStorage:getDataDir() .. "/file.pdf"
local d = docsettings:open(file) local d = docsettings:open(file)
d:saveSetting("a", "a") d:saveSetting("a", "a")
d:flush() d:flush()
@@ -179,7 +179,7 @@ describe("docsettings module", function()
describe("ignore empty sidecar file", function() describe("ignore empty sidecar file", function()
it("should ignore empty file", function() it("should ignore empty file", function()
G_reader_settings:delSetting("document_metadata_folder") G_reader_settings:delSetting("document_metadata_folder")
local file = "file.pdf" local file = DataStorage:getDataDir() .. "/file.pdf"
local d = docsettings:open(file) local d = docsettings:open(file)
d:saveSetting("a", "a") d:saveSetting("a", "a")
d:flush() d:flush()
@@ -213,7 +213,7 @@ describe("docsettings module", function()
it("should ignore empty table", function() it("should ignore empty table", function()
G_reader_settings:delSetting("document_metadata_folder") G_reader_settings:delSetting("document_metadata_folder")
local file = "file.pdf" local file = DataStorage.getDataDir() .. "/file.pdf"
local d = docsettings:open(file) local d = docsettings:open(file)
d:saveSetting("a", "a") d:saveSetting("a", "a")
d:flush() d:flush()

View File

@@ -1,21 +1,23 @@
describe("FileManager module", function() describe("FileManager module", function()
local FileManager, lfs, docsettings, UIManager, Screen, util local DataStorage, FileManager, lfs, docsettings, UIManager, Screen, makePath, util
setup(function() setup(function()
require("commonrequire") require("commonrequire")
package.unloadAll() package.unloadAll()
require("document/canvascontext"):init(require("device")) require("document/canvascontext"):init(require("device"))
DataStorage = require("datastorage")
FileManager = require("apps/filemanager/filemanager") FileManager = require("apps/filemanager/filemanager")
Screen = require("device").screen Screen = require("device").screen
UIManager = require("ui/uimanager") UIManager = require("ui/uimanager")
docsettings = require("docsettings") docsettings = require("docsettings")
lfs = require("libs/libkoreader-lfs") lfs = require("libs/libkoreader-lfs")
makePath = require("util").makePath
util = require("ffi/util") util = require("ffi/util")
end) end)
it("should show file manager", function() it("should show file manager", function()
UIManager:quit() UIManager:quit()
local filemanager = FileManager:new{ local filemanager = FileManager:new{
dimen = Screen:getSize(), dimen = Screen:getSize(),
root_path = "../../test", root_path = "spec/front/unit/data",
} }
UIManager:show(filemanager) UIManager:show(filemanager)
UIManager:scheduleIn(1, function() filemanager:onClose() end) UIManager:scheduleIn(1, function() filemanager:onClose() end)
@@ -24,7 +26,7 @@ describe("FileManager module", function()
it("should show error on non-existent file", function() it("should show error on non-existent file", function()
local filemanager = FileManager:new{ local filemanager = FileManager:new{
dimen = Screen:getSize(), dimen = Screen:getSize(),
root_path = "../../test", root_path = "spec/front/unit/data",
} }
local old_show = UIManager.show local old_show = UIManager.show
local tmp_fn = "/abc/123/test/foo.bar.baz.tmp.epub.pdf" local tmp_fn = "/abc/123/test/foo.bar.baz.tmp.epub.pdf"
@@ -39,15 +41,15 @@ describe("FileManager module", function()
it("should not delete not empty sidecar folder", function() it("should not delete not empty sidecar folder", function()
local filemanager = FileManager:new{ local filemanager = FileManager:new{
dimen = Screen:getSize(), dimen = Screen:getSize(),
root_path = "../../test", root_path = "spec/front/unit/data",
} }
local tmp_fn = "../../test/2col.test.tmp.foo" local tmp_fn = DataStorage:getDataDir() .. "/2col.test.tmp.foo"
util.copyFile("../../test/2col.pdf", tmp_fn) util.copyFile("spec/front/unit/data/2col.pdf", tmp_fn)
local tmp_sidecar = docsettings:getSidecarDir(util.realpath(tmp_fn)) local tmp_sidecar = docsettings:getSidecarDir(tmp_fn)
lfs.mkdir(tmp_sidecar) makePath(tmp_sidecar)
local tmp_sidecar_file = docsettings:getSidecarDir(util.realpath(tmp_fn)).."/"..docsettings.getSidecarFilename(util.realpath(tmp_fn)) local tmp_sidecar_file = docsettings.getSidecarFilename(tmp_fn)
local tmp_sidecar_file_foo = tmp_sidecar_file .. ".foo" -- non-docsettings file local tmp_sidecar_file_foo = tmp_sidecar_file .. ".foo" -- non-docsettings file
local tmpsf = io.open(tmp_sidecar_file, "w") local tmpsf = io.open(tmp_sidecar_file, "w")
tmpsf:write("{}") tmpsf:write("{}")
@@ -77,15 +79,15 @@ describe("FileManager module", function()
it("should delete document with its settings", function() it("should delete document with its settings", function()
local filemanager = FileManager:new{ local filemanager = FileManager:new{
dimen = Screen:getSize(), dimen = Screen:getSize(),
root_path = "../../test", root_path = "spec/front/unit/data",
} }
local tmp_fn = "../../test/2col.test.tmp.pdf" local tmp_fn = DataStorage:getDataDir() .. "/2col.test.tmp.pdf"
util.copyFile("../../test/2col.pdf", tmp_fn) util.copyFile("spec/front/unit/data/2col.pdf", tmp_fn)
local tmp_sidecar = docsettings:getSidecarDir(util.realpath(tmp_fn)) local tmp_sidecar = docsettings:getSidecarDir(tmp_fn)
lfs.mkdir(tmp_sidecar) makePath(tmp_sidecar)
local tmp_sidecar_file = docsettings:getSidecarDir(util.realpath(tmp_fn)).."/"..docsettings.getSidecarFilename(util.realpath(tmp_fn)) local tmp_sidecar_file = docsettings.getSidecarFilename(tmp_fn)
local tmpsf = io.open(tmp_sidecar_file, "w") local tmpsf = io.open(tmp_sidecar_file, "w")
tmpsf:write("{}") tmpsf:write("{}")
tmpsf:close() tmpsf:close()

View File

@@ -1,9 +1,10 @@
describe("luadata module", function() describe("luadata module", function()
local Settings, lfs local DataStorage, Settings, lfs
setup(function() setup(function()
require("commonrequire") require("commonrequire")
DataStorage = require("datastorage")
lfs = require("libs/libkoreader-lfs") lfs = require("libs/libkoreader-lfs")
Settings = require("frontend/luadata"):open("this-is-not-a-valid-file") Settings = require("frontend/luadata"):open(DataStorage:getDataDir() .. "/this-is-not-a-valid-file")
end) end)
it("should handle undefined keys", function() it("should handle undefined keys", function()
@@ -94,7 +95,7 @@ describe("luadata module", function()
describe("backup data file", function() describe("backup data file", function()
local file, d local file, d
setup(function() setup(function()
file = "dummy-test-file" file = DataStorage:getDataDir() .. "/dummy-test-file"
d = Settings:open(file) d = Settings:open(file)
end) end)
it("should generate data file", function() it("should generate data file", function()

View File

@@ -1,8 +1,9 @@
describe("luasettings module", function() describe("luasettings module", function()
local Settings local DataStorage, Settings
setup(function() setup(function()
require("commonrequire") require("commonrequire")
Settings = require("frontend/luasettings"):open("this-is-not-a-valid-file") DataStorage = require("datastorage")
Settings = require("frontend/luasettings"):open(DataStorage:getDataDir() .. "/this-is-not-a-valid-file")
end) end)
it("should handle undefined keys", function() it("should handle undefined keys", function()

View File

@@ -27,11 +27,12 @@ describe("Persist module", function()
setup(function() setup(function()
require("commonrequire") require("commonrequire")
Persist = require("persist") Persist = require("persist")
bitserInstance = Persist:new{ path = "test.dat", codec = "bitser" } local datadir = require("datastorage"):getDataDir()
luajitInstance = Persist:new{ path = "testj.dat", codec = "luajit" } bitserInstance = Persist:new{ path = datadir .. "/test.dat", codec = "bitser" }
zstdInstance = Persist:new{ path = "test.zst", codec = "zstd" } luajitInstance = Persist:new{ path = datadir .. "/testj.dat", codec = "luajit" }
dumpInstance = Persist:new{ path = "test.lua", codec = "dump" } zstdInstance = Persist:new{ path = datadir .. "/test.zst", codec = "zstd" }
serpentInstance = Persist:new{ path = "tests.lua", codec = "serpent" } dumpInstance = Persist:new{ path = datadir .. "/test.lua", codec = "dump" }
serpentInstance = Persist:new{ path = datadir .. "/tests.lua", codec = "serpent" }
sample = arrayOf(1000) sample = arrayOf(1000)
end) end)

View File

@@ -19,6 +19,10 @@ describe("ReaderBookmark module", function()
Util.copyFile("spec/front/unit/data/sample.pdf", sample_pdf) Util.copyFile("spec/front/unit/data/sample.pdf", sample_pdf)
end) end)
local function screenshot(filename)
Screen:shot(DataStorage:getDataDir() .. "/screenshots/" .. filename)
end
local function highlight_text(readerui, pos0, pos1) local function highlight_text(readerui, pos0, pos1)
readerui.highlight:onHold(nil, { pos = pos0 }) readerui.highlight:onHold(nil, { pos = pos0 })
readerui.highlight:onHoldPan(nil, { pos = pos1 }) readerui.highlight:onHoldPan(nil, { pos = pos1 })
@@ -74,13 +78,13 @@ describe("ReaderBookmark module", function()
it("should show dogear after toggling non-bookmarked page", function() it("should show dogear after toggling non-bookmarked page", function()
assert.falsy(readerui.view.dogear_visible) assert.falsy(readerui.view.dogear_visible)
toggler_dogear(readerui) toggler_dogear(readerui)
Screen:shot("screenshots/reader_bookmark_dogear_epub.png") screenshot("reader_bookmark_dogear_epub.png")
assert.truthy(readerui.view.dogear_visible) assert.truthy(readerui.view.dogear_visible)
end) end)
it("should not show dogear after toggling bookmarked page", function() it("should not show dogear after toggling bookmarked page", function()
assert.truthy(readerui.view.dogear_visible) assert.truthy(readerui.view.dogear_visible)
toggler_dogear(readerui) toggler_dogear(readerui)
Screen:shot("screenshots/reader_bookmark_nodogear_epub.png") screenshot("reader_bookmark_nodogear_epub.png")
assert.falsy(readerui.view.dogear_visible) assert.falsy(readerui.view.dogear_visible)
end) end)
it("should sort bookmarks with ascending page numbers", function() it("should sort bookmarks with ascending page numbers", function()
@@ -91,7 +95,7 @@ describe("ReaderBookmark module", function()
end end
readerui.bookmark:onShowBookmark() readerui.bookmark:onShowBookmark()
show_bookmark_menu(readerui) show_bookmark_menu(readerui)
Screen:shot("screenshots/reader_bookmark_10marks_epub.png") screenshot("reader_bookmark_10marks_epub.png")
assert.are.same(10, #readerui.annotation.annotations) assert.are.same(10, #readerui.annotation.annotations)
assert.are.same(15, readerui.document:getPageFromXPointer(readerui.annotation.annotations[4].page)) assert.are.same(15, readerui.document:getPageFromXPointer(readerui.annotation.annotations[4].page))
end) end)
@@ -103,7 +107,7 @@ describe("ReaderBookmark module", function()
end end
readerui.bookmark:onShowBookmark() readerui.bookmark:onShowBookmark()
show_bookmark_menu(readerui) show_bookmark_menu(readerui)
Screen:shot("screenshots/reader_bookmark_5marks_epub.png") screenshot("reader_bookmark_5marks_epub.png")
assert.are.same(5, #readerui.annotation.annotations) assert.are.same(5, #readerui.annotation.annotations)
end) end)
it("should add bookmark by highlighting", function() it("should add bookmark by highlighting", function()
@@ -112,7 +116,7 @@ describe("ReaderBookmark module", function()
Geom:new{ x = 260, y = 90 }) Geom:new{ x = 260, y = 90 })
readerui.bookmark:onShowBookmark() readerui.bookmark:onShowBookmark()
show_bookmark_menu(readerui) show_bookmark_menu(readerui)
Screen:shot("screenshots/reader_bookmark_6marks_epub.png") screenshot("reader_bookmark_6marks_epub.png")
assert.are.same(6, #readerui.annotation.annotations) assert.are.same(6, #readerui.annotation.annotations)
end) end)
it("should get previous bookmark for certain page", function() it("should get previous bookmark for certain page", function()
@@ -149,12 +153,12 @@ describe("ReaderBookmark module", function()
end) end)
it("should show dogear after toggling non-bookmarked page", function() it("should show dogear after toggling non-bookmarked page", function()
toggler_dogear(readerui) toggler_dogear(readerui)
Screen:shot("screenshots/reader_bookmark_dogear_pdf.png") screenshot("reader_bookmark_dogear_pdf.png")
assert.truthy(readerui.view.dogear_visible) assert.truthy(readerui.view.dogear_visible)
end) end)
it("should not show dogear after toggling bookmarked page", function() it("should not show dogear after toggling bookmarked page", function()
toggler_dogear(readerui) toggler_dogear(readerui)
Screen:shot("screenshots/reader_bookmark_nodogear_pdf.png") screenshot("reader_bookmark_nodogear_pdf.png")
assert.truthy(not readerui.view.dogear_visible) assert.truthy(not readerui.view.dogear_visible)
end) end)
it("should sort bookmarks with ascending page numbers", function() it("should sort bookmarks with ascending page numbers", function()
@@ -165,7 +169,7 @@ describe("ReaderBookmark module", function()
end end
readerui.bookmark:onShowBookmark() readerui.bookmark:onShowBookmark()
show_bookmark_menu(readerui) show_bookmark_menu(readerui)
Screen:shot("screenshots/reader_bookmark_10marks_pdf.png") screenshot("reader_bookmark_10marks_pdf.png")
assert.are.same(10, #readerui.annotation.annotations) assert.are.same(10, #readerui.annotation.annotations)
assert.are.same(15, readerui.annotation.annotations[4].page) assert.are.same(15, readerui.annotation.annotations[4].page)
end) end)
@@ -177,14 +181,14 @@ describe("ReaderBookmark module", function()
end end
readerui.bookmark:onShowBookmark() readerui.bookmark:onShowBookmark()
show_bookmark_menu(readerui) show_bookmark_menu(readerui)
Screen:shot("screenshots/reader_bookmark_5marks_pdf.png") screenshot("reader_bookmark_5marks_pdf.png")
assert.are.same(5, #readerui.annotation.annotations) assert.are.same(5, #readerui.annotation.annotations)
end) end)
it("should add bookmark by highlighting", function() it("should add bookmark by highlighting", function()
highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 }) highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 })
readerui.bookmark:onShowBookmark() readerui.bookmark:onShowBookmark()
show_bookmark_menu(readerui) show_bookmark_menu(readerui)
Screen:shot("screenshots/reader_bookmark_6marks_pdf.png") screenshot("reader_bookmark_6marks_pdf.png")
assert.are.same(6, #readerui.annotation.annotations) assert.are.same(6, #readerui.annotation.annotations)
end) end)
it("should get previous bookmark for certain page", function() it("should get previous bookmark for certain page", function()

View File

@@ -1,14 +1,19 @@
describe("Readerdictionary module", function() describe("Readerdictionary module", function()
local DocumentRegistry, ReaderUI, UIManager, Screen local DataStorage, DocumentRegistry, ReaderUI, UIManager, Screen
setup(function() setup(function()
require("commonrequire") require("commonrequire")
DataStorage = require("datastorage")
DocumentRegistry = require("document/documentregistry") DocumentRegistry = require("document/documentregistry")
ReaderUI = require("apps/reader/readerui") ReaderUI = require("apps/reader/readerui")
UIManager = require("ui/uimanager") UIManager = require("ui/uimanager")
Screen = require("device").screen Screen = require("device").screen
end) end)
local function screenshot(filename)
Screen:shot(DataStorage:getDataDir() .. "/screenshots/" .. filename)
end
local readerui, rolling, dictionary local readerui, rolling, dictionary
setup(function() setup(function()
local sample_epub = "spec/front/unit/data/leaves.epub" local sample_epub = "spec/front/unit/data/leaves.epub"
@@ -35,7 +40,7 @@ describe("Readerdictionary module", function()
ReaderUI.instance = readerui ReaderUI.instance = readerui
end) end)
UIManager:run() UIManager:run()
Screen:shot("screenshots/reader_dictionary.png") screenshot("screenshots/reader_dictionary.png")
end) end)
it("should attempt to deinflect (Japanese) word on lookup", function() it("should attempt to deinflect (Japanese) word on lookup", function()
UIManager:quit() UIManager:quit()
@@ -65,6 +70,6 @@ describe("Readerdictionary module", function()
ReaderUI.instance = readerui ReaderUI.instance = readerui
end) end)
UIManager:run() UIManager:run()
Screen:shot("screenshots/reader_dictionary_japanese.png") screenshot("screenshots/reader_dictionary_japanese.png")
end) end)
end) end)

View File

@@ -17,6 +17,10 @@ describe("Readerhighlight module", function()
require("ffi/util").copyFile("spec/front/unit/data/sample.pdf", sample_pdf) require("ffi/util").copyFile("spec/front/unit/data/sample.pdf", sample_pdf)
end) end)
local function screenshot(filename)
Screen:shot(DataStorage:getDataDir() .. "/screenshots/" .. filename)
end
local function highlight_single_word(readerui, pos0) local function highlight_single_word(readerui, pos0)
local s = spy.on(readerui.languagesupport, "improveWordSelection") local s = spy.on(readerui.languagesupport, "improveWordSelection")
@@ -107,7 +111,7 @@ describe("Readerhighlight module", function()
end) end)
it("should highlight single word", function() it("should highlight single word", function()
highlight_single_word(readerui, Geom:new{ x = 400, y = 70 }) highlight_single_word(readerui, Geom:new{ x = 400, y = 70 })
Screen:shot("screenshots/reader_highlight_single_word_epub.png") screenshot("reader_highlight_single_word_epub.png")
assert.spy(selection_spy).was_called() assert.spy(selection_spy).was_called()
assert.truthy(#readerui.annotation.annotations == 1) assert.truthy(#readerui.annotation.annotations == 1)
end) end)
@@ -115,7 +119,7 @@ describe("Readerhighlight module", function()
highlight_text(readerui, highlight_text(readerui,
Geom:new{ x = 400, y = 110 }, Geom:new{ x = 400, y = 110 },
Geom:new{ x = 400, y = 170 }) Geom:new{ x = 400, y = 170 })
Screen:shot("screenshots/reader_highlight_text_epub.png") screenshot("reader_highlight_text_epub.png")
assert.spy(selection_spy).was_called() assert.spy(selection_spy).was_called()
assert.truthy(#readerui.annotation.annotations == 1) assert.truthy(#readerui.annotation.annotations == 1)
end) end)
@@ -124,7 +128,7 @@ describe("Readerhighlight module", function()
Geom:new{ x = 130, y = 100 }, Geom:new{ x = 130, y = 100 },
Geom:new{ x = 350, y = 395 }, Geom:new{ x = 350, y = 395 },
Geom:new{ x = 80, y = 265 }) Geom:new{ x = 80, y = 265 })
Screen:shot("screenshots/reader_tap_highlight_text_epub.png") screenshot("reader_tap_highlight_text_epub.png")
assert.spy(selection_spy).was_called() assert.spy(selection_spy).was_called()
end) end)
end) end)
@@ -158,16 +162,16 @@ describe("Readerhighlight module", function()
Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 70 },
Geom:new{ x = 260, y = 150 }, Geom:new{ x = 260, y = 150 },
Geom:new{ x = 280, y = 110 }) Geom:new{ x = 280, y = 110 })
Screen:shot("screenshots/reader_tap_highlight_text_pdf.png") screenshot("reader_tap_highlight_text_pdf.png")
end) end)
it("should highlight single word", function() it("should highlight single word", function()
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 }) highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
Screen:shot("screenshots/reader_highlight_single_word_pdf.png") screenshot("reader_highlight_single_word_pdf.png")
assert.truthy(#readerui.annotation.annotations == 1) assert.truthy(#readerui.annotation.annotations == 1)
end) end)
it("should highlight text", function() it("should highlight text", function()
highlight_text(readerui, Geom:new{ x = 260, y = 170 }, Geom:new{ x = 260, y = 250 }) highlight_text(readerui, Geom:new{ x = 260, y = 170 }, Geom:new{ x = 260, y = 250 })
Screen:shot("screenshots/reader_highlight_text_pdf.png") screenshot("reader_highlight_text_pdf.png")
assert.truthy(#readerui.annotation.annotations == 1) assert.truthy(#readerui.annotation.annotations == 1)
end) end)
end) end)
@@ -183,16 +187,16 @@ describe("Readerhighlight module", function()
end) end)
it("should respond to tap gesture #nocov", function() it("should respond to tap gesture #nocov", function()
tap_highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 }, Geom:new{ x = 280, y = 110 }) 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.png") screenshot("reader_tap_highlight_text_pdf_scanned.png")
end) end)
it("should highlight single word", function() it("should highlight single word", function()
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 }) highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
Screen:shot("screenshots/reader_highlight_single_word_pdf_scanned.png") screenshot("reader_highlight_single_word_pdf_scanned.png")
assert.truthy(#readerui.annotation.annotations == 1) assert.truthy(#readerui.annotation.annotations == 1)
end) end)
it("should highlight text", function() it("should highlight text", function()
highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 }) highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 })
Screen:shot("screenshots/reader_highlight_text_pdf_scanned.png") screenshot("reader_highlight_text_pdf_scanned.png")
assert.truthy(#readerui.annotation.annotations == 1) assert.truthy(#readerui.annotation.annotations == 1)
end) end)
end) end)
@@ -213,16 +217,16 @@ describe("Readerhighlight module", function()
end) end)
it("should response on tap gesture #nocov", function() it("should response on tap gesture #nocov", function()
tap_highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 }, Geom:new{ x = 280, y = 110 }) 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.png") screenshot("reader_tap_highlight_text_pdf_reflowed.png")
end) end)
it("should highlight single word", function() it("should highlight single word", function()
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 }) highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
Screen:shot("screenshots/reader_highlight_single_word_pdf_reflowed.png") screenshot("reader_highlight_single_word_pdf_reflowed.png")
assert.truthy(#readerui.annotation.annotations == 1) assert.truthy(#readerui.annotation.annotations == 1)
end) end)
it("should highlight text", function() it("should highlight text", function()
highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 }) highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 })
Screen:shot("screenshots/reader_highlight_text_pdf_reflowed.png") screenshot("reader_highlight_text_pdf_reflowed.png")
assert.truthy(#readerui.annotation.annotations == 1) assert.truthy(#readerui.annotation.annotations == 1)
end) end)
end) end)
@@ -256,11 +260,11 @@ describe("Readerhighlight module", function()
end) end)
it("should highlight single word", function() it("should highlight single word", function()
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 }) highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
Screen:shot("screenshots/reader_highlight_single_word_pdf_scroll.png") screenshot("reader_highlight_single_word_pdf_scroll.png")
end) end)
it("should highlight text", function() it("should highlight text", function()
highlight_text(readerui, Geom:new{ x = 260, y = 170 }, Geom:new{ x = 260, y = 250 }) highlight_text(readerui, Geom:new{ x = 260, y = 170 }, Geom:new{ x = 260, y = 250 })
Screen:shot("screenshots/reader_highlight_text_pdf_scroll.png") screenshot("reader_highlight_text_pdf_scroll.png")
assert.truthy(#readerui.annotation.annotations == 1) assert.truthy(#readerui.annotation.annotations == 1)
end) end)
it("should response on tap gesture", function() it("should response on tap gesture", function()
@@ -268,7 +272,7 @@ describe("Readerhighlight module", function()
Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 70 },
Geom:new{ x = 260, y = 150 }, Geom:new{ x = 260, y = 150 },
Geom:new{ x = 280, y = 110 }) Geom:new{ x = 280, y = 110 })
Screen:shot("screenshots/reader_tap_highlight_text_pdf_scroll.png") screenshot("reader_tap_highlight_text_pdf_scroll.png")
assert.truthy(#readerui.annotation.annotations == 1) assert.truthy(#readerui.annotation.annotations == 1)
end) end)
end) end)
@@ -285,17 +289,17 @@ describe("Readerhighlight module", function()
end) end)
it("should highlight single word", function() it("should highlight single word", function()
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 }) highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
Screen:shot("screenshots/reader_highlight_single_word_pdf_scanned_scroll.png") screenshot("reader_highlight_single_word_pdf_scanned_scroll.png")
assert.truthy(#readerui.annotation.annotations == 1) assert.truthy(#readerui.annotation.annotations == 1)
end) end)
it("should highlight text", function() it("should highlight text", function()
highlight_text(readerui, Geom:new{x = 192, y = 186}, Geom:new{x = 280, y = 186}) 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") screenshot("reader_highlight_text_pdf_scanned_scroll.png")
assert.truthy(#readerui.annotation.annotations == 1) assert.truthy(#readerui.annotation.annotations == 1)
end) end)
it("should response on tap gesture", function() 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 }) 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") screenshot("reader_tap_highlight_text_pdf_scanned_scroll.png")
end) end)
end) end)
describe("for reflowed page", function() describe("for reflowed page", function()
@@ -315,17 +319,17 @@ describe("Readerhighlight module", function()
end) end)
it("should highlight single word", function() it("should highlight single word", function()
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 }) highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
Screen:shot("screenshots/reader_highlight_single_word_pdf_reflowed_scroll.png") screenshot("reader_highlight_single_word_pdf_reflowed_scroll.png")
assert.truthy(#readerui.annotation.annotations == 1) assert.truthy(#readerui.annotation.annotations == 1)
end) end)
it("should highlight text", function() it("should highlight text", function()
highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 }) 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") screenshot("reader_highlight_text_pdf_reflowed_scroll.png")
assert.truthy(#readerui.annotation.annotations == 1) assert.truthy(#readerui.annotation.annotations == 1)
end) end)
it("should response on tap gesture", function() 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 }) 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") screenshot("reader_tap_highlight_text_pdf_reflowed_scroll.png")
end) end)
end) end)
end) end)

View File

@@ -1,9 +1,10 @@
describe("ReaderScreenshot module", function() describe("ReaderScreenshot module", function()
local DocumentRegistry, ReaderUI, lfs, UIManager, Event, Screen local DataStorage, DocumentRegistry, ReaderUI, lfs, UIManager, Event, Screen
local sample_epub = "spec/front/unit/data/leaves.epub" local sample_epub = "spec/front/unit/data/leaves.epub"
local readerui local readerui
setup(function() setup(function()
require("commonrequire") require("commonrequire")
DataStorage = require("datastorage")
DocumentRegistry = require("document/documentregistry") DocumentRegistry = require("document/documentregistry")
ReaderUI = require("apps/reader/readerui") ReaderUI = require("apps/reader/readerui")
lfs = require("libs/libkoreader-lfs") lfs = require("libs/libkoreader-lfs")
@@ -24,7 +25,7 @@ describe("ReaderScreenshot module", function()
end) end)
it("should get screenshot in portrait", function() it("should get screenshot in portrait", function()
local name = "screenshots/reader_screenshot_portrait.png" local name = DataStorage:getDataDir() .. "/screenshots/reader_screenshot_portrait.png"
readerui:handleEvent(Event:new("SetRotationMode", Screen.DEVICE_ROTATED_UPRIGHT)) readerui:handleEvent(Event:new("SetRotationMode", Screen.DEVICE_ROTATED_UPRIGHT))
UIManager:quit() UIManager:quit()
UIManager:show(readerui) UIManager:show(readerui)
@@ -40,7 +41,7 @@ describe("ReaderScreenshot module", function()
end) end)
it("should get screenshot in landscape", function() it("should get screenshot in landscape", function()
local name = "screenshots/reader_screenshot_landscape.png" local name = DataStorage:getDataDir() .. "/screenshots/reader_screenshot_landscape.png"
readerui:handleEvent(Event:new("SetRotationMode", Screen.DEVICE_ROTATED_CLOCKWISE)) readerui:handleEvent(Event:new("SetRotationMode", Screen.DEVICE_ROTATED_CLOCKWISE))
UIManager:quit() UIManager:quit()
UIManager:show(readerui) UIManager:show(readerui)