Skip to content

Commit

Permalink
Implemented tests to confirm SMTP assets are hidden. Minor text edit. (
Browse files Browse the repository at this point in the history
…#550)

* Edited help text to reference only the respective sender types.

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>

* Implemented unit tests to confirm SMTP assets are not visible when SMTP is an unsupported config type.

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>

Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
  • Loading branch information
AWSHurneyt authored Dec 2, 2022
1 parent 63e5f13 commit 8c73802
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { render, waitFor } from '@testing-library/react';
import { render, screen, waitFor } from '@testing-library/react';
import React from 'react';
import { RouteComponentProps } from 'react-router-dom';
import { MOCK_DATA } from '../../../../test/mocks/mockData';
Expand Down Expand Up @@ -42,6 +42,52 @@ describe('<CreateChannel/> spec', () => {
expect(utils.container.firstChild).toMatchSnapshot();
});

it('renders the component without SMTP sender type', async () => {
const notificationServiceMockEmail = jest.fn() as any;
const getEmailChannel = jest.fn(
async (queryObject: object) => MOCK_DATA.email
);
notificationServiceMockEmail.notificationService = {
getChannel: getEmailChannel,
getSenders: jest.fn(async (query) => MOCK_DATA.senders),
getEmailConfigDetails: jest.fn(async (channel) =>
Promise.resolve(channel)
),
updateConfig: updateConfigSuccess,
};
const props = {
location: { search: '' },
match: { params: { id: 'test' } },
};
const mainState = { ...mainStateMock,
availableConfigTypes: [
'slack',
'chime',
'webhook',
'email',
'sns',
'ses_account',
'email_group',
],
};

render(
<MainContext.Provider value={mainState}>
<ServicesContext.Provider value={notificationServiceMockEmail}>
<CoreServicesContext.Provider value={coreServicesMock}>
<CreateChannel
{...(props as RouteComponentProps<{ id: string }>)}
edit={true}
/>
</CoreServicesContext.Provider>
</ServicesContext.Provider>
</MainContext.Provider>
);

expect(await screen.queryByText('Sender type')).toBeNull();
expect(await screen.queryByText('SMTP sender')).toBeNull();
});

it('renders the component for editing slack', async () => {
const notificationServiceMockSlack = jest.fn() as any;
const getSlackChannel = jest.fn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export function EmailSettings(props: EmailSettingsProps) {
<EuiFlexItem style={{ maxWidth: 400 }}>
<EuiFormRow
label="SES sender"
helpText={`A destination only allows one SMTP or SES sender. Use "Create SES sender" to create a sender with its email address, IAM role, AWS region.`}
helpText={`A destination only allows one SES sender. Use "Create SES sender" to create a sender with its email address, IAM role, AWS region.`}
error={context.inputErrors.sesSender.join(' ')}
isInvalid={context.inputErrors.sesSender.length > 0}
>
Expand Down Expand Up @@ -221,7 +221,7 @@ export function EmailSettings(props: EmailSettingsProps) {
<EuiFlexItem style={{ maxWidth: 400 }}>
<EuiFormRow
label="SMTP sender"
helpText={`A destination only allows one SMTP or SES sender. Use "Create SMTP sender" to create a sender with its email address, host, port, encryption method.`}
helpText={`A destination only allows one SMTP sender. Use "Create SMTP sender" to create a sender with its email address, host, port, encryption method.`}
error={context.inputErrors.smtpSender.join(' ')}
isInvalid={context.inputErrors.smtpSender.length > 0}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import React from 'react';
import { routerComponentPropsMock } from '../../../../test/mocks/routerPropsMock';
import {
Expand All @@ -17,16 +17,56 @@ import { MainContext } from '../../Main/Main';
import { EmailSenders } from '../EmailSenders';

describe('<EmailSenders/> spec', () => {
it('renders the component', () => {
it('renders the component with SMTP config type', () => {
const mainState = { ...mainStateMock,
availableConfigTypes: [
'slack',
'chime',
'webhook',
'email',
'sns',
'smtp_account',
'ses_account',
'email_group',
],
};
const utils = render(
<ServicesContext.Provider value={notificationServiceMock}>
<CoreServicesContext.Provider value={coreServicesMock}>
<MainContext.Provider value={mainStateMock}>
<EmailSenders {...routerComponentPropsMock} />
</MainContext.Provider>
</CoreServicesContext.Provider>
</ServicesContext.Provider>
<ServicesContext.Provider value={notificationServiceMock}>
<CoreServicesContext.Provider value={coreServicesMock}>
<MainContext.Provider value={mainState}>
<EmailSenders {...routerComponentPropsMock} />
</MainContext.Provider>
</CoreServicesContext.Provider>
</ServicesContext.Provider>
);
expect(utils.container.firstChild).toMatchSnapshot();
expect(screen.queryByText('SMTP senders')).not.toBeNull();
expect(screen.queryByText('SES senders')).not.toBeNull();
});

it('renders the component without SMTP config type', async () => {
const mainState = { ...mainStateMock,
availableConfigTypes: [
'slack',
'chime',
'webhook',
'email',
'sns',
'ses_account',
'email_group',
],
};
const utils = render(
<ServicesContext.Provider value={notificationServiceMock}>
<CoreServicesContext.Provider value={coreServicesMock}>
<MainContext.Provider value={mainState}>
<EmailSenders {...routerComponentPropsMock} />
</MainContext.Provider>
</CoreServicesContext.Provider>
</ServicesContext.Provider>
);
expect(utils.container.firstChild).toMatchSnapshot();
expect(screen.queryByText('SMTP senders')).toBeNull();
expect(screen.queryByText('SES senders')).not.toBeNull();
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<EmailSenders/> spec renders the component 1`] = `
exports[`<EmailSenders/> spec renders the component with SMTP config type 1`] = `
<h1
class="euiTitle euiTitle--large"
>
Email senders
</h1>
`;

exports[`<EmailSenders/> spec renders the component without SMTP config type 1`] = `
<h1
class="euiTitle euiTitle--large"
>
Expand Down

0 comments on commit 8c73802

Please sign in to comment.