OpenProject is the leading open source project management software.
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.
 
 
 
 
 
 
openproject/frontend/app/components/wp-buttons/wp-buttons.module.test.ts

165 lines
5.0 KiB

// -- copyright
// 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.
// ++
import {WorkPackageNavigationButtonController} from './wp-buttons.module';
var expect = chai.expect;
class GenericWpButtonController extends WorkPackageNavigationButtonController {
public accessKey:number = 1;
public activeState:string = 'some-state.show';
public labelKey:string = 'js.some-label';
public textKey:string = 'js.some-text';
public buttonId:string = 'some-button-id';
public iconClass:string = 'some-icon-class';
constructor(public $state, public I18n) {
super($state, I18n);
}
public performAction() {
}
}
describe('WP button directives', () => {
var $state, I18n, scope, label, button;
var controller:GenericWpButtonController;
before(() => {
angular.module('openproject.wpButtons').directive('genericWpButton', function () {
return {
templateUrl: '/components/wp-buttons/wp-button.template.html',
scope: {
disabled: '=?'
},
controller: GenericWpButtonController,
controllerAs: 'vm',
bindToController: true
}
});
});
beforeEach(angular.mock.module('openproject.wpButtons', 'openproject.templates'));
beforeEach(angular.mock.inject(($compile:ng.ICompileService, $rootScope:ng.IRootScopeService,
_$state_:ng.ui.IStateService, _I18n_) => {
var html = '<generic-wp-button disabled="disabled"></generic-wp-button>';
$state = _$state_;
I18n = _I18n_;
scope = $rootScope.$new();
var element = angular.element(html);
var t = sinon.stub(I18n, 't');
t.withArgs('js.some-label').returns('a wonderful title');
t.withArgs('js.label_activate').returns('activate');
$compile(element)(scope);
scope.$digest();
controller = element.controller('genericWpButton');
label = element.find('label');
button = element.find('button');
}));
afterEach(() => {
I18n.t.restore();
});
describe('when initial', () => {
it('should have the performAction method', () => {
expect(controller.performAction).not.to.throw(Error);
});
it('should be enabled by default', () => {
expect(controller.disabled).not.to.be.ok;
});
it('should be disabled if disabled attribute is set', () => {
scope.disabled = true;
scope.$digest();
expect(controller.disabled).to.be.true;
});
});
describe('when activeState is set', () => {
var includes;
beforeEach(() => {
includes = sinon.stub($state, 'includes');
});
it('should be active if the current state includes the given activeState name', () => {
includes.withArgs(controller.activeState).returns(true);
expect(controller.isActive()).to.be.true;
});
it('should not be active if the current state does not include the activeState name', () => {
includes.returns(false);
expect(controller.isActive()).to.be.false;
});
});
describe('when active', () => {
beforeEach(() => {
sinon.stub(controller, 'isActive').returns(true);
scope.$digest();
});
it('should not have a label with an access key', () => {
expect(label.attr('accesskey')).not.to.eq(controller.activeAccessKey);
});
it("should have the button class set to '-active' ", () => {
expect(button.attr('class')).to.contain('-active')
});
it('should have equal text values', () => {
expect(label.text().trim()).to.eq(controller.label);
expect(button.text().trim()).to.eq(controller.label);
expect(button.attr('title').trim()).to.eq(controller.label);
});
});
describe('when not active', () => {
it('should have a label with an access key attribute', () => {
expect(parseInt(label.attr('accesskey'))).to.eq(controller.activeAccessKey);
});
it("should have the 'activate' prefix in the text values", () => {
expect(label.text()).to.contain('activate');
});
});
});