This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
notification.js
98 lines (86 loc) · 3.02 KB
/
notification.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
/*jshint node: true, browser: true */
'use strict';
var assert = require('assert'),
containerSelector = '#desktop-notifications-container .other-notifications';
function Notification(client) {
this.client = client;
}
module.exports = Notification;
Notification.prototype = {
getContainer: function() {
return this.client.findElement(containerSelector);
},
assertNoNotification: function() {
this.getContainer().findElement('div', function(error) {
assert.ok(!!error);
});
},
/**
* Uses Notification.get to get the first notification to show up. This
* approach is used instead of something like tapping on the notification,
* since the notification UI is normally hidden and it is non-trivial to open,
* and the data API really reflects the result of the notification work done
* by the email app.
*/
triggerFirstNotification: function() {
var client = this.client;
return client.executeAsyncScript(function() {
function getFirstNotification() {
window.Notification.get().then(function(notifications) {
if (!notifications) {
marionetteScriptFinished(false);
} else if (!notifications.length) {
// The check was done too fast. Wait for some time to pass
// and check again.
window.setTimeout(getFirstNotification, 300);
} else {
var notification = notifications[0],
evt = window.wrappedJSObject.require('evt');
evt.emit('notification', {
clicked: true,
imageURL: notification.imageURL,
data: notification.data,
tag: notification.tag
});
marionetteScriptFinished(true);
}
}).catch(function(error) {
console.error('Notification.get failed with: ' + error);
marionetteScriptFinished(false);
});
}
getFirstNotification();
});
},
/**
* Uses Notification.get to get the first notification's data.
*/
getFirstNotificationData: function() {
var client = this.client;
return client.executeAsyncScript(function() {
function getFirstNotification() {
window.Notification.get().then(function(notifications) {
if (!notifications) {
marionetteScriptFinished(false);
} else if (!notifications.length) {
// The check was done too fast. Wait for some time to pass
// and check again.
window.setTimeout(getFirstNotification, 300);
} else {
var notification = notifications[0];
marionetteScriptFinished({
imageURL: notification.imageURL,
data: notification.data,
tag: notification.tag
});
}
}).catch(function(error) {
console.error('Notification.get failed with: ' + error);
marionetteScriptFinished(false);
});
}
getFirstNotification();
});
}
};
require('./debug')('notification', Notification.prototype);