Skip to content

Commit a88f38c

Browse files
refactor: TTL-887 improve tests
1 parent cc9339c commit a88f38c

File tree

1 file changed

+22
-55
lines changed

1 file changed

+22
-55
lines changed

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

Lines changed: 22 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('DetailsFieldsComponent', () => {
4545
projects: {
4646
projects: [{ id: 'id', name: 'name', project_type_id: '', customer: { name: 'Juan', description: 'sadsa' } }],
4747
customerProjects: [{ id: 'id', name: 'name', description: 'description', project_type_id: '123' }],
48-
recentProjects: [{ id: 'id', name: 'name', customer: { name: 'Juan'} }],
48+
recentProjects: [{ id: 'id', name: 'name', customer: { name: 'Juan' } }],
4949
isLoading: false,
5050
message: '',
5151
projectToEdit: undefined,
@@ -104,6 +104,19 @@ describe('DetailsFieldsComponent', () => {
104104

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

107+
const entryWithoutRequiredFields = {
108+
project_id: 'p1',
109+
project_name: 'ioet inc.',
110+
activity_id: 'a1',
111+
uri: '',
112+
start_date: '2020-02-05',
113+
end_date: '2020-02-05',
114+
start_hour: '00:00',
115+
end_hour: '00:01',
116+
description: '',
117+
technology: '',
118+
};
119+
107120
beforeEach(
108121
waitForAsync(() => {
109122
TestBed.configureTestingModule({
@@ -156,15 +169,15 @@ describe('DetailsFieldsComponent', () => {
156169
});
157170

158171
it('onClearedComponent project id and name are set to empty', () => {
159-
const search = {term: ''};
172+
const search = { term: '' };
160173
component.onClearedComponent(search);
161174

162175
expect(component.project_id.value).toBe('');
163176
expect(component.project_name.value).toBe('');
164177
});
165178

166179
it('should change the listProjectsShowed to listProjects if search is not empty on onClearedComponent', () => {
167-
const search = {term: 'Ioet Inc.'};
180+
const search = { term: 'Ioet Inc.' };
168181
const listProjects: Project[] = [{ id: '1', name: 'abc', status: 'active' }];
169182
component.listProjects = listProjects;
170183
component.onClearedComponent(search);
@@ -709,47 +722,23 @@ describe('DetailsFieldsComponent', () => {
709722
});
710723

711724
it('if entry is set to project_name search_fiend is assigned in entryForm', () => {
712-
const listProjects: Project[] = [{ id: 'id', name: 'abc', status: 'active', search_field: 'name'}];
725+
const listProjects: Project[] = [{ id: 'id', name: 'abc', status: 'active', search_field: 'name' }];
713726
component.listProjects = listProjects;
714727
component.entryToEdit = { ...entryToEdit };
715728
component.ngOnChanges();
716729
expect(component.entryForm.value.project_name).toBe('name');
717730
});
718731

719732
it('should display a warning message when trying to save time entry of internal app without required fields', () => {
720-
component.entryForm.setValue({
721-
project_id: 'p1',
722-
project_name: 'ioet inc.',
723-
activity_id: 'a1',
724-
uri: '',
725-
start_date: '2020-02-05',
726-
end_date: '2020-02-05',
727-
start_hour: '00:00',
728-
end_hour: '00:01',
729-
description: '',
730-
technology: '',
731-
});
733+
component.entryForm.setValue(entryWithoutRequiredFields);
732734
spyOn(toastrServiceStub, 'warning');
733735

734736
component.onSubmit();
735737
expect(toastrServiceStub.warning).toHaveBeenCalled();
736-
737738
});
738739

739-
740740
it('should not display a warning message when trying to save time entry of internal app with uri and save', () => {
741-
component.entryForm.setValue({
742-
project_id: 'p1',
743-
project_name: 'ioet inc.',
744-
activity_id: 'a1',
745-
uri: 'TTL-666',
746-
start_date: '2020-02-05',
747-
end_date: '2020-02-05',
748-
start_hour: '00:00',
749-
end_hour: '00:01',
750-
description: '',
751-
technology: '',
752-
});
741+
component.entryForm.setValue({ ...entryWithoutRequiredFields, uri: 'TTL-886' });
753742
spyOn(toastrServiceStub, 'warning');
754743
spyOn(component.saveEntry, 'emit');
755744

@@ -759,20 +748,8 @@ describe('DetailsFieldsComponent', () => {
759748
expect(component.saveEntry.emit).toHaveBeenCalled();
760749
});
761750

762-
763751
it('should not display a warning message when trying to save time entry of external customer without required fields and save', () => {
764-
component.entryForm.setValue({
765-
project_id: 'p1',
766-
project_name: 'customer inc. - proj',
767-
activity_id: 'a1',
768-
uri: '',
769-
start_date: '2020-02-05',
770-
end_date: '2020-02-05',
771-
start_hour: '00:00',
772-
end_hour: '00:01',
773-
description: '',
774-
technology: '',
775-
});
752+
component.entryForm.setValue({ ...entryWithoutRequiredFields, project_name: 'Warby Parker' });
776753
spyOn(toastrServiceStub, 'warning');
777754
spyOn(component.saveEntry, 'emit');
778755

@@ -783,18 +760,8 @@ describe('DetailsFieldsComponent', () => {
783760
});
784761

785762
it('should not display a warning message when trying to save time entry of internal app with description and save', () => {
786-
component.entryForm.setValue({
787-
project_id: 'p1',
788-
project_name: 'ioet inc. - proj',
789-
activity_id: 'a1',
790-
uri: '',
791-
start_date: '2020-02-05',
792-
end_date: '2020-02-05',
793-
start_hour: '00:00',
794-
end_hour: '00:01',
795-
description: 'asdf',
796-
technology: '',
797-
});
763+
component.entryForm.setValue({ ...entryWithoutRequiredFields, description: 'Description' });
764+
798765
spyOn(toastrServiceStub, 'warning');
799766
spyOn(component.saveEntry, 'emit');
800767

0 commit comments

Comments
 (0)