Skip to content

Commit 455cb11

Browse files
authored
test(projects): Migrate project pages off deprecatedRouterMocks (#105468)
Use the built in memory test router instead of stubbed router mocks. removes unused location prop in one component
1 parent c411dcc commit 455cb11

File tree

5 files changed

+70
-133
lines changed

5 files changed

+70
-133
lines changed

static/app/views/projectDetail/projectDetail.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,7 @@ export default function ProjectDetail() {
277277
isProjectStabilized={isProjectStabilized}
278278
project={project}
279279
/>
280-
<ProjectQuickLinks
281-
organization={organization}
282-
project={project}
283-
location={location}
284-
/>
280+
<ProjectQuickLinks organization={organization} project={project} />
285281
</Layout.Side>
286282
</Layout.Body>
287283
</NoProjectMessage>

static/app/views/projectDetail/projectIssues.spec.tsx

Lines changed: 41 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {GroupFixture} from 'sentry-fixture/group';
2+
import {OrganizationFixture} from 'sentry-fixture/organization';
3+
import {ProjectFixture} from 'sentry-fixture/project';
24

3-
import {initializeOrg} from 'sentry-test/initializeOrg';
45
import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
56

67
import ProjectIssues from 'sentry/views/projectDetail/projectIssues';
@@ -10,11 +11,10 @@ describe('ProjectDetail > ProjectIssues', () => {
1011
filteredEndpointMock: ReturnType<typeof MockApiClient.addMockResponse>,
1112
newIssuesEndpointMock: ReturnType<typeof MockApiClient.addMockResponse>;
1213

13-
const {organization, router, project} = initializeOrg({
14-
organization: {
15-
features: ['discover-basic'],
16-
},
14+
const organization = OrganizationFixture({
15+
features: ['discover-basic'],
1716
});
17+
const project = ProjectFixture();
1818

1919
beforeEach(() => {
2020
endpointMock = MockApiClient.addMockResponse({
@@ -62,46 +62,40 @@ describe('ProjectDetail > ProjectIssues', () => {
6262
<ProjectIssues
6363
api={new MockApiClient()}
6464
organization={organization}
65-
location={router.location}
65+
location={{query: {}} as any}
6666
projectId={parseInt(project.id, 10)}
6767
/>,
6868
{
69-
router,
7069
organization,
71-
deprecatedRouterMocks: true,
7270
}
7371
);
7472

7573
expect(await screen.findAllByTestId('group')).toHaveLength(2);
7674
});
7775

7876
it('renders a link to Issues', async () => {
79-
render(
77+
const {router} = render(
8078
<ProjectIssues
8179
api={new MockApiClient()}
8280
organization={organization}
8381
projectId={parseInt(project.id, 10)}
84-
location={router.location}
82+
location={{query: {}} as any}
8583
/>,
8684
{
87-
router,
8885
organization,
89-
deprecatedRouterMocks: true,
9086
}
9187
);
9288

9389
const link = screen.getByLabelText('Open in Issues');
9490
expect(link).toBeInTheDocument();
9591
await userEvent.click(link);
9692

97-
expect(router.push).toHaveBeenCalledWith({
98-
pathname: '/organizations/org-slug/issues/',
99-
query: {
100-
limit: '5',
101-
query: 'error.unhandled:true is:unresolved',
102-
sort: 'freq',
103-
statsPeriod: '14d',
104-
},
93+
expect(router.location.pathname).toBe('/organizations/org-slug/issues/');
94+
expect(router.location.query).toEqual({
95+
limit: '5',
96+
query: 'error.unhandled:true is:unresolved',
97+
sort: 'freq',
98+
statsPeriod: '14d',
10599
});
106100
});
107101

@@ -110,13 +104,11 @@ describe('ProjectDetail > ProjectIssues', () => {
110104
<ProjectIssues
111105
api={new MockApiClient()}
112106
organization={organization}
113-
location={router.location}
107+
location={{query: {}} as any}
114108
projectId={parseInt(project.id, 10)}
115109
/>,
116110
{
117-
router,
118111
organization,
119-
deprecatedRouterMocks: true,
120112
}
121113
);
122114

@@ -137,53 +129,50 @@ describe('ProjectDetail > ProjectIssues', () => {
137129
});
138130

139131
it('renders a link to Discover', async () => {
140-
render(
132+
const {router} = render(
141133
<ProjectIssues
142134
api={new MockApiClient()}
143135
organization={organization}
144-
location={router.location}
136+
location={{query: {}} as any}
145137
projectId={parseInt(project.id, 10)}
146138
/>,
147139
{
148-
router,
149140
organization,
150-
deprecatedRouterMocks: true,
151141
}
152142
);
153143

154144
const link = screen.getByLabelText('Open in Discover');
155145
expect(link).toBeInTheDocument();
156146
await userEvent.click(link);
157147

158-
expect(router.push).toHaveBeenCalledWith({
159-
pathname: `/organizations/${organization.slug}/explore/discover/results/`,
160-
query: {
161-
display: 'top5',
162-
field: ['issue', 'title', 'count()', 'count_unique(user)', 'project'],
163-
name: 'Frequent Unhandled Issues',
164-
query: 'event.type:error error.unhandled:true',
165-
queryDataset: 'error-events',
166-
sort: '-count',
167-
statsPeriod: '14d',
168-
},
148+
expect(router.location.pathname).toBe(
149+
`/organizations/${organization.slug}/explore/discover/results/`
150+
);
151+
expect(router.location.query).toEqual({
152+
display: 'top5',
153+
field: ['issue', 'title', 'count()', 'count_unique(user)', 'project'],
154+
name: 'Frequent Unhandled Issues',
155+
query: 'event.type:error error.unhandled:true',
156+
queryDataset: 'error-events',
157+
sort: '-count',
158+
statsPeriod: '14d',
169159
});
170160
});
171161

172162
it('changes according to global header', async () => {
173-
render(
163+
const locationWithQuery = {
164+
query: {statsPeriod: '7d', environment: 'staging', somethingBad: 'nope'},
165+
} as any;
166+
167+
const {router} = render(
174168
<ProjectIssues
175169
organization={organization}
176170
api={new MockApiClient()}
177171
projectId={parseInt(project.id, 10)}
178-
location={{
179-
...router.location,
180-
query: {statsPeriod: '7d', environment: 'staging', somethingBad: 'nope'},
181-
}}
172+
location={locationWithQuery}
182173
/>,
183174
{
184-
router,
185175
organization,
186-
deprecatedRouterMocks: true,
187176
}
188177
);
189178

@@ -194,15 +183,13 @@ describe('ProjectDetail > ProjectIssues', () => {
194183
expect(link).toBeInTheDocument();
195184
await userEvent.click(link);
196185

197-
expect(router.push).toHaveBeenCalledWith({
198-
pathname: `/organizations/${organization.slug}/issues/`,
199-
query: {
200-
limit: '5',
201-
environment: 'staging',
202-
statsPeriod: '7d',
203-
query: 'error.unhandled:true is:unresolved',
204-
sort: 'freq',
205-
},
186+
expect(router.location.pathname).toBe(`/organizations/${organization.slug}/issues/`);
187+
expect(router.location.query).toEqual({
188+
limit: '5',
189+
environment: 'staging',
190+
statsPeriod: '7d',
191+
query: 'error.unhandled:true is:unresolved',
192+
sort: 'freq',
206193
});
207194
});
208195
});

static/app/views/projectDetail/projectQuickLinks.spec.tsx

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
1+
import {OrganizationFixture} from 'sentry-fixture/organization';
12
import {ProjectFixture} from 'sentry-fixture/project';
23

3-
import {initializeOrg} from 'sentry-test/initializeOrg';
44
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
55

66
import ProjectQuickLinks from 'sentry/views/projectDetail/projectQuickLinks';
77

88
describe('ProjectDetail > ProjectQuickLinks', () => {
9-
const {organization, router} = initializeOrg({
10-
organization: {features: ['performance-view']},
11-
});
9+
const organization = OrganizationFixture({features: ['performance-view']});
1210

1311
afterEach(() => {
1412
jest.clearAllMocks();
1513
});
1614

1715
it('renders a list', async () => {
18-
render(
19-
<ProjectQuickLinks
20-
organization={organization}
21-
location={router.location}
22-
project={ProjectFixture()}
23-
/>,
24-
{
25-
router,
26-
deprecatedRouterMocks: true,
27-
}
16+
const {router} = render(
17+
<ProjectQuickLinks organization={organization} project={ProjectFixture()} />
2818
);
2919

3020
expect(screen.getByRole('heading', {name: 'Quick Links'})).toBeInTheDocument();
@@ -34,35 +24,25 @@ describe('ProjectDetail > ProjectQuickLinks', () => {
3424
const keyTransactions = screen.getByRole('link', {name: 'View Transactions'});
3525

3626
await userEvent.click(userFeedback);
37-
expect(router.push).toHaveBeenCalledWith({
38-
pathname: '/organizations/org-slug/feedback/',
39-
query: {project: '2'},
40-
});
27+
expect(router.location.pathname).toBe('/organizations/org-slug/feedback/');
28+
expect(router.location.query).toEqual({project: '2'});
4129

4230
await userEvent.click(keyTransactions);
43-
expect(router.push).toHaveBeenCalledWith({
44-
pathname: '/organizations/org-slug/insights/backend/',
45-
query: {project: '2'},
46-
});
31+
expect(router.location.pathname).toBe('/organizations/org-slug/insights/backend/');
32+
expect(router.location.query).toEqual({project: '2'});
4733
});
4834

4935
it('disables link if feature is missing', async () => {
5036
render(
5137
<ProjectQuickLinks
5238
organization={{...organization, features: []}}
53-
location={router.location}
5439
project={ProjectFixture()}
55-
/>,
56-
{
57-
router,
58-
deprecatedRouterMocks: true,
59-
}
40+
/>
6041
);
6142

6243
const keyTransactions = screen.getByText('View Transactions');
6344

6445
await userEvent.click(keyTransactions);
65-
expect(router.push).toHaveBeenCalledTimes(0);
6646

6747
await userEvent.hover(keyTransactions);
6848
expect(

static/app/views/projectDetail/projectQuickLinks.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {css} from '@emotion/react';
22
import styled from '@emotion/styled';
3-
import type {Location} from 'history';
43

54
import {SectionHeading} from 'sentry/components/charts/styles';
65
import {FeatureBadge} from 'sentry/components/core/badge/featureBadge';
@@ -24,7 +23,6 @@ import {
2423
import {SidebarSection} from './styles';
2524

2625
type Props = {
27-
location: Location;
2826
organization: Organization;
2927
project?: Project;
3028
};

0 commit comments

Comments
 (0)