forked from koreader/koreader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readerrolling_spec.lua
109 lines (108 loc) · 4.41 KB
/
readerrolling_spec.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
require("commonrequire")
local DocumentRegistry = require("document/documentregistry")
local ReaderUI = require("apps/reader/readerui")
local Event = require("ui/event")
local DEBUG = require("dbg")
describe("Readerrolling module", function()
local sample_epub = "spec/front/unit/data/juliet.epub"
local readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_epub),
}
local rolling = readerui.rolling
describe("test in portrait screen mode", function()
it("should goto portrait screen mode", function()
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
end)
it("should goto certain page", function()
for i = 1, 10, 5 do
rolling:gotoPage(i)
assert.are.same(i, rolling.current_page)
end
end)
it("should goto relative page", function()
for i = 20, 40, 5 do
rolling:gotoPage(i)
rolling:onGotoViewRel(1)
assert.are.same(i + 1, rolling.current_page)
rolling:onGotoViewRel(-1)
assert.are.same(i, rolling.current_page)
end
end)
it("should goto next chapter", function()
local toc = readerui.toc
for i = 30, 50, 5 do
rolling:gotoPage(i)
rolling:onDoubleTapForward()
assert.are.same(toc:getNextChapter(i, 0), rolling.current_page)
end
end)
it("should goto previous chapter", function()
local toc = readerui.toc
for i = 60, 80, 5 do
rolling:gotoPage(i)
rolling:onDoubleTapBackward()
assert.are.same(toc:getPreviousChapter(i, 0), rolling.current_page)
end
end)
end)
describe("test in landscape screen mode", function()
it("should go to landscape screen mode", function()
readerui:handleEvent(Event:new("ChangeScreenMode", "landscape"))
end)
it("should goto certain page", function()
for i = 1, 10, 5 do
rolling:gotoPage(i)
assert.are.same(i, rolling.current_page)
end
end)
it("should goto relative page", function()
for i = 20, 40, 5 do
rolling:gotoPage(i)
rolling:onGotoViewRel(1)
assert.are.same(i + 1, rolling.current_page)
rolling:onGotoViewRel(-1)
assert.are.same(i, rolling.current_page)
end
end)
it("should goto next chapter", function()
local toc = readerui.toc
for i = 30, 50, 5 do
rolling:gotoPage(i)
rolling:onDoubleTapForward()
assert.are.same(toc:getNextChapter(i, 0), rolling.current_page)
end
end)
it("should goto previous chapter", function()
local toc = readerui.toc
for i = 60, 80, 5 do
rolling:gotoPage(i)
rolling:onDoubleTapBackward()
assert.are.same(toc:getPreviousChapter(i, 0), rolling.current_page)
end
end)
end)
describe("switching screen mode should not change current page number", function()
it("for portrait-landscape-portrait switching", function()
for i = 80, 100, 10 do
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
rolling:onGotoPage(i)
assert.are.same(i, rolling.current_page)
readerui:handleEvent(Event:new("ChangeScreenMode", "landscape"))
assert.are_not.same(i, rolling.current_page)
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
assert.are.same(i, rolling.current_page)
end
end)
it("for landscape-portrait-landscape switching", function()
for i = 110, 130, 10 do
readerui:handleEvent(Event:new("ChangeScreenMode", "landscape"))
rolling:onGotoPage(i)
assert.are.same(i, rolling.current_page)
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
assert.are_not.same(i, rolling.current_page)
readerui:handleEvent(Event:new("ChangeScreenMode", "landscape"))
assert.are.same(i, rolling.current_page)
end
end)
end)
end)