From 4c0732ae5fa443addbe2726ca15fbb886bb6aa27 Mon Sep 17 00:00:00 2001 From: Inga Mai Date: Mon, 4 Jun 2018 16:52:24 +0200 Subject: [PATCH] Tests fixed, new lint issues after changes fixed --- .../main-menu/main-menu-toggle.component.ts | 3 +- .../main-menu/main-menu-toggle.service.ts | 21 ++--- .../resizer/main-menu-resizer.component.ts | 3 +- .../controllers/main-menu-controller-test.js | 82 ------------------- 4 files changed, 12 insertions(+), 97 deletions(-) delete mode 100644 frontend/tests/unit/tests/layout/controllers/main-menu-controller-test.js diff --git a/frontend/app/components/main-menu/main-menu-toggle.component.ts b/frontend/app/components/main-menu/main-menu-toggle.component.ts index b8e2ffadb1..db46420d44 100644 --- a/frontend/app/components/main-menu/main-menu-toggle.component.ts +++ b/frontend/app/components/main-menu/main-menu-toggle.component.ts @@ -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(); } } diff --git a/frontend/app/components/main-menu/main-menu-toggle.service.ts b/frontend/app/components/main-menu/main-menu-toggle.service.ts index d86dd7c79a..6bac12765a 100644 --- a/frontend/app/components/main-menu/main-menu-toggle.service.ts +++ b/frontend/app/components/main-menu/main-menu-toggle.service.ts @@ -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(''); - public all$ = this.all.asObservable(); + private allData = new BehaviorSubject(''); + 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() { diff --git a/frontend/app/components/resizer/main-menu-resizer.component.ts b/frontend/app/components/resizer/main-menu-resizer.component.ts index 3eb833859e..e307eaecfc 100644 --- a/frontend/app/components/resizer/main-menu-resizer.component.ts +++ b/frontend/app/components/resizer/main-menu-resizer.component.ts @@ -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']) diff --git a/frontend/tests/unit/tests/layout/controllers/main-menu-controller-test.js b/frontend/tests/unit/tests/layout/controllers/main-menu-controller-test.js deleted file mode 100644 index cfe4763d67..0000000000 --- a/frontend/tests/unit/tests/layout/controllers/main-menu-controller-test.js +++ /dev/null @@ -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'); - }); - }); - -});