Tested notification
diff --git a/views/ngXosViews/synchronizerNotifier/spec/notification.test.js b/views/ngXosViews/synchronizerNotifier/spec/notification.test.js
new file mode 100644
index 0000000..265b7b9
--- /dev/null
+++ b/views/ngXosViews/synchronizerNotifier/spec/notification.test.js
@@ -0,0 +1,76 @@
+'use strict';
+
+describe('The Synchronizer Notification Panel', () => {
+
+ var scope, element, isolatedScope, XosUserPrefs;
+ const xosNotification = {
+ notify: jasmine.createSpy('notify')
+ };
+
+ const failureEvent = {
+ name: 'test',
+ status: false
+ };
+
+ const successEvent = {
+ name: 'test',
+ status: true
+ };
+
+ beforeEach(module('xos.synchronizerNotifier', ($provide) => {
+ $provide.value('Diag', {
+ start: () => null
+ });
+
+ $provide.value('xosNotification', xosNotification);
+ }));
+ beforeEach(module('templates'));
+
+ beforeEach(inject(function($compile, $rootScope, _XosUserPrefs_){
+
+ XosUserPrefs = _XosUserPrefs_;
+ scope = $rootScope.$new();
+ element = angular.element('<sync-status></sync-status>');
+ $compile(element)(scope);
+ scope.$digest();
+ isolatedScope = element.isolateScope().vm;
+ }));
+
+ describe('when an event is received', () => {
+
+ beforeEach(() => {
+ xosNotification.notify.calls.reset()
+ });
+
+ describe('and notification have not been sent', () => {
+
+ beforeEach(() => {
+ XosUserPrefs.setSynchronizerNotificationStatus('test', false);
+ scope.$emit('diag', failureEvent);
+ });
+
+ it('should trigger notification', () => {
+ expect(xosNotification.notify).toHaveBeenCalled();
+ });
+
+ it('should update status in the scope', () => {
+ expect(isolatedScope.synchronizers.test).toEqual(failureEvent);
+ scope.$emit('diag', successEvent);
+ expect(isolatedScope.synchronizers.test).toEqual(successEvent);
+ });
+ });
+
+ describe('and notification have been sent', () => {
+
+ beforeEach(() => {
+ XosUserPrefs.setSynchronizerNotificationStatus('test', true);
+ scope.$emit('diag', failureEvent);
+ });
+
+ it('should not trigger multiple notification for the same synchronizer', () => {
+ expect(xosNotification.notify).not.toHaveBeenCalled();
+ });
+ });
+ });
+
+});
\ No newline at end of file
diff --git a/views/ngXosViews/synchronizerNotifier/spec/sample.test.js b/views/ngXosViews/synchronizerNotifier/spec/sample.test.js
deleted file mode 100644
index 0e61572..0000000
--- a/views/ngXosViews/synchronizerNotifier/spec/sample.test.js
+++ /dev/null
@@ -1,37 +0,0 @@
-'use strict';
-
-describe('The User List', () => {
-
- var scope, element, isolatedScope, httpBackend;
-
- beforeEach(module('xos.synchronizerNotifier'));
- beforeEach(module('templates'));
-
- beforeEach(inject(function($httpBackend, $compile, $rootScope){
-
- httpBackend = $httpBackend;
- // Setting up mock request
- $httpBackend.expectGET('/api/core/users/?no_hyperlinks=1').respond([
- {
- email: 'matteo.scandolo@gmail.com',
- firstname: 'Matteo',
- lastname: 'Scandolo'
- }
- ]);
-
- scope = $rootScope.$new();
- element = angular.element('<users-list></users-list>');
- $compile(element)(scope);
- scope.$digest();
- isolatedScope = element.isolateScope().vm;
- }));
-
- xit('should load 1 users', () => {
- httpBackend.flush();
- expect(isolatedScope.users.length).toBe(1);
- expect(isolatedScope.users[0].email).toEqual('matteo.scandolo@gmail.com');
- expect(isolatedScope.users[0].firstname).toEqual('Matteo');
- expect(isolatedScope.users[0].lastname).toEqual('Scandolo');
- });
-
-});
\ No newline at end of file
diff --git a/views/ngXosViews/synchronizerNotifier/src/js/main.js b/views/ngXosViews/synchronizerNotifier/src/js/main.js
index 03c10be..a98f672 100644
--- a/views/ngXosViews/synchronizerNotifier/src/js/main.js
+++ b/views/ngXosViews/synchronizerNotifier/src/js/main.js
@@ -56,8 +56,8 @@
this.getSyncStatus = (status) => {
const now = new Date();
- // let gap = 15 * 60 * 1000; /* ms */
- const gap = 1 * 60 * 1000;
+ let gap = 15 * 60 * 1000; /* ms */
+ // const gap = 1 * 60 * 1000; // for demo use 1 minute
// if all of this values are older than 15 min,
// probably something is wrong
if (
@@ -98,10 +98,8 @@
$rootScope.$on('diag', (e, d) => {
this.synchronizers[d.name] = d;
-
// if errored
if(!d.status){
- console.log(d.name, XosUserPrefs.getSynchronizerNotificationStatus(d.name));
// and not already notified
if(!XosUserPrefs.getSynchronizerNotificationStatus(d.name)){
xosNotification.notify('CORD Synchronizer', {