2
0
mirror of https://github.com/koreader/koreader synced 2024-11-10 01:10:34 +00:00
koreader/spec/unit/screenshoter_spec.lua
chrox 7ea12c0198 fix broken unit tests on Travis CI
1. It turns out that `device_id` is not defined in unit test environment
which makes the `assert(self.kosync_device_id)` fail and somehow makes `luajit` segmentation fault.
2. In the device spec, stubbing `io.open` will make subsquent `require`
all return boolean value and segmentation fault `luajit`.

This patch is a minimum viable change that makes CI work on both my
local box and Travis.
2016-08-11 18:17:09 +08:00

47 lines
1.7 KiB
Lua

describe("ReaderScreenshot module", function()
local DocumentRegistry, ReaderUI, lfs, UIManager, Screen, Event
local sample_epub = "spec/front/unit/data/leaves.epub"
local readerui
setup(function()
require("commonrequire")
DocumentRegistry = require("document/documentregistry")
ReaderUI = require("apps/reader/readerui")
lfs = require("libs/libkoreader-lfs")
UIManager = require("ui/uimanager")
Screen = require("device").screen
Event = require("ui/event")
readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_epub),
}
end)
teardown(function()
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
end)
it("should get screenshot in portrait", function()
local name = "screenshots/reader_screenshot_portrait.png"
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
UIManager:quit()
UIManager:show(readerui)
UIManager:scheduleIn(1, function() UIManager:close(readerui) end)
UIManager:run()
readerui.screenshot:onScreenshot(name)
assert.truthy(lfs.attributes(name, "mode"))
UIManager:quit()
end)
it("should get screenshot in landscape", function()
local name = "screenshots/reader_screenshot_landscape.png"
readerui:handleEvent(Event:new("ChangeScreenMode", "landscape"))
UIManager:quit()
UIManager:show(readerui)
UIManager:scheduleIn(2, function() UIManager:close(readerui) end)
UIManager:run()
readerui.screenshot:onScreenshot(name)
assert.truthy(lfs.attributes(name, "mode"))
UIManager:quit()
end)
end)