Skip to content

Commit 2c9a164

Browse files
committed
refactor: TTL-887 english lessons and safari books can skip description and ticket number
1 parent a88f38c commit 2c9a164

File tree

4 files changed

+53
-14
lines changed

4 files changed

+53
-14
lines changed

src/app/modules/shared/components/details-fields/details-fields.component.spec.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ describe('DetailsFieldsComponent', () => {
721721
expect(toastrServiceStub.warning).toHaveBeenCalled();
722722
});
723723

724-
it('if entry is set to project_name search_fiend is assigned in entryForm', () => {
724+
it('if entry is set to project_name search_field is assigned in entryForm', () => {
725725
const listProjects: Project[] = [{ id: 'id', name: 'abc', status: 'active', search_field: 'name' }];
726726
component.listProjects = listProjects;
727727
component.entryToEdit = { ...entryToEdit };
@@ -771,6 +771,20 @@ describe('DetailsFieldsComponent', () => {
771771
expect(component.saveEntry.emit).toHaveBeenCalled();
772772
});
773773

774+
/* We allow saving time entries with empty fields in uri and description for safari books and english lessons */
775+
it('should not display a warning message when trying to save time entry of English Lessons without description and save', () => {
776+
component.entryForm.setValue({ ...entryWithoutRequiredFields, project_name: 'ioet inc. - English Lessons' });
777+
778+
spyOn(toastrServiceStub, 'warning');
779+
spyOn(component.saveEntry, 'emit');
780+
781+
component.onSubmit();
782+
expect(toastrServiceStub.warning).not.toHaveBeenCalled();
783+
784+
expect(component.saveEntry.emit).toHaveBeenCalled();
785+
});
786+
787+
774788
/*
775789
TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component,
776790
and now these couple of tests are failing. A solution to this error might be generate a Test Wrapper Component. More details here:

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ import { TechnologiesComponent } from '../technologies/technologies.component';
2828
import { MatDatepicker } from '@angular/material/datepicker';
2929
import { Observable } from 'rxjs';
3030

31+
const INTERNAL_APP_STRING = 'ioet';
32+
const PROJECT_NAME_TO_SKIP = ['English Lessons', 'Safari Books'];
33+
const EMPTY_FIELDS_ERROR_MESSAGE = 'Make sure to add a description and/or ticket number when working on an internal app.';
34+
3135
type Merged = TechnologyState & ProjectState & ActivityState & EntryState;
3236
@Component({
3337
selector: 'app-details-fields',
@@ -332,11 +336,13 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
332336

333337
onSubmit() {
334338

335-
if (this.entryForm.value.project_name.includes('ioet')) {
336-
if (this.entryForm.value.uri === '' && this.entryForm.value.description === '') {
337-
this.toastrService.warning('Make sure to add a description and/or ticket number when working on an internal app');
338-
return;
339-
}
339+
const emptyValue = '';
340+
const { project_name, uri, description } = this.entryForm.value;
341+
const areEmptyValues = [uri, description].every(item => item === emptyValue);
342+
const canSkipDescriptionAndURI = PROJECT_NAME_TO_SKIP.some(projectNameItem => project_name.includes(projectNameItem));
343+
if (project_name.includes(INTERNAL_APP_STRING) && areEmptyValues && !canSkipDescriptionAndURI) {
344+
this.toastrService.warning(EMPTY_FIELDS_ERROR_MESSAGE);
345+
return;
340346
}
341347

342348
if (this.entryForm.invalid) {

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,23 @@ describe('EntryFieldsComponent', () => {
522522

523523
it('should show an error message if description and ticket fields are empty for internal apps', () => {
524524
spyOn(toastrServiceStub, 'error');
525-
const result = component.requiredFieldsForInternalAppExist('ioet');
525+
const result = component.requiredFieldsForInternalAppExist('ioet', 'project name');
526526
expect(toastrServiceStub.error).toHaveBeenCalled();
527527
expect(result).toBe(false);
528528
});
529529

530530
it('should return true if customer name does not contain ioet ', () => {
531531
spyOn(toastrServiceStub, 'error');
532-
const result = component.requiredFieldsForInternalAppExist('Project Name');
532+
const result = component.requiredFieldsForInternalAppExist('customer', 'Project Name');
533+
expect(toastrServiceStub.error).not.toHaveBeenCalled();
534+
expect(result).toBe(true);
535+
});
536+
537+
it('should return true if customer name contain ioet and project name contain Safari Books', () => {
538+
spyOn(toastrServiceStub, 'error');
539+
const result = component.requiredFieldsForInternalAppExist('customer', 'Safari Books');
533540
expect(toastrServiceStub.error).not.toHaveBeenCalled();
534541
expect(result).toBe(true);
535542
});
536543
});
544+

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import { getTimeEntriesDataSource } from '../../store/entry.selectors';
1717
import { DATE_FORMAT } from 'src/environments/environment';
1818
import { Subscription } from 'rxjs';
1919

20+
21+
const INTERNAL_APP_STRING = 'ioet';
22+
const PROJECT_NAME_TO_SKIP = ['English Lessons', 'Safari Books'];
23+
const EMPTY_FIELDS_ERROR_MESSAGE = 'Make sure to add a description and/or ticket number when working on an internal app.';
24+
2025
type Merged = TechnologyState & ProjectState & ActivityState;
2126

2227
@Component({
@@ -134,11 +139,14 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
134139

135140
entryFormIsValidate() {
136141
let customerName = '';
142+
let projectName = '';
137143
this.store.pipe(select(getTimeEntriesDataSource)).subscribe((ds) => {
138144
const dataToUse = ds.data.find((item) => item.project_id === this.activeEntry.project_id);
139145
customerName = dataToUse.customer_name;
146+
projectName = dataToUse.project_name;
147+
140148
});
141-
return this.requiredFieldsForInternalAppExist(customerName) && this.entryForm.valid;
149+
return this.requiredFieldsForInternalAppExist(customerName, projectName) && this.entryForm.valid;
142150
}
143151

144152
onSubmit() {
@@ -199,12 +207,15 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
199207
this.actionSetDateSubscription.unsubscribe();
200208
}
201209

202-
requiredFieldsForInternalAppExist(customerName) {
203-
const emptyFields = this.entryForm.value.uri === '' && this.entryForm.value.description === '';
210+
requiredFieldsForInternalAppExist(customerName, projectName) {
211+
const emptyValue = '';
212+
const areEmptyValues = [this.entryForm.value.uri, this.entryForm.value.description].every(item => item === emptyValue);
213+
204214
const isInternalApp = customerName.includes('ioet');
205-
if (isInternalApp && emptyFields) {
206-
const message = 'The description field or ticket field should not be empty';
207-
this.toastrService.error(`Some fields are empty, ${message}.`);
215+
const canSkipDescriptionAndURI = PROJECT_NAME_TO_SKIP.some(projectNameItem => projectName.includes(projectNameItem));
216+
217+
if (isInternalApp && areEmptyValues && !canSkipDescriptionAndURI) {
218+
this.toastrService.error(EMPTY_FIELDS_ERROR_MESSAGE);
208219
return false;
209220
}
210221
return true;

0 commit comments

Comments
 (0)