Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('DetailsFieldsComponent', () => {
projects: {
projects: [{ id: 'id', name: 'name', project_type_id: '', customer: { name: 'Juan', description: 'sadsa' } }],
customerProjects: [{ id: 'id', name: 'name', description: 'description', project_type_id: '123' }],
recentProjects: [{ id: 'id', name: 'name', customer: { name: 'Juan'} }],
recentProjects: [{ id: 'id', name: 'name', customer: { name: 'Juan' } }],
isLoading: false,
message: '',
projectToEdit: undefined,
Expand Down Expand Up @@ -104,6 +104,19 @@ describe('DetailsFieldsComponent', () => {

const mockCurrentDate = '2020-12-01T12:00:00';

const entryWithoutRequiredFields = {
project_id: 'p1',
project_name: 'ioet inc.',
activity_id: 'a1',
uri: '',
start_date: '2020-02-05',
end_date: '2020-02-05',
start_hour: '00:00',
end_hour: '00:01',
description: '',
technology: '',
};

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
Expand Down Expand Up @@ -156,15 +169,15 @@ describe('DetailsFieldsComponent', () => {
});

it('onClearedComponent project id and name are set to empty', () => {
const search = {term: ''};
const search = { term: '' };
component.onClearedComponent(search);

expect(component.project_id.value).toBe('');
expect(component.project_name.value).toBe('');
});

it('should change the listProjectsShowed to listProjects if search is not empty on onClearedComponent', () => {
const search = {term: 'Ioet Inc.'};
const search = { term: 'Ioet Inc.' };
const listProjects: Project[] = [{ id: '1', name: 'abc', status: 'active' }];
component.listProjects = listProjects;
component.onClearedComponent(search);
Expand Down Expand Up @@ -709,13 +722,55 @@ describe('DetailsFieldsComponent', () => {
});

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'}];
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');
});

it('should display a warning message when trying to save time entry of internal app without required fields', () => {
component.entryForm.setValue(entryWithoutRequiredFields);
spyOn(toastrServiceStub, 'warning');

component.onSubmit();
expect(toastrServiceStub.warning).toHaveBeenCalled();
});

it('should not display a warning message when trying to save time entry of internal app with uri and save', () => {
component.entryForm.setValue({ ...entryWithoutRequiredFields, uri: 'TTL-886' });
spyOn(toastrServiceStub, 'warning');
spyOn(component.saveEntry, 'emit');

component.onSubmit();
expect(toastrServiceStub.warning).not.toHaveBeenCalled();

expect(component.saveEntry.emit).toHaveBeenCalled();
});

it('should not display a warning message when trying to save time entry of external customer without required fields and save', () => {
component.entryForm.setValue({ ...entryWithoutRequiredFields, project_name: 'Warby Parker' });
spyOn(toastrServiceStub, 'warning');
spyOn(component.saveEntry, 'emit');

component.onSubmit();
expect(toastrServiceStub.warning).not.toHaveBeenCalled();

expect(component.saveEntry.emit).toHaveBeenCalled();
});

it('should not display a warning message when trying to save time entry of internal app with description and save', () => {
component.entryForm.setValue({ ...entryWithoutRequiredFields, description: 'Description' });

spyOn(toastrServiceStub, 'warning');
spyOn(component.saveEntry, 'emit');

component.onSubmit();
expect(toastrServiceStub.warning).not.toHaveBeenCalled();

expect(component.saveEntry.emit).toHaveBeenCalled();
});

/*
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 @@ -331,6 +331,14 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
}

onSubmit() {

if (this.entryForm.value.project_name.includes('ioet')) {
if (this.entryForm.value.uri === '' && this.entryForm.value.description === '') {
this.toastrService.warning('Make sure to add a description and/or ticket number when working on an internal app');
return;
}
}

if (this.entryForm.invalid) {
this.toastrService.warning('Make sure to select a project and activity');
return;
Expand Down
Loading