Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecote committed Oct 15, 2020
1 parent 5ea01f4 commit cb269ab
Show file tree
Hide file tree
Showing 14 changed files with 404 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,51 @@ describe('EmailActionConnectorFields renders', () => {
expect(wrapper.find('[data-test-subj="emailUserInput"]').length > 0).toBeFalsy();
expect(wrapper.find('[data-test-subj="emailPasswordInput"]').length > 0).toBeFalsy();
});

test('should display a message to remember username and password when creating a connector with authentication', () => {
const actionConnector = {
actionTypeId: '.email',
config: {
hasAuth: true,
},
secrets: {},
} as EmailActionConnector;
const wrapper = mountWithIntl(
<EmailActionConnectorFields
action={actionConnector}
errors={{ from: [], port: [], host: [], user: [], password: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
readOnly={false}
/>
);
expect(wrapper.find('[data-test-subj="rememberValuesMessage"]').length).toBeGreaterThan(0);
expect(wrapper.find('[data-test-subj="reenterValuesMessage"]').length).toEqual(0);
});

test('should display a message when editing an authenticated email connector explaining why username and password must be re-entered', () => {
const actionConnector = {
secrets: {},
id: 'test',
actionTypeId: '.email',
name: 'email',
config: {
from: '[email protected]',
hasAuth: true,
},
} as EmailActionConnector;
const wrapper = mountWithIntl(
<EmailActionConnectorFields
action={actionConnector}
errors={{ from: [], port: [], host: [], user: [], password: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
readOnly={false}
/>
);
expect(wrapper.find('[data-test-subj="reenterValuesMessage"]').length).toBeGreaterThan(0);
expect(wrapper.find('[data-test-subj="rememberValuesMessage"]').length).toEqual(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ function getEncryptedFieldNotifyLabel(isCreate: boolean) {
return (
<Fragment>
<EuiSpacer size="s" />
<EuiText color="secondary" size="s">
<EuiText color="secondary" size="s" data-test-subj="rememberValuesMessage">
<FormattedMessage
id="xpack.triggersActionsUI.components.builtinActionTypes.emailAction.rememberValueLabel"
id="xpack.triggersActionsUI.components.builtinActionTypes.emailAction.rememberValuesLabel"
defaultMessage="Remember these values. You must reenter them each time you edit the connector."
/>
</EuiText>
Expand All @@ -301,8 +301,9 @@ function getEncryptedFieldNotifyLabel(isCreate: boolean) {
<EuiCallOut
size="s"
iconType="iInCircle"
data-test-subj="reenterValuesMessage"
title={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.emailAction.reenterValueLabel',
'xpack.triggersActionsUI.components.builtinActionTypes.emailAction.reenterValuesLabel',
{
defaultMessage:
'Username and password are encrypted. Please reenter values for these fields.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,60 @@ describe('JiraActionConnectorFields renders', () => {
wrapper.find('[data-test-subj="connector-jira-apiToken-form-input"]').length > 0
).toBeTruthy();
});

test('should display a message on create to remember credentials', () => {
const actionConnector = {
actionTypeId: '.jira',
isPreconfigured: false,
secrets: {},
config: {},
} as JiraActionConnector;
const deps = {
docLinks: { ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart,
};
const wrapper = mountWithIntl(
<JiraConnectorFields
action={actionConnector}
errors={{ apiUrl: [], email: [], apiToken: [], projectKey: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
docLinks={deps!.docLinks}
readOnly={false}
/>
);
expect(wrapper.find('[data-test-subj="rememberValuesMessage"]').length).toBeGreaterThan(0);
expect(wrapper.find('[data-test-subj="reenterValuesMessage"]').length).toEqual(0);
});

test('should display a message on edit to re-enter credentials', () => {
const actionConnector = {
secrets: {
email: 'email',
apiToken: 'token',
},
id: 'test',
actionTypeId: '.jira',
isPreconfigured: false,
name: 'jira',
config: {
apiUrl: 'https://test/',
projectKey: 'CK',
},
} as JiraActionConnector;
const deps = {
docLinks: { ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart,
};
const wrapper = mountWithIntl(
<JiraConnectorFields
action={actionConnector}
errors={{ apiUrl: [], email: [], apiToken: [], projectKey: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
docLinks={deps!.docLinks}
readOnly={false}
/>
);
expect(wrapper.find('[data-test-subj="reenterValuesMessage"]').length).toBeGreaterThan(0);
expect(wrapper.find('[data-test-subj="rememberValuesMessage"]').length).toEqual(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,19 @@ const JiraConnectorFields: React.FC<ActionConnectorFieldsProps<JiraActionConnect
function getEncryptedFieldNotifyLabel(isCreate: boolean) {
if (isCreate) {
return (
<EuiText color="secondary" size="s">
<EuiText color="secondary" size="s" data-test-subj="rememberValuesMessage">
{i18n.JIRA_REMEMBER_VALUES_LABEL}
</EuiText>
);
}
return <EuiCallOut size="s" iconType="iInCircle" title={i18n.JIRA_REENTER_VALUES_LABEL} />;
return (
<EuiCallOut
size="s"
iconType="iInCircle"
title={i18n.JIRA_REENTER_VALUES_LABEL}
data-test-subj="reenterValuesMessage"
/>
);
}

// eslint-disable-next-line import/no-default-export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,56 @@ describe('PagerDutyActionConnectorFields renders', () => {
);
expect(wrapper.find('[data-test-subj="pagerdutyRoutingKeyInput"]').length > 0).toBeTruthy();
});

test('should display a message on create to remember credentials', () => {
const actionConnector = {
actionTypeId: '.pagerduty',
secrets: {},
config: {},
} as PagerDutyActionConnector;
const deps = {
docLinks: { ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart,
};
const wrapper = mountWithIntl(
<PagerDutyActionConnectorFields
action={actionConnector}
errors={{ index: [], routingKey: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
docLinks={deps!.docLinks}
readOnly={false}
/>
);
expect(wrapper.find('[data-test-subj="rememberValuesMessage"]').length).toBeGreaterThan(0);
expect(wrapper.find('[data-test-subj="reenterValuesMessage"]').length).toEqual(0);
});

test('should display a message on edit to re-enter credentials', () => {
const actionConnector = {
secrets: {
routingKey: 'test',
},
id: 'test',
actionTypeId: '.pagerduty',
name: 'pagerduty',
config: {
apiUrl: 'http:\\test',
},
} as PagerDutyActionConnector;
const deps = {
docLinks: { ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart,
};
const wrapper = mountWithIntl(
<PagerDutyActionConnectorFields
action={actionConnector}
errors={{ index: [], routingKey: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
docLinks={deps!.docLinks}
readOnly={false}
/>
);
expect(wrapper.find('[data-test-subj="reenterValuesMessage"]').length).toBeGreaterThan(0);
expect(wrapper.find('[data-test-subj="rememberValuesMessage"]').length).toEqual(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function getEncryptedFieldNotifyLabel(isCreate: boolean) {
return (
<Fragment>
<EuiSpacer size="s" />
<EuiText color="secondary" size="s">
<EuiText color="secondary" size="s" data-test-subj="rememberValuesMessage">
<FormattedMessage
id="xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.rememberValueLabel"
defaultMessage="Remember this value. You must reenter it each time you edit the connector."
Expand All @@ -111,6 +111,7 @@ function getEncryptedFieldNotifyLabel(isCreate: boolean) {
<EuiCallOut
size="s"
iconType="iInCircle"
data-test-subj="reenterValuesMessage"
title={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.reenterValueLabel',
{ defaultMessage: 'This key is encrypted. Please reenter a value for this field.' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,60 @@ describe('ResilientActionConnectorFields renders', () => {
wrapper.find('[data-test-subj="connector-resilient-apiKeySecret-form-input"]').length > 0
).toBeTruthy();
});

test('should display a message on create to remember credentials', () => {
const actionConnector = {
actionTypeId: '.resilient',
isPreconfigured: false,
config: {},
secrets: {},
} as ResilientActionConnector;
const deps = {
docLinks: { ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart,
};
const wrapper = mountWithIntl(
<ResilientConnectorFields
action={actionConnector}
errors={{ apiUrl: [], apiKeyId: [], apiKeySecret: [], orgId: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
docLinks={deps!.docLinks}
readOnly={false}
/>
);
expect(wrapper.find('[data-test-subj="rememberValuesMessage"]').length).toBeGreaterThan(0);
expect(wrapper.find('[data-test-subj="reenterValuesMessage"]').length).toEqual(0);
});

test('should display a message on edit to re-enter credentials', () => {
const actionConnector = {
secrets: {
apiKeyId: 'key',
apiKeySecret: 'secret',
},
id: 'test',
actionTypeId: '.resilient',
isPreconfigured: false,
name: 'resilient',
config: {
apiUrl: 'https://test/',
orgId: '201',
},
} as ResilientActionConnector;
const deps = {
docLinks: { ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart,
};
const wrapper = mountWithIntl(
<ResilientConnectorFields
action={actionConnector}
errors={{ apiUrl: [], apiKeyId: [], apiKeySecret: [], orgId: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
docLinks={deps!.docLinks}
readOnly={false}
/>
);
expect(wrapper.find('[data-test-subj="reenterValuesMessage"]').length).toBeGreaterThan(0);
expect(wrapper.find('[data-test-subj="rememberValuesMessage"]').length).toEqual(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,19 @@ const ResilientConnectorFields: React.FC<ActionConnectorFieldsProps<ResilientAct
function getEncryptedFieldNotifyLabel(isCreate: boolean) {
if (isCreate) {
return (
<EuiText color="secondary" size="s">
<EuiText color="secondary" size="s" data-test-subj="rememberValuesMessage">
{i18n.REMEMBER_VALUES_LABEL}
</EuiText>
);
}
return <EuiCallOut size="s" iconType="iInCircle" title={i18n.REENTER_VALUES_LABEL} />;
return (
<EuiCallOut
size="s"
iconType="iInCircle"
title={i18n.REENTER_VALUES_LABEL}
data-test-subj="reenterValuesMessage"
/>
);
}

// eslint-disable-next-line import/no-default-export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,59 @@ describe('ServiceNowActionConnectorFields renders', () => {
wrapper.find('[data-test-subj="connector-servicenow-password-form-input"]').length > 0
).toBeTruthy();
});

test('should display a message on create to remember credentials', () => {
const actionConnector = {
actionTypeId: '.servicenow',
isPreconfigured: false,
config: {},
secrets: {},
} as ServiceNowActionConnector;
const deps = {
docLinks: { ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart,
};
const wrapper = mountWithIntl(
<ServiceNowConnectorFields
action={actionConnector}
errors={{ apiUrl: [], username: [], password: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
docLinks={deps!.docLinks}
readOnly={false}
/>
);
expect(wrapper.find('[data-test-subj="rememberValuesMessage"]').length).toBeGreaterThan(0);
expect(wrapper.find('[data-test-subj="reenterValuesMessage"]').length).toEqual(0);
});

test('should display a message on edit to re-enter credentials', () => {
const actionConnector = {
secrets: {
username: 'user',
password: 'pass',
},
id: 'test',
actionTypeId: '.servicenow',
isPreconfigured: false,
name: 'servicenow',
config: {
apiUrl: 'https://test/',
},
} as ServiceNowActionConnector;
const deps = {
docLinks: { ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart,
};
const wrapper = mountWithIntl(
<ServiceNowConnectorFields
action={actionConnector}
errors={{ apiUrl: [], username: [], password: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
docLinks={deps!.docLinks}
readOnly={false}
/>
);
expect(wrapper.find('[data-test-subj="reenterValuesMessage"]').length).toBeGreaterThan(0);
expect(wrapper.find('[data-test-subj="rememberValuesMessage"]').length).toEqual(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,19 @@ const ServiceNowConnectorFields: React.FC<ActionConnectorFieldsProps<
function getEncryptedFieldNotifyLabel(isCreate: boolean) {
if (isCreate) {
return (
<EuiText color="secondary" size="s">
<EuiText color="secondary" size="s" data-test-subj="rememberValuesMessage">
{i18n.REMEMBER_VALUES_LABEL}
</EuiText>
);
}
return <EuiCallOut size="s" iconType="iInCircle" title={i18n.REENTER_VALUES_LABEL} />;
return (
<EuiCallOut
size="s"
iconType="iInCircle"
title={i18n.REENTER_VALUES_LABEL}
data-test-subj="reenterValuesMessage"
/>
);
}

// eslint-disable-next-line import/no-default-export
Expand Down
Loading

0 comments on commit cb269ab

Please sign in to comment.