Skip to content

Commit f9c7560

Browse files
committed
added missing test
1 parent 00f7ef3 commit f9c7560

File tree

4 files changed

+189
-13
lines changed

4 files changed

+189
-13
lines changed

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/email/email_params.test.tsx

+93
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,97 @@ describe('EmailParamsFields renders', () => {
3333
expect(wrapper.find('[data-test-subj="subjectInput"]').length > 0).toBeTruthy();
3434
expect(wrapper.find('[data-test-subj="messageTextArea"]').length > 0).toBeTruthy();
3535
});
36+
37+
test('message param field is rendered with default value if not set', () => {
38+
const actionParams = {
39+
cc: [],
40+
bcc: [],
41+
to: ['test@test.com'],
42+
subject: 'test',
43+
};
44+
45+
const editAction = jest.fn();
46+
const wrapper = mountWithIntl(
47+
<EmailParamsFields
48+
actionParams={actionParams}
49+
errors={{ to: [], cc: [], bcc: [], subject: [], message: [] }}
50+
editAction={editAction}
51+
defaultMessage={'Some default message'}
52+
index={0}
53+
/>
54+
);
55+
56+
expect(editAction).toHaveBeenCalledWith('message', 'Some default message', 0);
57+
});
58+
59+
test('when the default message changes, so is the underlying message if it was set by the previous default', () => {
60+
const actionParams = {
61+
cc: [],
62+
bcc: [],
63+
to: ['test@test.com'],
64+
subject: 'test',
65+
};
66+
67+
const editAction = jest.fn();
68+
const wrapper = mountWithIntl(
69+
<EmailParamsFields
70+
actionParams={actionParams}
71+
errors={{ to: [], cc: [], bcc: [], subject: [], message: [] }}
72+
editAction={editAction}
73+
defaultMessage={'Some default message'}
74+
index={0}
75+
/>
76+
);
77+
78+
expect(editAction).toHaveBeenCalledWith('message', 'Some default message', 0);
79+
80+
wrapper.setProps({
81+
defaultMessage: 'Some different default message',
82+
});
83+
84+
expect(editAction).toHaveBeenCalledWith('message', 'Some different default message', 0);
85+
});
86+
87+
test('when the default message changes, it doesnt change the underlying message if it wasnt set by a previous default', () => {
88+
const actionParams = {
89+
cc: [],
90+
bcc: [],
91+
to: ['test@test.com'],
92+
subject: 'test',
93+
};
94+
95+
const editAction = jest.fn();
96+
const wrapper = mountWithIntl(
97+
<EmailParamsFields
98+
actionParams={actionParams}
99+
errors={{ to: [], cc: [], bcc: [], subject: [], message: [] }}
100+
editAction={editAction}
101+
defaultMessage={'Some default message'}
102+
index={0}
103+
/>
104+
);
105+
106+
expect(editAction).toHaveBeenCalledWith('message', 'Some default message', 0);
107+
108+
// simulate value being updated
109+
const valueToSimulate = 'some new value';
110+
wrapper
111+
.find('[data-test-subj="messageTextArea"]')
112+
.first()
113+
.simulate('change', { target: { value: valueToSimulate } });
114+
expect(editAction).toHaveBeenCalledWith('message', valueToSimulate, 0);
115+
wrapper.setProps({
116+
actionParams: {
117+
...actionParams,
118+
message: valueToSimulate,
119+
},
120+
});
121+
122+
// simulate default changing
123+
wrapper.setProps({
124+
defaultMessage: 'Some different default message',
125+
});
126+
127+
expect(editAction).not.toHaveBeenCalledWith('message', 'Some different default message', 0);
128+
});
36129
});

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/server_log/server_log_params.test.tsx

+91-8
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { ServerLogLevelOptions } from '.././types';
99
import ServerLogParamsFields from './server_log_params';
1010

