feat(core): add notification feedback with angular-ui-notification (#1532)

Added visual notification for user/article updates
angular-ui-notification config added to core client config
Notification idea from #369
This commit is contained in:
Sujeeth
2016-10-10 17:51:44 -04:00
committed by Michael Leanos
parent 5725c449c7
commit 607ed061e3
26 changed files with 122 additions and 137 deletions

View File

@@ -9,7 +9,8 @@
$state,
Authentication,
ArticlesService,
mockArticle;
mockArticle,
Notification;
// The $resource service augments the response object with methods for updating and deleting the resource.
// If we were to use the standard toEqual matcher, our tests would fail because the test values would not match
@@ -36,7 +37,7 @@
// The injector ignores leading and trailing underscores here (i.e. _$httpBackend_).
// This allows us to inject a service but then attach it to a variable
// with the same name as the service.
beforeEach(inject(function ($controller, $rootScope, _$state_, _$httpBackend_, _Authentication_, _ArticlesService_) {
beforeEach(inject(function ($controller, $rootScope, _$state_, _$httpBackend_, _Authentication_, _ArticlesService_, _Notification_) {
// Set a new global scope
$scope = $rootScope.$new();
@@ -45,6 +46,7 @@
$state = _$state_;
Authentication = _Authentication_;
ArticlesService = _ArticlesService_;
Notification = _Notification_;
// create mock article
mockArticle = new ArticlesService({
@@ -66,6 +68,8 @@
// Spy on state go
spyOn($state, 'go');
spyOn(Notification, 'error');
spyOn(Notification, 'success');
}));
describe('vm.save() as create', function () {
@@ -89,11 +93,13 @@
$scope.vm.save(true);
$httpBackend.flush();
// Test Notification success was called
expect(Notification.success).toHaveBeenCalledWith({ message: '<i class="glyphicon glyphicon-ok"></i> Article saved successfully!' });
// Test URL redirection after the article was created
expect($state.go).toHaveBeenCalledWith('admin.articles.list');
}));
it('should set $scope.vm.error if error', function () {
it('should call Notification.error if error', function () {
var errorMessage = 'this is an error message';
$httpBackend.expectPOST('api/articles', sampleArticlePostData).respond(400, {
message: errorMessage
@@ -102,7 +108,7 @@
$scope.vm.save(true);
$httpBackend.flush();
expect($scope.vm.error).toBe(errorMessage);
expect(Notification.error).toHaveBeenCalledWith({ message: errorMessage, title: '<i class="glyphicon glyphicon-remove"></i> Article save error!' });
});
});
@@ -120,11 +126,13 @@
$scope.vm.save(true);
$httpBackend.flush();
// Test Notification success was called
expect(Notification.success).toHaveBeenCalledWith({ message: '<i class="glyphicon glyphicon-ok"></i> Article saved successfully!' });
// Test URL location to new object
expect($state.go).toHaveBeenCalledWith('admin.articles.list');
}));
it('should set $scope.vm.error if error', inject(function (ArticlesService) {
it('should call Notification.error if error', inject(function (ArticlesService) {
var errorMessage = 'error';
$httpBackend.expectPUT(/api\/articles\/([0-9a-fA-F]{24})$/).respond(400, {
message: errorMessage
@@ -133,7 +141,7 @@
$scope.vm.save(true);
$httpBackend.flush();
expect($scope.vm.error).toBe(errorMessage);
expect(Notification.error).toHaveBeenCalledWith({ message: errorMessage, title: '<i class="glyphicon glyphicon-remove"></i> Article save error!' });
}));
});
@@ -152,6 +160,7 @@
$scope.vm.remove();
$httpBackend.flush();
expect(Notification.success).toHaveBeenCalledWith({ message: '<i class="glyphicon glyphicon-ok"></i> Article deleted successfully!' });
expect($state.go).toHaveBeenCalledWith('admin.articles.list');
});