2014-11-21 10:32:43 +00:00
|
|
|
describe("Readerdictionary module", function()
|
2017-08-08 20:35:40 +00:00
|
|
|
local DocumentRegistry, ReaderUI, UIManager, Screen
|
2016-04-19 06:50:36 +00:00
|
|
|
|
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
|
|
|
DocumentRegistry = require("document/documentregistry")
|
|
|
|
ReaderUI = require("apps/reader/readerui")
|
|
|
|
UIManager = require("ui/uimanager")
|
|
|
|
Screen = require("device").screen
|
|
|
|
end)
|
|
|
|
|
2014-11-21 10:32:43 +00:00
|
|
|
local readerui, rolling, dictionary
|
|
|
|
setup(function()
|
2016-04-19 06:50:36 +00:00
|
|
|
local sample_epub = "spec/front/unit/data/leaves.epub"
|
2014-11-21 10:32:43 +00:00
|
|
|
readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2014-11-21 10:32:43 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_epub),
|
|
|
|
}
|
|
|
|
rolling = readerui.rolling
|
|
|
|
dictionary = readerui.dictionary
|
|
|
|
end)
|
2020-12-19 04:32:23 +00:00
|
|
|
teardown(function()
|
|
|
|
readerui:closeDocument()
|
|
|
|
readerui:onClose()
|
|
|
|
end)
|
2014-11-21 10:32:43 +00:00
|
|
|
it("should show quick lookup window", function()
|
|
|
|
UIManager:quit()
|
|
|
|
UIManager:show(readerui)
|
2016-03-27 22:39:47 +00:00
|
|
|
rolling:onGotoPage(100)
|
2014-11-21 10:32:43 +00:00
|
|
|
dictionary:onLookupWord("test")
|
|
|
|
UIManager:scheduleIn(1, function()
|
2014-11-21 10:45:07 +00:00
|
|
|
UIManager:close(dictionary.dict_window)
|
2014-11-21 10:32:43 +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-21 10:32:43 +00:00
|
|
|
end)
|
|
|
|
UIManager:run()
|
2021-10-23 10:13:18 +00:00
|
|
|
Screen:shot("screenshots/reader_dictionary.png")
|
|
|
|
end)
|
|
|
|
it("should attempt to deinflect (Japanese) word on lookup", function()
|
|
|
|
UIManager:quit()
|
|
|
|
UIManager:show(readerui)
|
|
|
|
rolling:onGotoPage(100)
|
|
|
|
|
|
|
|
local word = "喋っている"
|
|
|
|
local s = spy.on(readerui.languagesupport, "extraDictionaryFormCandidates")
|
|
|
|
|
|
|
|
-- We can't use onLookupWord because we need to check whether
|
|
|
|
-- extraDictionaryFormCandidates was called synchronously.
|
|
|
|
dictionary:stardictLookup(word)
|
|
|
|
|
|
|
|
assert.spy(s).was_called()
|
|
|
|
assert.spy(s).was_called_with(match.is_ref(readerui.languagesupport), word)
|
|
|
|
if readerui.languagesupport.plugins["japanese_support"] then
|
2021-10-23 14:29:00 +00:00
|
|
|
--- @todo This should probably check against a set or sorted list
|
2021-10-23 10:13:18 +00:00
|
|
|
-- of the candidates we'd expect.
|
|
|
|
assert.spy(s).was_returned_with(match.is_not_nil())
|
|
|
|
end
|
|
|
|
readerui.languagesupport.extraDictionaryFormCandidates:revert()
|
|
|
|
|
|
|
|
UIManager:scheduleIn(1, function()
|
|
|
|
UIManager:close(dictionary.dict_window)
|
|
|
|
UIManager:close(readerui)
|
|
|
|
-- We haven't torn it down yet
|
|
|
|
ReaderUI.instance = readerui
|
|
|
|
end)
|
|
|
|
UIManager:run()
|
|
|
|
Screen:shot("screenshots/reader_dictionary_japanese.png")
|
2014-11-21 10:32:43 +00:00
|
|
|
end)
|
|
|
|
end)
|