feat(splunk-on-call-plugin): REST endpoint tests

Signed-off-by: Remi <remi.d45@gmail.com>
This commit is contained in:
Remi
2021-02-25 22:56:19 +01:00
parent fde006b434
commit 98fb840b4d
3 changed files with 44 additions and 50 deletions
@@ -62,7 +62,10 @@ describe('Incidents', () => {
),
);
await waitFor(() => !queryByTestId('progress'));
expect(getByText('Nice! No incidents found!')).toBeInTheDocument();
await waitFor(
() => expect(getByText('Nice! No incidents found!')).toBeInTheDocument(),
{ timeout: 2000 },
);
});
it('Renders all incidents', async () => {
@@ -87,11 +90,15 @@ describe('Incidents', () => {
),
);
await waitFor(() => !queryByTestId('progress'));
expect(
getByText('user', {
exact: false,
}),
).toBeInTheDocument();
await waitFor(
() =>
expect(
getByText('user', {
exact: false,
}),
).toBeInTheDocument(),
{ timeout: 2000 },
);
expect(getByText('test-incident')).toBeInTheDocument();
expect(getByTitle('Acknowledged')).toBeInTheDocument();
expect(getByLabelText('Status warning')).toBeInTheDocument();
@@ -113,8 +120,14 @@ describe('Incidents', () => {
),
);
await waitFor(() => !queryByTestId('progress'));
expect(
getByText('Error encountered while fetching information. Error occurred'),
).toBeInTheDocument();
await waitFor(
() =>
expect(
getByText(
'Error encountered while fetching information. Error occurred',
),
).toBeInTheDocument(),
{ timeout: 2000 },
);
});
});
@@ -91,7 +91,10 @@ describe('SplunkOnCallCard', () => {
);
await waitFor(() => !queryByTestId('progress'));
expect(getByText('Create Incident')).toBeInTheDocument();
expect(getByText('Nice! No incidents found!')).toBeInTheDocument();
await waitFor(
() => expect(getByText('Nice! No incidents found!')).toBeInTheDocument(),
{ timeout: 2000 },
);
expect(getByText('Empty escalation policy')).toBeInTheDocument();
});
@@ -24,13 +24,12 @@ import {
} from '@backstage/core';
import { splunkOnCallApiRef } from '../../api';
import { TriggerDialog } from './TriggerDialog';
import { ESCALATION_POLICIES, MOCKED_USER } from '../../api/mocks';
import { MOCKED_USER } from '../../api/mocks';
describe('TriggerDialog', () => {
const mockTriggerAlarmFn = jest.fn();
const mockSplunkOnCallApi = {
triggerAlarm: mockTriggerAlarmFn,
getEscalationPolicies: async () => ESCALATION_POLICIES,
incidentAction: mockTriggerAlarmFn,
};
const apis = ApiRegistry.from([
@@ -45,14 +44,13 @@ describe('TriggerDialog', () => {
]);
it('open the dialog and trigger an alarm', async () => {
const { getByText, getByRole, getAllByRole, getByTestId } = render(
const { getByText, getByRole, getByTestId } = render(
wrapInTestApp(
<ApiProvider apis={apis}>
<TriggerDialog
showDialog
incidentCreator={MOCKED_USER}
handleDialog={() => {}}
users={[MOCKED_USER]}
onIncidentCreated={() => {}}
/>
</ApiProvider>,
@@ -65,36 +63,20 @@ describe('TriggerDialog', () => {
exact: false,
}),
).toBeInTheDocument();
const summary = getByTestId('trigger-summary-input');
const body = getByTestId('trigger-body-input');
const behavior = getByTestId('trigger-select-behavior');
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.mouseDown(getAllByRole('button')[0]);
});
const incidentType = getByTestId('trigger-incident-type');
const incidentId = getByTestId('trigger-incident-id');
const incidentDisplayName = getByTestId('trigger-incident-displayName');
const incidentMessage = getByTestId('trigger-incident-message');
// 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,
fireEvent.change(incidentType, { target: { value: 'CRITICAL' } });
fireEvent.change(incidentId, { target: { value: 'incident-id' } });
fireEvent.change(incidentDisplayName, {
target: { value: 'incident-display-name' },
});
fireEvent.change(incidentMessage, {
target: { value: 'incident-message' },
});
});
// 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
@@ -104,14 +86,10 @@ describe('TriggerDialog', () => {
});
expect(mockTriggerAlarmFn).toHaveBeenCalled();
expect(mockTriggerAlarmFn).toHaveBeenCalledWith({
summary: description,
details: description,
userName: 'test_user',
targets: [
{ slug: 'test_user', type: 'User' },
{ slug: 'team-zEalMCgwYSA0Lt40', type: 'EscalationPolicy' },
],
isMultiResponder: false,
incidentType: 'CRITICAL',
incidentId: 'incident-id',
incidentDisplayName: 'incident-display-name',
incidentMessage: 'incident-message',
});
});
});