diff --git a/public/pages/Destinations/components/createDestinations/Email/Sender.js b/public/pages/Destinations/components/createDestinations/Email/Sender.js index 2dd7ee37..ce334bd9 100644 --- a/public/pages/Destinations/components/createDestinations/Email/Sender.js +++ b/public/pages/Destinations/components/createDestinations/Email/Sender.js @@ -62,13 +62,13 @@ const Sender = ({ sender, arrayHelpers, context, index, onDelete }) => { label: 'Sender name', helpText: 'A unique and descriptive name that is easy to search. ' + - 'Valid characters are upper and lowercase a-z, 0-9, _ (underscore) and - (hyphen).', + 'Valid characters are upper and lowercase a-z, 0-9, and _ (underscore).', style: { padding: '10px 0px' }, isInvalid, error: hasError, }} inputProps={{ - placeholder: 'my-sender', + placeholder: 'my_sender', onChange: (e, field, form) => { field.onChange(e); onSenderChange(index, sender, arrayHelpers); diff --git a/public/pages/Destinations/components/createDestinations/Email/utils/validate.js b/public/pages/Destinations/components/createDestinations/Email/utils/validate.js index 28095a23..90a99753 100644 --- a/public/pages/Destinations/components/createDestinations/Email/utils/validate.js +++ b/public/pages/Destinations/components/createDestinations/Email/utils/validate.js @@ -18,7 +18,7 @@ import _ from 'lodash'; export const validateSenderName = (senders) => (value) => { if (!value) return 'Required'; - if (!/^[A-Z0-9_-]+$/i.test(value)) return 'Invalid sender name'; + if (!/^[A-Z0-9_]+$/i.test(value)) return 'Invalid sender name'; const matches = senders.filter((sender) => sender.name === value); if (matches.length > 1) return 'Sender name is already being used'; diff --git a/public/pages/Destinations/containers/CreateDestination/ManageEmailGroups/ManageEmailGroups.test.js b/public/pages/Destinations/containers/CreateDestination/ManageEmailGroups/ManageEmailGroups.test.js index 2a7e61c3..6b7360f8 100644 --- a/public/pages/Destinations/containers/CreateDestination/ManageEmailGroups/ManageEmailGroups.test.js +++ b/public/pages/Destinations/containers/CreateDestination/ManageEmailGroups/ManageEmailGroups.test.js @@ -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: 'test@email.com' }], + }; + + // Mock return in getEmailGroups function + httpClientMock.get.mockResolvedValue({ + data: { ok: true, emailGroups: [mockEmailGroup] }, + }); + + const wrapper = mount( + + ); + + await runAllPromises(); + expect(wrapper.instance().state.initialValues.emailGroups.length).toBe(1); + expect(wrapper.instance().state.initialValues.emailGroups[0].emails).toEqual([ + { label: 'test@email.com' }, + ]); + }); + + 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( + + ); + + 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( + + ); + + await runAllPromises(); + expect(wrapper.instance().state.initialValues.emailGroups).toEqual([]); + }); }); diff --git a/public/pages/Destinations/containers/CreateDestination/ManageSenders/ManageSenders.test.js b/public/pages/Destinations/containers/CreateDestination/ManageSenders/ManageSenders.test.js index 83dfe0be..4b636958 100644 --- a/public/pages/Destinations/containers/CreateDestination/ManageSenders/ManageSenders.test.js +++ b/public/pages/Destinations/containers/CreateDestination/ManageSenders/ManageSenders.test.js @@ -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: 'test@email.com', + host: 'smtp.test.com', + port: 25, + method: 'none', + }; + + // Mock return in getSenders function + httpClientMock.get.mockResolvedValue({ + data: { ok: true, emailAccounts: [mockEmailAccount] }, + }); + + const wrapper = mount( + + ); + + 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( + + ); + + 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( + + ); + + await runAllPromises(); + expect(wrapper.instance().state.initialValues.senders).toEqual([]); + }); });