Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
fix(mock): Fixed mock for work item types
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbornsen authored and michaelkleinhenz committed Mar 6, 2017
1 parent b78b601 commit dc1acb9
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/app/iteration/iteration.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class IterationComponent implements OnInit, OnDestroy {
this.listenToEvents();
this.loggedIn = this.auth.isLoggedIn();
this.getAndfilterIterations();
this.editEnabled = true;
this.spaceSubscription = this.broadcaster.on<Space>('spaceChanged').subscribe(space => {
if (space) {
console.log('[IterationComponent] New Space selected: ' + space.attributes.name);
Expand Down
4 changes: 4 additions & 0 deletions src/app/shared/mock-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ export class MockDataService {
return this.schemaMockGenerator.getWorkItemTypes();
}

public getWorkItemTypeById(id: string): any {
return this.schemaMockGenerator.getWorkItemTypeById(id);
}

public getWorkItemLinkTypes(): any {
return this.schemaMockGenerator.getWorkItemLinkTypes();
}
Expand Down
8 changes: 7 additions & 1 deletion src/app/shared/mock-data/schema-mock-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class SchemaMockGenerator {
/*
* Creates the work item types structure.
*/
public getWorkItemTypes() {
public getWorkItemTypes(): any[] {
if (this.workItemTypes)
return this.workItemTypes;
else {
Expand Down Expand Up @@ -706,6 +706,12 @@ export class SchemaMockGenerator {
}
}

public getWorkItemTypeById(id) {
let allWorkItemTypes = this.getWorkItemTypes();
let item = allWorkItemTypes.find((item) => item.id === id);
return item ? item : allWorkItemTypes[0];
}

public renderText(text: string) {
return {
attributes: {
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/mock-data/work-item-mock-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class WorkItemMockGenerator {
'assignees': { },
'baseType': {
'data': {
'id': 'planneritem',
'id': '86af5178-9b41-469b-9096-57e5155c3f31',
'type': 'workitemtypes'
}
},
Expand Down
10 changes: 9 additions & 1 deletion src/app/shared/mock-http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export class MockHttp extends Http {
result['extraPath'] = result.path.replace(/^\/workitemlinks\//, '');
result['path'] = '/workitemlinks';
}
if (result.path.indexOf('/workitemtypes/') == 0) {
result['extraPath'] = result.path.replace(/^\/workitemtypes\//, '');
result['path'] = '/workitemtypes';
}
// if request hat a /space prefix, note the space id, the re-parse the extra path
if (result.path.indexOf('/spaces/') == 0) {
console.log('Space prefix detected, reparsing url..');
Expand Down Expand Up @@ -171,7 +175,11 @@ export class MockHttp extends Http {
// add new paths here
switch (path.path) {
case '/workitemtypes':
return this.createResponse(url.toString(), 200, 'ok', { data: this.mockDataService.getWorkItemTypes() } );
if (path.extraPath) {
return this.createResponse(url.toString(), 200, 'ok', { data: this.mockDataService.getWorkItemTypeById(path.extraPath) } );
} else {
return this.createResponse(url.toString(), 200, 'ok', { data: this.mockDataService.getWorkItemTypes() } );
}
case '/workitems':
if (path.extraPath) {
return this.createResponse(url.toString(), 200, 'ok', this.mockDataService.getWorkItemOrEntity(path.extraPath) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@angular/core';
import { Subscription } from 'rxjs/Subscription';

import { Logger, Broadcaster } from 'ngx-login-client';
import { Logger, Broadcaster, AuthenticationService } from 'ngx-login-client';

import { WorkItem, WorkItemAttributes, WorkItemRelations } from '../../models/work-item';
import { WorkItemService } from '../work-item.service';
Expand Down Expand Up @@ -47,12 +47,13 @@ export class WorkItemQuickAddComponent implements OnInit, OnDestroy, AfterViewIn
private workItemService: WorkItemService,
private broadcaster: Broadcaster,
private logger: Logger,
private renderer: Renderer) {}
private renderer: Renderer,
private auth: AuthenticationService) {}

ngOnInit(): void {
this.createWorkItemObj();
this.showQuickAdd = false;
this.showQuickAddBtn = false;
this.showQuickAddBtn = this.auth.isLoggedIn();
this.spaceSubscription = this.broadcaster.on<Space>('spaceChanged').subscribe(space => {
if (space) {
console.log('[WorkItemQuickAddComponent] New Space selected: ' + space.attributes.name);
Expand Down
14 changes: 11 additions & 3 deletions src/app/work-item/work-item.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,12 +597,20 @@ export class WorkItemService {
} else {
let workItemTypeUrl = this.baseApiUrl + 'workitemtypes/' + id;
return this.http.get(workItemTypeUrl)
.map((response) => {
.toPromise()
.then((response) => {
workItemType = response.json().data as WorkItemType;
this.workItemTypes.push(workItemType);
return workItemType;
})
.toPromise();
});
// FIXME: Use observavble instead promise
// Can't use observable now, because the mock will not support that
// .map((response) => {
// workItemType = response.json().data as WorkItemType;
// this.workItemTypes.push(workItemType);
// return workItemType;
// })
// .toPromise();
}
} else {
return Promise.resolve<WorkItemType>( {} as WorkItemType );
Expand Down

0 comments on commit dc1acb9

Please sign in to comment.