@@ -8,7 +8,7 @@ import mockDest from "test-utils/mock-data/mockDestinationDefinition.json";
8
8
import mockWorkspace from "test-utils/mock-data/mockWorkspace.json" ;
9
9
import { TestWrapper } from "test-utils/testutils" ;
10
10
11
- import { WebBackendConnectionRead } from "core/request/AirbyteClient" ;
11
+ import { ConnectionScheduleType , WebBackendConnectionRead } from "core/request/AirbyteClient" ;
12
12
13
13
import { ModalCancel } from "../Modal" ;
14
14
import {
@@ -74,7 +74,12 @@ describe("ConnectionFormService", () => {
74
74
expect ( resetForm ) . toBeCalledWith ( { values : testValues } ) ;
75
75
expect ( onSubmit ) . toBeCalledWith ( {
76
76
operations : [ ] ,
77
- scheduleType : "manual" ,
77
+ scheduleData : {
78
+ cron : {
79
+ cronExpression : undefined ,
80
+ cronTimeZone : undefined ,
81
+ } ,
82
+ } ,
78
83
syncCatalog : {
79
84
streams : undefined ,
80
85
} ,
@@ -83,6 +88,59 @@ describe("ConnectionFormService", () => {
83
88
expect ( result . current . errorMessage ) . toBe ( null ) ;
84
89
} ) ;
85
90
91
+ const expectation = {
92
+ [ ConnectionScheduleType . basic ] : {
93
+ basicSchedule : {
94
+ timeUnit : undefined ,
95
+ units : undefined ,
96
+ } ,
97
+ } ,
98
+ [ ConnectionScheduleType . manual ] : undefined ,
99
+ [ ConnectionScheduleType . cron ] : {
100
+ cron : {
101
+ cronExpression : undefined ,
102
+ cronTimeZone : undefined ,
103
+ } ,
104
+ } ,
105
+ } ;
106
+
107
+ Object . values ( ConnectionScheduleType ) . forEach ( ( scheduleType ) => {
108
+ it ( `should return expected results when onSubmit is called with ${ scheduleType } ` , async ( ) => {
109
+ const { result } = renderHook ( useConnectionFormService , {
110
+ wrapper : Wrapper ,
111
+ initialProps : {
112
+ connection : mockConnection as WebBackendConnectionRead ,
113
+ mode : "create" ,
114
+ formId : Math . random ( ) . toString ( ) ,
115
+ onSubmit,
116
+ onAfterSubmit,
117
+ onCancel,
118
+ formDirty : false ,
119
+ } ,
120
+ } ) ;
121
+
122
+ const resetForm = jest . fn ( ) ;
123
+ const testValues : any = {
124
+ scheduleType,
125
+ } ;
126
+ await act ( async ( ) => {
127
+ await result . current . onFormSubmit ( testValues , { resetForm } as any ) ;
128
+ } ) ;
129
+
130
+ expect ( resetForm ) . toBeCalledWith ( { values : testValues } ) ;
131
+ expect ( onSubmit ) . toBeCalledWith ( {
132
+ operations : [ ] ,
133
+ scheduleData : expectation [ scheduleType ] ,
134
+ scheduleType,
135
+ syncCatalog : {
136
+ streams : undefined ,
137
+ } ,
138
+ } ) ;
139
+ expect ( onAfterSubmit ) . toBeCalledWith ( ) ;
140
+ expect ( result . current . errorMessage ) . toBe ( null ) ;
141
+ } ) ;
142
+ } ) ;
143
+
86
144
it ( "should catch if onSubmit throws and generate an error message" , async ( ) => {
87
145
const errorMessage = "asdf" ;
88
146
onSubmit . mockImplementation ( async ( ) => {
0 commit comments