@@ -45,7 +45,7 @@ describe('DetailsFieldsComponent', () => {
45
45
projects : {
46
46
projects : [ { id : 'id' , name : 'name' , project_type_id : '' , customer : { name : 'Juan' , description : 'sadsa' } } ] ,
47
47
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' } } ] ,
49
49
isLoading : false ,
50
50
message : '' ,
51
51
projectToEdit : undefined ,
@@ -104,6 +104,19 @@ describe('DetailsFieldsComponent', () => {
104
104
105
105
const mockCurrentDate = '2020-12-01T12:00:00' ;
106
106
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
+
107
120
beforeEach (
108
121
waitForAsync ( ( ) => {
109
122
TestBed . configureTestingModule ( {
@@ -156,15 +169,15 @@ describe('DetailsFieldsComponent', () => {
156
169
} ) ;
157
170
158
171
it ( 'onClearedComponent project id and name are set to empty' , ( ) => {
159
- const search = { term : '' } ;
172
+ const search = { term : '' } ;
160
173
component . onClearedComponent ( search ) ;
161
174
162
175
expect ( component . project_id . value ) . toBe ( '' ) ;
163
176
expect ( component . project_name . value ) . toBe ( '' ) ;
164
177
} ) ;
165
178
166
179
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.' } ;
168
181
const listProjects : Project [ ] = [ { id : '1' , name : 'abc' , status : 'active' } ] ;
169
182
component . listProjects = listProjects ;
170
183
component . onClearedComponent ( search ) ;
@@ -708,14 +721,65 @@ describe('DetailsFieldsComponent', () => {
708
721
expect ( toastrServiceStub . warning ) . toHaveBeenCalled ( ) ;
709
722
} ) ;
710
723
711
- 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' } ] ;
724
+ it ( 'if entry is set to project_name search_field is assigned in entryForm' , ( ) => {
725
+ const listProjects : Project [ ] = [ { id : 'id' , name : 'abc' , status : 'active' , search_field : 'name' } ] ;
713
726
component . listProjects = listProjects ;
714
727
component . entryToEdit = { ...entryToEdit } ;
715
728
component . ngOnChanges ( ) ;
716
729
expect ( component . entryForm . value . project_name ) . toBe ( 'name' ) ;
717
730
} ) ;
718
731
732
+ it ( 'should display a warning message when trying to save time entry of internal app without required fields' , ( ) => {
733
+ component . entryForm . setValue ( entryWithoutRequiredFields ) ;
734
+ spyOn ( toastrServiceStub , 'warning' ) ;
735
+
736
+ component . onSubmit ( ) ;
737
+ expect ( toastrServiceStub . warning ) . toHaveBeenCalled ( ) ;
738
+ } ) ;
739
+
740
+ it ( 'should not display a warning message when trying to save time entry of internal app with uri and save' , ( ) => {
741
+ component . entryForm . setValue ( { ...entryWithoutRequiredFields , uri : 'TTL-886' } ) ;
742
+ spyOn ( toastrServiceStub , 'warning' ) ;
743
+ spyOn ( component . saveEntry , 'emit' ) ;
744
+
745
+ component . onSubmit ( ) ;
746
+ expect ( toastrServiceStub . warning ) . not . toHaveBeenCalled ( ) ;
747
+ expect ( component . saveEntry . emit ) . toHaveBeenCalled ( ) ;
748
+ } ) ;
749
+
750
+ it ( 'should not display a warning message when trying to save time entry of external customer without required fields and save' , ( ) => {
751
+ component . entryForm . setValue ( { ...entryWithoutRequiredFields , project_name : 'Warby Parker' } ) ;
752
+ spyOn ( component . saveEntry , 'emit' ) ;
753
+ spyOn ( toastrServiceStub , 'warning' ) ;
754
+
755
+ component . onSubmit ( ) ;
756
+ expect ( toastrServiceStub . warning ) . not . toHaveBeenCalled ( ) ;
757
+
758
+ expect ( component . saveEntry . emit ) . toHaveBeenCalled ( ) ;
759
+ } ) ;
760
+
761
+ it ( 'should not display a warning message when trying to save time entry of internal app with description and save' , ( ) => {
762
+ component . entryForm . setValue ( { ...entryWithoutRequiredFields , description : 'Description' } ) ;
763
+ spyOn ( component . saveEntry , 'emit' ) ;
764
+ spyOn ( toastrServiceStub , 'warning' ) ;
765
+
766
+ component . onSubmit ( ) ;
767
+ expect ( toastrServiceStub . warning ) . not . toHaveBeenCalled ( ) ;
768
+ expect ( component . saveEntry . emit ) . toHaveBeenCalled ( ) ;
769
+ } ) ;
770
+
771
+ /* We allow saving time entries with empty fields in uri and description for safari books and english lessons */
772
+ it ( 'should not display a warning message when trying to save time entry of English Lessons without description and save' , ( ) => {
773
+ component . entryForm . setValue ( { ...entryWithoutRequiredFields , project_name : 'ioet inc. - English Lessons' } ) ;
774
+ spyOn ( toastrServiceStub , 'warning' ) ;
775
+ spyOn ( component . saveEntry , 'emit' ) ;
776
+
777
+ component . onSubmit ( ) ;
778
+ expect ( toastrServiceStub . warning ) . not . toHaveBeenCalled ( ) ;
779
+
780
+ expect ( component . saveEntry . emit ) . toHaveBeenCalled ( ) ;
781
+ } ) ;
782
+
719
783
/*
720
784
TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component,
721
785
and now these couple of tests are failing. A solution to this error might be generate a Test Wrapper Component. More details here:
0 commit comments