@@ -3,6 +3,7 @@ import ReactTestRenderer from 'react-test-renderer';
33
44import WorkflowDetailForm from '../WorkflowDetailForm' ;
55import { mockAPI } from './mocks'
6+ import API from "../API" ;
67
78it ( 'WorkflowDetailForm editable' , ( ) => {
89 mockAPI ( [ { versions : [ 1 ] } ] ) ;
@@ -21,3 +22,46 @@ it('WorkflowDetailForm editable', () => {
2122 let tree = component . toJSON ( ) ;
2223 expect ( tree ) . toMatchSnapshot ( ) ;
2324} ) ;
25+
26+ it ( 'WorkflowDetailForm componentWillReceiveProps' , ( ) => {
27+ mockAPI ( [ { versions : [ ] } ] ) ;
28+ const workflow = {
29+ "id" : 1 ,
30+ "name" : "Simple Workflow Example" ,
31+ "name_id" : 1 ,
32+ "version" : 1 ,
33+ "schedule_active" : false ,
34+ "schedule" : null ,
35+ "next_run" : null ,
36+ "parameters" : { "MY_OBJECT_ID" : "1" , "SOME_SETTING" : "false" }
37+ } ;
38+ const component = ReactTestRenderer . create ( < WorkflowDetailForm workflow = { workflow } /> ) ;
39+ const instance = component . getInstance ( ) ;
40+ instance . setState = jest . fn ( ) ;
41+ // same but different object
42+ instance . componentWillReceiveProps ( { workflow : { ...workflow } } ) ;
43+ expect ( instance . setState . mock . calls [ 0 ] [ 0 ] . parameters ) . toEqual ( 'MY_OBJECT_ID=1\nSOME_SETTING=false' ) ;
44+ } ) ;
45+
46+ it ( 'WorkflowDetailForm submit' , ( ) => {
47+ mockAPI ( [ { versions : [ ] } ] ) ;
48+ const workflow = {
49+ "id" : 1 ,
50+ "name" : "Simple Workflow Example" ,
51+ "name_id" : 1 ,
52+ "version" : 1 ,
53+ "schedule_active" : false ,
54+ "schedule" : null ,
55+ "next_run" : null ,
56+ "parameters" : { "MY_OBJECT_ID" : "1" , "SOME_SETTING" : "false" }
57+ } ;
58+ const component = ReactTestRenderer . create ( < WorkflowDetailForm workflow = { workflow } /> ) ;
59+ const instance = component . getInstance ( ) ;
60+ instance . toggleEditable ( ) ;
61+ const event = { preventDefault : jest . fn ( ) } ;
62+ API . patch = jest . fn ( ) ;
63+ instance . handleSubmit ( event ) ;
64+ expect ( event . preventDefault ) . toBeCalled ( ) ;
65+ // this does a roundtrip through formValues:
66+ expect ( API . patch . mock . calls [ 0 ] [ 1 ] . parameters ) . toEqual ( workflow . parameters ) ;
67+ } ) ;
0 commit comments