From 98fb840b4daabe57c5d9c43a637c73c1e56fd678 Mon Sep 17 00:00:00 2001 From: Remi Date: Thu, 25 Feb 2021 22:56:19 +0100 Subject: [PATCH] feat(splunk-on-call-plugin): REST endpoint tests Signed-off-by: Remi --- .../components/Incident/Incidents.test.tsx | 31 +++++++--- .../src/components/SplunkOnCallCard.test.tsx | 5 +- .../TriggerDialog/TriggerDialog.test.tsx | 58 ++++++------------- 3 files changed, 44 insertions(+), 50 deletions(-) diff --git a/plugins/splunk-on-call/src/components/Incident/Incidents.test.tsx b/plugins/splunk-on-call/src/components/Incident/Incidents.test.tsx index d1f973735c..d0171df985 100644 --- a/plugins/splunk-on-call/src/components/Incident/Incidents.test.tsx +++ b/plugins/splunk-on-call/src/components/Incident/Incidents.test.tsx @@ -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 }, + ); }); }); diff --git a/plugins/splunk-on-call/src/components/SplunkOnCallCard.test.tsx b/plugins/splunk-on-call/src/components/SplunkOnCallCard.test.tsx index b1280ab21c..3418ed3398 100644 --- a/plugins/splunk-on-call/src/components/SplunkOnCallCard.test.tsx +++ b/plugins/splunk-on-call/src/components/SplunkOnCallCard.test.tsx @@ -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(); }); diff --git a/plugins/splunk-on-call/src/components/TriggerDialog/TriggerDialog.test.tsx b/plugins/splunk-on-call/src/components/TriggerDialog/TriggerDialog.test.tsx index 741a15fb41..5308148afa 100644 --- a/plugins/splunk-on-call/src/components/TriggerDialog/TriggerDialog.test.tsx +++ b/plugins/splunk-on-call/src/components/TriggerDialog/TriggerDialog.test.tsx @@ -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( {}} - users={[MOCKED_USER]} onIncidentCreated={() => {}} /> , @@ -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', }); }); });