Merge pull request #1224 from chrox/cover_60

add unit tests for readerdictionary and readerhighlight
pull/1228/head
HW 10 years ago
commit 9b5ff4ca41

@ -68,7 +68,7 @@ function ReaderDictionary:stardictLookup(word, box)
--DEBUG("result str:", word, results_str)
local ok, results = pcall(JSON.decode, JSON, results_str)
if ok and results then
DEBUG("lookup result table:", word, results)
--DEBUG("lookup result table:", word, results)
self:showDict(word, tidy_markup(results), box)
else
-- dummy results
@ -88,7 +88,7 @@ end
function ReaderDictionary:showDict(word, results, box)
if results and results[1] then
DEBUG("showing quick lookup window")
UIManager:show(DictQuickLookup:new{
self.dict_window = DictQuickLookup:new{
ui = self.ui,
highlight = self.highlight,
dialog = self.dialog,
@ -100,7 +100,8 @@ function ReaderDictionary:showDict(word, results, box)
word_box = box,
-- differentiate between dict and wiki
wiki = self.wiki,
})
}
UIManager:show(self.dict_window)
end
end

@ -402,12 +402,14 @@ function ReaderHighlight:saveHighlight()
hl_item["datetime"] = os.date("%Y-%m-%d %H:%M:%S")
hl_item["drawer"] = self.view.highlight.saved_drawer
table.insert(self.view.highlight.saved[page], hl_item)
--[[
-- disable exporting hightlights to My Clippings
-- since it's not portable and there is a better Evernote plugin
-- to do the same thing
if self.selected_text.text ~= "" then
-- disable exporting hightlights to My Clippings
-- since it's not potable and there is a better Evernote plugin
-- to do the same thing
--self:exportToClippings(page, hl_item)
self:exportToClippings(page, hl_item)
end
--]]
if self.selected_text.pboxes then
self:exportToDocument(page, hl_item)
end
@ -415,6 +417,7 @@ function ReaderHighlight:saveHighlight()
--DEBUG("saved hightlights", self.view.highlight.saved[page])
end
--[[
function ReaderHighlight:exportToClippings(page, item)
DEBUG("export highlight to clippings", item)
local clippings = io.open("/mnt/us/documents/My Clippings.txt", "a+")
@ -431,6 +434,7 @@ function ReaderHighlight:exportToClippings(page, item)
os.setlocale(current_locale)
end
end
--]]
function ReaderHighlight:exportToDocument(page, item)
DEBUG("export highlight to document", item)

@ -0,0 +1,33 @@
require("commonrequire")
local DocumentRegistry = require("document/documentregistry")
local ReaderUI = require("apps/reader/readerui")
local lfs = require("libs/libkoreader-lfs")
local UIManager = require("ui/uimanager")
local Screen = require("device").screen
local Event = require("ui/event")
local DEBUG = require("dbg")
describe("Readerdictionary module", function()
local sample_epub = "spec/front/unit/data/leaves.epub"
local readerui, rolling, dictionary
setup(function()
readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_epub),
}
rolling = readerui.rolling
dictionary = readerui.dictionary
end)
it("should show quick lookup window", function()
local name = "screenshots/reader_dictionary.png"
UIManager:quit()
UIManager:show(readerui)
rolling:gotoPage(100)
dictionary:onLookupWord("test")
UIManager:scheduleIn(1, function()
UIManager:close(dictionary.dict_window)
UIManager:close(readerui)
end)
UIManager:run()
Screen:shot(name)
end)
end)

@ -0,0 +1,156 @@
require("commonrequire")
local DocumentRegistry = require("document/documentregistry")
local ReaderUI = require("apps/reader/readerui")
local UIManager = require("ui/uimanager")
local Screen = require("device").screen
local Geom = require("ui/geometry")
local DEBUG = require("dbg")
local sample_epub = "spec/front/unit/data/juliet.epub"
local sample_pdf = "spec/front/unit/data/sample.pdf"
describe("Readerhighlight module", function()
local function highlight_single_word(readerui, pos0)
readerui.highlight:onHold(nil, { pos = pos0 })
readerui.highlight:onHoldRelease()
readerui.highlight:onHighlight()
UIManager:scheduleIn(1, function()
UIManager:close(readerui.dictionary.dict_window)
UIManager:close(readerui)
end)
UIManager:run()
end
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)
readerui.highlight:onHighlight()
UIManager:scheduleIn(1, function()
UIManager:close(readerui.highlight.highlight_dialog)
UIManager:close(readerui)
end)
UIManager:run()
end
local function tap_highlight_text(readerui, pos0, pos1, pos2)
readerui.highlight:onHold(nil, { pos = pos0 })
readerui.highlight:onHoldPan(nil, { pos = pos1 })
readerui.highlight:onHoldRelease()
readerui.highlight:onHighlight()
readerui.highlight:clear()
UIManager:close(readerui.highlight.highlight_dialog)
readerui.highlight:onTap(nil, { pos = pos2 })
assert.truthy(readerui.highlight.edit_highlight_dialog)
UIManager:scheduleIn(2, function()
UIManager:close(readerui.highlight.edit_highlight_dialog)
UIManager:close(readerui)
end)
UIManager:run()
end
describe("highlight for EPUB documents", function()
local page = 10
local readerui
setup(function()
readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_epub),
}
end)
before_each(function()
UIManager:quit()
UIManager:show(readerui)
readerui.rolling:gotoPage(page)
end)
after_each(function()
readerui.highlight:clear()
end)
it("should highlight single word", function()
highlight_single_word(readerui, Geom:new{ x = 260, y = 80 })
Screen:shot("screenshots/reader_highlight_single_word_epub.png")
assert.truthy(readerui.view.highlight.saved[page])
end)
it("should highlight text", function()
highlight_text(readerui, Geom:new{ x = 260, y = 60 }, Geom:new{ x = 260, y = 90 })
Screen:shot("screenshots/reader_highlight_text_epub.png")
assert.truthy(readerui.view.highlight.saved[page])
end)
it("should response on tap gesture", function()
tap_highlight_text(readerui, Geom:new{ x = 260, y = 60 }, Geom:new{ x = 260, y = 90 }, Geom:new{ x = 260, y = 80 })
Screen:shot("screenshots/reader_tap_highlight_text_epub.png")
end)
end)
describe("highlight for PDF documents", function()
local readerui
setup(function()
readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_pdf),
}
end)
describe("for scanned page with text layer", function()
before_each(function()
UIManager:quit()
UIManager:show(readerui)
readerui.paging:gotoPage(10)
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.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.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.png")
end)
end)
describe("for scanned page without text layer", function()
before_each(function()
UIManager:quit()
UIManager:show(readerui)
readerui.paging:gotoPage(28)
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.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_scanned.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.png")
end)
end)
describe("for reflowed page", function()
before_each(function()
UIManager:quit()
readerui.document.configurable.text_wrap = 1
UIManager:show(readerui)
readerui.paging:gotoPage(31)
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_reflowed.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.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.png")
end)
end)
end)
end)
Loading…
Cancel
Save