diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/email/email_params.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/email/email_params.test.tsx
index 3cd54b58bf29a..1020b784f3c58 100644
--- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/email/email_params.test.tsx
+++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/email/email_params.test.tsx
@@ -33,4 +33,97 @@ describe('EmailParamsFields renders', () => {
expect(wrapper.find('[data-test-subj="subjectInput"]').length > 0).toBeTruthy();
expect(wrapper.find('[data-test-subj="messageTextArea"]').length > 0).toBeTruthy();
});
+
+ test('message param field is rendered with default value if not set', () => {
+ const actionParams = {
+ cc: [],
+ bcc: [],
+ to: ['test@test.com'],
+ subject: 'test',
+ };
+
+ const editAction = jest.fn();
+ const wrapper = mountWithIntl(
+
+ );
+
+ expect(editAction).toHaveBeenCalledWith('message', 'Some default message', 0);
+ });
+
+ test('when the default message changes, so is the underlying message if it was set by the previous default', () => {
+ const actionParams = {
+ cc: [],
+ bcc: [],
+ to: ['test@test.com'],
+ subject: 'test',
+ };
+
+ const editAction = jest.fn();
+ const wrapper = mountWithIntl(
+
+ );
+
+ expect(editAction).toHaveBeenCalledWith('message', 'Some default message', 0);
+
+ wrapper.setProps({
+ defaultMessage: 'Some different default message',
+ });
+
+ expect(editAction).toHaveBeenCalledWith('message', 'Some different default message', 0);
+ });
+
+ test('when the default message changes, it doesnt change the underlying message if it wasnt set by a previous default', () => {
+ const actionParams = {
+ cc: [],
+ bcc: [],
+ to: ['test@test.com'],
+ subject: 'test',
+ };
+
+ const editAction = jest.fn();
+ const wrapper = mountWithIntl(
+
+ );
+
+ expect(editAction).toHaveBeenCalledWith('message', 'Some default message', 0);
+
+ // simulate value being updated
+ const valueToSimulate = 'some new value';
+ wrapper
+ .find('[data-test-subj="messageTextArea"]')
+ .first()
+ .simulate('change', { target: { value: valueToSimulate } });
+ expect(editAction).toHaveBeenCalledWith('message', valueToSimulate, 0);
+ wrapper.setProps({
+ actionParams: {
+ ...actionParams,
+ message: valueToSimulate,
+ },
+ });
+
+ // simulate default changing
+ wrapper.setProps({
+ defaultMessage: 'Some different default message',
+ });
+
+ expect(editAction).not.toHaveBeenCalledWith('message', 'Some different default message', 0);
+ });
});
diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/server_log/server_log_params.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/server_log/server_log_params.test.tsx
index 0552a126ca66f..86dd304bf6b12 100644
--- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/server_log/server_log_params.test.tsx
+++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/server_log/server_log_params.test.tsx
@@ -9,8 +9,8 @@ import { ServerLogLevelOptions } from '.././types';
import ServerLogParamsFields from './server_log_params';
describe('ServerLogParamsFields renders', () => {
- const editAction = jest.fn();
test('all params fields is rendered', () => {
+ const editAction = jest.fn();
const actionParams = {
level: ServerLogLevelOptions.TRACE,
message: 'test',
@@ -35,20 +35,103 @@ describe('ServerLogParamsFields renders', () => {
test('level param field is rendered with default value if not selected', () => {
const actionParams = {
message: 'test message',
- level: ServerLogLevelOptions.INFO,
};
+ const editAction = jest.fn();
+
+ mountWithIntl(
+
+ );
+
+ expect(editAction).toHaveBeenCalledWith('level', 'info', 0);
+ });
+
+ test('message param field is rendered with default value if not set', () => {
+ const actionParams = {
+ level: ServerLogLevelOptions.TRACE,
+ };
+
+ const editAction = jest.fn();
+
+ mountWithIntl(
+
+ );
+
+ expect(editAction).toHaveBeenCalledWith('message', 'Some default message', 0);
+ });
+
+ test('when the default message changes, so is the underlying message if it was set by the previous default', () => {
+ const actionParams = {
+ level: ServerLogLevelOptions.TRACE,
+ };
+
+ const editAction = jest.fn();
const wrapper = mountWithIntl(
{}}
+ editAction={editAction}
index={0}
/>
);
- expect(wrapper.find('[data-test-subj="loggingLevelSelect"]').length > 0).toBeTruthy();
- expect(
- wrapper.find('[data-test-subj="loggingLevelSelect"]').first().prop('value')
- ).toStrictEqual('info');
- expect(wrapper.find('[data-test-subj="messageTextArea"]').length > 0).toBeTruthy();
+
+ expect(editAction).toHaveBeenCalledWith('message', 'Some default message', 0);
+
+ wrapper.setProps({
+ defaultMessage: 'Some different default message',
+ });
+
+ expect(editAction).toHaveBeenCalledWith('message', 'Some different default message', 0);
+ });
+
+ test('when the default message changes, it doesnt change the underlying message if it wasnt set by a previous default', () => {
+ const actionParams = {
+ level: ServerLogLevelOptions.TRACE,
+ };
+
+ const editAction = jest.fn();
+ const wrapper = mountWithIntl(
+
+ );
+
+ expect(editAction).toHaveBeenCalledWith('message', 'Some default message', 0);
+
+ // simulate value being updated
+ const valueToSimulate = 'some new value';
+ wrapper
+ .find('[data-test-subj="messageTextArea"]')
+ .first()
+ .simulate('change', { target: { value: valueToSimulate } });
+ expect(editAction).toHaveBeenCalledWith('message', valueToSimulate, 0);
+ wrapper.setProps({
+ actionParams: {
+ ...actionParams,
+ message: valueToSimulate,
+ },
+ });
+
+ // simulate default changing
+ wrapper.setProps({
+ defaultMessage: 'Some different default message',
+ });
+
+ expect(editAction).not.toHaveBeenCalledWith('message', 'Some different default message', 0);
});
});
diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/server_log/server_log_params.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/server_log/server_log_params.tsx
index ea734439ef41a..ce426c72b64b4 100644
--- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/server_log/server_log_params.tsx
+++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/server_log/server_log_params.tsx
@@ -10,9 +10,9 @@ import { ActionParamsProps } from '../../../../types';
import { ServerLogActionParams } from '.././types';
import { TextAreaWithMessageVariables } from '../../text_area_with_message_variables';
-export const ServerLogParamsFields: React.FunctionComponent> = ({ actionParams, editAction, index, errors, messageVariables, defaultMessage }) => {
+export const ServerLogParamsFields: React.FunctionComponent<
+ ActionParamsProps
+> = ({ actionParams, editAction, index, errors, messageVariables, defaultMessage }) => {
const { message, level } = actionParams;
const levelOptions = [
{ value: 'trace', text: 'Trace' },
@@ -23,7 +23,7 @@ export const ServerLogParamsFields: React.FunctionComponent {
- if (!actionParams?.level) {
+ if (!actionParams.level) {
editAction('level', 'info', index);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
diff --git a/x-pack/plugins/triggers_actions_ui/public/types.ts b/x-pack/plugins/triggers_actions_ui/public/types.ts
index be8b7b9757e9e..a4eac1ab1da21 100644
--- a/x-pack/plugins/triggers_actions_ui/public/types.ts
+++ b/x-pack/plugins/triggers_actions_ui/public/types.ts
@@ -48,7 +48,7 @@ export interface ActionConnectorFieldsProps {
}
export interface ActionParamsProps {
- actionParams: TParams;
+ actionParams: Partial;
index: number;
editAction: (key: string, value: AlertActionParam, index: number) => void;
errors: IErrorObject;