2014-11-05 08:58:09 +00:00
|
|
|
describe("ReaderScreenshot module", function()
|
2020-07-01 20:17:41 +00:00
|
|
|
local DocumentRegistry, ReaderUI, lfs, UIManager, Event, Screen
|
2014-11-05 08:58:09 +00:00
|
|
|
local sample_epub = "spec/front/unit/data/leaves.epub"
|
|
|
|
local readerui
|
|
|
|
setup(function()
|
2016-06-02 04:32:35 +00:00
|
|
|
require("commonrequire")
|
|
|
|
DocumentRegistry = require("document/documentregistry")
|
|
|
|
ReaderUI = require("apps/reader/readerui")
|
|
|
|
lfs = require("libs/libkoreader-lfs")
|
|
|
|
UIManager = require("ui/uimanager")
|
|
|
|
Event = require("ui/event")
|
2020-07-01 20:17:41 +00:00
|
|
|
Screen = require("device").screen
|
2016-06-02 04:32:35 +00:00
|
|
|
|
2014-11-05 08:58:09 +00:00
|
|
|
readerui = ReaderUI:new{
|
2020-07-01 20:17:41 +00:00
|
|
|
dimen = Screen:getSize(),
|
2014-11-05 08:58:09 +00:00
|
|
|
document = DocumentRegistry:openDocument(sample_epub),
|
|
|
|
}
|
|
|
|
end)
|
2016-06-02 04:32:35 +00:00
|
|
|
|
2016-08-11 09:12:55 +00:00
|
|
|
teardown(function()
|
2022-12-21 14:50:39 +00:00
|
|
|
readerui:handleEvent(Event:new("SetRotationMode", Screen.DEVICE_ROTATED_UPRIGHT))
|
2020-12-19 04:32:23 +00:00
|
|
|
readerui:closeDocument()
|
|
|
|
readerui:onClose()
|
2016-08-11 09:12:55 +00:00
|
|
|
end)
|
|
|
|
|
2014-11-05 08:58:09 +00:00
|
|
|
it("should get screenshot in portrait", function()
|
|
|
|
local name = "screenshots/reader_screenshot_portrait.png"
|
2022-12-21 14:50:39 +00:00
|
|
|
readerui:handleEvent(Event:new("SetRotationMode", Screen.DEVICE_ROTATED_UPRIGHT))
|
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()
|
|
|
|
readerui.screenshot:onScreenshot(name)
|
|
|
|
assert.truthy(lfs.attributes(name, "mode"))
|
2016-06-02 04:32:35 +00:00
|
|
|
UIManager:quit()
|
2014-11-05 08:58:09 +00:00
|
|
|
end)
|
2016-06-02 04:32:35 +00:00
|
|
|
|
2014-11-05 08:58:09 +00:00
|
|
|
it("should get screenshot in landscape", function()
|
|
|
|
local name = "screenshots/reader_screenshot_landscape.png"
|
2022-12-21 14:50:39 +00:00
|
|
|
readerui:handleEvent(Event:new("SetRotationMode", Screen.DEVICE_ROTATED_CLOCKWISE))
|
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(2, 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()
|
|
|
|
readerui.screenshot:onScreenshot(name)
|
|
|
|
assert.truthy(lfs.attributes(name, "mode"))
|
2016-06-02 04:32:35 +00:00
|
|
|
UIManager:quit()
|
2014-11-05 08:58:09 +00:00
|
|
|
end)
|
|
|
|
end)
|