Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: TTL-989 add tests for entryFormIsValidate function
  • Loading branch information
mmaquina committed Jul 10, 2023
commit 40587091ebe7e21a33ddb7e86013165d3cf1f6fd
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ describe('EntryFieldsComponent', () => {
expect(component.showTimeInbuttons).toEqual(false);
});

fit('when a start hour is updated, but the entry is invalid, then do not dispatch UpdateActiveEntry', () => {
it('when a start hour is updated, but the entry is invalid, then do not dispatch UpdateActiveEntry', () => {
component.newData = mockEntryOverlap;
component.activeEntry = entry;
component.setDataToUpdate(entry);
const updatedTime = moment(mockDate).format('HH:mm');

component.entryForm.patchValue({ start_hour: updatedTime });
spyOn(store, 'dispatch');
spyOn(component, 'entryFormIsValidate').and.returnValue(entryForm.invalid);
spyOn(component, 'entryFormIsValidate').and.returnValue(false);

component.onUpdateStartHour();

Expand Down Expand Up @@ -335,13 +335,40 @@ describe('EntryFieldsComponent', () => {
expect(store.dispatch).toHaveBeenCalled();
});

it('uses the form to check if is valid or not', () => {
it('entryFormIsValidate returns false when data in the form is not valid', () => {
component.newData = mockEntryOverlap;

const invalidEntry = {...entry, 'activity_id': ''}
component.activeEntry = invalidEntry;
component.setDataToUpdate(invalidEntry);

spyOn(component, 'requiredFieldsForInternalAppExist').and.returnValue(true);

const result = component.entryFormIsValidate();

expect(result).toBe(false);
});

it('entryFormIsValidate returns false if not all required fields are present despite data in the form being valid', () => {
component.newData = mockEntryOverlap;
component.activeEntry = entry;
component.setDataToUpdate(entry);
spyOn(component, 'requiredFieldsForInternalAppExist').and.returnValue(false);

const result = component.entryFormIsValidate();

expect(result).toBe(false);
});

it('entryFormIsValidate returns true when required fields are present and data in the form is valid', () => {
component.newData = mockEntryOverlap;
component.activeEntry = entry;
entryForm.valid = false;
component.setDataToUpdate(entry);
spyOn(component, 'requiredFieldsForInternalAppExist').and.returnValue(true);

const result = component.entryFormIsValidate();

expect(result).toBe(entryForm.valid);
expect(result).toBe(true);
});

it('dispatches an action when onSubmit is called', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
}
}

/**
* Makes activity mandatory when clocking in.
* Also makes uri or description mandatory if it is an internal app.
*/
entryFormIsValidate() {
let customerName = '';
let projectName = '';
Expand Down Expand Up @@ -210,6 +214,10 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
this.actionSetDateSubscription.unsubscribe();
}

/**
* Manages the conditions for requiring uri or description fields
* when clocking in an internal app.
*/
requiredFieldsForInternalAppExist(customerName: string, projectName: string) {
const emptyValue = '';
const areEmptyValues = [this.entryForm.value.uri, this.entryForm.value.description].every(
Expand Down