Skip to content

Commit

Permalink
Minor: Alert form user list suggestion fixes (open-metadata#15560)
Browse files Browse the repository at this point in the history
* improve user list suggestion in the notification alert form to suggest bots along with users only for `updateByUserList` argument

* refactor code to improve performance and readability of alert utils

* Add unit tests for getFieldByArgumentType function in AlertsUtil
  • Loading branch information
aniketkatkar97 authored Mar 14, 2024
1 parent 2d1cc58 commit 0006988
Show file tree
Hide file tree
Showing 2 changed files with 508 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 }) => (
<button onClick={() => api()}>AsyncSelect</button>
)),
}));

jest.mock('../../rest/miscAPI', () => ({
searchData: jest.fn(),
}));

describe('AlertsUtil tests', () => {
it('getFunctionDisplayName should return correct text for matchAnyEntityFqn', () => {
expect(getFunctionDisplayName('matchAnyEntityFqn')).toBe(
Expand Down Expand Up @@ -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();
});
});
Loading

0 comments on commit 0006988

Please sign in to comment.