|
2 | 2 | * Class to handle the interaction with the Dialog (Popup) Class from Puppeteer
|
3 | 3 | */
|
4 | 4 | class Popup {
|
5 |
| - constructor(popup, defaultAction) { |
6 |
| - this._popup = popup || null; |
7 |
| - this._actionType = ''; |
8 |
| - this._defaultAction = defaultAction || ''; |
| 5 | + constructor(popup = null, defaultAction = '') { |
| 6 | + this._popup = popup |
| 7 | + this._actionType = '' |
| 8 | + this._defaultAction = defaultAction |
9 | 9 | }
|
10 | 10 |
|
11 | 11 | _assertValidActionType(action) {
|
12 | 12 | if (['accept', 'cancel'].indexOf(action) === -1) {
|
13 |
| - throw new Error('Invalid Popup action type. Only "accept" or "cancel" actions are accepted'); |
| 13 | + throw new Error('Invalid Popup action type. Only "accept" or "cancel" actions are accepted') |
14 | 14 | }
|
15 | 15 | }
|
16 | 16 |
|
17 | 17 | set defaultAction(action) {
|
18 |
| - this._assertValidActionType(action); |
19 |
| - this._defaultAction = action; |
| 18 | + this._assertValidActionType(action) |
| 19 | + this._defaultAction = action |
20 | 20 | }
|
21 | 21 |
|
22 | 22 | get defaultAction() {
|
23 |
| - return this._defaultAction; |
| 23 | + return this._defaultAction |
24 | 24 | }
|
25 | 25 |
|
26 | 26 | get popup() {
|
27 |
| - return this._popup; |
| 27 | + return this._popup |
28 | 28 | }
|
29 | 29 |
|
30 | 30 | set popup(popup) {
|
31 | 31 | if (this._popup) {
|
32 |
| - console.error('Popup already exists and was not closed. Popups must always be closed by calling either I.acceptPopup() or I.cancelPopup()'); |
| 32 | + return |
33 | 33 | }
|
34 |
| - this._popup = popup; |
| 34 | + this._popup = popup |
35 | 35 | }
|
36 | 36 |
|
37 | 37 | get actionType() {
|
38 |
| - return this._actionType; |
| 38 | + return this._actionType |
39 | 39 | }
|
40 | 40 |
|
41 | 41 | set actionType(action) {
|
42 |
| - this._assertValidActionType(action); |
43 |
| - this._actionType = action; |
| 42 | + this._assertValidActionType(action) |
| 43 | + this._actionType = action |
44 | 44 | }
|
45 | 45 |
|
46 | 46 | clear() {
|
47 |
| - this._popup = null; |
48 |
| - this._actionType = ''; |
| 47 | + this._popup = null |
| 48 | + this._actionType = '' |
49 | 49 | }
|
50 | 50 |
|
51 | 51 | assertPopupVisible() {
|
52 | 52 | if (!this._popup) {
|
53 |
| - throw new Error('There is no Popup visible'); |
| 53 | + throw new Error('There is no Popup visible') |
54 | 54 | }
|
55 | 55 | }
|
56 | 56 |
|
57 | 57 | assertPopupActionType(type) {
|
58 |
| - this.assertPopupVisible(); |
59 |
| - const expectedAction = this._actionType || this._defaultAction; |
| 58 | + this.assertPopupVisible() |
| 59 | + const expectedAction = this._actionType || this._defaultAction |
60 | 60 | if (expectedAction !== type) {
|
61 |
| - throw new Error(`Popup action does not fit the expected action type. Expected popup action to be '${expectedAction}' not '${type}`); |
| 61 | + throw new Error(`Popup action does not fit the expected action type. Expected popup action to be '${expectedAction}' not '${type}`) |
62 | 62 | }
|
63 |
| - this.clear(); |
| 63 | + this.clear() |
64 | 64 | }
|
65 | 65 | }
|
66 | 66 |
|
67 |
| -module.exports = Popup; |
| 67 | +module.exports = Popup |
0 commit comments