From 680baabe5f1a5129c55c6e6fb029e1adcd538a0e Mon Sep 17 00:00:00 2001 From: Juan Lulkin Date: Wed, 24 Feb 2021 23:04:27 +0100 Subject: [PATCH] Removes testId prop and change specs accordingly --- .../components/PagerDutyCard/index.test.tsx | 6 ++-- .../src/components/PagerDutyCard/index.tsx | 1 - .../components/TriggerButton/index.test.tsx | 31 +++++++------------ .../src/components/TriggerButton/index.tsx | 1 - .../TriggerDialog/TriggerDialog.tsx | 7 +---- 5 files changed, 16 insertions(+), 30 deletions(-) diff --git a/plugins/pagerduty/src/components/PagerDutyCard/index.test.tsx b/plugins/pagerduty/src/components/PagerDutyCard/index.test.tsx index 5a0854c929..397f897f65 100644 --- a/plugins/pagerduty/src/components/PagerDutyCard/index.test.tsx +++ b/plugins/pagerduty/src/components/PagerDutyCard/index.test.tsx @@ -138,7 +138,7 @@ describe('PageDutyCard', () => { .fn() .mockImplementationOnce(async () => [service]); - const { getByText, queryByTestId, getByTestId, getByRole } = render( + const { getByText, queryByTestId, getByRole } = render( wrapInTestApp( @@ -149,8 +149,8 @@ describe('PageDutyCard', () => { ); await waitFor(() => !queryByTestId('progress')); expect(getByText('Service Directory')).toBeInTheDocument(); - expect(getByText('Create Incident')).toBeInTheDocument(); - const triggerLink = getByTestId('trigger-link'); + + const triggerLink = getByText('Create Incident'); await act(async () => { fireEvent.click(triggerLink); }); diff --git a/plugins/pagerduty/src/components/PagerDutyCard/index.tsx b/plugins/pagerduty/src/components/PagerDutyCard/index.tsx index 772fb0b044..5a361518a7 100644 --- a/plugins/pagerduty/src/components/PagerDutyCard/index.tsx +++ b/plugins/pagerduty/src/components/PagerDutyCard/index.tsx @@ -94,7 +94,6 @@ export const PagerDutyCard = () => { onClick: showDialog, icon: , color: 'secondary', - testId: 'trigger-link', }; return ( diff --git a/plugins/pagerduty/src/components/TriggerButton/index.test.tsx b/plugins/pagerduty/src/components/TriggerButton/index.test.tsx index a6fd494472..1ba6368d72 100644 --- a/plugins/pagerduty/src/components/TriggerButton/index.test.tsx +++ b/plugins/pagerduty/src/components/TriggerButton/index.test.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ import React from 'react'; -import { act, fireEvent, waitFor } from '@testing-library/react'; +import { act, fireEvent, screen, waitFor } from '@testing-library/react'; import { renderInTestApp } from '@backstage/test-utils'; import { ApiRegistry, @@ -63,7 +63,7 @@ describe('TriggerButton', () => { }, }; - const { queryByRole, getByRole, getByTestId } = await renderInTestApp( + await renderInTestApp( @@ -71,25 +71,22 @@ describe('TriggerButton', () => { , ); - expect(getByTestId('trigger-button')).toBeInTheDocument(); - expect(queryByRole('dialog')).not.toBeInTheDocument(); - - const triggerButton = getByTestId('trigger-button'); - expect(triggerButton.textContent).toBe('Create Incident'); + const triggerButton = screen.getByText('Create Incident'); + expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); await act(async () => { fireEvent.click(triggerButton); }); await waitFor(() => { - expect(getByRole('dialog')).toBeInTheDocument(); + expect(screen.getByRole('dialog')).toBeInTheDocument(); }); - const closeButton = getByTestId('close-button'); + const closeButton = screen.getByText('Close'); await act(async () => { fireEvent.click(closeButton); }); await waitFor(() => { - expect(queryByRole('dialog')).not.toBeInTheDocument(); + expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); }); }); @@ -105,7 +102,7 @@ describe('TriggerButton', () => { }, }; - const { getByTestId } = await renderInTestApp( + await renderInTestApp( Send an alert @@ -113,8 +110,7 @@ describe('TriggerButton', () => { , ); - const triggerButton = getByTestId('trigger-button'); - expect(triggerButton.textContent).toBe('Send an alert'); + expect(screen.getByText('Send an alert')).toBeInTheDocument(); }); it('renders a disabled trigger button if entity does not include key', async () => { @@ -126,7 +122,7 @@ describe('TriggerButton', () => { }, }; - const { queryByRole, getByTestId } = await renderInTestApp( + await renderInTestApp( @@ -134,16 +130,13 @@ describe('TriggerButton', () => { , ); - expect(getByTestId('trigger-button')).toBeInTheDocument(); - - const triggerButton = getByTestId('trigger-button'); - expect(triggerButton.textContent).toBe('Missing integration key'); + const triggerButton = screen.getByText('Missing integration key'); await act(async () => { fireEvent.click(triggerButton); }); await waitFor(() => { - expect(queryByRole('dialog')).not.toBeInTheDocument(); + expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); }); }); }); diff --git a/plugins/pagerduty/src/components/TriggerButton/index.tsx b/plugins/pagerduty/src/components/TriggerButton/index.tsx index 9ebbaf4f1d..6aa2c1c3d4 100644 --- a/plugins/pagerduty/src/components/TriggerButton/index.tsx +++ b/plugins/pagerduty/src/components/TriggerButton/index.tsx @@ -50,7 +50,6 @@ export function TriggerButton({ return ( <> -