Skip to content

Commit 6293ee9

Browse files
authored
test(releases): Move release comparison off deprecated route props (#103706)
no longer need to manually rerender since the test router updates query parameters on navigate
1 parent b1ce1a2 commit 6293ee9

File tree

3 files changed

+33
-55
lines changed

3 files changed

+33
-55
lines changed

static/app/views/releases/detail/overview/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,10 @@ function ReleaseOverview() {
368368
releaseSessions={thisRelease}
369369
allSessions={allReleases}
370370
platform={project.platform}
371-
location={location}
372371
loading={loading}
373372
reloading={reloading}
374373
errored={errored}
375374
project={project}
376-
organization={organization}
377375
api={api}
378376
hasHealthData={hasHealthData}
379377
/>

static/app/views/releases/detail/overview/releaseComparisonChart/index.spec.tsx

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
1+
import {OrganizationFixture} from 'sentry-fixture/organization';
2+
import {ProjectFixture} from 'sentry-fixture/project';
13
import {ReleaseFixture} from 'sentry-fixture/release';
24
import {
35
SessionUserCountByStatus2Fixture,
46
SessionUserCountByStatusFixture,
57
} from 'sentry-fixture/sessions';
68

7-
import {initializeOrg} from 'sentry-test/initializeOrg';
8-
import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
9+
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
10+
import type {RouterConfig} from 'sentry-test/reactTestingLibrary';
911

1012
import type {ReleaseProject} from 'sentry/types/release';
1113
import ReleaseComparisonChart from 'sentry/views/releases/detail/overview/releaseComparisonChart';
1214

1315
describe('Releases > Detail > Overview > ReleaseComparison', () => {
14-
const {router, organization, project: rawProject} = initializeOrg();
15-
const api = new MockApiClient();
16+
const organization = OrganizationFixture();
17+
const rawProject = ProjectFixture();
1618
const release = ReleaseFixture();
19+
const initialRouterConfig: RouterConfig = {
20+
location: {
21+
pathname: `/organizations/${organization.slug}/releases/${release.version}/`,
22+
query: {},
23+
},
24+
routes: ['/organizations/:orgId/releases/:release/'],
25+
};
26+
const api = new MockApiClient();
1727
const releaseSessions = SessionUserCountByStatusFixture();
1828
const allSessions = SessionUserCountByStatus2Fixture();
1929

@@ -32,18 +42,16 @@ describe('Releases > Detail > Overview > ReleaseComparison', () => {
3242
releaseSessions={releaseSessions}
3343
allSessions={allSessions}
3444
platform="javascript"
35-
location={{...router.location, query: {}}}
3645
loading={false}
3746
reloading={false}
3847
errored={false}
3948
project={project}
40-
organization={organization}
4149
api={api}
4250
hasHealthData
4351
/>,
4452
{
45-
router,
46-
deprecatedRouterMocks: true,
53+
organization,
54+
initialRouterConfig,
4755
}
4856
);
4957

@@ -63,48 +71,29 @@ describe('Releases > Detail > Overview > ReleaseComparison', () => {
6371
});
6472

6573
it('can change chart by clicking on a row', async () => {
66-
const {rerender} = render(
74+
const {router} = render(
6775
<ReleaseComparisonChart
6876
release={release}
6977
releaseSessions={releaseSessions}
7078
allSessions={allSessions}
7179
platform="javascript"
72-
location={{...router.location, query: {}}}
7380
loading={false}
7481
reloading={false}
7582
errored={false}
7683
project={project}
77-
organization={organization}
7884
api={api}
7985
hasHealthData
8086
/>,
8187
{
82-
router,
83-
deprecatedRouterMocks: true,
88+
organization,
89+
initialRouterConfig,
8490
}
8591
);
8692

8793
await userEvent.click(screen.getByLabelText(/crash free user rate/i));
8894

89-
expect(router.push).toHaveBeenCalledWith(
90-
expect.objectContaining({query: {chart: 'crashFreeUsers'}})
91-
);
92-
93-
rerender(
94-
<ReleaseComparisonChart
95-
release={release}
96-
releaseSessions={releaseSessions}
97-
allSessions={allSessions}
98-
platform="javascript"
99-
location={{...router.location, query: {chart: 'crashFreeUsers'}}}
100-
loading={false}
101-
reloading={false}
102-
errored={false}
103-
project={project}
104-
organization={organization}
105-
api={api}
106-
hasHealthData
107-
/>
95+
expect(router.location.query).toEqual(
96+
expect.objectContaining({chart: 'crashFreeUsers'})
10897
);
10998

11099
expect(screen.getByLabelText('Chart Title')).toHaveTextContent(
@@ -120,18 +109,16 @@ describe('Releases > Detail > Overview > ReleaseComparison', () => {
120109
releaseSessions={releaseSessions}
121110
allSessions={allSessions}
122111
platform="javascript"
123-
location={{...router.location, query: {}}}
124112
loading={false}
125113
reloading={false}
126114
errored={false}
127115
project={project}
128-
organization={organization}
129116
api={api}
130117
hasHealthData
131118
/>,
132119
{
133-
router,
134-
deprecatedRouterMocks: true,
120+
organization,
121+
initialRouterConfig,
135122
}
136123
);
137124

@@ -171,36 +158,31 @@ describe('Releases > Detail > Overview > ReleaseComparison', () => {
171158
url: `/organizations/${organization.slug}/issues-count/`,
172159
body: 0,
173160
});
161+
const noHealthDataOrganization = OrganizationFixture({
162+
features: [...organization.features, 'discover-basic'],
163+
});
174164

175165
render(
176166
<ReleaseComparisonChart
177167
release={release}
178168
releaseSessions={null}
179169
allSessions={null}
180170
platform="javascript"
181-
location={{...router.location, query: {}}}
182171
loading={false}
183172
reloading={false}
184173
errored={false}
185174
project={project}
186-
organization={{
187-
...organization,
188-
features: [...organization.features, 'discover-basic'],
189-
}}
190175
api={api}
191176
hasHealthData={false}
192177
/>,
193178
{
194-
router,
195-
deprecatedRouterMocks: true,
179+
organization: noHealthDataOrganization,
180+
initialRouterConfig,
196181
}
197182
);
198183

199-
expect(screen.getAllByRole('radio')).toHaveLength(1);
184+
expect(await screen.findAllByRole('radio')).toHaveLength(1);
200185
expect(screen.queryByLabelText(/toggle chart/i)).not.toBeInTheDocument();
201186
expect(screen.queryByLabelText(/toggle additional/i)).not.toBeInTheDocument();
202-
203-
// Wait for api requests to propegate
204-
await act(tick);
205187
});
206188
});

static/app/views/releases/detail/overview/releaseComparisonChart/index.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, {Fragment, useCallback, useEffect, useMemo, useState} from 'react';
22
import styled from '@emotion/styled';
33
import * as Sentry from '@sentry/react';
4-
import type {Location} from 'history';
54

65
import type {Client} from 'sentry/api';
76
import ErrorPanel from 'sentry/components/charts/errorPanel';
@@ -20,7 +19,6 @@ import {space} from 'sentry/styles/space';
2019
import {
2120
SessionFieldWithOperation,
2221
SessionStatus,
23-
type Organization,
2422
type SessionApiResponse,
2523
} from 'sentry/types/organization';
2624
import type {PlatformKey} from 'sentry/types/project';
@@ -38,7 +36,9 @@ import {decodeList, decodeScalar} from 'sentry/utils/queryString';
3836
import {getCount, getCrashFreeRate, getSessionStatusRate} from 'sentry/utils/sessions';
3937
import type {Color} from 'sentry/utils/theme';
4038
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
39+
import {useLocation} from 'sentry/utils/useLocation';
4140
import {useNavigate} from 'sentry/utils/useNavigate';
41+
import useOrganization from 'sentry/utils/useOrganization';
4242
import {
4343
displaySessionStatusPercent,
4444
getReleaseBounds,
@@ -69,8 +69,6 @@ type Props = {
6969
errored: boolean;
7070
hasHealthData: boolean;
7171
loading: boolean;
72-
location: Location;
73-
organization: Organization;
7472
platform: PlatformKey;
7573
project: ReleaseProject;
7674
release: ReleaseWithHealth;
@@ -98,14 +96,14 @@ export default function ReleaseComparisonChart({
9896
releaseSessions,
9997
allSessions,
10098
platform,
101-
location,
10299
loading,
103100
reloading,
104101
errored,
105102
api,
106-
organization,
107103
hasHealthData,
108104
}: Props) {
105+
const organization = useOrganization();
106+
const location = useLocation();
109107
const navigate = useNavigate();
110108
const [issuesTotals, setIssuesTotals] = useState<IssuesTotals>(null);
111109
const [eventsTotals, setEventsTotals] = useState<EventsTotals>(null);

0 commit comments

Comments
 (0)