@@ -42,58 +42,63 @@ describe('CreateProjectComponent', () => {
4242 name : 'Project Test 13' ,
4343 description : 'description' ,
4444 } ;
45-
4645 component . projectToEdit = newData ;
46+
4747 component . ngOnChanges ( ) ;
48+
4849 expect ( component . projectForm . value . name ) . toEqual ( newData . name ) ;
4950 expect ( component . projectForm . value . description ) . toEqual ( newData . description ) ;
5051 expect ( component . isUpdating ) . toEqual ( true ) ;
5152 } ) ;
5253
53- it ( 'should emit ngOnChange and reset ProjectForm ' , ( ) => {
54+ it ( 'on ngOnChange with projectToEdit=null should reset projectForm ' , ( ) => {
5455 component . projectToEdit = null ;
56+
5557 component . ngOnChanges ( ) ;
5658
5759 expect ( component . projectForm . value . name ) . toEqual ( null ) ;
5860 expect ( component . projectForm . value . description ) . toEqual ( null ) ;
5961 expect ( component . isUpdating ) . toEqual ( false ) ;
6062 } ) ;
6163
62- it ( 'should dispatch CreateProject action #onSubmit' , ( ) => {
64+ it ( 'should dispatch CreateProject action #onSubmit if isUpdating=false ' , ( ) => {
6365 const project = {
6466 id : '1' ,
6567 name : 'app 4' ,
6668 description : 'It is a good app' ,
6769 } ;
68-
6970 component . isUpdating = false ;
7071 spyOn ( store , 'dispatch' ) ;
72+
7173 component . onSubmit ( project ) ;
74+
7275 expect ( store . dispatch ) . toHaveBeenCalledWith ( new actions . CreateProject ( project ) ) ;
7376 } ) ;
7477
75- it ( 'should dispatch UpdateProject action #onSubmit' , ( ) => {
78+ it ( 'should dispatch UpdateProject action #onSubmit if isUpdating=true ' , ( ) => {
7679 const project = {
7780 id : '1' ,
7881 name : 'app 4' ,
7982 description : 'It is a good app' ,
8083 } ;
81-
8284 component . isUpdating = true ;
8385 spyOn ( store , 'dispatch' ) ;
86+
8487 component . onSubmit ( project ) ;
88+
8589 expect ( store . dispatch ) . toHaveBeenCalledWith ( new actions . UpdateProject ( project ) ) ;
8690 } ) ;
8791
88- it ( 'should clean the form and send a cancelForm event #reset' , ( ) => {
92+ it ( 'should clean the form and emmit a cancelForm event on #reset' , ( ) => {
8993 const project = {
9094 name : 'app 4' ,
9195 description : 'It is a good app' ,
9296 } ;
93-
9497 component . projectForm . setValue ( project ) ;
9598 spyOn ( component . cancelForm , 'emit' ) ;
99+
96100 component . reset ( ) ;
101+
97102 expect ( component . projectForm . value . name ) . toEqual ( null ) ;
98103 expect ( component . projectForm . value . description ) . toEqual ( null ) ;
99104 expect ( component . cancelForm . emit ) . toHaveBeenCalled ( ) ;
0 commit comments