tests: speedup readerdictionary tests

This commit is contained in:
Benoit Pierre
2024-12-25 15:46:19 +01:00
committed by Frans de Jonge
parent fbcda02726
commit 616d52ba88

View File

@@ -11,38 +11,35 @@ describe("Readerdictionary module", function()
Screen = require("device").screen
end)
local readerui, rolling, dictionary
local readerui, dictionary
setup(function()
local sample_epub = "spec/front/unit/data/leaves.epub"
readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
document = DocumentRegistry:openDocument("spec/front/unit/data/sample.txt"),
}
rolling = readerui.rolling
dictionary = readerui.dictionary
end)
teardown(function()
ReaderUI.instance = readerui
readerui:closeDocument()
readerui:onClose()
end)
it("should show quick lookup window", function()
UIManager:quit()
before_each(function()
ReaderUI.instance = readerui
UIManager:show(readerui)
rolling:onGotoPage(100)
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()
dictionary:onLookupWord("test")
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()
fastforward_ui_events()
screenshot(Screen, "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")
@@ -50,6 +47,8 @@ describe("Readerdictionary module", function()
-- We can't use onLookupWord because we need to check whether
-- extraDictionaryFormCandidates was called synchronously.
dictionary:stardictLookup(word)
fastforward_ui_events()
screenshot(Screen, "reader_dictionary_japanese.png")
assert.spy(s).was_called()
assert.spy(s).was_called_with(match.is_ref(readerui.languagesupport), word)
@@ -59,14 +58,5 @@ describe("Readerdictionary module", function()
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()
screenshot(Screen, "reader_dictionary_japanese.png")
end)
end)