2
0
mirror of https://github.com/koreader/koreader synced 2024-11-18 03:25:46 +00:00
koreader/spec/unit/readerui_spec.lua

61 lines
2.5 KiB
Lua
Raw Normal View History

2014-10-07 05:06:06 +00:00
describe("Readerui module", function()
local DocumentRegistry, ReaderUI, DocSettings, UIManager, Screen
2014-10-07 05:06:06 +00:00
local sample_epub = "spec/front/unit/data/leaves.epub"
local readerui
setup(function()
require("commonrequire")
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 05:06:06 +00:00
it("should save settings", function()
-- remove history settings and sidecar settings
DocSettings:open(sample_epub):purge()
2014-10-07 05:06:06 +00:00
local doc_settings = DocSettings:open(sample_epub)
assert.are.same(doc_settings.data, {doc_path = sample_epub})
2014-10-07 05:06:06 +00:00
readerui:saveSettings()
assert.are_not.same(readerui.doc_settings.data, {doc_path = sample_epub})
2014-10-07 05:06:06 +00: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 08:58:09 +00:00
it("should show reader", function()
UIManager:quit()
2014-11-05 08:58:09 +00: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 08:58:09 +00:00
UIManager:run()
end)
2014-10-07 05:06:06 +00:00
it("should close document", function()
readerui:closeDocument()
assert(readerui.document == nil)
readerui:onClose()
2014-10-07 05:06:06 +00:00
end)
it("should not reset ReaderUI.instance by mistake", function()
ReaderUI:doShowReader(sample_epub) -- spins up a new, sane instance
2023-07-03 14:43:13 +00:00
local new_readerui = ReaderUI.instance
2016-02-17 08:06:55 +00: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-17 07:10:09 +00:00
ReaderUI:new{
dimen = Screen:getSize(),
2016-02-17 07:10:09 +00:00
document = DocumentRegistry:openDocument(sample_epub)
}:onClose()
2016-02-17 08:06:55 +00:00
assert.is.truthy(new_readerui.document)
new_readerui:closeDocument()
2016-02-17 08:06:55 +00:00
new_readerui:onClose()
2016-02-17 07:10:09 +00:00
end)
2014-10-07 05:06:06 +00:00
end)