2014-11-21 18:32:43 +08:00
|
|
|
describe("Readerdictionary module", function()
|
2024-12-25 15:46:06 +01:00
|
|
|
local DocumentRegistry, ReaderUI, UIManager, Screen
|
2016-04-18 23:50:36 -07:00
|
|
|
|
|
|
|
|
setup(function()
|
|
|
|
|
require("commonrequire")
|
2024-12-25 15:46:02 +01:00
|
|
|
disable_plugins()
|
|
|
|
|
load_plugin("japanese.koplugin")
|
2016-04-18 23:50:36 -07:00
|
|
|
DocumentRegistry = require("document/documentregistry")
|
|
|
|
|
ReaderUI = require("apps/reader/readerui")
|
|
|
|
|
UIManager = require("ui/uimanager")
|
|
|
|
|
Screen = require("device").screen
|
|
|
|
|
end)
|
|
|
|
|
|
2024-12-25 15:46:19 +01:00
|
|
|
local readerui, dictionary
|
2014-11-21 18:32:43 +08:00
|
|
|
setup(function()
|
|
|
|
|
readerui = ReaderUI:new{
|
2020-07-01 16:17:41 -04:00
|
|
|
dimen = Screen:getSize(),
|
2024-12-25 15:46:19 +01:00
|
|
|
document = DocumentRegistry:openDocument("spec/front/unit/data/sample.txt"),
|
2014-11-21 18:32:43 +08:00
|
|
|
}
|
|
|
|
|
dictionary = readerui.dictionary
|
|
|
|
|
end)
|
2020-12-19 05:32:23 +01:00
|
|
|
teardown(function()
|
2024-12-25 15:46:19 +01:00
|
|
|
ReaderUI.instance = readerui
|
2020-12-19 05:32:23 +01:00
|
|
|
readerui:closeDocument()
|
|
|
|
|
readerui:onClose()
|
|
|
|
|
end)
|
2024-12-25 15:46:19 +01:00
|
|
|
before_each(function()
|
|
|
|
|
ReaderUI.instance = readerui
|
2014-11-21 18:32:43 +08:00
|
|
|
UIManager:show(readerui)
|
2024-12-25 15:46:19 +01:00
|
|
|
end)
|
|
|
|
|
after_each(function()
|
|
|
|
|
UIManager:close(dictionary.dict_window)
|
|
|
|
|
UIManager:close(readerui)
|
|
|
|
|
UIManager:quit()
|
|
|
|
|
UIManager._exit_code = nil
|
|
|
|
|
end)
|
|
|
|
|
it("should show quick lookup window", function()
|
2014-11-21 18:32:43 +08:00
|
|
|
dictionary:onLookupWord("test")
|
2024-12-25 15:46:19 +01:00
|
|
|
fastforward_ui_events()
|
2024-12-25 15:46:06 +01:00
|
|
|
screenshot(Screen, "reader_dictionary.png")
|
2021-10-23 21:13:18 +11:00
|
|
|
end)
|
|
|
|
|
it("should attempt to deinflect (Japanese) word on lookup", function()
|
|
|
|
|
|
|
|
|
|
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)
|
2024-12-25 15:46:19 +01:00
|
|
|
fastforward_ui_events()
|
|
|
|
|
screenshot(Screen, "reader_dictionary_japanese.png")
|
2021-10-23 21:13:18 +11:00
|
|
|
|
|
|
|
|
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 16:29:00 +02:00
|
|
|
--- @todo This should probably check against a set or sorted list
|
2021-10-23 21:13:18 +11:00
|
|
|
-- of the candidates we'd expect.
|
|
|
|
|
assert.spy(s).was_returned_with(match.is_not_nil())
|
|
|
|
|
end
|
|
|
|
|
readerui.languagesupport.extraDictionaryFormCandidates:revert()
|
2014-11-21 18:32:43 +08:00
|
|
|
end)
|
|
|
|
|
end)
|