This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Email Sender name validation and add tests related to Email Desti…
…nation (#189) * Remove dashes from valid sender name requirements * Add additional tests for email changes
- Loading branch information
Showing
4 changed files
with
144 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ import { mount } from 'enzyme'; | |
import ManageEmailGroups from './ManageEmailGroups'; | ||
import { httpClientMock } from '../../../../../../test/mocks'; | ||
|
||
const runAllPromises = () => new Promise(setImmediate); | ||
|
||
const onClickCancel = jest.fn(); | ||
const onClickSave = jest.fn(); | ||
|
||
|
@@ -50,4 +52,72 @@ describe('ManageEmailGroups', () => { | |
); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test('loadInitialValues', async () => { | ||
const mockEmailGroup = { | ||
id: 'id', | ||
name: 'test_group', | ||
emails: [{ email: '[email protected]' }], | ||
}; | ||
|
||
// Mock return in getEmailGroups function | ||
httpClientMock.get.mockResolvedValue({ | ||
data: { ok: true, emailGroups: [mockEmailGroup] }, | ||
}); | ||
|
||
const wrapper = mount( | ||
<ManageEmailGroups | ||
httpClient={httpClientMock} | ||
isVisible={true} | ||
onClickCancel={onClickCancel} | ||
onClickSave={onClickSave} | ||
/> | ||
); | ||
|
||
await runAllPromises(); | ||
expect(wrapper.instance().state.initialValues.emailGroups.length).toBe(1); | ||
expect(wrapper.instance().state.initialValues.emailGroups[0].emails).toEqual([ | ||
{ label: '[email protected]' }, | ||
]); | ||
}); | ||
|
||
test('getEmailGroups logs resp.data.err when ok:false', async () => { | ||
const log = jest.spyOn(global.console, 'log'); | ||
// Mock return in getEmailGroups function | ||
httpClientMock.get.mockResolvedValue({ | ||
data: { ok: false, err: 'test' }, | ||
}); | ||
|
||
const wrapper = mount( | ||
<ManageEmailGroups | ||
httpClient={httpClientMock} | ||
isVisible={true} | ||
onClickCancel={onClickCancel} | ||
onClickSave={onClickSave} | ||
/> | ||
); | ||
|
||
await runAllPromises(); | ||
expect(log).toHaveBeenCalled(); | ||
expect(log).toHaveBeenCalledWith('Unable to get email groups', 'test'); | ||
}); | ||
|
||
test('loads empty list of email groups when ok:false', async () => { | ||
// Mock return in getEmailGroups function | ||
httpClientMock.get.mockResolvedValue({ | ||
data: { ok: false, err: 'test' }, | ||
}); | ||
|
||
const wrapper = mount( | ||
<ManageEmailGroups | ||
httpClient={httpClientMock} | ||
isVisible={true} | ||
onClickCancel={onClickCancel} | ||
onClickSave={onClickSave} | ||
/> | ||
); | ||
|
||
await runAllPromises(); | ||
expect(wrapper.instance().state.initialValues.emailGroups).toEqual([]); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -17,9 +17,10 @@ import React from 'react'; | |
import { mount } from 'enzyme'; | ||
|
||
import ManageSenders from './ManageSenders'; | ||
import * as helpers from './utils/helpers'; | ||
import { httpClientMock } from '../../../../../../test/mocks'; | ||
|
||
const runAllPromises = () => new Promise(setImmediate); | ||
|
||
const onClickCancel = jest.fn(); | ||
const onClickSave = jest.fn(); | ||
|
||
|
@@ -51,4 +52,73 @@ describe('ManageSenders', () => { | |
); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test('loadInitialValues', async () => { | ||
const mockEmailAccount = { | ||
id: 'id', | ||
name: 'test_account', | ||
email: '[email protected]', | ||
host: 'smtp.test.com', | ||
port: 25, | ||
method: 'none', | ||
}; | ||
|
||
// Mock return in getSenders function | ||
httpClientMock.get.mockResolvedValue({ | ||
data: { ok: true, emailAccounts: [mockEmailAccount] }, | ||
}); | ||
|
||
const wrapper = mount( | ||
<ManageSenders | ||
httpClient={httpClientMock} | ||
isVisible={true} | ||
onClickCancel={onClickCancel} | ||
onClickSave={onClickSave} | ||
/> | ||
); | ||
|
||
await runAllPromises(); | ||
expect(wrapper.instance().state.initialValues.senders.length).toBe(1); | ||
expect(wrapper.instance().state.initialValues.senders[0].name).toBe('test_account'); | ||
}); | ||
|
||
test('getSenders logs resp.data.err when ok:false', async () => { | ||
const log = jest.spyOn(global.console, 'log'); | ||
// Mock return in getSenders function | ||
httpClientMock.get.mockResolvedValue({ | ||
data: { ok: false, err: 'test' }, | ||
}); | ||
|
||
const wrapper = mount( | ||
<ManageSenders | ||
httpClient={httpClientMock} | ||
isVisible={true} | ||
onClickCancel={onClickCancel} | ||
onClickSave={onClickSave} | ||
/> | ||
); | ||
|
||
await runAllPromises(); | ||
expect(log).toHaveBeenCalled(); | ||
expect(log).toHaveBeenCalledWith('Unable to get email accounts', 'test'); | ||
}); | ||
|
||
test('loads empty list of senders when ok:false', async () => { | ||
// Mock return in getSenders function | ||
httpClientMock.get.mockResolvedValue({ | ||
data: { ok: false, err: 'test' }, | ||
}); | ||
|
||
const wrapper = mount( | ||
<ManageSenders | ||
httpClient={httpClientMock} | ||
isVisible={true} | ||
onClickCancel={onClickCancel} | ||
onClickSave={onClickSave} | ||
/> | ||
); | ||
|
||
await runAllPromises(); | ||
expect(wrapper.instance().state.initialValues.senders).toEqual([]); | ||
}); | ||
}); |