2016-03-29 06:37:15 +00:00
|
|
|
describe("ReaderBookmark module", function()
|
2024-05-09 00:28:41 +00:00
|
|
|
local DataStorage, DocumentRegistry, ReaderUI, UIManager, Screen, Geom, DocSettings, Util
|
2016-03-27 22:39:47 +00:00
|
|
|
local sample_epub, sample_pdf
|
2014-11-27 13:59:27 +00:00
|
|
|
|
2016-03-27 22:39:47 +00:00
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
2024-05-09 00:28:41 +00:00
|
|
|
DataStorage = require("datastorage")
|
2016-03-28 00:17:46 +00:00
|
|
|
DocSettings = require("docsettings")
|
2016-03-27 22:39:47 +00:00
|
|
|
DocumentRegistry = require("document/documentregistry")
|
|
|
|
ReaderUI = require("apps/reader/readerui")
|
|
|
|
UIManager = require("ui/uimanager")
|
|
|
|
Screen = require("device").screen
|
|
|
|
Geom = require("ui/geometry")
|
2024-05-09 00:28:41 +00:00
|
|
|
Util = require("ffi/util")
|
2016-03-27 22:39:47 +00:00
|
|
|
|
|
|
|
sample_epub = "spec/front/unit/data/juliet.epub"
|
2024-05-09 00:28:41 +00:00
|
|
|
sample_pdf = DataStorage:getDataDir() .. "/readerbookmark.pdf"
|
|
|
|
|
|
|
|
Util.copyFile("spec/front/unit/data/sample.pdf", sample_pdf)
|
2016-03-27 22:39:47 +00:00
|
|
|
end)
|
2014-11-27 13:59:27 +00:00
|
|
|
|
|
|
|
local function highlight_text(readerui, pos0, pos1)
|
|
|
|
readerui.highlight:onHold(nil, { pos = pos0 })
|
|
|
|
readerui.highlight:onHoldPan(nil, { pos = pos1 })
|
|
|
|
readerui.highlight:onHoldRelease()
|
|
|
|
assert.truthy(readerui.highlight.highlight_dialog)
|
2024-05-03 06:08:57 +00:00
|
|
|
readerui.highlight:saveHighlight()
|
2019-08-23 17:53:53 +00:00
|
|
|
UIManager:nextTick(function()
|
2014-11-27 13:59:27 +00:00
|
|
|
UIManager:close(readerui.highlight.highlight_dialog)
|
|
|
|
UIManager:close(readerui)
|
2021-05-18 18:54:54 +00:00
|
|
|
-- We haven't torn it down yet
|
|
|
|
ReaderUI.instance = readerui
|
2014-11-27 13:59:27 +00:00
|
|
|
end)
|
|
|
|
UIManager:run()
|
|
|
|
end
|
|
|
|
local function toggler_dogear(readerui)
|
|
|
|
readerui.bookmark:onToggleBookmark()
|
2021-05-18 18:54:54 +00:00
|
|
|
UIManager:nextTick(function()
|
2014-11-27 13:59:27 +00:00
|
|
|
UIManager:close(readerui)
|
2021-05-18 18:54:54 +00:00
|
|
|
-- We haven't torn it down yet
|
|
|
|
ReaderUI.instance = readerui
|
2014-11-27 13:59:27 +00:00
|
|
|
end)
|
|
|
|
UIManager:run()
|
|
|
|
end
|
|
|
|
local function show_bookmark_menu(readerui)
|
2019-08-23 17:53:53 +00:00
|
|
|
UIManager:nextTick(function()
|
2014-11-27 13:59:27 +00:00
|
|
|
UIManager:close(readerui.bookmark.bookmark_menu)
|
|
|
|
UIManager:close(readerui)
|
2021-05-18 18:54:54 +00:00
|
|
|
-- We haven't torn it down yet
|
|
|
|
ReaderUI.instance = readerui
|
2014-11-27 13:59:27 +00:00
|
|
|
end)
|
|
|
|
UIManager:run()
|
|
|
|
end
|
2015-04-27 00:49:27 +00:00
|
|
|
|
2019-08-23 17:53:53 +00:00
|
|
|
describe("EPUB document", function()
|
2014-11-27 13:59:27 +00:00
|
|
|
local readerui
|
|
|
|
setup(function()
|
2016-06-04 05:05:14 +00:00
|
|
|
DocSettings:open(sample_epub):purge()
|
2014-11-27 13:59:27 +00:00
|
|
|
readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2014-11-27 13:59:27 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_epub),
|
|
|
|
}
|
2016-02-15 07:52:34 +00:00
|
|
|
readerui.status.enabled = false
|
2014-11-27 13:59:27 +00:00
|
|
|
end)
|
2020-12-19 04:32:23 +00:00
|
|
|
teardown(function()
|
|
|
|
readerui:closeDocument()
|
|
|
|
readerui:onClose()
|
|
|
|
end)
|
2014-11-27 13:59:27 +00:00
|
|
|
before_each(function()
|
|
|
|
UIManager:quit()
|
|
|
|
UIManager:show(readerui)
|
2016-03-27 22:39:47 +00:00
|
|
|
readerui.rolling:onGotoPage(10)
|
2014-11-27 13:59:27 +00:00
|
|
|
end)
|
2019-08-23 17:53:53 +00:00
|
|
|
it("should show dogear after toggling non-bookmarked page", function()
|
2016-04-19 06:50:36 +00:00
|
|
|
assert.falsy(readerui.view.dogear_visible)
|
2014-11-27 13:59:27 +00:00
|
|
|
toggler_dogear(readerui)
|
|
|
|
Screen:shot("screenshots/reader_bookmark_dogear_epub.png")
|
|
|
|
assert.truthy(readerui.view.dogear_visible)
|
|
|
|
end)
|
2019-08-23 17:53:53 +00:00
|
|
|
it("should not show dogear after toggling bookmarked page", function()
|
2016-04-19 06:50:36 +00:00
|
|
|
assert.truthy(readerui.view.dogear_visible)
|
2014-11-27 13:59:27 +00:00
|
|
|
toggler_dogear(readerui)
|
|
|
|
Screen:shot("screenshots/reader_bookmark_nodogear_epub.png")
|
2016-04-19 06:50:36 +00:00
|
|
|
assert.falsy(readerui.view.dogear_visible)
|
2014-11-27 13:59:27 +00:00
|
|
|
end)
|
2024-05-03 06:08:57 +00:00
|
|
|
it("should sort bookmarks with ascending page numbers", function()
|
2014-11-27 13:59:27 +00:00
|
|
|
local pages = {1, 20, 5, 30, 10, 40, 15, 25, 35, 45}
|
|
|
|
for _, page in ipairs(pages) do
|
2016-03-27 22:39:47 +00:00
|
|
|
readerui.rolling:onGotoPage(page)
|
2014-11-27 13:59:27 +00:00
|
|
|
toggler_dogear(readerui)
|
|
|
|
end
|
|
|
|
readerui.bookmark:onShowBookmark()
|
|
|
|
show_bookmark_menu(readerui)
|
|
|
|
Screen:shot("screenshots/reader_bookmark_10marks_epub.png")
|
2024-05-03 06:08:57 +00:00
|
|
|
assert.are.same(10, #readerui.annotation.annotations)
|
|
|
|
assert.are.same(15, readerui.document:getPageFromXPointer(readerui.annotation.annotations[4].page))
|
2014-11-27 13:59:27 +00:00
|
|
|
end)
|
|
|
|
it("should keep descending page numbers after removing bookmarks", function()
|
|
|
|
local pages = {1, 30, 10, 40, 20}
|
|
|
|
for _, page in ipairs(pages) do
|
2016-03-27 22:39:47 +00:00
|
|
|
readerui.rolling:onGotoPage(page)
|
2014-11-27 13:59:27 +00:00
|
|
|
toggler_dogear(readerui)
|
|
|
|
end
|
|
|
|
readerui.bookmark:onShowBookmark()
|
|
|
|
show_bookmark_menu(readerui)
|
|
|
|
Screen:shot("screenshots/reader_bookmark_5marks_epub.png")
|
2024-05-03 06:08:57 +00:00
|
|
|
assert.are.same(5, #readerui.annotation.annotations)
|
2014-11-27 13:59:27 +00:00
|
|
|
end)
|
|
|
|
it("should add bookmark by highlighting", function()
|
2016-04-19 06:50:36 +00:00
|
|
|
highlight_text(readerui,
|
|
|
|
Geom:new{ x = 260, y = 60 },
|
|
|
|
Geom:new{ x = 260, y = 90 })
|
2014-11-27 13:59:27 +00:00
|
|
|
readerui.bookmark:onShowBookmark()
|
|
|
|
show_bookmark_menu(readerui)
|
|
|
|
Screen:shot("screenshots/reader_bookmark_6marks_epub.png")
|
2024-05-03 06:08:57 +00:00
|
|
|
assert.are.same(6, #readerui.annotation.annotations)
|
2014-11-27 13:59:27 +00:00
|
|
|
end)
|
|
|
|
it("should get previous bookmark for certain page", function()
|
|
|
|
local xpointer = readerui.document:getXPointer()
|
|
|
|
local bm_xpointer = readerui.bookmark:getPreviousBookmarkedPage(xpointer)
|
2024-05-03 06:08:57 +00:00
|
|
|
assert.are.same(6, #readerui.annotation.annotations)
|
|
|
|
assert.are.same(5, readerui.document:getPageFromXPointer(bm_xpointer))
|
2014-11-27 13:59:27 +00:00
|
|
|
end)
|
|
|
|
it("should get next bookmark for certain page", function()
|
|
|
|
local xpointer = readerui.document:getXPointer()
|
|
|
|
local bm_xpointer = readerui.bookmark:getNextBookmarkedPage(xpointer)
|
2024-05-03 06:08:57 +00:00
|
|
|
assert.are.same(15, readerui.document:getPageFromXPointer(bm_xpointer))
|
2014-11-27 13:59:27 +00:00
|
|
|
end)
|
|
|
|
end)
|
2016-04-19 06:50:36 +00:00
|
|
|
|
2019-08-23 17:53:53 +00:00
|
|
|
describe("PDF document", function()
|
2014-11-27 13:59:27 +00:00
|
|
|
local readerui
|
|
|
|
setup(function()
|
2016-06-04 05:05:14 +00:00
|
|
|
DocSettings:open(sample_pdf):purge()
|
2014-11-27 13:59:27 +00:00
|
|
|
readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2014-11-27 13:59:27 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_pdf),
|
|
|
|
}
|
2016-02-15 07:52:34 +00:00
|
|
|
readerui.status.enabled = false
|
2014-11-27 13:59:27 +00:00
|
|
|
end)
|
2020-12-19 04:32:23 +00:00
|
|
|
teardown(function()
|
|
|
|
readerui:closeDocument()
|
|
|
|
readerui:onClose()
|
|
|
|
end)
|
2014-11-27 13:59:27 +00:00
|
|
|
before_each(function()
|
|
|
|
UIManager:quit()
|
|
|
|
UIManager:show(readerui)
|
2016-03-27 22:39:47 +00:00
|
|
|
readerui.paging:onGotoPage(10)
|
2014-11-27 13:59:27 +00:00
|
|
|
end)
|
2019-08-23 17:53:53 +00:00
|
|
|
it("should show dogear after toggling non-bookmarked page", function()
|
2014-11-27 13:59:27 +00:00
|
|
|
toggler_dogear(readerui)
|
|
|
|
Screen:shot("screenshots/reader_bookmark_dogear_pdf.png")
|
|
|
|
assert.truthy(readerui.view.dogear_visible)
|
|
|
|
end)
|
2019-08-23 17:53:53 +00:00
|
|
|
it("should not show dogear after toggling bookmarked page", function()
|
2014-11-27 13:59:27 +00:00
|
|
|
toggler_dogear(readerui)
|
|
|
|
Screen:shot("screenshots/reader_bookmark_nodogear_pdf.png")
|
|
|
|
assert.truthy(not readerui.view.dogear_visible)
|
|
|
|
end)
|
2024-05-03 06:08:57 +00:00
|
|
|
it("should sort bookmarks with ascending page numbers", function()
|
2014-11-27 13:59:27 +00:00
|
|
|
local pages = {1, 20, 5, 30, 10, 40, 15, 25, 35, 45}
|
|
|
|
for _, page in ipairs(pages) do
|
2016-03-27 22:39:47 +00:00
|
|
|
readerui.paging:onGotoPage(page)
|
2014-11-27 13:59:27 +00:00
|
|
|
toggler_dogear(readerui)
|
|
|
|
end
|
|
|
|
readerui.bookmark:onShowBookmark()
|
|
|
|
show_bookmark_menu(readerui)
|
|
|
|
Screen:shot("screenshots/reader_bookmark_10marks_pdf.png")
|
2024-05-03 06:08:57 +00:00
|
|
|
assert.are.same(10, #readerui.annotation.annotations)
|
|
|
|
assert.are.same(15, readerui.annotation.annotations[4].page)
|
2014-11-27 13:59:27 +00:00
|
|
|
end)
|
|
|
|
it("should keep descending page numbers after removing bookmarks", function()
|
|
|
|
local pages = {1, 30, 10, 40, 20}
|
|
|
|
for _, page in ipairs(pages) do
|
2016-03-27 22:39:47 +00:00
|
|
|
readerui.paging:onGotoPage(page)
|
2014-11-27 13:59:27 +00:00
|
|
|
toggler_dogear(readerui)
|
|
|
|
end
|
|
|
|
readerui.bookmark:onShowBookmark()
|
|
|
|
show_bookmark_menu(readerui)
|
|
|
|
Screen:shot("screenshots/reader_bookmark_5marks_pdf.png")
|
2024-05-03 06:08:57 +00:00
|
|
|
assert.are.same(5, #readerui.annotation.annotations)
|
2014-11-27 13:59:27 +00:00
|
|
|
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)
|
|
|
|
Screen:shot("screenshots/reader_bookmark_6marks_pdf.png")
|
2024-05-03 06:08:57 +00:00
|
|
|
assert.are.same(6, #readerui.annotation.annotations)
|
2014-11-27 13:59:27 +00:00
|
|
|
end)
|
|
|
|
it("should get previous bookmark for certain page", function()
|
|
|
|
assert.are.same(5, readerui.bookmark:getPreviousBookmarkedPage(10))
|
|
|
|
end)
|
|
|
|
it("should get next bookmark for certain page", function()
|
|
|
|
assert.are.same(15, readerui.bookmark:getNextBookmarkedPage(10))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|