Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 69e8b5b

Browse files
committed
Added e2e tests
1 parent f15faf5 commit 69e8b5b

File tree

8 files changed

+311
-33
lines changed

8 files changed

+311
-33
lines changed

‎.husky/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

‎.husky/pre-commit‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "0ドル")/_/husky.sh"
3+
4+
cd example && npm run unittest && cd .. && npm run build && git add dist

‎example/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
},
2424
"scripts": {
2525
"start": "react-scripts start",
26-
"start-server": "PUBLIC_URL=/ react-scripts build && serve -s build",
26+
"start-server": "PUBLIC_URL=/ react-scripts build && serve -s build -l 3000",
2727
"build": "react-scripts build",
2828
"unittest": "react-scripts test --env=jsdom --watchAll=false",
2929
"e2etest": "wdio run ./wdio.conf.js",
3030
"testall": "npm run unittest && npm run e2etest",
31-
"test": "start-server-and-test start-server http://localhost:5000 testall",
31+
"test": "start-server-and-test start-server http://localhost:3000 testall",
3232
"predeploy": "npm run build",
3333
"deploy": "gh-pages -d build"
3434
},

‎example/test/pageobjects/app.page.js‎

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,79 @@ class AppPage {
77
return browser.url('/')
88
}
99

10-
takeScreenShot(name) {
11-
return browser.saveScreenshot(`./test/ss/${name}.png`)
10+
/**
11+
* @param {string} id
12+
*/
13+
set section(id) {
14+
this.selectedSection = `#${id}`
1215
}
1316

14-
get loadFromURL() {
15-
return $('#url')
17+
get section() {
18+
return $(this.selectedSection)
1619
}
17-
get getButtons() {
18-
return $('#url').$('button=keyboard_arrow_right')
20+
21+
get alert() {
22+
return this.section.$('.container').$('div*=Error')
23+
}
24+
25+
get loader() {
26+
return this.section.$('.container').$$('div')[0]
27+
}
28+
29+
get pdfViewer() {
30+
return this.section.$('.container').$$('div')[1]
31+
}
32+
33+
get canvas() {
34+
return this.section.$('canvas')
35+
}
36+
37+
get thumbnails() {
38+
return this.section.$$('img')
39+
}
40+
41+
get zoomOutButton() {
42+
return this.section.$('button=zoom_out')
43+
}
44+
45+
get zoomResetButton() {
46+
return this.section.$$('button=refresh')[0]
47+
}
48+
49+
get zoomInButton() {
50+
return this.section.$('button=zoom_in')
51+
}
52+
53+
get prevPageButton() {
54+
return this.section.$('button=keyboard_arrow_left')
55+
}
56+
57+
get pageIndicator() {
58+
return this.section.$('span*=Page')
59+
}
60+
61+
get nextPageButton() {
62+
return this.section.$('button=keyboard_arrow_right')
63+
}
64+
65+
get rotateLeftButton() {
66+
return this.section.$('button=rotate_left')
67+
}
68+
69+
get rotateResetButton() {
70+
return this.section.$$('button=refresh')[1]
71+
}
72+
73+
get rotateRightButton() {
74+
return this.section.$('button=rotate_right')
75+
}
76+
77+
get extZoomInButton() {
78+
return this.section.$('button=+')
1979
}
2080

21-
get getPageIndicator() {
22-
return $('#url').$('span*=Page')
81+
get extZoomOutButton() {
82+
return this.section.$('button=-')
2383
}
2484
}
2585

‎example/test/specs/app.e2e.js‎

Lines changed: 216 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,228 @@
11
const AppPage = require('../pageobjects/app.page')
22

3-
describe('My application', () => {
3+
describe('Example App for "pdf-viewer-reactjs"', () => {
44
before(() => {
55
AppPage.open()
66
})
77

8-
it('Should display the viewer', () => {
9-
expect(AppPage.loadFromURL).toBeExisting()
8+
describe('"Custom loader element" section', () => {
9+
before(() => {
10+
AppPage.section = 'cl'
11+
})
12+
13+
it('Should be displayed', () => {
14+
expect(AppPage.section).toBeExisting()
15+
})
16+
17+
it('Should display the custom loader message', () => {
18+
expect(AppPage.loader).toHaveText('Custom loader element')
19+
})
20+
})
21+
22+
describe('"Fetch PDF by URL" section', () => {
23+
before(() => {
24+
AppPage.section = 'url'
25+
})
26+
27+
it('Should be displayed', () => {
28+
expect(AppPage.section).toBeExisting()
29+
})
30+
31+
it('Should display the loader', () => {
32+
expect(AppPage.loader).toBeExisting()
33+
})
34+
35+
it('Loader should become hidden', () => {
36+
expect(
37+
AppPage.loader.waitForDisplayed({
38+
timeout: 60000,
39+
reverse: true,
40+
interval: 5000,
41+
})
42+
).toBe(true)
43+
})
44+
45+
it('PDF Viewer should become visible', () => {
46+
expect(
47+
AppPage.pdfViewer.waitForDisplayed({
48+
timeout: 60000,
49+
reverse: true,
50+
interval: 5000,
51+
})
52+
).toBe(true)
53+
})
54+
55+
it('Should display thumbnails of all the pages', () => {
56+
expect(AppPage.thumbnails).toBeElementsArrayOfSize(65)
57+
})
58+
})
59+
60+
describe('"Load PDF from base 64 string" section', () => {
61+
before(() => {
62+
AppPage.section = 'base64'
63+
})
64+
65+
it('Should be displayed', () => {
66+
expect(AppPage.section).toBeExisting()
67+
})
68+
69+
it('Should display first page initially', () => {
70+
expect(AppPage.pageIndicator).toHaveText('Page 1 / 1')
71+
})
72+
73+
it('Zoom Out & Zoom Reset button should be disabled', () => {
74+
expect(AppPage.zoomOutButton.isEnabled()).toBe(false)
75+
expect(AppPage.zoomResetButton.isEnabled()).toBe(false)
76+
})
77+
78+
it('Previous & Next page button should be disabled', () => {
79+
expect(AppPage.nextPageButton.isEnabled()).toBe(false)
80+
expect(AppPage.prevPageButton.isEnabled()).toBe(false)
81+
})
82+
83+
it('Rotation Reset button should be disabled', () => {
84+
expect(AppPage.rotateResetButton.isEnabled()).toBe(false)
85+
})
86+
})
87+
88+
describe('"Error message for failures" section', () => {
89+
before(() => {
90+
AppPage.section = 'eh'
91+
})
92+
93+
it('Should be displayed', () => {
94+
expect(AppPage.section).toBeExisting()
95+
})
96+
97+
it('Should display the error message', () => {
98+
expect(AppPage.alert).toHaveText(
99+
'error_outline\nError while opening the document !'
100+
)
101+
})
10102
})
11103

12-
it.skip('Should have page at 1', () => {
13-
expect(AppPage.getPageIndicator).toHaveText('Page 1 / 43')
104+
describe('"Custom Error component for failures" section', () => {
105+
before(() => {
106+
AppPage.section = 'ceh'
107+
})
108+
109+
it('Should be displayed', () => {
110+
expect(AppPage.section).toBeExisting()
111+
})
112+
113+
it('Should display the custom error message', () => {
114+
expect(AppPage.alert).toHaveText(
115+
'Failed To load !!!\nError while opening the document !'
116+
)
117+
})
118+
})
119+
120+
describe('"Custom starting page" section', () => {
121+
before(() => {
122+
AppPage.section = 'csp'
123+
})
124+
125+
it('Should be displayed', () => {
126+
expect(AppPage.section).toBeExisting()
127+
})
128+
129+
it('Should display Fifth page initially', () => {
130+
expect(AppPage.pageIndicator).toHaveText('Page 5 / 65')
131+
})
132+
133+
it('Should change the page on next & previous button click', () => {
134+
AppPage.nextPageButton.click()
135+
expect(AppPage.pageIndicator).toHaveText('Page 6 / 65')
136+
AppPage.prevPageButton.click()
137+
expect(AppPage.pageIndicator).toHaveText('Page 5 / 65')
138+
})
139+
140+
it('Should change the rotation on left & right rotation button click', () => {
141+
const H = AppPage.canvas.getSize('height')
142+
const W = AppPage.canvas.getSize('width')
143+
AppPage.rotateRightButton.click()
144+
expect(AppPage.canvas.getSize('height')).toBe(W)
145+
expect(AppPage.canvas.getSize('width')).toBe(H)
146+
AppPage.rotateResetButton.click()
147+
expect(AppPage.canvas.getSize('height')).toBe(H)
148+
expect(AppPage.canvas.getSize('width')).toBe(W)
149+
AppPage.rotateLeftButton.click()
150+
expect(AppPage.canvas.getSize('height')).toBe(W)
151+
expect(AppPage.canvas.getSize('width')).toBe(H)
152+
})
153+
154+
it('Should change the scale on Zoom Out & Zoom In button click', () => {
155+
const H = AppPage.canvas.getSize('height')
156+
const W = AppPage.canvas.getSize('width')
157+
AppPage.zoomInButton.click()
158+
expect(AppPage.canvas.getSize('height')).toBe(H * 2)
159+
expect(AppPage.canvas.getSize('width')).toBe(W * 2)
160+
AppPage.zoomResetButton.click()
161+
expect(AppPage.canvas.getSize('height')).toBe(H)
162+
expect(AppPage.canvas.getSize('width')).toBe(W)
163+
AppPage.zoomInButton.click()
164+
expect(AppPage.canvas.getSize('height')).toBe(H * 2)
165+
expect(AppPage.canvas.getSize('width')).toBe(W * 2)
166+
AppPage.zoomOutButton.click()
167+
expect(AppPage.canvas.getSize('height')).toBe(H)
168+
expect(AppPage.canvas.getSize('width')).toBe(W)
169+
})
170+
})
171+
172+
describe('"Without Navigation" section', () => {
173+
before(() => {
174+
AppPage.section = 'wn'
175+
})
176+
177+
it('Should be displayed', () => {
178+
expect(AppPage.section).toBeExisting()
179+
})
180+
181+
it('Should not display the navigation', () => {
182+
expect(AppPage.prevPageButton.isExisting()).toBe(false)
183+
expect(AppPage.pageIndicator.isExisting()).toBe(false)
184+
expect(AppPage.nextPageButton.isExisting()).toBe(false)
185+
})
186+
})
187+
188+
describe('"Without Zoom and Rotation" section', () => {
189+
before(() => {
190+
AppPage.section = 'wzr'
191+
})
192+
193+
it('Should be displayed', () => {
194+
expect(AppPage.section).toBeExisting()
195+
})
196+
197+
it('Should not display the zoom controls', () => {
198+
expect(AppPage.zoomOutButton.isExisting()).toBe(false)
199+
expect(AppPage.zoomInButton.isExisting()).toBe(false)
200+
})
201+
202+
it('Should not display the rotation controls', () => {
203+
expect(AppPage.rotateLeftButton.isExisting()).toBe(false)
204+
expect(AppPage.rotateRightButton.isExisting()).toBe(false)
205+
})
14206
})
15207

16-
it.skip('Should display the second page on next click', () => {
17-
AppPage.getButtons.click()
18-
expect(AppPage.getPageIndicator).toHaveText('Page 2 / 43')
208+
describe('"External Controls" section', () => {
209+
before(() => {
210+
AppPage.section = 'ec'
211+
})
212+
213+
it('Should be displayed', () => {
214+
expect(AppPage.section).toBeExisting()
215+
})
216+
217+
it('External Controls should work', () => {
218+
const H = AppPage.canvas.getSize('height')
219+
const W = AppPage.canvas.getSize('width')
220+
AppPage.extZoomInButton.click()
221+
expect(AppPage.canvas.getSize('height')).toBe(H * 2)
222+
expect(AppPage.canvas.getSize('width')).toBe(W * 2)
223+
AppPage.extZoomOutButton.click()
224+
expect(AppPage.canvas.getSize('height')).toBe(H)
225+
expect(AppPage.canvas.getSize('width')).toBe(W)
226+
})
19227
})
20228
})

‎example/wdio.conf.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ exports.config = {
1717
],
1818
logLevel: 'warn', // Level of logging verbosity: trace | debug | info | warn | error | silent
1919
bail: 0,
20-
baseUrl: 'http://localhost:5000',
20+
baseUrl: 'http://localhost:3000',
2121
waitforTimeout: 10000,
2222
connectionRetryTimeout: 120000,
2323
connectionRetryCount: 3,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /