Skip to content

Commit 0ef5e46

Browse files
authored
Disable name field for update and add tests (#109)
* disable name field for update and add tests * update CHANGELOG * typo
1 parent 48bb0ce commit 0ef5e46

File tree

3 files changed

+96
-8
lines changed

3 files changed

+96
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Fixed
1313

1414
- Use dynamic public URL for static assets, [PR-107](https://github.com/reductstore/web-console/pull/107)
15+
- Disable name field for update and add tests, [PR-109](https://github.com/reductstore/web-console/pull/109)
1516

1617
## [1.10.1] - 2025-05-20
1718

src/Components/Replication/ReplicationSettingsForm.test.tsx

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { Client, ReplicationInfo, ReplicationSettings } from "reduct-js";
66
import { mockJSDOM, waitUntilFind } from "../../Helpers/TestHelpers";
77
import ReplicationSettingsForm from "./ReplicationSettingsForm";
88
import { Diagnostics } from "reduct-js/lib/cjs/messages/Diagnostics";
9+
import { act } from "react-dom/test-utils";
10+
import waitUntil from "async-wait-until";
911

1012
describe("Replication::ReplicationSettingsForm", () => {
1113
const client = new Client("dummyURL");
@@ -98,10 +100,10 @@ describe("Replication::ReplicationSettingsForm", () => {
98100
expect(wrapper.find({ name: "eachS" }).exists()).toBeTruthy();
99101
});
100102

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();
105107
});
106108

107109
it("shows the selected source bucket if it is provided", async () => {
@@ -265,4 +267,89 @@ describe("Replication::ReplicationSettingsForm", () => {
265267

266268
setStateSpy.mockRestore();
267269
});
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+
});
268355
});

src/Components/Replication/ReplicationSettingsForm.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ export default class ReplicationSettingsFormReplication extends React.Component<
8080
entries: [],
8181
};
8282

83-
refreshInterval: NodeJS.Timeout | null = null;
84-
8583
codeMirrorInstance: any;
8684

8785
/**
@@ -105,7 +103,7 @@ export default class ReplicationSettingsFormReplication extends React.Component<
105103
}
106104

107105
try {
108-
let parsedWhen: Record<string, any> | undefined;
106+
let parsedWhen: Record<string, any> = {};
109107
if (this.state.formattedWhen && this.state.formattedWhen.trim()) {
110108
try {
111109
parsedWhen = JSON.parse(this.state.formattedWhen);
@@ -311,7 +309,9 @@ export default class ReplicationSettingsFormReplication extends React.Component<
311309
{ required: true, message: "Please input the replication name!" },
312310
]}
313311
>
314-
<Input disabled={readOnly} />
312+
<Input
313+
disabled={readOnly || this.props.replicationName !== undefined}
314+
/>
315315
</Form.Item>
316316

317317
<Row>

0 commit comments

Comments
 (0)