-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d04eac
commit 71ee062
Showing
3 changed files
with
202 additions
and
6 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
src/openlmis-offline-events-indicator/offline-events-indicator.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* This program is part of the OpenLMIS logistics management information system platform software. | ||
* Copyright © 2017 VillageReach | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Affero General Public License as published by the Free Software Foundation, either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Affero General Public License for more details. You should have received a copy of | ||
* the GNU Affero General Public License along with this program. If not, see | ||
* http://www.gnu.org/licenses. For additional information contact [email protected]. | ||
*/ | ||
|
||
(function() { | ||
|
||
'use strict'; | ||
|
||
/** | ||
* @ngdoc controller | ||
* @name offline-events-indicator.controller:OfflineEventsIndicatorController | ||
* | ||
* @description | ||
* Exposes count of the pending offline events or count of stock event sync errors. | ||
*/ | ||
angular | ||
.module('openlmis-offline-events-indicator') | ||
.controller('OfflineEventsIndicatorController', controller); | ||
|
||
controller.$inject = ['offlineEventsService', '$rootScope', '$state']; | ||
|
||
function controller(offlineEventsService, $rootScope, $state) { | ||
|
||
var vm = this; | ||
|
||
vm.$onInit = onInit; | ||
vm.goToPendingOfflineEventsPage = goToPendingOfflineEventsPage; | ||
vm.goToSynchronizationErrorsPage = goToSynchronizationErrorsPage; | ||
|
||
/** | ||
* @ngdoc property | ||
* @propertyOf offline-events-indicator.controller:OfflineEventsIndicatorController | ||
* @name pendingEventsCount | ||
* @type {Number} | ||
* | ||
* @description | ||
* Holds pending offline events count. | ||
*/ | ||
vm.pendingEventsCount; | ||
|
||
/** | ||
* @ngdoc property | ||
* @propertyOf offline-events-indicator.controller:OfflineEventsIndicatorController | ||
* @name offlineSyncErrorsCount | ||
* @type {Number} | ||
* | ||
* @description | ||
* Holds event synchronization errors count. | ||
*/ | ||
vm.offlineSyncErrorsCount; | ||
|
||
function onInit() { | ||
offlineEventsService.getCountOfPendingOfflineEvents() | ||
.then(function(result) { | ||
vm.pendingEventsCount = result; | ||
}); | ||
|
||
offlineEventsService.getCountOfSyncErrorEvents() | ||
.then(function(result) { | ||
vm.offlineSyncErrorsCount = result; | ||
}); | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf offline-events-indicator.controller:OfflineEventsIndicatorController | ||
* @name goToPendingOfflineEventsPage | ||
* | ||
* @description | ||
* Takes the user to the pending offline events page. | ||
*/ | ||
function goToPendingOfflineEventsPage() { | ||
$state.go('openlmis.pendingOfflineEvents'); | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @methodOf offline-events-indicator.controller:OfflineEventsIndicatorController | ||
* @name goToSynchronizationErrorsPage | ||
* | ||
* @description | ||
* Takes the user to the synchronization errors page. | ||
*/ | ||
function goToSynchronizationErrorsPage() { | ||
$state.go('openlmis.eventsSynchronizationErrors'); | ||
} | ||
|
||
$rootScope.$on('openlmis-referencedata.offline-events-indicator', function() { | ||
offlineEventsService.getCountOfPendingOfflineEvents() | ||
.then(function(result) { | ||
vm.pendingEventsCount = result; | ||
}); | ||
|
||
offlineEventsService.getCountOfSyncErrorEvents() | ||
.then(function(result) { | ||
vm.offlineSyncErrorsCount = result; | ||
}); | ||
}); | ||
} | ||
|
||
})(); |
83 changes: 83 additions & 0 deletions
83
src/openlmis-offline-events-indicator/offline-events-indicator.controller.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* This program is part of the OpenLMIS logistics management information system platform software. | ||
* Copyright © 2017 VillageReach | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Affero General Public License as published by the Free Software Foundation, either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Affero General Public License for more details. You should have received a copy of | ||
* the GNU Affero General Public License along with this program. If not, see | ||
* http://www.gnu.org/licenses. For additional information contact [email protected]. | ||
*/ | ||
|
||
describe('OfflineEventsIndicatorController', function() { | ||
|
||
beforeEach(function() { | ||
module('openlmis-offline-events-indicator'); | ||
|
||
inject(function($injector) { | ||
this.$q = $injector.get('$q'); | ||
this.$rootScope = $injector.get('$rootScope'); | ||
this.$state = $injector.get('$state'); | ||
this.$controller = $injector.get('$controller'); | ||
this.offlineEventsService = $injector.get('offlineEventsService'); | ||
}); | ||
|
||
this.pendingEventsCount = 2; | ||
this.offlineSyncErrorsCount = 1; | ||
|
||
spyOn(this.offlineEventsService, 'getCountOfPendingOfflineEvents') | ||
.andReturn(this.$q.resolve(this.pendingEventsCount)); | ||
spyOn(this.offlineEventsService, 'getCountOfSyncErrorEvents') | ||
.andReturn(this.$q.resolve(this.offlineSyncErrorsCount)); | ||
|
||
spyOn(this.$state, 'go').andReturn(); | ||
|
||
this.vm = this.$controller('OfflineEventsIndicatorController'); | ||
}); | ||
|
||
describe('$onInit', function() { | ||
|
||
it('should expose pending offline events and offline sync errors', function() { | ||
this.vm.$onInit(); | ||
this.$rootScope.$apply(); | ||
|
||
expect(this.offlineEventsService.getCountOfPendingOfflineEvents).toHaveBeenCalled(); | ||
expect(this.vm.pendingEventsCount).toEqual(this.pendingEventsCount); | ||
expect(this.offlineEventsService.getCountOfSyncErrorEvents).toHaveBeenCalled(); | ||
expect(this.vm.offlineSyncErrorsCount).toEqual(this.offlineSyncErrorsCount); | ||
}); | ||
|
||
it('should update offline events count and errors', function() { | ||
this.$rootScope.$emit('openlmis-referencedata.offline-events-indicator'); | ||
this.$rootScope.$apply(); | ||
|
||
expect(this.offlineEventsService.getCountOfPendingOfflineEvents).toHaveBeenCalled(); | ||
expect(this.offlineEventsService.getCountOfSyncErrorEvents).toHaveBeenCalled(); | ||
}); | ||
|
||
}); | ||
|
||
describe('goToPendingOfflineEventsPage', function() { | ||
|
||
it('should call state go method', function() { | ||
this.vm.goToPendingOfflineEventsPage(); | ||
this.$rootScope.$apply(); | ||
|
||
expect(this.$state.go).toHaveBeenCalledWith('openlmis.pendingOfflineEvents'); | ||
}); | ||
}); | ||
|
||
describe('goToSynchronizationErrorsPage', function() { | ||
|
||
it('should call state go method', function() { | ||
this.vm.goToSynchronizationErrorsPage(); | ||
this.$rootScope.$apply(); | ||
|
||
expect(this.$state.go).toHaveBeenCalledWith('openlmis.eventsSynchronizationErrors'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters