2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00
koreader/spec/unit/readerui_spec.lua

54 lines
2.0 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, {})
readerui:saveSettings()
assert.are_not.same(readerui.doc_settings.data, {})
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) end)
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)
2016-02-17 07:10:09 +00:00
it("should not reset running_instance by mistake", function()
2016-02-17 08:06:55 +00:00
ReaderUI:doShowReader(sample_epub)
local new_readerui = ReaderUI:_getRunningInstance()
assert.is.truthy(new_readerui.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)