Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TextArea #5749

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelogs/unreleased/5748-textarea-fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: "Fix issue with updating textarea fields"
issue-nr: 5748
change-type: patch
destination-branches: [master, iso7]
sections:
bugfix: "{{description}}"
12 changes: 12 additions & 0 deletions src/Test/Data/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@ import {
TextField,
BooleanField,
EnumField,
Textarea,
} from "@/Core";

export const textArea: Textarea = {
kind: "Textarea",
name: "textarea_field",
description: "description",
isOptional: true,
isDisabled: false,
defaultValue: "",
inputType: TextInputTypes.text,
type: "string",
};

export const text: TextField = {
kind: "Text",
name: "text_field",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export const TextFormInput: React.FC<Props> = ({
>
{isTextarea ? (
<TextArea
value={attributeValue || ""}
onChange={(event, value) => handleInputChange(value, event)}
value={inputValue || ""}
onChange={(_event, value) => handleChange(value)}
id={attributeName}
name={attributeName}
placeholder={placeholder}
Expand Down
49 changes: 49 additions & 0 deletions src/UI/Components/ServiceInstanceForm/ServiceInstanceForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
InstanceAttributeModel,
NestedField,
TextField,
Textarea,
} from "@/Core";
import {
getStoreInstance,
Expand All @@ -35,6 +36,7 @@ const setup = (
| NestedField
| DictListField
| EnumField
| Textarea
)[],
func: undefined | jest.Mock = undefined,
isEdit = false,
Expand Down Expand Up @@ -537,3 +539,50 @@ test("GIVEN ServiceInstanceForm WHEN clicking the submit button THEN callback is
expect.any(Function),
);
});

test.only.each`
input | label | newValue
${Test.Field.textArea} | ${"TextareaInput-textarea_field"} | ${"new text"}
${Test.Field.text} | ${"TextInput-text_field"} | ${"new text"}
`(
"Given ServiceInstanceForm and InputField WHEN updating the input THEN current value is correctly displayed",
async ({ input, label, newValue }) => {
const { component } = setup([input], undefined, false, undefined);
render(component);

expect(screen.getByLabelText(label)).toHaveValue("");

await act(async () => {
await userEvent.type(screen.getByLabelText(label), newValue);
});

expect(screen.getByLabelText(label)).toHaveValue(newValue);
},
);

test.each`
input | label | value | newValue
${Test.Field.textArea} | ${"TextareaInput-textarea_field"} | ${"test text"} | ${"new text"}
${Test.Field.text} | ${"TextInput-text_field"} | ${"test text"} | ${"new text"}
`(
"Given ServiceInstanceForm and InputField WHEN updating the input THEN current value is correctly displayed",
async ({ input, label, value, newValue }) => {
const originalAttributes = {
[input.name]: value,
};
const { component } = setup([input], undefined, false, originalAttributes);
render(component);

expect(screen.getByLabelText(label)).toHaveValue(value);

await act(async () => {
await userEvent.clear(screen.getByLabelText(label));
await userEvent.type(
screen.getByLabelText(label),
"{selectAll}{backspace}" + newValue,
);
});

expect(screen.getByLabelText(label)).toHaveValue(newValue);
},
);
Loading