Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -20,6 +20,7 @@ export enum ActivityManagementActionTypes {
UNARCHIVE_ACTIVITY_FAIL = '[ActivityManagement] UNARCHIVE_ACTIVITY_FAIL',
SET_ACTIVITY_ID_TO_EDIT = '[ActivityManagement] SET_ACTIVITY_ID_TO_EDIT',
RESET_ACTIVITY_ID_TO_EDIT = '[ActivityManagement] RESET_ACTIVITY_ID_TO_EDIT',
DEFAULT_ACTIVITY = '[ActivityManagement] DEFAULT_ACTIVITY',
}

export class LoadActivities implements Action {
Expand Down Expand Up @@ -118,6 +119,10 @@ export class ResetActivityToEdit implements Action {
public readonly type = ActivityManagementActionTypes.RESET_ACTIVITY_ID_TO_EDIT;
}

export class DefaultActivities implements Action {
public readonly type = ActivityManagementActionTypes.DEFAULT_ACTIVITY;
}

export type ActivityManagementActions =
| LoadActivities
| LoadActivitiesSuccess
Expand All @@ -135,4 +140,5 @@ export type ActivityManagementActions =
| UnarchiveActivitySuccess
| UnarchiveActivityFail
| SetActivityToEdit
| ResetActivityToEdit;
| ResetActivityToEdit
| DefaultActivities;
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,25 @@ describe('activityManagementReducer', () => {
expect(state.message).toEqual('Something went wrong unarchiving activities!');
expect(state.isLoading).toBeFalse();
});

it('on SetActivityidToEdit, message equal to \"Set activityIdToEdit property\"', () => {
const action = new actions.SetActivityToEdit('1');
const state = activityManagementReducer(initialState, action);
expect(state.message).toEqual('Set activityIdToEdit property');
expect(state.isLoading).toBeFalse();
});

it('on ResetActivityIdToEdit, message equal to \"Reset activityIdToEdit property\"', () => {
const action = new actions.ResetActivityToEdit();
const state = activityManagementReducer(initialState, action);
expect(state.message).toEqual('Reset activityIdToEdit property');
expect(state.isLoading).toBeFalse();
});

it('on DefaultAction, state equal to initial state', () => {
const action = new actions.DefaultActivities();
const state = activityManagementReducer(initialState, action);
expect(state.data).toEqual(initialState.data);
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { ManagementCustomerProjectsComponent } from './management-customer-projects.component';
import { MockStore, provideMockStore } from '@ngrx/store/testing';
import { CustomerState } from '../../store';
import { of } from 'rxjs';

describe('ManagmentCustomerProjectsComponent', () => {
let component: ManagementCustomerProjectsComponent;
Expand Down Expand Up @@ -38,6 +39,18 @@ describe('ManagmentCustomerProjectsComponent', () => {
expect(component).toBeTruthy();
});

it('set customerName on ngOnInit', () => {
spyOn(store, 'dispatch');
spyOn(store, 'pipe').and.returnValue(of({
id: 1,
name: 'project 4',
description: 'project 1 to test methos projectss',
status: 'inactive'
}));
component.ngOnInit();
expect(component.customerName).toEqual('project 4');
});

it('should be enable tabs', () => {
component.areTabsActive = false;
component.activeTabs(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NgxPaginationModule } from 'ngx-pagination';
import { DeleteProjectType, SetProjectTypeToEdit } from './../../store/project-type.actions';
import { allProjectTypes, ProjectTypeState } from '../../store';
import { ProjectTypeListComponent } from './project-type-list.component';
import { ProjectType } from 'src/app/modules/shared/models';

describe('ProjectTypeTableListComponent', () => {
let component: ProjectTypeListComponent;
Expand Down Expand Up @@ -68,4 +69,16 @@ describe('ProjectTypeTableListComponent', () => {
expect(store.dispatch).toHaveBeenCalledWith(new SetProjectTypeToEdit('id'));
});

it('open the modal with the correct parameters', () => {
const item: ProjectType = {
id: `1`,
name: `Project 1`,
description: `Description project 1`
};
component.openModal(item);
expect(component.idToDelete).toEqual(item.id);
expect(component.message).toEqual(`Are you sure you want to delete ${item.name}?`);
expect(component.showModal).toBe(true);
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('projectTypeReducer', () => {
const initialState: ProjectTypeState = { data: [], isLoading: false, message: '', projectTypeIdToEdit: '' };
const projectType: ProjectType = { id: '1', name: 'Training', description: 'It is good for learning' };

it('on Default, ', () => {
it('on DefaultAction, state equal to initial state', () => {
const action = new actions.DefaultProjectTypes();
const state = projectTypeReducer(initialState, action);
expect(state.data).toEqual(initialState.data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ describe('ProjectService', () => {
}
));

it('all projects are read using GET from url', () => {
const projectsFoundSize = projectsList.length;
service.getAllProjects().subscribe((projectsInResponse) => {
expect(projectsInResponse.length).toBe(projectsFoundSize);
});
const getProjectsRequest = httpMock.expectOne(service.url);
expect(getProjectsRequest.request.method).toBe('GET');
getProjectsRequest.flush(projectsList);
});

it('projects are read using GET from url', () => {
const projectsFoundSize = projectsList.length;
service.url = '/projects';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export enum ProjectActionTypes {
UNARCHIVE_PROJECT = '[Projects] UNARCHIVE_PROJECT',
UNARCHIVE_PROJECT_SUCCESS = '[Projects] UNARCHIVE_PROJECT_SUCCESS',
UNARCHIVE_PROJECT_FAIL = '[Projects] UNARCHIVE_PROJECT_FAIL',
DEFAULT_PROJECT = '[Projects] DEFAULT_PROJECTS',
}

export class CleanCustomerProjects implements Action {
Expand Down Expand Up @@ -154,6 +155,10 @@ export class UnarchiveProjectFail implements Action {
constructor(public error: string) {}
}

export class DefaultProjects implements Action {
public readonly type = ProjectActionTypes.DEFAULT_PROJECT;
}

export type ProjectActions =
| CleanCustomerProjects
| LoadProjects
Expand All @@ -177,4 +182,5 @@ export type ProjectActions =
| DeleteProjectFail
| UnarchiveProject
| UnarchiveProjectSuccess
| UnarchiveProjectFail;
| UnarchiveProjectFail
| DefaultProjects;
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ describe('projectReducer', () => {
});

it('on LoadProjects, isLoading is true', () => {
const action = new actions.LoadProjects();
const state = projectReducer(initialState, action);
expect(state.isLoading).toEqual(true);
});

it('on LoadProjectsSucces, projectsFound are saved in the store', () => {
const projectsFound: Project[] = [project];
const action = new actions.LoadProjectsSuccess(projectsFound);
const state = projectReducer(initialState, action);
expect(action.payload).toEqual([project]);
expect(state.isLoading).toEqual(false);
});

it('on LoadProjectsFail, loadProject equal []', () => {
const action = new actions.LoadProjectsFail('error');
const state = projectReducer(initialState, action);
expect(state.isLoading).toEqual(false);
});

it('on LoadCustomerProjects, isLoading is true', () => {
const action = new actions.LoadCustomerProjects('1');
const state = projectReducer(initialState, action);
expect(state.isLoading).toEqual(true);
Expand Down Expand Up @@ -201,4 +221,11 @@ describe('projectReducer', () => {
expect(state.message).toEqual('Something went wrong unarchiving projects!');
expect(state.isLoading).toEqual(false);
});

it('on DefaultAction, state equal to initial state', () => {
const action = new actions.DefaultProjects();
const state = projectReducer(initialState, action);
expect(state).toEqual(initialState);
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export enum CustomerManagementActionTypes {
UNARCHIVE_CUSTOMER = '[CustomerManagement] UNARCHIVE_CUSTOMER',
UNARCHIVE_CUSTOMER_SUCCESS = '[CustomerManagement] UNARCHIVE_CUSTOMER_SUCCESS',
UNARCHIVE_CUSTOMER_FAIL = '[CustomerManagement] UNARCHIVE_CUSTOMER_FAIL',
DEFAULT_CUSTOMER = '[CustomerManagement] DEFAULT_CUSTOMER',
}

export class LoadCustomers implements Action {
Expand Down Expand Up @@ -118,6 +119,10 @@ export class UnarchiveCustomerFail implements Action {
constructor(public error: string) {}
}

export class DefaultCustomer implements Action {
public readonly type = CustomerManagementActionTypes.DEFAULT_CUSTOMER;
}

export type CustomerManagementActions =
| CreateCustomer
| CreateCustomerSuccess
Expand All @@ -135,4 +140,5 @@ export type CustomerManagementActions =
| ResetCustomerToEdit
| UnarchiveCustomer
| UnarchiveCustomerSuccess
| UnarchiveCustomerFail;
| UnarchiveCustomerFail
| DefaultCustomer;
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,10 @@ describe('customerManagementReducer', () => {
expect(state.message).toEqual('Something went wrong unarchiving customer!');
expect(state.isLoading).toEqual(false);
});

it('on DefaultAction, state equal to initial state', () => {
const action = new actions.DefaultCustomer();
const state = customerManagementReducer(initialState, action);
expect(state.data).toEqual(initialState.data);
});
});
7 changes: 7 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 @@ -21,6 +21,7 @@ describe('AzureAdB2CService', () => {
name: 'abc',
idToken: {
iss: ' http://hostname.com/12345/v0/',
emails: 'abcd'
},
idTokenClaims: {},
sid: 'abc',
Expand Down Expand Up @@ -179,4 +180,10 @@ describe('AzureAdB2CService', () => {

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

it('should get email', () => {
spyOn(UserAgentApplication.prototype, 'getAccount').and.returnValues(account);
const email = service.getUserEmail();
expect(email).toEqual('a');
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { MockStore, provideMockStore } from '@ngrx/store/testing';
import { DataTableDirective } from 'angular-datatables';
import { Entry } from 'src/app/modules/shared/models';
import { SubstractDatePipe } from 'src/app/modules/shared/pipes/substract-date/substract-date.pipe';
import { getReportDataSource } from 'src/app/modules/time-clock/store/entry.selectors';
Expand Down Expand Up @@ -134,6 +135,17 @@ describe('Reports Page', () => {
expect(component.bodyExportOptions(entry, row, column, node)).toBe('https://TT-392-uri');
});

it('when the rerenderDataTable method is called and dtElement and dtInstance are defined, the destroy and next methods are called ',
() => {
component.dtElement = {
dtInstance: {
then : (dtInstance: DataTables.Api) => { dtInstance.destroy(); }
}
} as unknown as DataTableDirective;
spyOn(component.dtElement.dtInstance, 'then');
component.ngAfterViewInit();
expect(component.dtElement.dtInstance.then).toHaveBeenCalled();
});

afterEach(() => {
fixture.destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ describe('DetailsFieldsComponent', () => {
technology: '',
};
component.ngOnChanges();

expect(component.shouldRestartEntry).toBeFalse();
expect(component.entryForm.value).toEqual(formValue);
component.activities$.subscribe((item) => {
Expand Down Expand Up @@ -730,6 +729,27 @@ describe('DetailsFieldsComponent', () => {
expect(numberinISOFormat).toBe(expectedISOFormatNumbers[numberIndex]);
});
});

it('when the user selects technologies, set them in the variable selectedTechnologies', () => {
const techs = ['php', 'angular'];
component.onTechnologiesUpdated(techs);
expect(component.selectedTechnologies).toEqual(techs);
});

it('when the user does not select a project, display a warning message.', () => {
spyOn(toastrServiceStub, 'warning');
component.onclickFormAction(true);
expect(toastrServiceStub.warning).toHaveBeenCalled();
});

it('if entry is set to project_name search_fiend is assigned in entryForm', () => {
const listProjects: Project[] = [{ id: 'id', name: 'abc', status: 'active', search_field: 'name'}];
component.listProjects = listProjects;
component.entryToEdit = { ...entryToEdit };
component.ngOnChanges();
expect(component.entryForm.value.project_name).toBe('name');
});

/*
TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component,
and now these couple of tests are failing. A solution to this error might be generate a Test Wrapper Component. More details here:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,42 @@ describe('InputDateComponent', () => {
expect(component.value).toEqual('2020-05-20');
}));

it('call the close method if opened equals true', () => {
const datepicker: any = { opened : true, open : () => ({}), close : () => ({}) };
spyOn(datepicker, 'close');
component.openOrCloseDatePicker(datepicker);
expect(datepicker.close).toHaveBeenCalled();
});

it('call the open method if opened equals false', () => {
const datepicker: any = { opened : false, open : () => ({}), close : () => ({}) };
spyOn(datepicker, 'open');
component.openOrCloseDatePicker(datepicker);
expect(datepicker.open).toHaveBeenCalled();
});

it('isDisabled should be true if parameter is true', () => {
component.setDisabledState(true);
expect(component.isDisabled).toBe(true);
});

it('isDisabled should be false if parameter is false', () => {
component.setDisabledState(false);
expect(component.isDisabled).toBe(false);
});

it(`value should be '' in writeValue function when parameter is null`, () => {
const value: any = null;
component.writeValue(value);
expect(component.value).toEqual('');
});

it(`value should be '' in writeValue function when parameter is not defined`, () => {
const value: any = undefined;
component.writeValue(value);
expect(component.value).toEqual('');
});

const params: boolean[] = [true, false];
params.forEach(disable => {
it('when the disabled attribute is provided, it should disable the input ', fakeAsync(() => {
Expand Down
Loading