Skip to content

Commit

Permalink
Add two test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Puczynski committed Dec 21, 2018
1 parent b826b28 commit e1d6051
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/ObjectField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,24 @@ describe("ObjectField", () => {
expect(comp.state.formData.newFirst).eql(1);
});

it("should keep order of renamed key-value pairs while renaming key", () => {
const { comp, node } = createFormComponent({
schema,
formData: { first: 1, second: 2, third: 3 },
});

const textNode = node.querySelector("#root_second-key");
Simulate.blur(textNode, {
target: { value: "newSecond" },
});

expect(Object.keys(comp.state.formData)).eql([
"first",
"newSecond",
"third",
]);
});

it("should attach suffix to formData key if new key already exists when key input is renamed", () => {
const formData = {
first: 1,
Expand All @@ -538,6 +556,21 @@ describe("ObjectField", () => {
expect(comp.state.formData["second-1"]).eql(1);
});

it("should not attach suffix when input is only clicked", () => {
const formData = {
first: 1,
};
const { comp, node } = createFormComponent({
schema,
formData,
});

const textNode = node.querySelector("#root_first-key");
Simulate.blur(textNode);

expect(comp.state.formData.hasOwnProperty("first")).to.be.true;
});

it("should continue incrementing suffix to formData key until that key name is unique after a key input collision", () => {
const formData = {
first: 1,
Expand Down

0 comments on commit e1d6051

Please sign in to comment.