fix(splunk-on-call-plugin): resolves failing tests
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import { Incident, Team, User } from '../components/types';
|
||||
import {
|
||||
EscalationPolicyInfo,
|
||||
Incident,
|
||||
Team,
|
||||
User,
|
||||
} from '../components/types';
|
||||
|
||||
/*
|
||||
* Copyright 2021 Spotify AB
|
||||
@@ -57,7 +62,7 @@ export const MOCK_INCIDENT: Incident = {
|
||||
pagedPolicies: [
|
||||
{
|
||||
policy: {
|
||||
name: 'Generated Direct User Policy for test',
|
||||
name: 'Generated Direct User Policy for test_user',
|
||||
slug: 'directUserPolicySlug-test',
|
||||
_selfUrl: '/test',
|
||||
},
|
||||
@@ -81,3 +86,14 @@ export const MOCK_TEAM: Team = {
|
||||
version: 1,
|
||||
isDefaultTeam: false,
|
||||
};
|
||||
|
||||
export const ESCALATION_POLICIES: EscalationPolicyInfo[] = [
|
||||
{
|
||||
policy: {
|
||||
name: 'Example',
|
||||
slug: 'team-zEalMCgwYSA0Lt40',
|
||||
_selfUrl: '/api-public/v1/policies/team-zEalMCgwYSA0Lt40',
|
||||
},
|
||||
team: { name: 'Example', slug: 'team-zEalMCgwYSA0Lt40' },
|
||||
},
|
||||
];
|
||||
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
SplunkOnCallClient,
|
||||
} from '../api';
|
||||
import {
|
||||
ESCALATION_POLICIES,
|
||||
MOCKED_ON_CALL,
|
||||
MOCKED_USER,
|
||||
MOCK_INCIDENT,
|
||||
@@ -44,6 +45,7 @@ const mockSplunkOnCallApi: Partial<SplunkOnCallClient> = {
|
||||
getIncidents: async () => [MOCK_INCIDENT],
|
||||
getOnCallUsers: async () => MOCKED_ON_CALL,
|
||||
getTeams: async () => [MOCK_TEAM],
|
||||
getEscalationPolicies: async () => ESCALATION_POLICIES,
|
||||
};
|
||||
|
||||
const configApi: ConfigApi = new ConfigReader({
|
||||
|
||||
@@ -21,31 +21,16 @@ import {
|
||||
alertApiRef,
|
||||
createApiRef,
|
||||
ApiProvider,
|
||||
IdentityApi,
|
||||
identityApiRef,
|
||||
} from '@backstage/core';
|
||||
import { splunkOnCallApiRef } from '../../api';
|
||||
import { TriggerDialog } from './TriggerDialog';
|
||||
import { MOCKED_USER } from '../../api/mocks';
|
||||
import { ESCALATION_POLICIES, MOCKED_USER } from '../../api/mocks';
|
||||
|
||||
describe('TriggerDialog', () => {
|
||||
const mockIdentityApi: Partial<IdentityApi> = {
|
||||
getUserId: () => 'guest@example.com',
|
||||
};
|
||||
|
||||
const mockTriggerAlarmFn = jest.fn();
|
||||
const mockSplunkOnCallApi = {
|
||||
triggerAlarm: mockTriggerAlarmFn,
|
||||
getEscalationPolicies: async () => [
|
||||
{
|
||||
policy: {
|
||||
name: 'Example',
|
||||
slug: 'team-zEalMCgwYSA0Lt40',
|
||||
_selfUrl: '/api-public/v1/policies/team-zEalMCgwYSA0Lt40',
|
||||
},
|
||||
team: { name: 'Example', slug: 'team-zEalMCgwYSA0Lt40' },
|
||||
},
|
||||
],
|
||||
getEscalationPolicies: async () => ESCALATION_POLICIES,
|
||||
};
|
||||
|
||||
const apis = ApiRegistry.from([
|
||||
@@ -56,12 +41,11 @@ describe('TriggerDialog', () => {
|
||||
description: 'Used to report alerts and forward them to the app',
|
||||
}),
|
||||
],
|
||||
[identityApiRef, mockIdentityApi],
|
||||
[splunkOnCallApiRef, mockSplunkOnCallApi],
|
||||
]);
|
||||
|
||||
it('open the dialog and trigger an alarm', async () => {
|
||||
const { getByText, getByRole, getByTestId } = render(
|
||||
const { getByText, getByRole, getAllByRole, getByTestId } = render(
|
||||
wrapInTestApp(
|
||||
<ApiProvider apis={apis}>
|
||||
<TriggerDialog
|
||||
@@ -83,19 +67,37 @@ describe('TriggerDialog', () => {
|
||||
).toBeInTheDocument();
|
||||
const summary = getByTestId('trigger-summary-input');
|
||||
const body = getByTestId('trigger-body-input');
|
||||
const userTarget = getByTestId('trigger-select-user-target');
|
||||
const behavior = getByTestId('trigger-select-behavior');
|
||||
const policiesTarget = getByTestId('trigger-select-policies-target');
|
||||
const description = 'Test Trigger Alarm';
|
||||
await act(async () => {
|
||||
fireEvent.change(summary, { target: { value: description } });
|
||||
fireEvent.change(body, { target: { value: description } });
|
||||
fireEvent.change(behavior, { target: { value: '0' } });
|
||||
fireEvent.change(userTarget, { target: { value: ['test_user'] } });
|
||||
fireEvent.change(policiesTarget, {
|
||||
target: { value: ['team-zEalMCgwYSA0Lt40'] },
|
||||
fireEvent.mouseDown(getAllByRole('button')[0]);
|
||||
});
|
||||
|
||||
// Trigger user targets select
|
||||
const options = getAllByRole('option');
|
||||
await act(async () => {
|
||||
fireEvent.click(options[0]);
|
||||
fireEvent.keyDown(options[0], {
|
||||
key: 'Escape',
|
||||
code: 'Escape',
|
||||
keyCode: 27,
|
||||
charCode: 27,
|
||||
});
|
||||
});
|
||||
|
||||
// Trigger policy targets select
|
||||
await act(async () => {
|
||||
fireEvent.mouseDown(getAllByRole('button')[1]);
|
||||
});
|
||||
const policiesOptions = getAllByRole('option');
|
||||
await act(async () => {
|
||||
fireEvent.click(policiesOptions[0]);
|
||||
});
|
||||
|
||||
// Trigger incident creation button
|
||||
const triggerButton = getByTestId('trigger-button');
|
||||
await act(async () => {
|
||||
fireEvent.click(triggerButton);
|
||||
@@ -104,7 +106,7 @@ describe('TriggerDialog', () => {
|
||||
expect(mockTriggerAlarmFn).toHaveBeenCalledWith({
|
||||
summary: description,
|
||||
details: description,
|
||||
userName: 'guest@example.com',
|
||||
userName: 'test_user',
|
||||
targets: [
|
||||
{ slug: 'test_user', type: 'User' },
|
||||
{ slug: 'team-zEalMCgwYSA0Lt40', type: 'EscalationPolicy' },
|
||||
|
||||
@@ -34,7 +34,7 @@ import {
|
||||
FormControl,
|
||||
InputLabel,
|
||||
} from '@material-ui/core';
|
||||
import { useApi, alertApiRef, identityApiRef } from '@backstage/core';
|
||||
import { useApi, alertApiRef } from '@backstage/core';
|
||||
import { useAsync, useAsyncFn } from 'react-use';
|
||||
import { splunkOnCallApiRef } from '../../api';
|
||||
import { Alert } from '@material-ui/lab';
|
||||
@@ -86,8 +86,6 @@ export const TriggerDialog = ({
|
||||
onIncidentCreated: onIncidentCreated,
|
||||
}: Props) => {
|
||||
const alertApi = useApi(alertApiRef);
|
||||
const identityApi = useApi(identityApiRef);
|
||||
const userName = identityApi.getUserId();
|
||||
const api = useApi(splunkOnCallApiRef);
|
||||
const classes = useStyles();
|
||||
|
||||
@@ -166,7 +164,7 @@ export const TriggerDialog = ({
|
||||
onIncidentCreated();
|
||||
handleDialog();
|
||||
}
|
||||
}, [value, alertApi, handleDialog, userName, onIncidentCreated]);
|
||||
}, [value, alertApi, handleDialog, onIncidentCreated]);
|
||||
|
||||
if (triggerError) {
|
||||
alertApi.post({
|
||||
@@ -216,7 +214,6 @@ export const TriggerDialog = ({
|
||||
id="user-targets"
|
||||
multiple
|
||||
value={userTargets}
|
||||
inputProps={{ 'data-testid': 'trigger-select-user-target' }}
|
||||
onChange={handleUserTargets}
|
||||
input={<Input />}
|
||||
renderValue={selected => (
|
||||
@@ -252,9 +249,6 @@ export const TriggerDialog = ({
|
||||
value={policyTargets}
|
||||
onChange={handlePolicyTargets}
|
||||
input={<Input />}
|
||||
inputProps={{
|
||||
'data-testid': 'trigger-select-policies-target',
|
||||
}}
|
||||
renderValue={selected => (
|
||||
<div className={classes.chips}>
|
||||
{(selected as string[]).map(value => {
|
||||
@@ -353,7 +347,7 @@ export const TriggerDialog = ({
|
||||
handleTriggerAlarm(
|
||||
summary,
|
||||
details,
|
||||
userName,
|
||||
incidentCreator.username!,
|
||||
targets(),
|
||||
!!Number(isMultiResponder),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user