1111
describe('ServerLogParamsFields renders', () => {
12-
const editAction = jest.fn();
1312
test('all params fields is rendered', () => {
13+
const editAction = jest.fn();
1414
const actionParams = {
1515
level: ServerLogLevelOptions.TRACE,
1616
message: 'test',
@@ -35,20 +35,103 @@ describe('ServerLogParamsFields renders', () => {
3535
test('level param field is rendered with default value if not selected', () => {
3636
const actionParams = {
3737
message: 'test message',
38-
level: ServerLogLevelOptions.INFO,
3938
};
39+
const editAction = jest.fn();
40+
41+
mountWithIntl(
42+
<ServerLogParamsFields
43+
actionParams={actionParams}
44+
errors={{ message: [] }}
45+
editAction={editAction}
46+
index={0}
47+
/>
48+
);
49+
50+
expect(editAction).toHaveBeenCalledWith('level', 'info', 0);
51+
});
52+
53+
test('message param field is rendered with default value if not set', () => {
54+
const actionParams = {
55+
level: ServerLogLevelOptions.TRACE,
56+
};
57+
58+
const editAction = jest.fn();
59+
60+
mountWithIntl(
61+
<ServerLogParamsFields
62+
actionParams={actionParams}
63+
defaultMessage={'Some default message'}
64+
errors={{ message: [] }}
65+
editAction={editAction}
66+
index={0}
67+
/>
68+
);
69+
70+
expect(editAction).toHaveBeenCalledWith('message', 'Some default message', 0);
71+
});
72+
73+
test('when the default message changes, so is the underlying message if it was set by the previous default', () => {
74+
const actionParams = {
75+
level: ServerLogLevelOptions.TRACE,
76+
};
77+
78+
const editAction = jest.fn();
4079
const wrapper = mountWithIntl(
4180
<ServerLogParamsFields
4281
actionParams={actionParams}
82+
defaultMessage={'Some default message'}
4383
errors={{ message: [] }}
44-
editAction={() => {}}
84+
editAction={editAction}
4585
index={0}
4686
/>
4787
);
48-
expect(wrapper.find('[data-test-subj="loggingLevelSelect"]').length > 0).toBeTruthy();
49-
expect(
50-
wrapper.find('[data-test-subj="loggingLevelSelect"]').first().prop('value')
51-
).toStrictEqual('info');
52-
expect(wrapper.find('[data-test-subj="messageTextArea"]').length > 0).toBeTruthy();
88+
89+
expect(editAction).toHaveBeenCalledWith('message', 'Some default message', 0);
90+
91+
wrapper.setProps({
92+
defaultMessage: 'Some different default message',
93+
});
94+
95+
expect(editAction).toHaveBeenCalledWith('message', 'Some different default message', 0);
96+
});
97+
98+
test('when the default message changes, it doesnt change the underlying message if it wasnt set by a previous default', () => {
99+
const actionParams = {
100+
level: ServerLogLevelOptions.TRACE,
101+
};
102+
103+
const editAction = jest.fn();
104+
const wrapper = mountWithIntl(
105+
<ServerLogParamsFields
106+
actionParams={actionParams}
107+
defaultMessage={'Some default message'}
108+
errors={{ message: [] }}
109+
editAction={editAction}
110+
index={0}
111+
/>
112+
);
113+
114+
expect(editAction).toHaveBeenCalledWith('message', 'Some default message', 0);
115+
116+
// simulate value being updated
117+
const valueToSimulate = 'some new value';
118+
wrapper
119+
.find('[data-test-subj="messageTextArea"]')
120+
.first()
121+
.simulate('change', { target: { value: valueToSimulate } });
122+
expect(editAction).toHaveBeenCalledWith('message', valueToSimulate, 0);
123+
wrapper.setProps({
124+
actionParams: {
125+
...actionParams,
126+
message: valueToSimulate,
127+
},
128+
});
129+
130+
// simulate default changing
131+
wrapper.setProps({
132+
defaultMessage: 'Some different default message',
133+
});
134+
135+
expect(editAction).not.toHaveBeenCalledWith('message', 'Some different default message', 0);
53136
});
54137
});

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/server_log/server_log_params.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import { ActionParamsProps } from '../../../../types';
1010
import { ServerLogActionParams } from '.././types';
1111
import { TextAreaWithMessageVariables } from '../../text_area_with_message_variables';
1212

13-
export const ServerLogParamsFields: React.FunctionComponent<ActionParamsProps<
14-
ServerLogActionParams
15-
>> = ({ actionParams, editAction, index, errors, messageVariables, defaultMessage }) => {
13+
export const ServerLogParamsFields: React.FunctionComponent<
14+
ActionParamsProps<ServerLogActionParams>
15+
> = ({ actionParams, editAction, index, errors, messageVariables, defaultMessage }) => {
1616
const { message, level } = actionParams;
1717
const levelOptions = [
1818
{ value: 'trace', text: 'Trace' },
@@ -23,7 +23,7 @@ export const ServerLogParamsFields: React.FunctionComponent<ActionParamsProps<
2323
{ value: 'fatal', text: 'Fatal' },
2424
];
2525
useEffect(() => {
26-
if (!actionParams?.level) {
26+
if (!actionParams.level) {
2727
editAction('level', 'info', index);
2828
}
2929
// eslint-disable-next-line react-hooks/exhaustive-deps

x-pack/plugins/triggers_actions_ui/public/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface ActionConnectorFieldsProps<TActionConnector> {
4848
}
4949

5050
export interface ActionParamsProps<TParams> {
51-
actionParams: TParams;
51+
actionParams: Partial<TParams>;
5252
index: number;
5353
editAction: (key: string, value: AlertActionParam, index: number) => void;
5454
errors: IErrorObject;

0 commit comments

Comments
 (0)