From dffe2b5c83e92626fc32313d4488cb90acb93aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Wed, 18 Apr 2018 21:38:37 +0200 Subject: [PATCH] Fix query menu ng2 test --- .../wp-edit-multi-select-field.module.ts | 2 +- .../wp-query-menu/wp-query-menu.ng2.test.ts | 16 ++++++++-------- .../wp-query-menu/wp-query-menu.service.ts | 8 +++++++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/frontend/app/components/wp-edit/field-types/wp-edit-multi-select-field.module.ts b/frontend/app/components/wp-edit/field-types/wp-edit-multi-select-field.module.ts index c11a1f73ca..2db7f6dc6b 100644 --- a/frontend/app/components/wp-edit/field-types/wp-edit-multi-select-field.module.ts +++ b/frontend/app/components/wp-edit/field-types/wp-edit-multi-select-field.module.ts @@ -152,7 +152,7 @@ export class MultiSelectEditField extends EditField { if (option) { result = _.find(this.valueOptions, (valueOption) => valueOption.href === option.href)!; } - + return result || this.nullOption; } diff --git a/frontend/app/components/wp-query-menu/wp-query-menu.ng2.test.ts b/frontend/app/components/wp-query-menu/wp-query-menu.ng2.test.ts index d09e4c6118..a969d20339 100644 --- a/frontend/app/components/wp-query-menu/wp-query-menu.ng2.test.ts +++ b/frontend/app/components/wp-query-menu/wp-query-menu.ng2.test.ts @@ -37,17 +37,15 @@ import {$stateToken} from 'core-app/angular4-transition-utils'; @Component({ template: ` -
  • - +
  • + ` }) class WpQueryMenuTestComponent { } -describe('wp-query-menu', () => { +describe.only('wp-query-menu', () => { let app:WpQueryMenuTestComponent; let fixture:ComponentFixture; let element:JQuery; @@ -59,7 +57,7 @@ describe('wp-query-menu', () => { const $transitionStub = { onStart: (criteria:any, callback:(transition:any) => any) => { transitionCallback = (id:any) => callback({ - params: (val:string) => { return { queryId: id }; } + params: (val:string) => { return { query_id: id }; } } as any); } }; @@ -75,7 +73,7 @@ describe('wp-query-menu', () => { { provide: $stateToken, useValue: { go: (...args:any[]) => undefined } }, { provide: WorkPackagesListChecksumService, useValue: { clear: () => undefined } }, { provide: TransitionService, useValue: $transitionStub }, - { provide: QueryMenuService, useValue: queryMenuService }, + QueryMenuService, ] }).compileComponents() .then(() => { @@ -84,6 +82,7 @@ describe('wp-query-menu', () => { app = fixture.debugElement.componentInstance; element = jQuery(fixture.elementRef.nativeElement); menuContainer = element.find('ul.menu-children'); + queryMenuService.initialize(); }); })); @@ -94,6 +93,7 @@ describe('wp-query-menu', () => { objectId = '1'; var generateMenuItem = function() { + queryMenuService = TestBed.get(QueryMenuService); queryMenuService.add(title, path, objectId); fixture.detectChanges(); diff --git a/frontend/app/components/wp-query-menu/wp-query-menu.service.ts b/frontend/app/components/wp-query-menu/wp-query-menu.service.ts index 8c832e715e..b19380a90a 100644 --- a/frontend/app/components/wp-query-menu/wp-query-menu.service.ts +++ b/frontend/app/components/wp-query-menu/wp-query-menu.service.ts @@ -46,7 +46,7 @@ export class QueryMenuService { private currentQueryId:string|null = null; private uiRouteStateName = 'work-packages.list'; - private container = jQuery('#main-menu-work-packages').parent().find('ul.menu-children'); + private container:JQuery; constructor(@Inject($stateToken) protected $state:StateService, protected $transitions:TransitionService, @@ -57,6 +57,8 @@ export class QueryMenuService { this.onQueryIdChanged(queryId); }); + this.initialize(); + this.container.on('click', `.${QUERY_MENU_ITEM_TYPE}`, (event) => { if (LinkHandling.isClickedWithModifier(event) || LinkHandling.isOutsideAngular()) { return true; @@ -69,6 +71,10 @@ export class QueryMenuService { } + public initialize() { + this.container = jQuery('#main-menu-work-packages').parent().find('ul.menu-children'); + } + /** * Add a query menu item */