From fb247b39d842800736c039d6b463fe428aa56389 Mon Sep 17 00:00:00 2001 From: Jay Gabriels Date: Fri, 21 Jan 2022 12:29:10 -0800 Subject: [PATCH] Add test Signed-off-by: Jay Gabriels --- .../ChangeEvents/ChangeEvents.test.tsx | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/plugins/pagerduty/src/components/ChangeEvents/ChangeEvents.test.tsx b/plugins/pagerduty/src/components/ChangeEvents/ChangeEvents.test.tsx index 723e7b7b19..fca2422198 100644 --- a/plugins/pagerduty/src/components/ChangeEvents/ChangeEvents.test.tsx +++ b/plugins/pagerduty/src/components/ChangeEvents/ChangeEvents.test.tsx @@ -92,6 +92,54 @@ describe('Incidents', () => { expect(getAllByTitle('View in PagerDuty').length).toEqual(2); }); + it('Does not render a pagerduty link when html_url is not present in response', async () => { + mockPagerDutyApi.getChangeEventsByServiceId = jest + .fn() + .mockImplementationOnce( + async () => + [ + { + id: 'id1', + source: 'changeSource1', + links: [ + { + href: 'www.externalLink1.com', + text: 'link1', + }, + ], + summary: 'summary of event', + timestamp: '2020-07-17T08:42:58.315+0000', + }, + { + id: 'id2', + source: 'changeSource1', + html_url: 'www.pdlink.com/link', + links: [ + { + href: 'www.externalLink1.com', + text: 'link1', + }, + ], + summary: 'sum of EVENT', + timestamp: '2020-07-18T08:42:58.315+0000', + }, + ] as ChangeEvent[], + ); + const { getByText, getAllByTitle, queryByTestId } = render( + wrapInTestApp( + + + , + ), + ); + await waitFor(() => !queryByTestId('progress')); + expect(getByText('summary of event')).toBeInTheDocument(); + expect(getByText('sum of EVENT')).toBeInTheDocument(); + + // assert links, mailto and hrefs, date calculation + expect(getAllByTitle('View in PagerDuty').length).toEqual(1); + }); + it('Handle errors', async () => { mockPagerDutyApi.getChangeEventsByServiceId = jest .fn()