Files
koreader/spec/unit/readerui_spec.lua

62 lines
2.5 KiB
Lua
Raw Normal View History

2014-10-07 13:06:06 +08:00
describe("Readerui module", function()
local DocumentRegistry, ReaderUI, DocSettings, UIManager, Screen
2024-12-25 15:46:08 +01:00
local sample_epub = "spec/front/unit/data/juliet.epub"
local readerui
setup(function()
require("commonrequire")
disable_plugins()
DocumentRegistry = require("document/documentregistry")
ReaderUI = require("apps/reader/readerui")
DocSettings = require("docsettings")
UIManager = require("ui/uimanager")
Screen = require("device").screen
readerui = ReaderUI:new{
dimen = Screen:getSize(),
document = DocumentRegistry:openDocument(sample_epub),
}
end)
2014-10-07 13:06:06 +08:00
it("should save settings", function()
-- remove history settings and sidecar settings
DocSettings:open(sample_epub):purge()
2014-10-07 13:06:06 +08:00
local doc_settings = DocSettings:open(sample_epub)
assert.are.same(doc_settings.data, {doc_path = sample_epub})
2014-10-07 13:06:06 +08:00
readerui:saveSettings()
assert.are_not.same(readerui.doc_settings.data, {doc_path = sample_epub})
2014-10-07 13:06:06 +08:00
doc_settings = DocSettings:open(sample_epub)
assert.truthy(doc_settings.data.last_xpointer)
assert.are.same(doc_settings.data.last_xpointer,
readerui.doc_settings.data.last_xpointer)
end)
2014-11-05 16:58:09 +08:00
it("should show reader", function()
UIManager:quit()
2014-11-05 16:58:09 +08:00
UIManager:show(readerui)
UIManager:scheduleIn(1, function()
UIManager:close(readerui)
-- We haven't torn it down yet
ReaderUI.instance = readerui
end)
2014-11-05 16:58:09 +08:00
UIManager:run()
end)
2014-10-07 13:06:06 +08:00
it("should close document", function()
readerui:closeDocument()
assert(readerui.document == nil)
readerui:onClose()
2014-10-07 13:06:06 +08:00
end)
it("should not reset ReaderUI.instance by mistake", function()
ReaderUI:doShowReader(sample_epub) -- spins up a new, sane instance
2023-07-03 17:43:13 +03:00
local new_readerui = ReaderUI.instance
2016-02-17 00:06:55 -08:00
assert.is.truthy(new_readerui.document)
-- This *will* trip:
-- * A pair of ReaderUI instance mimsatch warnings (on open/close) because it bypasses the safety of doShowReader!
-- * A refcount warning from DocumentRegistry, because bypassinf the safeties means that two different instances opened the same Document.
2016-02-16 23:10:09 -08:00
ReaderUI:new{
dimen = Screen:getSize(),
2016-02-16 23:10:09 -08:00
document = DocumentRegistry:openDocument(sample_epub)
}:onClose()
2016-02-17 00:06:55 -08:00
assert.is.truthy(new_readerui.document)
new_readerui:closeDocument()
2016-02-17 00:06:55 -08:00
new_readerui:onClose()
2016-02-16 23:10:09 -08:00
end)
2014-10-07 13:06:06 +08:00
end)