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)
|
2023-03-01 12:52:08 +00:00
|
|
|
assert.are.same(doc_settings.data, {doc_path = sample_epub})
|
2014-10-07 05:06:06 +00:00
|
|
|
readerui:saveSettings()
|
2023-03-01 12:52:08 +00:00
|
|
|
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()
|
2014-11-05 10:06:05 +00:00
|
|
|
UIManager:quit()
|
2014-11-05 08:58:09 +00:00
|
|
|
UIManager:show(readerui)
|
2021-05-18 18:54:54 +00:00
|
|
|
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)
|
2020-12-19 04:32:23 +00:00
|
|
|
readerui:onClose()
|
2014-10-07 05:06:06 +00:00
|
|
|
end)
|
2021-05-18 18:54:54 +00:00
|
|
|
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)
|
2021-05-18 18:54:54 +00:00
|
|
|
-- 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{
|
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)
|