Skip to content

Commit 8b5068a

Browse files
authored
TT-264 UI test coverage (#699)
* fix: TT-264 added unit testing in the missing methods * fix: TT-264 I removed the line code commented * fix: TT-264 removed the code smell * fix: TT-264 I divided each unit testing with line breaks * fix: TT-264 lines whites deleted
1 parent cf6e893 commit 8b5068a

File tree

11 files changed

+117
-57
lines changed

11 files changed

+117
-57
lines changed

src/app/modules/activities-management/store/activity-management.effects.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('ActivityEffects', () => {
9494
spyOn(service, 'updateActivity').and.returnValue(throwError({ error: { message: 'fail!' } }));
9595
spyOn(toastrService, 'error');
9696

97-
effects.updateActivity$.subscribe((action) => {
97+
effects.unarchiveActivity$.subscribe((action) => {
9898
expect(toastrService.error).toHaveBeenCalled();
9999
expect(action.type).toEqual(ActivityManagementActionTypes.UNARCHIVE_ACTIVITY_FAIL);
100100
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<tr class="d-flex" *ngFor="let project of projects">
1414
<td class="col-sm-4">{{ project.id }}</td>
1515
<td class="col-sm-3">{{ project.name }}</td>
16-
<td class="col-sm-3">{{ getProjectTypeName(project.project_type_id) }}</td>
16+
<td class="col-sm-3">{{ project.project_type.name }}</td>
1717
<td class="col-sm-1 text-center">
1818
<button type="button" class="btn btn-sm btn-primary" (click)="updateProject(project)">
1919
<i class="fa fa-pencil fa-xs"></i>

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

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ 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');
6665
});
6766

6867
afterEach(() => {
@@ -86,19 +85,26 @@ describe('ProjectListComponent', () => {
8685
it('should destroy the subscriptions', () => {
8786
component.projectsSubscription = new Subscription();
8887
const subscription = spyOn(component.projectsSubscription, 'unsubscribe');
89-
9088
component.ngOnDestroy();
9189

9290
expect(subscription).toHaveBeenCalledTimes(1);
9391
});
9492

93+
it('should destroy the projectTypesSubscription', () => {
94+
component.projectTypesSubscription = new Subscription();
95+
const subscriptionProjectTypes = spyOn(component.projectTypesSubscription, 'unsubscribe');
96+
97+
component.ngOnDestroy();
98+
99+
expect(subscriptionProjectTypes).toHaveBeenCalledTimes(1);
100+
});
101+
95102
it('updateProject, should dispatch SetProjectToEdit action', () => {
96103
spyOn(store, 'dispatch');
97104
component.projectsSubscription = new Subscription();
98105
const subscription = spyOn(component.projectsSubscription, 'unsubscribe');
99106

100107
component.updateProject(project);
101-
102108
component.ngOnDestroy();
103109

104110
expect(subscription).toHaveBeenCalledTimes(1);
@@ -156,28 +162,23 @@ describe('ProjectListComponent', () => {
156162
expect(component.showModal).toBeFalse();
157163
});
158164

159-
it('projects table should display Project Type', (done) => {
160-
const projectType = {
161-
id: '1234',
162-
name: 'BK',
163-
description: 'test',
165+
it('openModal should set showModal true when item.key !== inactive', () => {
166+
const itemData = {
167+
id: '123',
168+
name: 'aaa',
169+
description: 'xxx',
170+
project_type_id: '1234',
171+
status: 'activate',
172+
key: 'activate',
173+
_status: false,
174+
btnColor: 'btn-danger',
175+
btnIcon: 'fa-arrow-circle-down',
176+
btnName: 'Archive',
164177
};
165178

166-
component.projectsTypes = [projectType];
167-
fixture.detectChanges();
168-
fixture.whenStable().then(() => {
169-
fixture.detectChanges();
170-
171-
const tableRows = fixture.nativeElement.querySelectorAll('tr');
172-
expect(tableRows.length).toBe(2);
173-
174-
const headerRow = tableRows[0];
175-
expect(headerRow.cells[2].innerHTML).toBe('Project Type');
179+
component.openModal(itemData);
176180

177-
const dataRow = tableRows[1];
178-
expect(dataRow.cells[2].innerHTML).toBe('BK');
179-
180-
done();
181-
});
181+
expect(component.idToDelete).toEqual(itemData.id);
182+
expect(component.showModal).toBeTrue();
182183
});
183184
});

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ProjectState } from '../store/project.reducer';
66
import { getCustomerProjects } from '../store/project.selectors';
77
import * as actions from '../store/project.actions';
88
import { ProjectUI } from '../../../../../shared/models/project.model';
9-
import { allProjectTypes, ProjectTypeState } from '../../../projects-type/store';
9+
import { ProjectTypeState } from '../../../projects-type/store';
1010
import { ProjectType } from 'src/app/modules/shared/models';
1111

1212
@Component({
@@ -68,19 +68,6 @@ export class ProjectListComponent implements OnInit, OnDestroy {
6868
}
6969
}
7070

71-
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-
});
78-
const typeProject = this.projectsTypes.find(
79-
(prop) => prop.id === typeId
80-
);
81-
return typeProject !== undefined ? typeProject.name : '';
82-
}
83-
8471
updateProject(project) {
8572
this.store.dispatch(new actions.SetProjectToEdit(project));
8673
}

src/app/modules/customer-management/store/customer-management.effects.spec.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ describe('CustomerEffects', () => {
1616
let service: CustomerService;
1717
let toastrService;
1818
const customer: Customer = { id: 'id', name: 'name', description: 'description' };
19-
2019
beforeEach(() => {
2120
TestBed.configureTestingModule({
2221
providers: [CustomerEffects, provideMockActions(() => actions$)],
@@ -125,23 +124,23 @@ describe('CustomerEffects', () => {
125124
it('action type is UNARCHIVE_CUSTOMER_SUCCESS when service is executed sucessfully', async () => {
126125
const customerId = 'customerId';
127126
actions$ = of({ type: CustomerManagementActionTypes.UNARCHIVE_CUSTOMER, customerId });
128-
spyOn(toastrService, 'success');
129127
spyOn(service, 'updateCustomer').and.returnValue(of(customer));
128+
spyOn(toastrService, 'success');
130129

131-
effects.updateCustomer$.subscribe((action) => {
130+
effects.unarchiveCustomer$.subscribe((action) => {
132131
expect(toastrService.success).toHaveBeenCalledWith(INFO_SAVED_SUCCESSFULLY);
133-
expect(action.type).toEqual(CustomerManagementActionTypes.UNARCHIVE_CUSTOMER_SUCCESS);
132+
expect(action.type).toEqual(CustomerManagementActionTypes.UPDATE_CUSTOMER_SUCCESS);
134133
});
135134
});
136135

137136
it('action type is UNARCHIVE_CUSTOMER_FAIL when service fail in execution', async () => {
138137
actions$ = of({ type: CustomerManagementActionTypes.UNARCHIVE_CUSTOMER, customer });
139-
spyOn(toastrService, 'error');
140138
spyOn(service, 'updateCustomer').and.returnValue(throwError({ error: { message: 'fail!' } }));
139+
spyOn(toastrService, 'error');
141140

142-
effects.updateCustomer$.subscribe((action) => {
141+
effects.unarchiveCustomer$.subscribe((action) => {
143142
expect(toastrService.error).toHaveBeenCalled();
144-
expect(action.type).toEqual(CustomerManagementActionTypes.UNARCHIVE_CUSTOMER_FAIL);
143+
expect(action.type).toEqual(CustomerManagementActionTypes.UPDATE_CUSTOMER_FAIL);
145144
});
146145
});
147146
});

src/app/modules/login/services/azure.ad.b2c.service.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,12 @@ describe('AzureAdB2CService', () => {
171171

172172
expect(UserAgentApplication.prototype.getAccount).toHaveBeenCalled();
173173
});
174+
175+
it('should get userId from UserAgentApplication', () => {
176+
spyOn(UserAgentApplication.prototype, 'getAccount').and.returnValues(account);
177+
178+
service.getUserId();
179+
180+
expect(UserAgentApplication.prototype.getAccount).toHaveBeenCalled();
181+
});
174182
});

src/app/modules/time-clock/components/entry-fields/entry-fields.component.spec.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -439,20 +439,29 @@ describe('EntryFieldsComponent', () => {
439439
});
440440

441441
it('when feature-toggle "update-entries" enable for the user, the updateEntry function is executes to update the entries', () => {
442-
spyOn(featureToggleGeneralService, 'isActivated').and.returnValue(of(true));
443-
442+
spyOn(store, 'dispatch');
443+
const expected = { update_last_entry_if_overlap: true };
444444
const mockEntry = {
445445
...entry,
446446
start_date: moment().format(DATE_FORMAT_YEAR),
447-
start_hour: moment().format('HH:mm'),
448-
update_last_entry_if_overlap: true
447+
start_hour: moment().format('HH:mm')
449448
};
449+
const lastMockEntry = {
450+
...entry,
451+
end_date: moment().format(DATE_FORMAT_YEAR),
452+
end_hour: moment().format('HH:mm')
453+
};
454+
const hourInTheFuture = moment().format('HH:mm');
450455
component.newData = mockEntry;
451-
const expected = { update_last_entry_if_overlap: true };
452-
featureToggleGeneralService.isActivated(FeatureToggle.UPDATE_ENTRIES).subscribe(() => {
453-
expect(featureToggleGeneralService.isActivated).toHaveBeenCalled();
454-
expect(component.newData.update_last_entry_if_overlap).toEqual(expected.update_last_entry_if_overlap);
455-
});
456+
component.activeEntry = mockEntry;
457+
component.lastEntry = lastMockEntry;
458+
component.isFeatureToggleActive = true;
459+
component.entryForm.patchValue({ start_hour: hourInTheFuture });
460+
461+
component.onUpdateStartHour();
462+
463+
expect(component.newData.update_last_entry_if_overlap).toEqual(expected.update_last_entry_if_overlap);
464+
expect(store.dispatch).toHaveBeenCalled();
456465
});
457466

458467
it('Set true in isCookieFeatureToggleActive when feature-toggle "feature-toggle-in-cookies" is enable for user', () => {

src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
170170
if (this.isFeatureToggleActive) {
171171
this.newData.update_last_entry_if_overlap = true;
172172
this.store.dispatch(new entryActions.UpdateEntryRunning({ ...this.newData, ...this.entryForm.value }));
173+
173174
} else {
174175
this.store.dispatch(new entryActions.UpdateCurrentOrLastEntry({ ...this.newData, ...this.entryForm.value }));
175176
}

src/app/modules/user/services/user-info.service.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,22 @@ describe('UserInfoService', () => {
5757
});
5858
});
5959
});
60+
61+
it('should return true if is Admin', () => {
62+
const isMemberOf = spyOn(service, 'isMemberOf').and.returnValue(of(true));
63+
64+
service.isAdmin().subscribe((value) => {
65+
expect(value).toBeTrue();
66+
});
67+
expect(isMemberOf).toHaveBeenCalled();
68+
});
69+
70+
it('should return true if is Tester', () => {
71+
const isMemberOf = spyOn(service, 'isMemberOf').and.returnValue(of(true));
72+
73+
service.isTester().subscribe((value) => {
74+
expect(value).toBeTrue();
75+
});
76+
expect(isMemberOf).toHaveBeenCalled();
77+
});
6078
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { TestBed, inject } from '@angular/core/testing';
2+
import { UserService } from './user.service';
3+
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
4+
5+
describe('UserService', () => {
6+
let service: UserService;
7+
let httpMock: HttpTestingController;
8+
9+
beforeEach(() => {
10+
TestBed.configureTestingModule({
11+
imports: [HttpClientTestingModule]
12+
});
13+
service = TestBed.inject(UserService);
14+
httpMock = TestBed.inject(HttpTestingController);
15+
});
16+
17+
afterEach(() => {
18+
httpMock.verify();
19+
});
20+
21+
it('should create', inject(
22+
[HttpClientTestingModule, UserService],
23+
(httpClient: HttpClientTestingModule, apiService: UserService) => {
24+
expect(apiService).toBeTruthy();
25+
expect(httpClient).toBeTruthy();
26+
}
27+
));
28+
29+
it('load a user to idUser using GET', () => {
30+
service.baseUrl = '/users';
31+
service.loadUser('xyz').subscribe();
32+
33+
const loadUserRequest = httpMock.expectOne(`${service.baseUrl}/xyz`);
34+
expect(loadUserRequest.request.method).toBe('GET');
35+
});
36+
});

0 commit comments

Comments
 (0)