diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/Alerts/AlertsUtil.test.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/Alerts/AlertsUtil.test.tsx index ce6a3e9a8289..c6ac7a87ef26 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/Alerts/AlertsUtil.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/Alerts/AlertsUtil.test.tsx @@ -10,6 +10,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { act, render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import React from 'react'; import { ReactComponent as AllActivityIcon } from '../../assets/svg/all-activity.svg'; import { ReactComponent as MailIcon } from '../../assets/svg/ic-mail.svg'; @@ -26,15 +28,29 @@ import { mockNonTaskInternalDestinationOptions, mockTaskInternalDestinationOptions, } from '../../mocks/AlertUtil.mock'; +import { searchData } from '../../rest/miscAPI'; import { getAlertActionTypeDisplayName, getAlertsActionTypeIcon, getDisplayNameForEntities, + getFieldByArgumentType, getFilteredDestinationOptions, getFunctionDisplayName, listLengthValidator, } from './AlertsUtil'; +jest.mock('../../components/common/AsyncSelect/AsyncSelect', () => ({ + AsyncSelect: jest + .fn() + .mockImplementation(({ api }: { api: () => void }) => ( + + )), +})); + +jest.mock('../../rest/miscAPI', () => ({ + searchData: jest.fn(), +})); + describe('AlertsUtil tests', () => { it('getFunctionDisplayName should return correct text for matchAnyEntityFqn', () => { expect(getFunctionDisplayName('matchAnyEntityFqn')).toBe( @@ -213,3 +229,279 @@ describe('AlertsUtil tests', () => { }); }); }); + +describe('getFieldByArgumentType tests', () => { + it('should return correct fields for argumentType fqnList', async () => { + const field = getFieldByArgumentType(0, 'fqnList', 0, 'table'); + + render(field); + + const selectDiv = screen.getByText('AsyncSelect'); + + await act(async () => { + userEvent.click(selectDiv); + }); + + expect(searchData).toHaveBeenCalledWith( + undefined, + 1, + 50, + '', + '', + '', + 'table_search_index' + ); + }); + + it('should return correct fields for argumentType domainList', async () => { + const field = getFieldByArgumentType(0, 'domainList', 0, 'container'); + + render(field); + + const selectDiv = screen.getByText('AsyncSelect'); + + await act(async () => { + userEvent.click(selectDiv); + }); + + expect(searchData).toHaveBeenCalledWith( + undefined, + 1, + 50, + '', + '', + '', + 'domain_search_index' + ); + }); + + it('should return correct fields for argumentType tableNameList', async () => { + const field = getFieldByArgumentType( + 0, + 'tableNameList', + 0, + 'selectedTrigger' + ); + + render(field); + + const selectDiv = screen.getByText('AsyncSelect'); + + await act(async () => { + userEvent.click(selectDiv); + }); + + expect(searchData).toHaveBeenCalledWith( + undefined, + 1, + 50, + '', + '', + '', + 'table_search_index' + ); + }); + + it('should return correct fields for argumentType ownerNameList', async () => { + const field = getFieldByArgumentType( + 0, + 'ownerNameList', + 0, + 'selectedTrigger' + ); + + render(field); + + const selectDiv = screen.getByText('AsyncSelect'); + + await act(async () => { + userEvent.click(selectDiv); + }); + + expect(searchData).toHaveBeenCalledWith( + undefined, + 1, + 50, + 'isBot:false', + '', + '', + ['team_search_index', 'user_search_index'] + ); + }); + + it('should return correct fields for argumentType updateByUserList', async () => { + const field = getFieldByArgumentType( + 0, + 'updateByUserList', + 0, + 'selectedTrigger' + ); + + render(field); + + const selectDiv = screen.getByText('AsyncSelect'); + + await act(async () => { + userEvent.click(selectDiv); + }); + + expect(searchData).toHaveBeenCalledWith( + undefined, + 1, + 50, + '', + '', + '', + 'user_search_index' + ); + }); + + it('should return correct fields for argumentType userList', async () => { + const field = getFieldByArgumentType(0, 'userList', 0, 'selectedTrigger'); + + render(field); + + const selectDiv = screen.getByText('AsyncSelect'); + + await act(async () => { + userEvent.click(selectDiv); + }); + + expect(searchData).toHaveBeenCalledWith( + undefined, + 1, + 50, + 'isBot:false', + '', + '', + 'user_search_index' + ); + }); + + it('should return correct fields for argumentType eventTypeList', async () => { + const field = getFieldByArgumentType( + 0, + 'eventTypeList', + 0, + 'selectedTrigger' + ); + + render(field); + + const selectDiv = screen.getByTestId('event-type-select'); + + expect(selectDiv).toBeInTheDocument(); + }); + + it('should return correct fields for argumentType entityIdList', () => { + const field = getFieldByArgumentType( + 0, + 'entityIdList', + 0, + 'selectedTrigger' + ); + + render(field); + + const selectDiv = screen.getByTestId('entity-id-select'); + + expect(selectDiv).toBeInTheDocument(); + }); + + it('should return correct fields for argumentType pipelineStateList', () => { + const field = getFieldByArgumentType( + 0, + 'pipelineStateList', + 0, + 'selectedTrigger' + ); + + render(field); + + const selectDiv = screen.getByTestId('pipeline-status-select'); + + expect(selectDiv).toBeInTheDocument(); + }); + + it('should return correct fields for argumentType ingestionPipelineStateList', () => { + const field = getFieldByArgumentType( + 0, + 'ingestionPipelineStateList', + 0, + 'selectedTrigger' + ); + + render(field); + + const selectDiv = screen.getByTestId('pipeline-status-select'); + + expect(selectDiv).toBeInTheDocument(); + }); + + it('should return correct fields for argumentType testStatusList', () => { + const field = getFieldByArgumentType( + 0, + 'testStatusList', + 0, + 'selectedTrigger' + ); + + render(field); + + const selectDiv = screen.getByTestId('test-status-select'); + + expect(selectDiv).toBeInTheDocument(); + }); + + it('should return correct fields for argumentType testResultList', () => { + const field = getFieldByArgumentType( + 0, + 'testResultList', + 0, + 'selectedTrigger' + ); + + render(field); + + const selectDiv = screen.getByTestId('test-result-select'); + + expect(selectDiv).toBeInTheDocument(); + }); + + it('should return correct fields for argumentType testSuiteList', async () => { + const field = getFieldByArgumentType( + 0, + 'testSuiteList', + 0, + 'selectedTrigger' + ); + + render(field); + + const selectDiv = screen.getByText('AsyncSelect'); + + await act(async () => { + userEvent.click(selectDiv); + }); + + expect(searchData).toHaveBeenCalledWith( + undefined, + 1, + 50, + '', + '', + '', + 'test_suite_search_index' + ); + }); + + it('should not return select component for random argumentType', () => { + const field = getFieldByArgumentType(0, 'unknown', 0, 'selectedTrigger'); + + render(field); + + const selectDiv = screen.queryByText('AsyncSelect'); + + expect(selectDiv).toBeNull(); + }); +}); diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/Alerts/AlertsUtil.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/Alerts/AlertsUtil.tsx index 06663d7d9bad..cc5cb28b1ea2 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/Alerts/AlertsUtil.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/Alerts/AlertsUtil.tsx @@ -385,6 +385,91 @@ export const getDestinationConfigField = ( } }; +export const getMessageFromArgumentName = (argumentName: string) => { + switch (argumentName) { + case 'fqnList': + return t('message.field-text-is-required', { + fieldText: t('label.entity-list', { + entity: t('label.fqn-uppercase'), + }), + }); + case 'domainList': + return t('message.field-text-is-required', { + fieldText: t('label.entity-list', { + entity: t('label.domain'), + }), + }); + case 'tableNameList': + return t('message.field-text-is-required', { + fieldText: t('label.entity-list', { + entity: t('label.entity-name', { + entity: t('label.table'), + }), + }), + }); + case 'ownerNameList': + return t('message.field-text-is-required', { + fieldText: t('label.entity-list', { + entity: t('label.entity-name', { + entity: t('label.owner'), + }), + }), + }); + case 'updateByUserList': + case 'userList': + return t('message.field-text-is-required', { + fieldText: t('label.entity-list', { + entity: t('label.entity-name', { + entity: t('label.user'), + }), + }), + }); + case 'eventTypeList': + return t('message.field-text-is-required', { + fieldText: t('label.entity-list', { + entity: t('label.entity-name', { + entity: t('label.event'), + }), + }), + }); + case 'entityIdList': + return t('message.field-text-is-required', { + fieldText: t('label.entity-list', { + entity: t('label.entity-id', { + entity: t('label.data-asset'), + }), + }), + }); + case 'pipelineStateList': + case 'ingestionPipelineStateList': + return t('message.field-text-is-required', { + fieldText: t('label.entity-list', { + entity: t('label.pipeline-state'), + }), + }); + case 'testStatusList': + return t('message.field-text-is-required', { + fieldText: t('label.entity-list', { + entity: t('label.test-suite-status'), + }), + }); + case 'testResultList': + return t('message.field-text-is-required', { + fieldText: t('label.entity-list', { + entity: t('label.test-case-result'), + }), + }); + case 'testSuiteList': + return t('message.field-text-is-required', { + fieldText: t('label.entity-list', { + entity: t('label.test-suite'), + }), + }); + default: + return ''; + } +}; + export const getFieldByArgumentType = ( fieldName: number, argument: string, @@ -407,129 +492,65 @@ export const getFieldByArgumentType = ( switch (argument) { case 'fqnList': field = ( - - - - - + ); break; case 'domainList': field = ( - - - - - + ); break; case 'tableNameList': field = ( - - - - - + ); break; case 'ownerNameList': field = ( - - - - - + ); break; @@ -537,248 +558,126 @@ export const getFieldByArgumentType = ( case 'updateByUserList': case 'userList': field = ( - - - - - + ); break; case 'eventTypeList': field = ( - - - ); break; case 'entityIdList': field = ( - - - ); break; case 'pipelineStateList': field = ( - - - ); break; case 'ingestionPipelineStateList': field = ( - - - ); break; case 'testStatusList': field = ( - - - ); break; case 'testResultList': field = ( - - - ); break; case 'testSuiteList': field = ( - - - - - + ); break; @@ -788,7 +687,18 @@ export const getFieldByArgumentType = ( return ( <> - {field} + + + {field} + +