spec: add tests for LanguageSupport

This primarily consists of some spies added to ensure that the
LanguageSupport plugin is actually being called at the right time.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
Aleksa Sarai
2021-10-23 21:13:18 +11:00
committed by Frans de Jonge
parent 3d4e54c7e6
commit 56899eab8e
2 changed files with 46 additions and 3 deletions

View File

@@ -24,7 +24,6 @@ describe("Readerdictionary module", function()
readerui:onClose()
end)
it("should show quick lookup window", function()
local name = "screenshots/reader_dictionary.png"
UIManager:quit()
UIManager:show(readerui)
rolling:onGotoPage(100)
@@ -36,6 +35,36 @@ describe("Readerdictionary module", function()
ReaderUI.instance = readerui
end)
UIManager:run()
Screen:shot(name)
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
-- @todo This should probably check against a set or sorted list
-- 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")
end)
end)