Skip to content

Commit

Permalink
Added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Nov 11, 2020
1 parent 6e44558 commit c7e6efc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/alerts/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from './alert_instance';
export * from './alert_task_instance';
export * from './alert_navigation';
export * from './alert_instance_summary';
export * from './builtin_action_groups';

export interface ActionGroup {
id: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ beforeEach(() => jest.resetAllMocks());
describe('actionVariablesFromAlertType', () => {
test('should return correct variables when no state or context provided', async () => {
const alertType = getAlertType({ context: [], state: [], params: [] });
expect(actionVariablesFromAlertType(alertType)).toMatchInlineSnapshot(`
expect(actionVariablesFromAlertType(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [
Object {
"description": "The id of the alert.",
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('actionVariablesFromAlertType', () => {
state: [],
params: [],
});
expect(actionVariablesFromAlertType(alertType)).toMatchInlineSnapshot(`
expect(actionVariablesFromAlertType(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [
Object {
"description": "The id of the alert.",
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('actionVariablesFromAlertType', () => {
],
params: [],
});
expect(actionVariablesFromAlertType(alertType)).toMatchInlineSnapshot(`
expect(actionVariablesFromAlertType(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [
Object {
"description": "The id of the alert.",
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('actionVariablesFromAlertType', () => {
],
params: [{ name: 'fooP', description: 'fooP-description' }],
});
expect(actionVariablesFromAlertType(alertType)).toMatchInlineSnapshot(`
expect(actionVariablesFromAlertType(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [
Object {
"description": "The id of the alert.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { act } from 'react-dom/test-utils';
import { actionTypeRegistryMock } from '../../action_type_registry.mock';
import { ValidationResult, Alert, AlertAction } from '../../../types';
import ActionForm from './action_form';
import { ResolvedActionGroup } from '../../../../../alerts/common';
jest.mock('../../lib/action_connector_api', () => ({
loadAllActions: jest.fn(),
loadActionTypes: jest.fn(),
Expand Down Expand Up @@ -217,15 +218,22 @@ describe('action_form', () => {
const wrapper = mountWithIntl(
<ActionForm
actions={initialAlert.actions}
messageVariables={[
{ name: 'testVar1', description: 'test var1' },
{ name: 'testVar2', description: 'test var2' },
]}
messageVariables={{
params: [
{ name: 'testVar1', description: 'test var1' },
{ name: 'testVar2', description: 'test var2' },
],
state: [],
context: [{ name: 'contextVar', description: 'context var1' }],
}}
defaultActionGroupId={'default'}
setActionIdByIndex={(id: string, index: number) => {
initialAlert.actions[index].id = id;
}}
actionGroups={[{ id: 'default', name: 'Default' }]}
actionGroups={[
{ id: 'default', name: 'Default' },
{ id: 'resolved', name: 'Resolved' },
]}
setActionGroupIdByIndex={(group: string, index: number) => {
initialAlert.actions[index].group = group;
}}
Expand Down Expand Up @@ -346,10 +354,52 @@ describe('action_form', () => {
"inputDisplay": "Default",
"value": "default",
},
Object {
"data-test-subj": "addNewActionConnectorActionGroup-0-option-resolved",
"inputDisplay": "Resolved",
"value": "resolved",
},
]
`);
});

it('renders selected Resolved action group', async () => {
const wrapper = await setup([
{
group: ResolvedActionGroup.id,
id: 'test',
actionTypeId: actionType.id,
params: {
message: '',
},
},
]);
const actionOption = wrapper.find(
`[data-test-subj="${actionType.id}-ActionTypeSelectOption"]`
);
actionOption.first().simulate('click');
const actionGroupsSelect = wrapper.find(
`[data-test-subj="addNewActionConnectorActionGroup-0"]`
);
expect((actionGroupsSelect.first().props() as any).options).toMatchInlineSnapshot(`
Array [
Object {
"data-test-subj": "addNewActionConnectorActionGroup-0-option-default",
"inputDisplay": "Default",
"value": "default",
},
Object {
"data-test-subj": "addNewActionConnectorActionGroup-0-option-resolved",
"inputDisplay": "Resolved",
"value": "resolved",
},
]
`);
expect(actionGroupsSelect.first().text()).toEqual(
'Select an option: Resolved, is selectedResolved'
);
});

it('renders available connectors for the selected action type', async () => {
const wrapper = await setup();
const actionOption = wrapper.find(
Expand Down

0 comments on commit c7e6efc

Please sign in to comment.