@@ -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 ) ;
@@ -708,14 +721,65 @@ describe('DetailsFieldsComponent', () => {
708721 expect ( toastrServiceStub . warning ) . toHaveBeenCalled ( ) ;
709722 } ) ;
710723
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' } ] ;
713726 component . listProjects = listProjects ;
714727 component . entryToEdit = { ...entryToEdit } ;
715728 component . ngOnChanges ( ) ;
716729 expect ( component . entryForm . value . project_name ) . toBe ( 'name' ) ;
717730 } ) ;
718731
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+
719783 /*
720784 TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component,
721785 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