From 23eb4ee1c95ee01474f6beb601d83ca35480d06a Mon Sep 17 00:00:00 2001 From: Ashish Gupta Date: Tue, 16 Apr 2024 15:58:38 +0530 Subject: [PATCH] MINOR: fix search index language configuration not saving (#15896) * fix search index language configuration not saving * minor changes --- .../e2e/Pages/SearchIndexApplication.spec.ts | 4 + .../JsonSchemaWidgets/SelectWidget.test.tsx | 100 ++++++++++++++++++ ...MultiSelectWidget.tsx => SelectWidget.tsx} | 16 +-- .../common/FormBuilder/FormBuilder.tsx | 4 +- .../ui/src/mocks/SelectWidget.mock.ts | 41 +++++++ .../src/main/resources/ui/src/rest/testAPI.ts | 1 + .../resources/ui/src/styles/variables.less | 2 + 7 files changed, 160 insertions(+), 8 deletions(-) create mode 100644 openmetadata-ui/src/main/resources/ui/src/components/common/Form/JSONSchema/JsonSchemaWidgets/SelectWidget.test.tsx rename openmetadata-ui/src/main/resources/ui/src/components/common/Form/JSONSchema/JsonSchemaWidgets/{MultiSelectWidget.tsx => SelectWidget.tsx} (77%) create mode 100644 openmetadata-ui/src/main/resources/ui/src/mocks/SelectWidget.mock.ts diff --git a/openmetadata-ui/src/main/resources/ui/cypress/e2e/Pages/SearchIndexApplication.spec.ts b/openmetadata-ui/src/main/resources/ui/cypress/e2e/Pages/SearchIndexApplication.spec.ts index 3a4c16e0fa2..405c4df6b7d 100644 --- a/openmetadata-ui/src/main/resources/ui/cypress/e2e/Pages/SearchIndexApplication.spec.ts +++ b/openmetadata-ui/src/main/resources/ui/cypress/e2e/Pages/SearchIndexApplication.spec.ts @@ -52,6 +52,10 @@ describe('Search Index Application', { tags: 'Settings' }, () => { cy.get('#root\\/batchSize').type('0'); cy.get('form [title="Chart"] [role="img"]').click(); + cy.get( + '[data-testid="select-widget"] > .ant-select-selector > .ant-select-selection-item' + ).click(); + cy.get('[data-testid="select-option-JP"]').click(); cy.get('[data-testid="submit-btn"]').click(); verifyResponseStatusCode('@updateApplication', 200); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/common/Form/JSONSchema/JsonSchemaWidgets/SelectWidget.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/common/Form/JSONSchema/JsonSchemaWidgets/SelectWidget.test.tsx new file mode 100644 index 00000000000..75f3172b10f --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/components/common/Form/JSONSchema/JsonSchemaWidgets/SelectWidget.test.tsx @@ -0,0 +1,100 @@ +/* + * Copyright 2024 Collate. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Registry, WidgetProps } from '@rjsf/utils'; +import { + act, + findByRole, + fireEvent, + render, + screen, + waitForElement, +} from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import React from 'react'; +import { MOCK_SELECT_WIDGET } from '../../../../../mocks/SelectWidget.mock'; +import SelectWidget from './SelectWidget'; + +const mockOnFocus = jest.fn(); +const mockOnBlur = jest.fn(); +const mockOnChange = jest.fn(); + +const mockProps: WidgetProps = { + onFocus: mockOnFocus, + onBlur: mockOnBlur, + onChange: mockOnChange, + registry: {} as Registry, + ...MOCK_SELECT_WIDGET, +}; + +describe('Test SelectWidget Component', () => { + it('Should render select component', async () => { + render(); + + const selectInput = screen.getByTestId('select-widget'); + + expect(selectInput).toBeInTheDocument(); + }); + + it('Should be disabled', async () => { + render(); + + const selectInput = await findByRole( + screen.getByTestId('select-widget'), + 'combobox' + ); + + expect(selectInput).toBeDisabled(); + }); + + it('Should call onFocus', async () => { + render(); + + const selectInput = screen.getByTestId('select-widget'); + + fireEvent.focus(selectInput); + + expect(mockOnFocus).toHaveBeenCalled(); + }); + + it('Should call onBlur', async () => { + render(); + + const selectInput = screen.getByTestId('select-widget'); + + fireEvent.blur(selectInput); + + expect(mockOnBlur).toHaveBeenCalled(); + }); + + it('Should call onChange', async () => { + render(); + + const selectInput = await findByRole( + screen.getByTestId('select-widget'), + 'combobox' + ); + + await act(async () => { + userEvent.click(selectInput); + }); + + await waitForElement(() => screen.getByTestId('select-option-JP')); + + await act(async () => { + fireEvent.click(screen.getByTestId('select-option-EN')); + }); + + expect(mockOnChange).toHaveBeenCalledTimes(1); + }); +}); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/common/Form/JSONSchema/JsonSchemaWidgets/MultiSelectWidget.tsx b/openmetadata-ui/src/main/resources/ui/src/components/common/Form/JSONSchema/JsonSchemaWidgets/SelectWidget.tsx similarity index 77% rename from openmetadata-ui/src/main/resources/ui/src/components/common/Form/JSONSchema/JsonSchemaWidgets/MultiSelectWidget.tsx rename to openmetadata-ui/src/main/resources/ui/src/components/common/Form/JSONSchema/JsonSchemaWidgets/SelectWidget.tsx index 45502511a3e..84611eeef4e 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/common/Form/JSONSchema/JsonSchemaWidgets/MultiSelectWidget.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/common/Form/JSONSchema/JsonSchemaWidgets/SelectWidget.tsx @@ -1,5 +1,5 @@ /* - * Copyright 2023 Collate. + * Copyright 2024 Collate. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,10 +12,10 @@ */ import { WidgetProps } from '@rjsf/utils'; import { Select } from 'antd'; -import { capitalize, uniqueId } from 'lodash'; +import { capitalize } from 'lodash'; import React, { FC } from 'react'; -const MultiSelectWidget: FC = ({ +const SelectWidget: FC = ({ onFocus, onBlur, onChange, @@ -25,16 +25,20 @@ const MultiSelectWidget: FC = ({