This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 972
/
Copy pathmessageBoxTest.js
281 lines (246 loc) · 8.4 KB
/
messageBoxTest.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/* global describe, beforeEach, it */
const Brave = require('../../../lib/brave')
const {
urlInput, backButtonEnabled, forwardButtonEnabled, forwardButtonDisabled,
msgBoxSuppress, msgBoxSuppressTrue, msgBoxMessage, msgBoxTitle
} = require('../../../lib/selectors')
const assert = require('assert')
const getActiveTabState = (appState) => {
const tabs = appState.tabs
const activeTab = tabs.find((tab) => {
return tab.active
})
return activeTab
}
const getBackgroundTabState = (appState) => {
const tabs = appState.tabs
const nonActiveTab = tabs.find((tab) => {
return !tab.active && tab.messageBoxDetail
})
return nonActiveTab
}
let modalAlert
let alertText
describe('MessageBox component tests', function () {
function * setup (client) {
yield client
.waitForUrl(Brave.newTabUrl)
.waitForBrowserWindow()
.waitForEnabled(urlInput)
}
function * showsExpectedMessage (client) {
yield client
.waitForTextValue(msgBoxMessage, alertText)
}
function * storesDetailsInTabState (client) {
let alertTitle
let alertMessage
yield client
.waitForVisible(msgBoxTitle)
.getText(msgBoxTitle).then((val) => {
alertTitle = val
})
.waitForVisible(msgBoxMessage)
.getText(msgBoxMessage).then((val) => {
alertMessage = val
})
.getAppState().then((val) => {
const tabState = getActiveTabState(val.value)
assert(tabState.messageBoxDetail.title === alertTitle)
assert(tabState.messageBoxDetail.message === alertMessage)
})
}
Brave.beforeEach(this)
describe('alert', function () {
beforeEach(function * () {
alertText = undefined
modalAlert = Brave.server.url('modal_alert.html')
yield setup(this.app.client)
yield this.app.client
.tabByUrl(Brave.newTabUrl)
.loadUrl(modalAlert)
.waitForVisible('#trigger')
.leftClick('#trigger')
.waitUntil(function () {
return this.alertText().then((response) => {
alertText = response
return response
}, () => {
return false
})
})
.windowByUrl(Brave.browserWindowUrl)
.waitForVisible(msgBoxMessage)
})
it('shows the expected message', function * () {
yield showsExpectedMessage(this.app.client)
})
it('stores the message box details in the tabState', function * () {
yield storesDetailsInTabState(this.app.client)
})
it('closes the alert when you press enter', function * () {
yield this.app.client
.keys(Brave.keys.ENTER)
.waitUntil(function () {
return this.getAppState().then((val) => {
const tabState = getActiveTabState(val.value)
return tabState.messageBoxDetail === undefined
})
})
})
it('closes the alert when you press escape', function * () {
yield this.app.client
.keys(Brave.keys.ESCAPE)
.waitUntil(function () {
return this.getAppState().then((val) => {
const tabState = getActiveTabState(val.value)
return tabState.messageBoxDetail === undefined
})
})
})
describe('when showing an alerts multiple times', function () {
beforeEach(function * () {
yield this.app.client
.keys(Brave.keys.ENTER)
.waitUntil(function () {
return this.getAppState().then((val) => {
const tabState = getActiveTabState(val.value)
return tabState.messageBoxDetail === undefined
})
})
// Show modal a 2nd time
.tabByUrl(modalAlert)
.leftClick('#trigger')
.waitUntil(function () {
return this.alertText().then((response) => {
alertText = response
return response
}, () => {
return false
})
})
// 2nd time an alert from this source is shown,
// we display a "suppress" switch
.windowByUrl(Brave.browserWindowUrl)
})
it('shows a suppress switch', function * () {
yield this.app.client
.waitForVisible(msgBoxSuppress)
})
it('lets you suppress future notifications', function * () {
yield this.app.client
// click to set Suppress = true
.click(msgBoxSuppress)
.waitForVisible(msgBoxSuppressTrue)
// Close alert again
.keys(Brave.keys.ENTER)
.waitUntil(function () {
return this.getAppState().then((val) => {
const tabState = getActiveTabState(val.value)
return tabState.messageBoxDetail === undefined
})
})
// Try to show modal a 3rd time
.tabByUrl(modalAlert)
.leftClick('#trigger')
.windowByUrl(Brave.browserWindowUrl)
.pause(2000)
.waitUntil(function () {
return this.getAppState().then((val) => {
const tabState = getActiveTabState(val.value)
return tabState.messageBoxDetail === undefined
})
})
})
})
describe('when opening a new tab (while alert is showing)', function () {
beforeEach(function * () {
const page1 = Brave.server.url('page1.html')
const page2 = Brave.server.url('page2.html')
// open a new tab
yield this.app.client
.newTab({ url: page1 })
.waitForTabCount(2)
yield this.app.client
.waitForVisible('#thelink[href="page2.html"]', 5000)
// load a basic history for this tab
yield this.app.client
.url(page2)
.waitForVisible('#thelink[href="page1.html"]', 5000)
.url(page1)
.waitForVisible('#thelink[href="page2.html"]', 5000)
})
it('lets you follow links in the tab', function * () {
// click link
yield this.app.client
.leftClick('#thelink')
// verify link was followed
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.waitForTextValue('[data-test-id="tab"][data-test-active-tab="true"] [data-test-id="tabTitle"]', 'Page 2')
})
it('lets you use the back button', function * () {
// click back button
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.leftClick(backButtonEnabled)
// verify page is previous
yield this.app.client
.waitForTextValue('[data-test-id="tab"][data-test-active-tab="true"] [data-test-id="tabTitle"]', 'Page 2')
})
it('lets you use the forward button', function * () {
// click back button
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.leftClick(backButtonEnabled)
.waitForElementCount(forwardButtonDisabled, 0)
// click forward button
yield this.app.client
.leftClick(forwardButtonEnabled)
// verify page is previous
yield this.app.client
.waitForTextValue('[data-test-id="tab"][data-test-active-tab="true"] [data-test-id="tabTitle"]', 'Page 1')
})
it('original tab does not respond to escape or enter being pressed', function * () {
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.keys(Brave.keys.ENTER)
.pause(250)
.keys(Brave.keys.ESCAPE)
.pause(250)
.getAppState().then((val) => {
const detail = getBackgroundTabState(val.value)
assert(detail)
})
})
})
})
describe('confirm', function () {
beforeEach(function * () {
alertText = undefined
modalAlert = Brave.server.url('modal_confirm.html')
yield setup(this.app.client)
yield this.app.client
.tabByUrl(Brave.newTabUrl)
.loadUrl(modalAlert)
.waitForVisible('#trigger')
.leftClick('#trigger')
.waitUntil(function () {
return this.alertText().then((response) => {
alertText = response
return response
}, () => {
return false
})
})
.windowByUrl(Brave.browserWindowUrl)
.waitForVisible(msgBoxMessage)
})
it('shows the expected message', function * () {
yield showsExpectedMessage(this.app.client)
})
it('stores the message box details in the tabState', function * () {
yield storesDetailsInTabState(this.app.client)
})
})
})