Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/apps/system/test/unit/notifications_test.js
diff options
context:
space:
mode:
Diffstat (limited to 'apps/system/test/unit/notifications_test.js')
-rw-r--r--apps/system/test/unit/notifications_test.js132
1 files changed, 132 insertions, 0 deletions
diff --git a/apps/system/test/unit/notifications_test.js b/apps/system/test/unit/notifications_test.js
new file mode 100644
index 0000000..e323f07
--- /dev/null
+++ b/apps/system/test/unit/notifications_test.js
@@ -0,0 +1,132 @@
+'use strict';
+
+requireApp('system/test/unit/mock_statusbar.js');
+requireApp('system/test/unit/mock_gesture_detector.js');
+requireApp('system/test/unit/mock_settings_listener.js');
+requireApp('system/test/unit/mocks_helper.js');
+
+requireApp('system/js/notifications.js');
+
+var mocksForNotificationScreen = ['StatusBar', 'GestureDetector',
+ 'SettingsListener'];
+
+mocksForNotificationScreen.forEach(function(mockName) {
+ if (! window[mockName]) {
+ window[mockName] = null;
+ }
+});
+
+
+suite('system/NotificationScreen >', function() {
+ var fakeNotifContainer, fakeLockScreenContainer, fakeToaster,
+ fakeButton, fakeToasterIcon, fakeToasterTitle, fakeToasterDetail;
+
+ var mocksHelper;
+
+ suiteSetup(function() {
+ mocksHelper = new MocksHelper(mocksForNotificationScreen);
+ mocksHelper.suiteSetup();
+ });
+
+ suiteTeardown(function() {
+ mocksHelper.suiteTeardown();
+ });
+
+ setup(function() {
+ fakeNotifContainer = document.createElement('div');
+ fakeNotifContainer.id = 'desktop-notifications-container';
+ // add some children, we don't care what they are
+ fakeNotifContainer.appendChild(document.createElement('div'));
+ fakeNotifContainer.appendChild(document.createElement('div'));
+
+ function createFakeElement(tag, id) {
+ var obj = document.createElement(tag);
+ obj.id = id;
+ return obj;
+ };
+
+ fakeLockScreenContainer = createFakeElement('div',
+ 'notifications-lockscreen-container');
+ fakeToaster = createFakeElement('div', 'notification-toaster');
+ fakeButton = createFakeElement('button', 'notification-clear');
+ fakeToasterIcon = createFakeElement('img', 'toaster-icon');
+ fakeToasterTitle = createFakeElement('div', 'toaster-title');
+ fakeToasterDetail = createFakeElement('div', 'toaster-detail');
+
+ document.body.appendChild(fakeNotifContainer);
+
+ document.body.appendChild(fakeLockScreenContainer);
+ document.body.appendChild(fakeToaster);
+ document.body.appendChild(fakeButton);
+ document.body.appendChild(fakeToasterIcon);
+ document.body.appendChild(fakeToasterTitle);
+ document.body.appendChild(fakeToasterDetail);
+
+ mocksHelper.setup();
+
+ NotificationScreen.init();
+ });
+
+ teardown(function() {
+ fakeNotifContainer.parentNode.removeChild(fakeNotifContainer);
+ fakeLockScreenContainer.parentNode.removeChild(fakeLockScreenContainer);
+ fakeToaster.parentNode.removeChild(fakeToaster);
+ fakeButton.parentNode.removeChild(fakeButton);
+
+ mocksHelper.teardown();
+ });
+
+ suite('updateStatusBarIcon >', function() {
+ setup(function() {
+ NotificationScreen.updateStatusBarIcon();
+ });
+
+ test('should update the icon in the status bar', function() {
+ assert.ok(MockStatusBar.wasMethodCalled['updateNotification']);
+ assert.equal(2, MockStatusBar.notificationsCount);
+ });
+
+ test('external notif should not be able to decrease the global count',
+ function() {
+
+ NotificationScreen.decExternalNotifications();
+ assert.equal(2, MockStatusBar.notificationsCount);
+ });
+
+ test('external notif should increase the global count',
+ function() {
+
+ NotificationScreen.incExternalNotifications();
+ assert.isTrue(MockStatusBar.mNotificationUnread);
+ assert.equal(3, MockStatusBar.notificationsCount);
+ });
+
+ test('external notif should decrease the global count',
+ function() {
+
+ NotificationScreen.incExternalNotifications();
+ MockStatusBar.mNotificationUnread = false;
+ NotificationScreen.decExternalNotifications();
+ assert.isFalse(MockStatusBar.mNotificationUnread);
+ assert.equal(2, MockStatusBar.notificationsCount);
+ });
+
+ test('should change the read status', function() {
+ NotificationScreen.updateStatusBarIcon(true);
+ assert.isTrue(MockStatusBar.mNotificationUnread);
+ });
+
+ test('calling addNotification without icon', function() {
+ var toasterIcon = NotificationScreen.toasterIcon;
+ var imgpath = 'http://example.com/test.png';
+ var detail = {icon: imgpath, title: 'title', detail: 'detail'};
+ NotificationScreen.addNotification(detail);
+ assert.equal(imgpath, toasterIcon.src);
+ assert.isFalse(toasterIcon.hidden);
+ delete detail.icon;
+ NotificationScreen.addNotification(detail);
+ assert.isTrue(toasterIcon.hidden);
+ });
+ });
+
+});