MINOR: fix search index language configuration not saving (#15896)

* fix search index language configuration not saving

* minor changes
This commit is contained in:
Ashish Gupta 2024-04-16 15:58:38 +05:30 committed by GitHub
parent 9995a13ac9
commit 23eb4ee1c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 160 additions and 8 deletions

View File

@ -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);

View File

@ -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(<SelectWidget {...mockProps} />);
const selectInput = screen.getByTestId('select-widget');
expect(selectInput).toBeInTheDocument();
});
it('Should be disabled', async () => {
render(<SelectWidget {...mockProps} disabled />);
const selectInput = await findByRole(
screen.getByTestId('select-widget'),
'combobox'
);
expect(selectInput).toBeDisabled();
});
it('Should call onFocus', async () => {
render(<SelectWidget {...mockProps} />);
const selectInput = screen.getByTestId('select-widget');
fireEvent.focus(selectInput);
expect(mockOnFocus).toHaveBeenCalled();
});
it('Should call onBlur', async () => {
render(<SelectWidget {...mockProps} />);
const selectInput = screen.getByTestId('select-widget');
fireEvent.blur(selectInput);
expect(mockOnBlur).toHaveBeenCalled();
});
it('Should call onChange', async () => {
render(<SelectWidget {...mockProps} />);
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);
});
});

View File

@ -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<WidgetProps> = ({
const SelectWidget: FC<WidgetProps> = ({
onFocus,
onBlur,
onChange,
@ -25,16 +25,20 @@ const MultiSelectWidget: FC<WidgetProps> = ({
<Select
autoFocus={rest.autofocus}
className="d-block w-full"
data-testid="select-widget"
disabled={rest.disabled}
id={rest.id}
mode={rest.multiple ? 'multiple' : 'tags'}
mode={rest.multiple ? 'multiple' : undefined}
placeholder={rest.placeholder}
value={rest.value}
onBlur={() => onBlur(rest.id, rest.value)}
onChange={(value) => onChange(value)}
onFocus={() => onFocus(rest.id, rest.value)}>
{(rest.options.enumOptions ?? []).map((option) => (
<Select.Option key={uniqueId()} value={option.value}>
<Select.Option
data-testid={`select-option-${option.label}`}
key={option.value}
value={option.value}>
{capitalize(option.label)}
</Select.Option>
))}
@ -42,4 +46,4 @@ const MultiSelectWidget: FC<WidgetProps> = ({
);
};
export default MultiSelectWidget;
export default SelectWidget;

View File

@ -26,8 +26,8 @@ import DescriptionFieldTemplate from '../Form/JSONSchema/JSONSchemaTemplate/Desc
import { FieldErrorTemplate } from '../Form/JSONSchema/JSONSchemaTemplate/FieldErrorTemplate/FieldErrorTemplate';
import { ObjectFieldTemplate } from '../Form/JSONSchema/JSONSchemaTemplate/ObjectFieldTemplate';
import AsyncSelectWidget from '../Form/JSONSchema/JsonSchemaWidgets/AsyncSelectWidget';
import MultiSelectWidget from '../Form/JSONSchema/JsonSchemaWidgets/MultiSelectWidget';
import PasswordWidget from '../Form/JSONSchema/JsonSchemaWidgets/PasswordWidget';
import SelectWidget from '../Form/JSONSchema/JsonSchemaWidgets/SelectWidget';
import Loader from '../Loader/Loader';
export interface Props extends FormProps {
@ -70,7 +70,7 @@ const FormBuilder: FunctionComponent<Props> = forwardRef(
const widgets = {
PasswordWidget: PasswordWidget,
autoComplete: AsyncSelectWidget,
...(useSelectWidget && { SelectWidget: MultiSelectWidget }),
...(useSelectWidget && { SelectWidget: SelectWidget }),
};
const handleCancel = () => {

View File

@ -0,0 +1,41 @@
/*
* 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.
*/
export const MOCK_SELECT_WIDGET = {
autofocus: false,
disabled: false,
formContext: { handleFocus: undefined },
hideError: undefined,
hideLabel: false,
id: 'root/searchIndexMappingLanguage',
label: 'Search Index Language',
name: 'searchIndexMappingLanguage',
options: {
enumOptions: [
{ label: 'EN', value: 'EN' },
{ label: 'JP', value: 'JP' },
{ label: 'ZH', value: 'ZH' },
],
},
placeholder: '',
rawErrors: undefined,
readonly: false,
required: false,
schema: {
description: 'Recreate Indexes with updated Language',
title: 'Search Index Language',
javaType: 'org.openmetadata.schema.type.IndexMappingLanguage',
enum: ['EN', 'JP', 'ZH'],
},
uiSchema: {},
value: 'JP',
};

View File

@ -72,6 +72,7 @@ export type ListTestCaseParamsBySearch = ListTestCaseParams & {
endTimestamp?: number;
testPlatforms?: TestPlatform[];
offset?: number;
owner?: string;
};
export type ListTestDefinitionsParams = ListParams & {

View File

@ -50,6 +50,8 @@
@blue-2: #3ca2f4;
@blue-3: #0950c5;
@blue-4: #f1f9ff;
@partial-success-1: #06a4a4;
@partial-success-2: #bdeeee;
@black: #000000;
@aborted-color: #efae2f;
@text-color: #292929;