* Bugzilla 530162-Filtermatrix/responsibility filter: Show all Person with full name (forename and lastname)
diff --git a/src/app/common/session-context.spec.ts b/src/app/common/session-context.spec.ts
index 5151bfd..073146e 100644
--- a/src/app/common/session-context.spec.ts
+++ b/src/app/common/session-context.spec.ts
@@ -30,7 +30,7 @@
expect(service.getCurrUser().name).toBe('Rudi');
}));
- it('create a usermapper should fails when empty', inject([SessionContext], (service: SessionContext) => {
+ it('create a usermapper should fail when empty', inject([SessionContext], (service: SessionContext) => {
let errorOccured = false;
try {
const um = service.getUserMap();
diff --git a/src/app/common/session-context.ts b/src/app/common/session-context.ts
index ddc8a75..8ac6a7b 100644
--- a/src/app/common/session-context.ts
+++ b/src/app/common/session-context.ts
@@ -56,8 +56,7 @@
}
getCurrUser(): User {
- const user = localStorage.getItem(Globals.CURRENT_USER);
- return JSON.parse(user);
+ return this.getSaveFromLocalStorage(Globals.CURRENT_USER);
}
setCurrUser(usr: any): void {
@@ -65,8 +64,7 @@
}
getAllUsers(): User[] {
- const allUsers = localStorage.getItem(Globals.ALL_USERS);
- return JSON.parse(allUsers);
+ return this.getSaveFromLocalStorage(Globals.ALL_USERS);
}
setAllUsers(allUsr: User[]) {
@@ -336,4 +334,13 @@
}
return this.userMap;
}
+
+ getSaveFromLocalStorage( key: string): any {
+ const retValue = localStorage.getItem(key);
+ if (!retValue ) {
+ console.log('WARNING: Try to access LocalStorage key [' + key + '] which is empty!');
+ return null;
+ }
+ return JSON.parse(retValue);
+ }
}
diff --git a/src/app/common/user-map.spec.ts b/src/app/common/user-map.spec.ts
new file mode 100644
index 0000000..278b709
--- /dev/null
+++ b/src/app/common/user-map.spec.ts
@@ -0,0 +1,28 @@
+import { TestBed, async, inject } from '@angular/core/testing';
+import { User } from '../model/user';
+import { USERS } from '../test-data/users';
+import { UserMap } from 'app/common/user-map';
+
+
+describe('UserMap', () => {
+ beforeEach(() => {
+ TestBed.configureTestingModule({
+ });
+
+ });
+
+ it('can render a valid user', () => {
+ const userMap = new UserMap( USERS );
+ expect( userMap.findAndRenderUser('otto')).toBe('Otto Normalverbraucher');
+ });
+
+ it('can render a unknown user', () => {
+ const userMap = new UserMap( USERS );
+ expect( userMap.findAndRenderUser('Unknown')).toBe('[Unknown]');
+ });
+
+ it('throws an exception when not initialized', () => {
+ expect( function() { new UserMap( null ); }).toThrowError( EvalError );
+ });
+});
+
diff --git a/src/app/common/user-map.ts b/src/app/common/user-map.ts
index 051a6b7..f81cb6b 100644
--- a/src/app/common/user-map.ts
+++ b/src/app/common/user-map.ts
@@ -6,6 +6,7 @@
constructor( allUsers: User[] ) {
this.mappedUsers = [];
if ( !allUsers ) {
+ console.log('UserMap was created without any Users!');
throw new EvalError('UserMap was created without any Users!');
}
for ( const usr of allUsers ) {
@@ -14,9 +15,15 @@
}
public findUser( usrShort: string ): User {
- if ( this.mappedUsers == null ) {
- throw new EvalError( 'Usermap has not been initialized before first access');
- }
return this.mappedUsers[ usrShort ];
}
+
+ public findAndRenderUser( shortUsr: string ): string {
+ const usr = this.findUser(shortUsr);
+ if ( !usr ) {
+ return '[' + shortUsr + ']';
+ } else {
+ return usr.name;
+ }
+ }
}
diff --git a/src/app/filter/filter.component.spec.ts b/src/app/filter/filter.component.spec.ts
index 2aab8f7..eabedfa 100644
--- a/src/app/filter/filter.component.spec.ts
+++ b/src/app/filter/filter.component.spec.ts
@@ -76,6 +76,7 @@
it('should retrieve all responsibilities onInit/onChange and put the filtermatrix into SessionContext', async(() => {
spyOn(component, 'initFilterMatrixWithDefaults').and.callThrough();
const resps = RESPONSIBILITIES;
+ sessionContext.setAllUsers(USERS);
mockService.content = resps;
fixture.detectChanges();
@@ -109,6 +110,7 @@
it('should refresh responsibilities (filtermatrix) on checkbox change', async(() => {
spyOn(component, 'responsibilitiesSelectionChanged').and.callThrough();
const resps = RESPONSIBILITIES;
+ sessionContext.setAllUsers(USERS);
mockService.content = resps;
fixture.detectChanges();
@@ -138,6 +140,7 @@
spyOn(component, 'getUpdatedResponsibilities').and.callThrough();
const responsibilityContainerMatrixOld = RESPONSIBILITIES;
const resps = RESPONSIBILITIES;
+ sessionContext.setAllUsers(USERS);
const newResponsibleUser = 'otto';
resps[0].responsibilityList[0].responsibleUser = newResponsibleUser;
const filterMatrix: FilterMatrix = new FilterMatrix(responsibilityContainerMatrixOld);
@@ -163,6 +166,7 @@
it('should select all responsibilities after button "Alle setzen" pressed', async(() => {
spyOn(component, 'selectAllResponsibilities').and.callThrough();
const resps = RESPONSIBILITIES;
+ sessionContext.setAllUsers(USERS);
component.responsibilityContainerMatrix = resps;
fixture.detectChanges();
@@ -187,6 +191,7 @@
it('should deselect all responsibilities after button "Alle löschen" pressed', async(() => {
spyOn(component, 'deselectAllResponsibilities').and.callThrough();
const resps = RESPONSIBILITIES;
+ sessionContext.setAllUsers(USERS);
component.responsibilityContainerMatrix = resps;
fixture.detectChanges();
diff --git a/src/app/filter/filter.component.ts b/src/app/filter/filter.component.ts
index 83b5a7d..1086642 100644
--- a/src/app/filter/filter.component.ts
+++ b/src/app/filter/filter.component.ts
@@ -148,12 +148,8 @@
}
mapUserName( shortUsr: string ) {
- const usr = this.sessionContext.getUserMap().findUser(shortUsr);
- if ( !usr ) {
- return '[' + shortUsr + ']';
- } else {
- return usr.name;
- }
+ const userMap = this.sessionContext.getUserMap();
+ return userMap ? this.sessionContext.getUserMap().findAndRenderUser(shortUsr) : shortUsr;
}
}