Skip to content

Commit 496bf76

Browse files
authored
Merge pull request #250 from ioet/227_Enhance_entries_modal_fix
fix: #227 Enhance entries modal fix
2 parents 9d94484 + 1feb388 commit 496bf76

File tree

6 files changed

+23
-33
lines changed

6 files changed

+23
-33
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as actions from '../../store/technology.actions';
1010
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
1111
import { getCustomerProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
1212
import { EntryState } from '../../../time-clock/store/entry.reducer';
13+
import * as entryActions from '../../../time-clock/store/entry.actions';
1314
import { getUpdateError, getCreateError } from 'src/app/modules/time-clock/store/entry.selectors';
1415

1516
describe('DetailsFieldsComponent', () => {
@@ -116,15 +117,15 @@ describe('DetailsFieldsComponent', () => {
116117

117118
it('should emit ngOnChange with new data', () => {
118119
const entryToEdit = {
119-
project_id: 'id',
120+
project_id: 'abc',
120121
activity_id: '',
121122
uri: 'ticketUri',
122123
start_date: null,
123124
end_date: null,
124125
description: '',
125126
};
126127
const formValue = {
127-
project: 'name',
128+
project: '',
128129
activity: '',
129130
uri: 'ticketUri',
130131
start_date: '',
@@ -149,7 +150,7 @@ describe('DetailsFieldsComponent', () => {
149150
start_hour: '00:00',
150151
end_hour: '00:00',
151152
description: '',
152-
technology: ''
153+
technology: '',
153154
};
154155
component.entryToEdit = null;
155156
component.ngOnChanges();
@@ -220,6 +221,20 @@ describe('DetailsFieldsComponent', () => {
220221
expect(component.selectedTechnology.length).toBe(1);
221222
});
222223

224+
it('should call createError ', () => {
225+
mockEntriesUpdateErrorSelector = store.overrideSelector(getCreateError, false);
226+
spyOn(store, 'dispatch');
227+
component.ngOnInit();
228+
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.CleanEntryCreateError(null));
229+
});
230+
231+
it('should call updateError ', () => {
232+
mockEntriesUpdateErrorSelector = store.overrideSelector(getUpdateError, false);
233+
spyOn(store, 'dispatch');
234+
component.ngOnInit();
235+
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.CleanEntryUpdateError(null));
236+
});
237+
223238
it('should emit saveEntry event', () => {
224239
spyOn(component.saveEntry, 'emit');
225240
component.onSubmit();

src/app/modules/time-clock/store/entry.effects.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ export class EntryEffects {
6262
return new actions.CreateEntrySuccess(entryData);
6363
}),
6464
catchError((error) => {
65-
console.error(error);
66-
this.toastrService.success(UNEXPECTED_ERROR);
65+
this.toastrService.error(UNEXPECTED_ERROR);
6766
return of(new actions.CreateEntryFail(error.error.message));
6867
})
6968
)
@@ -81,8 +80,7 @@ export class EntryEffects {
8180
return new actions.DeleteEntrySuccess(entryId);
8281
}),
8382
catchError((error) => {
84-
console.log(error);
85-
this.toastrService.success(UNEXPECTED_ERROR);
83+
this.toastrService.error(UNEXPECTED_ERROR);
8684
return of(new actions.DeleteEntryFail(error));
8785
})
8886
)
@@ -96,11 +94,11 @@ export class EntryEffects {
9694
mergeMap((project) =>
9795
this.entryService.updateActiveEntry(project).pipe(
9896
map((projectData) => {
97+
this.toastrService.success(INFO_DELETE_SUCCESSFULLY);
9998
return new actions.UpdateActiveEntrySuccess(projectData);
10099
}),
101100
catchError((error) => {
102-
console.log(error);
103-
this.toastrService.success(UNEXPECTED_ERROR);
101+
this.toastrService.error(UNEXPECTED_ERROR);
104102
return of(new actions.UpdateActiveEntryFail(error));
105103
})
106104
)

src/app/modules/time-clock/store/entry.reducer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi
133133
case EntryActionTypes.DELETE_ENTRY_FAIL: {
134134
return {
135135
...state,
136-
entryList: [],
137136
isLoading: false,
138137
message: 'Something went wrong deleting entry!',
139138
};

src/app/modules/time-entries/pages/time-entries.component.html

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
class="btn btn-sm btn-secondary ml-2"
4747
data-toggle="modal"
4848
data-target="#deleteModal"
49-
(click)="openModal(entry)"
49+
(click)="removeEntry(entry.id)"
5050
>
5151
<i class="fa fa-trash fa-xs"></i>
5252
</button>
@@ -73,14 +73,3 @@ <h5 class="modal-title" id="exampleModalLongTitle">{{entryId ? "Edit Entry": "Ne
7373
</div>
7474
</div>
7575
</div>
76-
<app-modal
77-
*ngIf="showModal"
78-
class="modal fade"
79-
id="deleteModal"
80-
tabindex="-1"
81-
role="dialog"
82-
aria-hidden="true"
83-
[list]="entryToDelete"
84-
(removeList)="removeEntry($event)"
85-
>
86-
</app-modal>

src/app/modules/time-entries/pages/time-entries.component.spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,6 @@ describe('TimeEntriesComponent', () => {
146146
expect(component.dataByMonth.length).toEqual(0);
147147
}));
148148

149-
it('should open Delete Modal', () => {
150-
component.openModal(entry);
151-
expect(component.entryToDelete).toBe(entry);
152-
expect(component.showModal).toBe(true);
153-
});
154-
155149
it('should set entry and entryid to null', () => {
156150
component.newEntry();
157151
expect(component.entry).toBe(null);

src/app/modules/time-entries/pages/time-entries.component.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ export class TimeEntriesComponent implements OnInit {
3535
});
3636
}
3737

38-
openModal(itemToDelete: Entry) {
39-
this.entryToDelete = itemToDelete;
40-
this.showModal = true;
41-
}
42-
4338
newEntry() {
4439
this.entry = null;
4540
this.entryId = null;

0 commit comments

Comments
 (0)