Skip to content

Commit ad7fb0d

Browse files
committed
ref(test): Remove location from context
This should have never been in here. Location was never in react routers context.
1 parent 51ccc1d commit ad7fb0d

File tree

4 files changed

+15
-35
lines changed

4 files changed

+15
-35
lines changed

static/app/components/sidebar/index.spec.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import type {UseQueryResult} from '@tanstack/react-query';
22
import {BroadcastFixture} from 'sentry-fixture/broadcast';
3+
import {LocationFixture} from 'sentry-fixture/locationFixture';
34
import {OrganizationFixture} from 'sentry-fixture/organization';
45
import {ServiceIncidentFixture} from 'sentry-fixture/serviceIncident';
56
import {UserFixture} from 'sentry-fixture/user';
67

7-
import {initializeOrg} from 'sentry-test/initializeOrg';
88
import {act, render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
99

1010
import {OnboardingContextProvider} from 'sentry/components/onboarding/onboardingContext';
1111
import SidebarContainer from 'sentry/components/sidebar';
1212
import ConfigStore from 'sentry/stores/configStore';
1313
import type {Organization, StatuspageIncident} from 'sentry/types';
14+
import {useLocation} from 'sentry/utils/useLocation';
1415
import * as incidentsHook from 'sentry/utils/useServiceIncidents';
1516

1617
jest.mock('sentry/utils/useServiceIncidents');
18+
jest.mock('sentry/utils/useLocation');
19+
20+
const mockUseLocation = jest.mocked(useLocation);
1721

1822
const sidebarAccordionFeatures = [
1923
'performance-view',
@@ -23,7 +27,7 @@ const sidebarAccordionFeatures = [
2327
];
2428

2529
describe('Sidebar', function () {
26-
const {organization, routerContext} = initializeOrg();
30+
const organization = OrganizationFixture();
2731
const broadcast = BroadcastFixture();
2832
const user = UserFixture();
2933
const apiMocks = {
@@ -39,9 +43,10 @@ describe('Sidebar', function () {
3943
);
4044

4145
const renderSidebar = ({organization: org}: {organization: Organization | null}) =>
42-
render(getElement(), {context: routerContext, organization: org});
46+
render(getElement(), {organization: org});
4347

4448
beforeEach(function () {
49+
mockUseLocation.mockReset();
4550
jest.spyOn(incidentsHook, 'useServiceIncidents').mockImplementation(
4651
() =>
4752
({
@@ -149,11 +154,9 @@ describe('Sidebar', function () {
149154
expect(await screen.findByRole('dialog')).toBeInTheDocument();
150155
expect(screen.getByText("What's new in Sentry")).toBeInTheDocument();
151156

152-
const oldPath = routerContext.context.location.pathname;
153-
routerContext.context.location.pathname = '/other/path';
157+
mockUseLocation.mockReturnValue({...LocationFixture(), pathname: '/other/path'});
154158
rerender(getElement());
155159
expect(screen.queryByText("What's new in Sentry")).not.toBeInTheDocument();
156-
routerContext.context.location.pathname = oldPath;
157160
});
158161

159162
it('can have onboarding feature', async function () {

static/app/views/performance/vitalDetail/index.spec.tsx

+3-18
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,7 @@ describe('Performance > VitalDetail', function () {
279279
},
280280
};
281281

282-
const context = RouterContextFixture([
283-
{
284-
router: newRouter,
285-
location: newRouter.location,
286-
},
287-
]);
282+
const context = RouterContextFixture([{router: newRouter}]);
288283

289284
render(<TestComponent router={newRouter} />, {
290285
context,
@@ -331,12 +326,7 @@ describe('Performance > VitalDetail', function () {
331326
},
332327
};
333328

334-
const context = RouterContextFixture([
335-
{
336-
router: newRouter,
337-
location: newRouter.location,
338-
},
339-
]);
329+
const context = RouterContextFixture([{router: newRouter}]);
340330

341331
render(<TestComponent router={newRouter} />, {
342332
context,
@@ -384,12 +374,7 @@ describe('Performance > VitalDetail', function () {
384374
},
385375
};
386376

387-
const context = RouterContextFixture([
388-
{
389-
router: newRouter,
390-
location: newRouter.location,
391-
},
392-
]);
377+
const context = RouterContextFixture([{router: newRouter}]);
393378

394379
render(<TestComponent router={newRouter} />, {
395380
context,

tests/js/fixtures/routerContextFixture.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
import {LocationFixture} from 'sentry-fixture/locationFixture';
21
import {RouterFixture} from 'sentry-fixture/routerFixture';
32

43
import {SentryPropTypeValidators} from 'sentry/sentryPropTypeValidators';
54

65
export function RouterContextFixture([context, childContextTypes] = []) {
76
return {
87
context: {
9-
location: LocationFixture(),
108
router: RouterFixture(),
119
...context,
1210
},
1311
childContextTypes: {
1412
router: SentryPropTypeValidators.isObject,
15-
location: SentryPropTypeValidators.isObject,
1613
...childContextTypes,
1714
},
1815
};

tests/js/sentry-test/initializeOrg.tsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ interface InitializeOrgOptions<RouterParams> {
3636
* - a project or projects
3737
* - organization owning above projects
3838
* - router
39-
* - context that contains org + projects + router
39+
* - context that contains router
4040
*/
4141
export function initializeOrg<RouterParams = {orgId: string; projectId: string}>({
4242
organization: additionalOrg,
@@ -65,12 +65,7 @@ export function initializeOrg<RouterParams = {orgId: string; projectId: string}>
6565
},
6666
});
6767

68-
const routerContext: any = RouterContextFixture([
69-
{
70-
router,
71-
location: router.location,
72-
},
73-
]);
68+
const routerContext: any = RouterContextFixture([{router}]);
7469

7570
/**
7671
* A collection of router props that are passed to components by react-router
@@ -86,7 +81,7 @@ export function initializeOrg<RouterParams = {orgId: string; projectId: string}>
8681
router,
8782
route: router.routes[0],
8883
routes: router.routes,
89-
location: routerContext.context.location,
84+
location: router.location,
9085
};
9186

9287
return {

0 commit comments

Comments
 (0)