From e6f5cc5c4902e6f4ad7077c269c6d37164bc621c Mon Sep 17 00:00:00 2001 From: Scott Cooper Date: Mon, 24 Jul 2023 21:01:10 -0700 Subject: [PATCH] test(ui): Reset api mocks between EventDetails tests - Reset the mock api between tests - use the built in OrganizationContext.Provider --- .../transactionDetails/index.spec.tsx | 66 ++++++++----------- 1 file changed, 29 insertions(+), 37 deletions(-) diff --git a/static/app/views/performance/transactionDetails/index.spec.tsx b/static/app/views/performance/transactionDetails/index.spec.tsx index e98efba9057720..74ee541fe4ccc1 100644 --- a/static/app/views/performance/transactionDetails/index.spec.tsx +++ b/static/app/views/performance/transactionDetails/index.spec.tsx @@ -1,41 +1,46 @@ -import {act, cleanup, render, screen} from 'sentry-test/reactTestingLibrary'; +import {act, render, screen} from 'sentry-test/reactTestingLibrary'; import ProjectsStore from 'sentry/stores/projectsStore'; -import {OrganizationContext} from 'sentry/views/organizationContext'; import EventDetails from 'sentry/views/performance/transactionDetails'; const alertText = 'You are viewing a sample transaction. Configure performance to start viewing real transactions.'; describe('EventDetails', () => { - afterEach(cleanup); + const project = TestStubs.Project(); + const organization = TestStubs.Organization({ + features: ['performance-view'], + projects: [project], + }); - it('renders alert for sample transaction', async () => { - const project = TestStubs.Project(); + beforeEach(() => { ProjectsStore.loadInitialData([project]); - const organization = TestStubs.Organization({ - features: ['performance-view'], - projects: [project], - }); - const event = TestStubs.Event(); - event.tags.push({key: 'sample_event', value: 'yes'}); - const routerContext = TestStubs.routerContext([]); - MockApiClient.addMockResponse({ - url: `/projects/${organization.slug}/latest/events/1/grouping-info/`, + url: `/organizations/${organization.slug}/projects/`, statusCode: 200, - body: {}, + body: [], }); MockApiClient.addMockResponse({ - url: `/organizations/${organization.slug}/projects/`, + url: `/projects/${organization.slug}/latest/events/1/grouping-info/`, statusCode: 200, - body: [], + body: {}, }); MockApiClient.addMockResponse({ url: `/projects/${organization.slug}/latest/events/1/committers/`, statusCode: 200, body: [], }); + }); + + afterEach(() => { + ProjectsStore.reset(); + MockApiClient.clearMockResponses(); + }); + + it('renders alert for sample transaction', async () => { + const event = TestStubs.Event(); + event.tags.push({key: 'sample_event', value: 'yes'}); + MockApiClient.addMockResponse({ url: `/organizations/${organization.slug}/events/latest/`, statusCode: 200, @@ -45,14 +50,10 @@ describe('EventDetails', () => { }); render( - - - + , + {organization} ); expect(screen.getByText(alertText)).toBeInTheDocument(); @@ -61,14 +62,7 @@ describe('EventDetails', () => { }); it('does not reender alert if already received transaction', async () => { - const project = TestStubs.Project(); - ProjectsStore.loadInitialData([project]); - const organization = TestStubs.Organization({ - features: ['performance-view'], - projects: [project], - }); const event = TestStubs.Event(); - const routerContext = TestStubs.routerContext([]); MockApiClient.addMockResponse({ url: `/organizations/${organization.slug}/events/latest/`, @@ -80,11 +74,9 @@ describe('EventDetails', () => { render( + {...TestStubs.routeComponentProps({params: {eventSlug: 'latest'}})} + />, + {organization} ); expect(screen.queryByText(alertText)).not.toBeInTheDocument();