kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
4.7 KiB
142 lines
4.7 KiB
9 years ago
|
// -- copyright
|
||
9 years ago
|
// OpenProject is a project management system.
|
||
|
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License version 3.
|
||
|
//
|
||
|
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
// Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License
|
||
|
// as published by the Free Software Foundation; either version 2
|
||
|
// 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 General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program; if not, write to the Free Software
|
||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
//
|
||
|
// See doc/COPYRIGHT.rdoc for more details.
|
||
9 years ago
|
// ++
|
||
9 years ago
|
|
||
9 years ago
|
describe('NotificationsService', function () {
|
||
9 years ago
|
var NotificationsService,
|
||
9 years ago
|
$rootScope;
|
||
9 years ago
|
|
||
9 years ago
|
beforeEach(angular.mock.module('openproject.services'));
|
||
|
beforeEach(angular.mock.inject(function (_$rootScope_, _NotificationsService_) {
|
||
9 years ago
|
$rootScope = _$rootScope_;
|
||
9 years ago
|
NotificationsService = _NotificationsService_;
|
||
|
}));
|
||
|
|
||
9 years ago
|
it('should be able to create notifications', function () {
|
||
9 years ago
|
var notification = NotificationsService.add('message');
|
||
|
|
||
9 years ago
|
expect(notification).to.eql({message: 'message'});
|
||
9 years ago
|
});
|
||
|
|
||
9 years ago
|
it('should be able to create warnings', function () {
|
||
9 years ago
|
var notification = NotificationsService.addWarning('warning!');
|
||
|
|
||
9 years ago
|
expect(notification).to.eql({message: 'warning!', type: 'warning'});
|
||
9 years ago
|
});
|
||
|
|
||
9 years ago
|
it('should be able to create error messages with errors', function () {
|
||
9 years ago
|
var notification = NotificationsService.addError('a super cereal error', ['fooo', 'baarr']);
|
||
|
expect(notification).to.eql({
|
||
|
message: 'a super cereal error',
|
||
|
errors: ['fooo', 'baarr'],
|
||
|
type: 'error'
|
||
|
});
|
||
|
});
|
||
|
|
||
9 years ago
|
it('should be able to create error messages with only a message', function () {
|
||
9 years ago
|
var notification = NotificationsService.addError('a super cereal error');
|
||
|
expect(notification).to.eql({
|
||
|
message: 'a super cereal error',
|
||
|
errors: [],
|
||
|
type: 'error'
|
||
|
});
|
||
|
});
|
||
|
|
||
9 years ago
|
it('should be able to create upload messages with uploads', function () {
|
||
9 years ago
|
var notification = NotificationsService.addWorkPackageUpload('uploading...', [0, 1, 2]);
|
||
|
expect(notification).to.eql({
|
||
|
message: 'uploading...',
|
||
|
type: 'upload',
|
||
|
uploads: [0, 1, 2]
|
||
|
});
|
||
|
});
|
||
9 years ago
|
|
||
9 years ago
|
it('should throw an Error if trying to create an upload without uploads', function () {
|
||
|
expect(function () {
|
||
9 years ago
|
NotificationsService.addWorkPackageUpload('themUploads');
|
||
|
}).to.throw(Error);
|
||
|
});
|
||
9 years ago
|
|
||
9 years ago
|
it('sends a broadcast on rootScope upon adding', function () {
|
||
9 years ago
|
sinon.spy($rootScope, '$broadcast');
|
||
|
|
||
|
NotificationsService.add('very important');
|
||
|
|
||
|
expect($rootScope.$broadcast).to.have.been.calledWith('notification.add');
|
||
|
});
|
||
|
|
||
9 years ago
|
it('sends a broadcast on rootScope upon removal', function () {
|
||
9 years ago
|
sinon.spy($rootScope, '$broadcast');
|
||
|
|
||
9 years ago
|
NotificationsService.remove({message: 'blubs', type: 'success'});
|
||
9 years ago
|
|
||
|
expect($rootScope.$broadcast).to.have.been.calledWith('notification.remove');
|
||
|
});
|
||
|
|
||
|
it('sends a broadcast to remove the first notification upon adding a second success notification',
|
||
9 years ago
|
function () {
|
||
9 years ago
|
|
||
9 years ago
|
sinon.spy($rootScope, '$broadcast');
|
||
9 years ago
|
|
||
9 years ago
|
var firstNotification = NotificationsService.add('blubs');
|
||
9 years ago
|
|
||
9 years ago
|
NotificationsService.addSuccess('blubs2');
|
||
9 years ago
|
|
||
9 years ago
|
expect($rootScope.$broadcast).to.have.been.calledWith('notification.remove',
|
||
|
firstNotification);
|
||
|
});
|
||
9 years ago
|
|
||
|
it('sends a broadcast to remove the first notification upon adding a second error notification',
|
||
9 years ago
|
function () {
|
||
9 years ago
|
|
||
9 years ago
|
sinon.spy($rootScope, '$broadcast');
|
||
9 years ago
|
|
||
9 years ago
|
var firstNotification = NotificationsService.add('blubs');
|
||
9 years ago
|
|
||
9 years ago
|
NotificationsService.addError('blubs2');
|
||
9 years ago
|
|
||
9 years ago
|
expect($rootScope.$broadcast).to.have.been.calledWith('notification.remove',
|
||
|
firstNotification);
|
||
|
});
|
||
9 years ago
|
|
||
|
it('does not send a broadcast upon the second error/success ' +
|
||
9 years ago
|
'if the notification has already been removed',
|
||
|
function () {
|
||
9 years ago
|
|
||
9 years ago
|
var firstNotification = NotificationsService.add('blubs');
|
||
|
$rootScope.$broadcast('notification.remove', firstNotification);
|
||
9 years ago
|
|
||
9 years ago
|
sinon.spy($rootScope, '$broadcast');
|
||
9 years ago
|
|
||
9 years ago
|
NotificationsService.addError('blubs2');
|
||
9 years ago
|
|
||
9 years ago
|
expect($rootScope.$broadcast).not.to.have.been.calledWith('notification.remove',
|
||
|
firstNotification);
|
||
9 years ago
|
|
||
9 years ago
|
});
|
||
9 years ago
|
});
|