2014-10-07 05:06:06 +00:00
|
|
|
describe("Readerui module", function()
|
2020-07-01 20:17:41 +00:00
|
|
|
local DocumentRegistry, ReaderUI, DocSettings, UIManager, Screen
|
2014-10-07 05:06:06 +00:00
|
|
|
local sample_epub = "spec/front/unit/data/leaves.epub"
|
2014-11-05 10:06:05 +00:00
|
|
|
local readerui
|
|
|
|
setup(function()
|
2016-06-04 05:05:14 +00:00
|
|
|
require("commonrequire")
|
|
|
|
DocumentRegistry = require("document/documentregistry")
|
|
|
|
ReaderUI = require("apps/reader/readerui")
|
|
|
|
DocSettings = require("docsettings")
|
|
|
|
UIManager = require("ui/uimanager")
|
2020-07-01 20:17:41 +00:00
|
|
|
Screen = require("device").screen
|
2016-06-04 05:05:14 +00:00
|
|
|
|
2014-11-05 10:06:05 +00:00
|
|
|
readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2014-11-05 10:06:05 +00:00
|
|
|
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
|
2016-06-04 05:05:14 +00:00
|
|
|
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()
|
2014-11-05 10:06:05 +00:00
|
|
|
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)
|
2020-12-19 04:32:23 +00:00
|
|
|
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{
|
2020-07-01 20:17:41 +00:00
|
|
|
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)
|
2020-12-19 04:32:23 +00:00
|
|
|
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)
|