Skip to content

test(ui): Reset api mocks between EventDetails tests #53497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 29 additions & 37 deletions static/app/views/performance/transactionDetails/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -45,14 +50,10 @@ describe('EventDetails', () => {
});

render(
<OrganizationContext.Provider value={organization}>
<EventDetails
{...TestStubs.routeComponentProps()}
organization={organization}
params={{eventSlug: 'latest'}}
location={routerContext.context.location}
/>
</OrganizationContext.Provider>
<EventDetails
{...TestStubs.routeComponentProps({params: {eventSlug: 'latest'}})}
/>,
{organization}
);
expect(screen.getByText(alertText)).toBeInTheDocument();

Expand All @@ -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/`,
Expand All @@ -80,11 +74,9 @@ describe('EventDetails', () => {

render(
<EventDetails
{...TestStubs.routeComponentProps()}
organization={organization}
params={{eventSlug: 'latest'}}
location={routerContext.context.location}
/>
{...TestStubs.routeComponentProps({params: {eventSlug: 'latest'}})}
/>,
{organization}
);
expect(screen.queryByText(alertText)).not.toBeInTheDocument();

Expand Down