Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -171,6 +171,7 @@ describe('DetailsFieldsComponent', () => {

it('should emit ngOnChange without data', () => {
component.entryToEdit = null;
component.isEdit = true;
component.ngOnChanges();
expect(component.shouldRestartEntry).toBeFalse();
expect(component.entryForm.value).toEqual(initialData);
Expand All @@ -192,6 +193,7 @@ describe('DetailsFieldsComponent', () => {
technology: '',
};
component.entryToEdit = null;
component.isEdit = true;
component.ngOnChanges();
expect(component.entryForm.value).toEqual(formValue);
});
Expand Down Expand Up @@ -443,6 +445,20 @@ describe('DetailsFieldsComponent', () => {
expect(component.projectSelected.emit).toHaveBeenCalledWith(data);
});

it('should clear the form fields', () => {
spyOn(component, 'cleanForm');
component.isEdit = true;
component.ngOnChanges();
expect(component.cleanForm).toHaveBeenCalled();
});

it('should persist entry form value', () => {
spyOn(component, 'cleanForm');
component.isEdit = false;
component.ngOnChanges();
expect(component.cleanForm).toHaveBeenCalledTimes(0);
});

/*
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 @@ -30,6 +30,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
keyword = 'search_field';
@Input() entryToEdit: Entry;
@Input() canMarkEntryAsWIP: boolean;
@Input() isEdit: boolean;
@Output() saveEntry = new EventEmitter<SaveEntryEvent>();
@Output() projectSelected = new EventEmitter<ProjectSelectedEvent>();
@ViewChild('closeModal') closeModal: ElementRef;
Expand Down Expand Up @@ -143,7 +144,9 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
technology: '',
});
} else {
this.cleanForm();
if (this.isEdit) {
this.cleanForm();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ <h5 class="modal-title">{{ entryId ? 'Edit Entry' : 'New Entry' }}</h5>
<div class="modal-body">
<app-details-fields
[entryToEdit]="entry"
[isEdit]="isEdit"
(saveEntry)="saveEntry($event)"
(projectSelected)="projectSelected($event)"
[canMarkEntryAsWIP]='canMarkEntryAsWIP'
Expand Down
3 changes: 3 additions & 0 deletions src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
selectedMonth: number;
selectedYear: number;
selectedMonthAsText: string;
isEdit: boolean;

constructor(private store: Store<EntryState>, private toastrService: ToastrService, private actionsSubject$: ActionsSubject) {
this.timeEntriesDataSource$ = this.store.pipe(delay(0), select(getTimeEntriesDataSource));
Expand Down Expand Up @@ -75,6 +76,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {

editEntry(entryId: string) {
this.entryId = entryId;
this.isEdit = true;
this.store.pipe(select(getTimeEntriesDataSource)).subscribe(ds => {
this.entry = ds.data.find((entry) => entry.id === entryId);
this.canMarkEntryAsWIP = this.isEntryRunningEqualsToEntryToEdit(this.getEntryRunning(ds.data), this.entry)
Expand Down Expand Up @@ -123,6 +125,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
}

projectSelected(event: ProjectSelectedEvent): void {
this.isEdit = false;
this.store.pipe(select(getTimeEntriesDataSource)).subscribe(ds => {
const dataToUse = ds.data.find(item => item.project_id === event.projectId);
if (dataToUse && this.isNewEntry()) {
Expand Down