fieldProps.onChange(e.target.value, e)}
- />
- )}
- />
+
+ ,
+ value: idInputValue,
+ onBlur: (event) => saveComponentUpdate(event.target.value),
+ label: t('ux_editor.modal_properties_component_change_id'),
+ size: 'small',
+ error: errorMessage,
+ }}
+ customValidation={(value) => {
+ return validateId(value);
+ }}
+ />
+
);
};
diff --git a/frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.test.tsx b/frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.test.tsx
index 616f4408b9c..4ba1a1c70aa 100644
--- a/frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.test.tsx
+++ b/frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.test.tsx
@@ -1,5 +1,5 @@
import React from 'react';
-import { act, screen } from '@testing-library/react';
+import { act, fireEvent, screen } from '@testing-library/react';
import { PropertiesHeader, type PropertiesHeaderProps } from './PropertiesHeader';
import { FormItemContext } from '../../../containers/FormItemContext';
import userEvent from '@testing-library/user-event';
@@ -23,7 +23,7 @@ describe('PropertiesHeader', () => {
afterEach(jest.clearAllMocks);
it('renders the header name for the component', () => {
- render();
+ renderPropertiesHeader();
const heading = screen.getByRole('heading', {
name: textMock(`ux_editor.component_title.${component1Mock.type}`),
@@ -33,7 +33,7 @@ describe('PropertiesHeader', () => {
});
it('displays the help text when the help text button is clicked', async () => {
- render();
+ renderPropertiesHeader();
const helpTextButton = screen.getByRole('button', {
name: textMock('ux_editor.component_help_text_general_title'),
@@ -50,33 +50,41 @@ describe('PropertiesHeader', () => {
).toBeInTheDocument();
});
- it('calls "handleComponentUpdate" when the id changes', async () => {
- render();
+ it('should invoke "handleComponentUpdate" when id field blurs', async () => {
+ renderPropertiesHeader();
- const textBox = screen.getByRole('textbox', {
- name: textMock('ux_editor.modal_properties_component_change_id'),
- });
+ const editComponentIdButton = screen.getByRole('button', { name: 'ID: Component-1' });
+ await act(() => user.click(editComponentIdButton));
+
+ const inputField = screen.getByLabelText(
+ textMock('ux_editor.modal_properties_component_change_id'),
+ );
+ await act(() => user.type(inputField, 'someNewId'));
+ fireEvent.blur(inputField);
- await act(() => user.type(textBox, 'someId'));
- expect(mockHandleComponentUpdate).toHaveBeenCalledTimes(6);
+ expect(mockHandleComponentUpdate).toHaveBeenCalledTimes(1);
});
- it('should display an error when containerId is invalid', async () => {
- await render();
+ it('should not invoke "handleComponentUpdateMock" when input field has error', async () => {
+ renderPropertiesHeader();
- const containerIdInput = screen.getByRole('textbox', {
- name: textMock('ux_editor.modal_properties_component_change_id'),
- });
+ const editComponentIdButton = screen.getByRole('button', { name: 'ID: Component-1' });
+ await act(() => user.click(editComponentIdButton));
- await act(() => user.type(containerIdInput, 'test@'));
- expect(
- screen.getByText(textMock('ux_editor.modal_properties_component_id_not_valid')),
- ).toBeInTheDocument();
- expect(mockHandleComponentUpdate).toHaveBeenCalledTimes(4);
+ const containerIdInput = screen.getByLabelText(
+ textMock('ux_editor.modal_properties_component_change_id'),
+ );
+
+ const invalidId = 'test@';
+ await act(() => user.type(containerIdInput, invalidId));
+ fireEvent.blur(containerIdInput);
+
+ expect(screen.getByText(textMock('ux_editor.modal_properties_component_id_not_valid')));
+ expect(containerIdInput).toHaveAttribute('aria-invalid', 'true');
+ expect(mockHandleComponentUpdate).toHaveBeenCalledTimes(0);
});
});
-
-const render = (props: Partial = {}) => {
+const renderPropertiesHeader = (props: Partial = {}) => {
const componentType = props.form ? props.form.type : defaultProps.form.type;
queryClientMock.setQueryData(
[QueryKey.FormComponent, componentType],
diff --git a/yarn.lock b/yarn.lock
index 284f0b274f4..4c8b32d19ba 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3753,6 +3753,7 @@ __metadata:
"@testing-library/jest-dom": "npm:^6.1.3"
"@testing-library/react": "npm:^14.0.0"
"@types/jest": "npm:^29.5.5"
+ ajv: "npm:8.12.0"
eslint: "npm:8.57.0"
jest: "npm:^29.7.0"
jest-environment-jsdom: "npm:^29.7.0"