-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
189 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: ['[email protected]'], | ||
subject: 'test', | ||
}; | ||
|
||
const editAction = jest.fn(); | ||
const wrapper = mountWithIntl( | ||
<EmailParamsFields | ||
actionParams={actionParams} | ||
errors={{ to: [], cc: [], bcc: [], subject: [], message: [] }} | ||
editAction={editAction} | ||
defaultMessage={'Some default message'} | ||
index={0} | ||
/> | ||
); | ||
|
||
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: ['[email protected]'], | ||
subject: 'test', | ||
}; | ||
|
||
const editAction = jest.fn(); | ||
const wrapper = mountWithIntl( | ||
<EmailParamsFields | ||
actionParams={actionParams} | ||
errors={{ to: [], cc: [], bcc: [], subject: [], message: [] }} | ||
editAction={editAction} | ||
defaultMessage={'Some default message'} | ||
index={0} | ||
/> | ||
); | ||
|
||
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: ['[email protected]'], | ||
subject: 'test', | ||
}; | ||
|
||
const editAction = jest.fn(); | ||
const wrapper = mountWithIntl( | ||
<EmailParamsFields | ||
actionParams={actionParams} | ||
errors={{ to: [], cc: [], bcc: [], subject: [], message: [] }} | ||
editAction={editAction} | ||
defaultMessage={'Some default message'} | ||
index={0} | ||
/> | ||
); | ||
|
||
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters