-
-
Notifications
You must be signed in to change notification settings - Fork 737
/
Copy pathPopup.js
67 lines (56 loc) · 1.41 KB
/
Popup.js
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
/**
* Class to handle the interaction with the Dialog (Popup) Class from Puppeteer
*/
class Popup {
constructor(popup = null, defaultAction = '') {
this._popup = popup
this._actionType = ''
this._defaultAction = defaultAction
}
_assertValidActionType(action) {
if (['accept', 'cancel'].indexOf(action) === -1) {
throw new Error('Invalid Popup action type. Only "accept" or "cancel" actions are accepted')
}
}
set defaultAction(action) {
this._assertValidActionType(action)
this._defaultAction = action
}
get defaultAction() {
return this._defaultAction
}
get popup() {
return this._popup
}
set popup(popup) {
if (this._popup) {
return
}
this._popup = popup
}
get actionType() {
return this._actionType
}
set actionType(action) {
this._assertValidActionType(action)
this._actionType = action
}
clear() {
this._popup = null
this._actionType = ''
}
assertPopupVisible() {
if (!this._popup) {
throw new Error('There is no Popup visible')
}
}
assertPopupActionType(type) {
this.assertPopupVisible()
const expectedAction = this._actionType || this._defaultAction
if (expectedAction !== type) {
throw new Error(`Popup action does not fit the expected action type. Expected popup action to be '${expectedAction}' not '${type}`)
}
this.clear()
}
}
module.exports = Popup