Tests fixed, new lint issues after changes fixed

pull/6354/head
Inga Mai 7 years ago
parent b584623743
commit 4c0732ae5f
  1. 3
      frontend/app/components/main-menu/main-menu-toggle.component.ts
  2. 21
      frontend/app/components/main-menu/main-menu-toggle.service.ts
  3. 3
      frontend/app/components/resizer/main-menu-resizer.component.ts
  4. 82
      frontend/tests/unit/tests/layout/controllers/main-menu-controller-test.js

@ -72,7 +72,7 @@ export class MainMenuToggleComponent implements OnInit, OnDestroy {
ngOnInit() {
this.toggleService.initializeMenu();
this.subscription = this.toggleService.all$
this.subscription = this.toggleService.allData$
.pipe(
distinctUntilChanged(),
untilComponentDestroyed(this)
@ -83,6 +83,7 @@ export class MainMenuToggleComponent implements OnInit, OnDestroy {
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
}

@ -34,7 +34,7 @@ import {BehaviorSubject} from 'rxjs/BehaviorSubject';
@Injectable()
export class MainMenuToggleService {
showNavigation:boolean;
showNavigation:boolean = true;
toggleTitle:string;
oldStorageValue:number; // menu width after hiding menu (applied after reload)
localStorageValue:number;
@ -44,8 +44,8 @@ export class MainMenuToggleService {
mainMenu = jQuery('#main-menu')[0]; // main menu, containing sidebar and resizer
hideElements = jQuery('.can-hide-navigation');
private all = new BehaviorSubject<string>('');
public all$ = this.all.asObservable();
private allData = new BehaviorSubject<string>('');
public allData$ = this.allData.asObservable();
constructor(@Inject(I18nToken) protected I18n:op.I18n) {
}
@ -59,17 +59,12 @@ export class MainMenuToggleService {
else {
if (this.mainMenu.offsetWidth < 10) { // if mainMenu is collapsed, set width 0 in localStorage
this.saveWidth("openProject-mainMenuWidth", 0);
} else if (this.mainMenu.offsetWidth < 230) { // set back to default width
this.showNavigation = false;
} else if (this.mainMenu.offsetWidth < 230 && this.mainMenu.offsetWidth > 10) { // set back to default width
this.saveWidth("openProject-mainMenuWidth", 230);
} else { // Get initial width from mainMenu and save in storage
this.saveWidth("openProject-mainMenuWidth", this.mainMenu.offsetWidth);
}
// set correct value of boolean and label
if (this.localStorageValue < 10) {
this.showNavigation = false;
} else {
this.showNavigation = true;
}
}
this.addRemoveClassHidden();
this.setToggleTitle();
@ -81,8 +76,8 @@ export class MainMenuToggleService {
event.preventDefault();
// mobile version
if (window.innerWidth < 680) {
if(this.localStorageValue === 0) {
this.showNavigation = true; // main menu shall expand.
if (this.localStorageValue === 0) { // if main menu collapsed -> menu shall expand
this.showNavigation = true;
this.saveWidth("openProject-mainMenuWidth", window.innerWidth);
// On mobile the main menu shall close whenever you click outside the menu.
this.setupAutocloseMainMenu();
@ -126,7 +121,7 @@ export class MainMenuToggleService {
} else {
this.toggleTitle = I18n.t('js.label_expand_project_menu');
}
this.all.next(this.toggleTitle);
this.allData.next(this.toggleTitle);
}
private addRemoveClassHidden() {

@ -71,7 +71,7 @@ export class MainMenuResizerComponent implements OnInit, OnDestroy {
}
ngOnInit() {
this.subscription = this.toggleService.all$
this.subscription = this.toggleService.allData$
.pipe(
distinctUntilChanged(),
untilComponentDestroyed(this)
@ -85,6 +85,7 @@ export class MainMenuResizerComponent implements OnInit, OnDestroy {
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
@HostListener('mousedown', ['$event'])

@ -1,82 +0,0 @@
//-- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2018 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-2017 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 docs/COPYRIGHT.rdoc for more details.
//++
/*jshint expr: true*/
describe('MainMenuController', function() {
var rootScope, sessionStorage, ctrl;
beforeEach(angular.mock.module('openproject.layout.controllers'));
beforeEach(inject(function($rootScope, $controller) {
rootScope = $rootScope.$new();
event = new Event('conclick');
var fakeSession = {};
sessionStorage = {
setItem: function(k, v) { fakeSession[k] = v; },
getItem: function(k) { return fakeSession[k]; }
};
ctrl = $controller("MainMenuController", {
$rootScope: rootScope,
$window: { sessionStorage: sessionStorage }
});
}));
describe('toggleNavigation', function() {
it('should toggle navigation off', function() {
rootScope.showNavigation = true;
ctrl.toggleNavigation(event);
expect(rootScope.showNavigation).to.be.false;
});
it('should toggle navigation on', function() {
rootScope.showNavigation = false;
ctrl.toggleNavigation(event);
expect(rootScope.showNavigation).to.be.true;
});
it('should fire an event when toggled', function() {
var callback = sinon.spy();
rootScope.$on('openproject.layout.navigationToggled', callback);
ctrl.toggleNavigation(event);
expect(callback).to.have.been.calledWithMatch(sinon.match.any, sinon.match.truthy);
});
it('should persist choice to sessionStorage', function() {
expect(sessionStorage.getItem('openproject:navigation-toggle')).to.be.undefined;
ctrl.toggleNavigation(event);
expect(sessionStorage.getItem('openproject:navigation-toggle')).to.equal('expanded');
ctrl.toggleNavigation(event);
expect(sessionStorage.getItem('openproject:navigation-toggle')).to.equal('collapsed');
});
});
});
Loading…
Cancel
Save