@@ -6,6 +6,8 @@ import { Client, ReplicationInfo, ReplicationSettings } from "reduct-js";
6
6
import { mockJSDOM , waitUntilFind } from "../../Helpers/TestHelpers" ;
7
7
import ReplicationSettingsForm from "./ReplicationSettingsForm" ;
8
8
import { Diagnostics } from "reduct-js/lib/cjs/messages/Diagnostics" ;
9
+ import { act } from "react-dom/test-utils" ;
10
+ import waitUntil from "async-wait-until" ;
9
11
10
12
describe ( "Replication::ReplicationSettingsForm" , ( ) => {
11
13
const client = new Client ( "dummyURL" ) ;
@@ -98,10 +100,10 @@ describe("Replication::ReplicationSettingsForm", () => {
98
100
expect ( wrapper . find ( { name : "eachS" } ) . exists ( ) ) . toBeTruthy ( ) ;
99
101
} ) ;
100
102
101
- it ( "shows the replication name if it is provided" , ( ) => {
102
- expect ( wrapper . find ( { name : "name" } ) . find ( "input" ) . prop ( "value" ) ) . toEqual (
103
- " TestReplication",
104
- ) ;
103
+ it ( "shows the replication disabled name if it is provided" , ( ) => {
104
+ const input = wrapper . find ( { name : "name" } ) . find ( "input" ) ;
105
+ expect ( input . prop ( "value" ) ) . toEqual ( " TestReplication") ;
106
+ expect ( input . prop ( "disabled" ) ) . toBeTruthy ( ) ;
105
107
} ) ;
106
108
107
109
it ( "shows the selected source bucket if it is provided" , async ( ) => {
@@ -265,4 +267,89 @@ describe("Replication::ReplicationSettingsForm", () => {
265
267
266
268
setStateSpy . mockRestore ( ) ;
267
269
} ) ;
270
+
271
+ describe ( "api" , ( ) => {
272
+ const expected_settings = {
273
+ dstBucket : "destinationBucket" ,
274
+ dstHost : "destinationHost" ,
275
+ dstToken : "destinationToken" ,
276
+ eachN : 10n ,
277
+ eachS : 0.5 ,
278
+ entries : [ "entry1" , "entry2" ] ,
279
+ exclude : { } ,
280
+ include : { } ,
281
+ srcBucket : "Bucket1" ,
282
+ when : { } ,
283
+ } ;
284
+
285
+ const form_settings = {
286
+ name : "NewReplication" ,
287
+ srcBucket : "Bucket1" ,
288
+ dstBucket : "destinationBucket" ,
289
+ dstHost : "destinationHost" ,
290
+ dstToken : "destinationToken" ,
291
+ entries : [ "entry1" , "entry2" ] ,
292
+ eachN : 10n ,
293
+ eachS : 0.5 ,
294
+ when : { } ,
295
+ } ;
296
+
297
+ it ( "calls createReplication on form submission" , async ( ) => {
298
+ const onCreatedCalled = [ false ] ;
299
+ const wrapper = mount (
300
+ < MemoryRouter >
301
+ < ReplicationSettingsForm
302
+ client = { client }
303
+ onCreated = { ( ) => ( onCreatedCalled [ 0 ] = true ) }
304
+ sourceBuckets = { [ "Bucket1" , "Bucket2" ] }
305
+ readOnly = { false }
306
+ />
307
+ </ MemoryRouter > ,
308
+ ) ;
309
+
310
+ const form = wrapper . find ( { name : "replicationForm" } ) . at ( 0 ) ;
311
+
312
+ // fill the form fields
313
+ await act ( async ( ) => {
314
+ form . props ( ) . onFinish ( form_settings ) ;
315
+ } ) ;
316
+
317
+ await waitUntilFind ( wrapper , "form" ) ;
318
+ await waitUntil ( ( ) => onCreatedCalled [ 0 ] ) ;
319
+
320
+ expect ( client . createReplication ) . toBeCalledWith (
321
+ "NewReplication" ,
322
+ expected_settings ,
323
+ ) ;
324
+
325
+ expect ( onCreatedCalled [ 0 ] ) . toBe ( true ) ;
326
+ } ) ;
327
+
328
+ it ( "calls updateReplication on form submission" , async ( ) => {
329
+ const onCreatedCalled = [ false ] ;
330
+ const wrapper = mount (
331
+ < MemoryRouter >
332
+ < ReplicationSettingsForm
333
+ client = { client }
334
+ onCreated = { ( ) => ( onCreatedCalled [ 0 ] = true ) }
335
+ sourceBuckets = { [ "Bucket1" , "Bucket2" ] }
336
+ replicationName = { "TestReplication" }
337
+ readOnly = { false }
338
+ />
339
+ </ MemoryRouter > ,
340
+ ) ;
341
+
342
+ await waitUntilFind ( wrapper , "form" ) ;
343
+ const form = wrapper . find ( { name : "replicationForm" } ) . at ( 0 ) ;
344
+ // fill the form fields
345
+ await act ( async ( ) => {
346
+ form . props ( ) . onFinish ( form_settings ) ;
347
+ } ) ;
348
+ await waitUntil ( ( ) => onCreatedCalled [ 0 ] ) ;
349
+ expect ( client . updateReplication ) . toBeCalledWith (
350
+ "TestReplication" ,
351
+ expected_settings ,
352
+ ) ;
353
+ } ) ;
354
+ } ) ;
268
355
} ) ;
0 commit comments