Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #11732 from qdot/close-tests
Browse files Browse the repository at this point in the history
Bug 892528 - Integration tests for closing notifications
  • Loading branch information
lightsofapollo committed Aug 26, 2013
2 parents 23343e6 + 64339f4 commit a3b860b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
37 changes: 27 additions & 10 deletions apps/system/test/marionette/notification.js
@@ -1,19 +1,30 @@
'use strict';
var util = require('util');

function NotificationTest(client, origin, tag) {
function NotificationTest(client, origin, tag, title, body) {
this.client = client;
this.origin = origin;
this.tag = tag;
this.client.executeScript(function(notifyTag, notifyTitle, notifyBody) {
if (window.wrappedJSObject.persistNotify === undefined) {
window.wrappedJSObject.persistNotify = [];
}
window.wrappedJSObject.persistNotify[notifyTag] =
new Notification(notifyTitle, { body: notifyBody, tag: notifyTag });
}, [this.tag, title, body]);
}

module.exports = NotificationTest;

NotificationTest.Selector = Object.freeze({
containerElement: '[data-notification-id="%s#tag:%s"]',
titleElement: '[data-notification-id="%s#tag:%s"] > div',
bodyElement: '[data-notification-id="%s#tag:%s"] > .detail'
});
NotificationTest.Selector = Object.freeze((function() {
var baseSelector = '#desktop-notifications-container > ' +
'[data-notification-id="%s#tag:%s"]';
return {
containerElement: baseSelector,
titleElement: baseSelector + ' > div',
bodyElement: baseSelector + ' > .detail'
};
})());

NotificationTest.prototype = {
client: null,
Expand Down Expand Up @@ -41,11 +52,17 @@ NotificationTest.prototype = {
return this.bodyElement.getAttribute('textContent');
},
get titleText() {
return this.titleElement.getAttribute('textContent');
return this.titleElement.getAttribute('textContent');
},
createNotification: function(notifyTitle, notifyBody) {
replace: function(title, body) {
this.client.executeScript(function(notifyTag, notifyTitle, notifyBody) {
new Notification(notifyTitle, { body: notifyBody, tag: notifyTag });
}, [this.tag, notifyTitle, notifyBody]);
window.wrappedJSObject.persistNotify[notifyTag] =
new Notification(notifyTitle, { body: notifyBody, tag: notifyTag });
}, [this.tag, title, body]);
},
close: function() {
this.client.executeScript(function(notifyTag) {
window.wrappedJSObject.persistNotify[notifyTag].close();
}, [this.tag]);
}
};
25 changes: 19 additions & 6 deletions apps/system/test/marionette/notification_test.js
@@ -1,13 +1,15 @@

var assert = require('assert'),
NotificationTest = require('./notification');
NotificationTest = require('./notification'),
util = require('util');

marionette('notification tests', function() {
var client = marionette.client();

test('fire notification', function() {
var notify =
new NotificationTest(client, 'app://system.gaiamobile.org', '123');
notify.createNotification('test title', 'test body');
new NotificationTest(client, 'app://system.gaiamobile.org',
'123', 'test title', 'test body');
assert.ok(notify.containerElement,
'notification exists in UI with correct tag');
assert.ok(notify.titleElement, 'title div exists for notification');
Expand All @@ -18,10 +20,10 @@ marionette('notification tests', function() {

test('replace notification', function() {
var notify =
new NotificationTest(client, 'app://system.gaiamobile.org', '123');
notify.createNotification('test title', 'test body');
new NotificationTest(client, 'app://system.gaiamobile.org',
'123', 'test title', 'test body');
// Calling create notification again reuses the tag
notify.createNotification('test title 2', 'test body 2');
notify.replace('test title 2', 'test body 2');
assert.ok(notify.containerElement,
'notification exists in UI with correct tag');
assert.ok(notify.titleElement, 'title div exists for notification');
Expand All @@ -31,4 +33,15 @@ marionette('notification tests', function() {
assert.equal(notify.bodyText, 'test body 2', 'notification body correct');
});

test('close notification', function() {
var notify =
new NotificationTest(client, 'app://system.gaiamobile.org',
'123', 'test title', 'test body');
assert.ok(notify.containerElement,
'notification exists in UI with correct tag');
notify.close();
assert.throws(function() { return notify.containerElement; },
/Unable to locate element/,
'notification removed from UI');
});
});

0 comments on commit a3b860b

Please sign in to comment.