Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('ActivityEffects', () => {
spyOn(service, 'updateActivity').and.returnValue(throwError({ error: { message: 'fail!' } }));
spyOn(toastrService, 'error');

effects.updateActivity$.subscribe((action) => {
effects.unarchiveActivity$.subscribe((action) => {
expect(toastrService.error).toHaveBeenCalled();
expect(action.type).toEqual(ActivityManagementActionTypes.UNARCHIVE_ACTIVITY_FAIL);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<tr class="d-flex" *ngFor="let project of projects">
<td class="col-sm-4">{{ project.id }}</td>
<td class="col-sm-3">{{ project.name }}</td>
<td class="col-sm-3">{{ getProjectTypeName(project.project_type_id) }}</td>
<td class="col-sm-3">{{ project.project_type.name }}</td>
<td class="col-sm-1 text-center">
<button type="button" class="btn btn-sm btn-primary" (click)="updateProject(project)">
<i class="fa fa-pencil fa-xs"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ describe('ProjectListComponent', () => {
getCustomerProjectsSelectorMock = store.overrideSelector(getCustomerProjects, state);
allCustomerProjectsSelectorMock = store.overrideSelector(getProjects, state.projects);
component.projectsSubscription = new Subscription();
spyOn(component, 'getProjectTypeName').and.callFake((typeId: string) => 'BK');
});

afterEach(() => {
Expand All @@ -86,19 +85,26 @@ describe('ProjectListComponent', () => {
it('should destroy the subscriptions', () => {
component.projectsSubscription = new Subscription();
const subscription = spyOn(component.projectsSubscription, 'unsubscribe');

component.ngOnDestroy();

expect(subscription).toHaveBeenCalledTimes(1);
});

it('should destroy the projectTypesSubscription', () => {
component.projectTypesSubscription = new Subscription();
const subscriptionProjectTypes = spyOn(component.projectTypesSubscription, 'unsubscribe');

component.ngOnDestroy();

expect(subscriptionProjectTypes).toHaveBeenCalledTimes(1);
});

it('updateProject, should dispatch SetProjectToEdit action', () => {
spyOn(store, 'dispatch');
component.projectsSubscription = new Subscription();
const subscription = spyOn(component.projectsSubscription, 'unsubscribe');

component.updateProject(project);

component.ngOnDestroy();

expect(subscription).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -156,28 +162,23 @@ describe('ProjectListComponent', () => {
expect(component.showModal).toBeFalse();
});

it('projects table should display Project Type', (done) => {
const projectType = {
id: '1234',
name: 'BK',
description: 'test',
it('openModal should set showModal true when item.key !== inactive', () => {
const itemData = {
id: '123',
name: 'aaa',
description: 'xxx',
project_type_id: '1234',
status: 'activate',
key: 'activate',
_status: false,
btnColor: 'btn-danger',
btnIcon: 'fa-arrow-circle-down',
btnName: 'Archive',
};

component.projectsTypes = [projectType];
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();

const tableRows = fixture.nativeElement.querySelectorAll('tr');
expect(tableRows.length).toBe(2);

const headerRow = tableRows[0];
expect(headerRow.cells[2].innerHTML).toBe('Project Type');
component.openModal(itemData);

const dataRow = tableRows[1];
expect(dataRow.cells[2].innerHTML).toBe('BK');

done();
});
expect(component.idToDelete).toEqual(itemData.id);
expect(component.showModal).toBeTrue();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ProjectState } from '../store/project.reducer';
import { getCustomerProjects } from '../store/project.selectors';
import * as actions from '../store/project.actions';
import { ProjectUI } from '../../../../../shared/models/project.model';
import { allProjectTypes, ProjectTypeState } from '../../../projects-type/store';
import { ProjectTypeState } from '../../../projects-type/store';
import { ProjectType } from 'src/app/modules/shared/models';

@Component({
Expand Down Expand Up @@ -68,19 +68,6 @@ export class ProjectListComponent implements OnInit, OnDestroy {
}
}

getProjectTypeName(typeId: string) {
const projectsTypes$ = this.projectTypeStore.pipe(select(allProjectTypes));
this.projectTypesSubscription = projectsTypes$.subscribe((projectsType) => {
this.projectsTypes = projectsType.map((type: ProjectType) => {
return type;
});
});
const typeProject = this.projectsTypes.find(
(prop) => prop.id === typeId
);
return typeProject !== undefined ? typeProject.name : '';
}

updateProject(project) {
this.store.dispatch(new actions.SetProjectToEdit(project));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ describe('CustomerEffects', () => {
let service: CustomerService;
let toastrService;
const customer: Customer = { id: 'id', name: 'name', description: 'description' };

beforeEach(() => {
TestBed.configureTestingModule({
providers: [CustomerEffects, provideMockActions(() => actions$)],
Expand Down Expand Up @@ -125,23 +124,23 @@ describe('CustomerEffects', () => {
it('action type is UNARCHIVE_CUSTOMER_SUCCESS when service is executed sucessfully', async () => {
const customerId = 'customerId';
actions$ = of({ type: CustomerManagementActionTypes.UNARCHIVE_CUSTOMER, customerId });
spyOn(toastrService, 'success');
spyOn(service, 'updateCustomer').and.returnValue(of(customer));
spyOn(toastrService, 'success');

effects.updateCustomer$.subscribe((action) => {
effects.unarchiveCustomer$.subscribe((action) => {
expect(toastrService.success).toHaveBeenCalledWith(INFO_SAVED_SUCCESSFULLY);
expect(action.type).toEqual(CustomerManagementActionTypes.UNARCHIVE_CUSTOMER_SUCCESS);
expect(action.type).toEqual(CustomerManagementActionTypes.UPDATE_CUSTOMER_SUCCESS);
});
});

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

effects.updateCustomer$.subscribe((action) => {
effects.unarchiveCustomer$.subscribe((action) => {
expect(toastrService.error).toHaveBeenCalled();
expect(action.type).toEqual(CustomerManagementActionTypes.UNARCHIVE_CUSTOMER_FAIL);
expect(action.type).toEqual(CustomerManagementActionTypes.UPDATE_CUSTOMER_FAIL);
});
});
});
8 changes: 8 additions & 0 deletions src/app/modules/login/services/azure.ad.b2c.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,12 @@ describe('AzureAdB2CService', () => {

expect(UserAgentApplication.prototype.getAccount).toHaveBeenCalled();
});

it('should get userId from UserAgentApplication', () => {
spyOn(UserAgentApplication.prototype, 'getAccount').and.returnValues(account);

service.getUserId();

expect(UserAgentApplication.prototype.getAccount).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -439,20 +439,29 @@ describe('EntryFieldsComponent', () => {
});

it('when feature-toggle "update-entries" enable for the user, the updateEntry function is executes to update the entries', () => {
spyOn(featureToggleGeneralService, 'isActivated').and.returnValue(of(true));

spyOn(store, 'dispatch');
const expected = { update_last_entry_if_overlap: true };
const mockEntry = {
...entry,
start_date: moment().format(DATE_FORMAT_YEAR),
start_hour: moment().format('HH:mm'),
update_last_entry_if_overlap: true
start_hour: moment().format('HH:mm')
};
const lastMockEntry = {
...entry,
end_date: moment().format(DATE_FORMAT_YEAR),
end_hour: moment().format('HH:mm')
};
const hourInTheFuture = moment().format('HH:mm');
component.newData = mockEntry;
const expected = { update_last_entry_if_overlap: true };
featureToggleGeneralService.isActivated(FeatureToggle.UPDATE_ENTRIES).subscribe(() => {
expect(featureToggleGeneralService.isActivated).toHaveBeenCalled();
expect(component.newData.update_last_entry_if_overlap).toEqual(expected.update_last_entry_if_overlap);
});
component.activeEntry = mockEntry;
component.lastEntry = lastMockEntry;
component.isFeatureToggleActive = true;
component.entryForm.patchValue({ start_hour: hourInTheFuture });

component.onUpdateStartHour();

expect(component.newData.update_last_entry_if_overlap).toEqual(expected.update_last_entry_if_overlap);
expect(store.dispatch).toHaveBeenCalled();
});

it('Set true in isCookieFeatureToggleActive when feature-toggle "feature-toggle-in-cookies" is enable for user', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
if (this.isFeatureToggleActive) {
this.newData.update_last_entry_if_overlap = true;
this.store.dispatch(new entryActions.UpdateEntryRunning({ ...this.newData, ...this.entryForm.value }));

} else {
this.store.dispatch(new entryActions.UpdateCurrentOrLastEntry({ ...this.newData, ...this.entryForm.value }));
}
Expand Down
18 changes: 18 additions & 0 deletions src/app/modules/user/services/user-info.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,22 @@ describe('UserInfoService', () => {
});
});
});

it('should return true if is Admin', () => {
const isMemberOf = spyOn(service, 'isMemberOf').and.returnValue(of(true));

service.isAdmin().subscribe((value) => {
expect(value).toBeTrue();
});
expect(isMemberOf).toHaveBeenCalled();
});

it('should return true if is Tester', () => {
const isMemberOf = spyOn(service, 'isMemberOf').and.returnValue(of(true));

service.isTester().subscribe((value) => {
expect(value).toBeTrue();
});
expect(isMemberOf).toHaveBeenCalled();
});
});
36 changes: 36 additions & 0 deletions src/app/modules/user/services/user.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { TestBed, inject } from '@angular/core/testing';
import { UserService } from './user.service';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';

describe('UserService', () => {
let service: UserService;
let httpMock: HttpTestingController;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule]
});
service = TestBed.inject(UserService);
httpMock = TestBed.inject(HttpTestingController);
});

afterEach(() => {
httpMock.verify();
});

it('should create', inject(
[HttpClientTestingModule, UserService],
(httpClient: HttpClientTestingModule, apiService: UserService) => {
expect(apiService).toBeTruthy();
expect(httpClient).toBeTruthy();
}
));

it('load a user to idUser using GET', () => {
service.baseUrl = '/users';
service.loadUser('xyz').subscribe();

const loadUserRequest = httpMock.expectOne(`${service.baseUrl}/xyz`);
expect(loadUserRequest.request.method).toBe('GET');
});
});
5 changes: 3 additions & 2 deletions src/app/modules/user/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export class UserService {

baseUrl = `${environment.timeTrackerApiUrl}/users`;

loadUser(userId: string): Observable<User> {
return this.http.get<User>(`${this.baseUrl}/${userId}`);
loadUser(userId: any): Observable<User> {
const url = `${this.baseUrl}/${userId}`;
return this.http.get<User>(url);
}
}