Skip to content

Commit 62cf0fa

Browse files
authored
test(ui): Migrate deprecated router mocks to memory router (#103120)
Doing a batch of various files that cursor was able to do automatically.
1 parent a1580bc commit 62cf0fa

File tree

15 files changed

+204
-345
lines changed

15 files changed

+204
-345
lines changed

static/app/views/alerts/list/rules/alertRulesList.spec.tsx

Lines changed: 62 additions & 130 deletions
Large diffs are not rendered by default.

static/app/views/auth/loginForm.spec.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import {RouterFixture} from 'sentry-fixture/routerFixture';
2-
31
import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
42

53
import ConfigStore from 'sentry/stores/configStore';
@@ -32,16 +30,13 @@ describe('LoginForm', () => {
3230
},
3331
});
3432

35-
render(<LoginForm authConfig={emptyAuthConfig} />, {
36-
deprecatedRouterMocks: true,
37-
});
33+
render(<LoginForm authConfig={emptyAuthConfig} />);
3834
await doLogin();
3935

4036
expect(await screen.findByText('Bad username password')).toBeInTheDocument();
4137
});
4238

4339
it('handles success', async () => {
44-
const router = RouterFixture();
4540
const userObject = {
4641
id: 1,
4742
name: 'Joe',
@@ -57,10 +52,7 @@ describe('LoginForm', () => {
5752
},
5853
});
5954

60-
render(<LoginForm authConfig={emptyAuthConfig} />, {
61-
router,
62-
deprecatedRouterMocks: true,
63-
});
55+
const {router} = render(<LoginForm authConfig={emptyAuthConfig} />);
6456
await doLogin();
6557

6658
expect(mockRequest).toHaveBeenCalledWith(
@@ -71,7 +63,7 @@ describe('LoginForm', () => {
7163
);
7264

7365
await waitFor(() => expect(ConfigStore.get('user')).toEqual(userObject));
74-
expect(router.push).toHaveBeenCalledWith({pathname: '/next/'});
66+
expect(router.location.pathname).toBe('/next/');
7567
});
7668

7769
it('renders login provider buttons', () => {
@@ -81,9 +73,7 @@ describe('LoginForm', () => {
8173
githubLoginLink: '/githubLogin',
8274
};
8375

84-
render(<LoginForm authConfig={authConfig} />, {
85-
deprecatedRouterMocks: true,
86-
});
76+
render(<LoginForm authConfig={authConfig} />);
8777

8878
expect(screen.getByText('Sign in with GitHub')).toBeInTheDocument();
8979
expect(screen.getByText('Sign in with Azure DevOps')).toBeInTheDocument();

static/app/views/auth/registerForm.spec.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import {RouterFixture} from 'sentry-fixture/routerFixture';
2-
31
import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
42

53
import ConfigStore from 'sentry/stores/configStore';
@@ -46,16 +44,13 @@ describe('Register', () => {
4644
},
4745
});
4846

49-
render(<RegisterForm authConfig={emptyAuthConfig} />, {
50-
deprecatedRouterMocks: true,
51-
});
47+
render(<RegisterForm authConfig={emptyAuthConfig} />);
5248
await doLogin(mockRequest);
5349

5450
expect(await screen.findByText('Registration failed')).toBeInTheDocument();
5551
});
5652

5753
it('handles success', async () => {
58-
const router = RouterFixture();
5954
const userObject = {
6055
id: 1,
6156
name: 'Joe',
@@ -71,13 +66,10 @@ describe('Register', () => {
7166
},
7267
});
7368

74-
render(<RegisterForm authConfig={emptyAuthConfig} />, {
75-
router,
76-
deprecatedRouterMocks: true,
77-
});
69+
const {router} = render(<RegisterForm authConfig={emptyAuthConfig} />);
7870
await doLogin(mockRequest);
7971

8072
await waitFor(() => expect(ConfigStore.get('user')).toEqual(userObject));
81-
expect(router.push).toHaveBeenCalledWith({pathname: '/next/'});
73+
expect(router.location.pathname).toBe('/next/');
8274
});
8375
});

static/app/views/dashboards/widgetBuilder/components/datasetSelector.spec.tsx

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {OrganizationFixture} from 'sentry-fixture/organization';
2-
import {RouterFixture} from 'sentry-fixture/routerFixture';
32

43
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
54

@@ -14,33 +13,20 @@ jest.mock('sentry/utils/useNavigate', () => ({
1413
const mockUseNavigate = jest.mocked(useNavigate);
1514

1615
describe('DatasetSelector', () => {
17-
let router!: ReturnType<typeof RouterFixture>;
18-
let organization!: ReturnType<typeof OrganizationFixture>;
19-
beforeEach(() => {
20-
router = RouterFixture();
21-
organization = OrganizationFixture();
22-
});
23-
2416
it('changes the dataset', async () => {
2517
const mockNavigate = jest.fn();
2618
mockUseNavigate.mockReturnValue(mockNavigate);
2719

2820
render(
2921
<WidgetBuilderProvider>
3022
<DatasetSelector />
31-
</WidgetBuilderProvider>,
32-
{
33-
router,
34-
organization,
35-
deprecatedRouterMocks: true,
36-
}
23+
</WidgetBuilderProvider>
3724
);
3825

3926
await userEvent.click(await screen.findByLabelText('Issues'));
4027

4128
expect(mockNavigate).toHaveBeenCalledWith(
4229
expect.objectContaining({
43-
...router.location,
4430
query: expect.objectContaining({dataset: 'issue'}),
4531
}),
4632
expect.anything()
@@ -60,9 +46,7 @@ describe('DatasetSelector', () => {
6046
<DatasetSelector />
6147
</WidgetBuilderProvider>,
6248
{
63-
router,
6449
organization: organizationWithDeprecation,
65-
deprecatedRouterMocks: true,
6650
}
6751
);
6852

@@ -83,7 +67,6 @@ describe('DatasetSelector', () => {
8367
// Verify navigation to spans dataset
8468
expect(mockNavigate).toHaveBeenCalledWith(
8569
expect.objectContaining({
86-
...router.location,
8770
query: expect.objectContaining({dataset: 'spans'}),
8871
}),
8972
expect.anything()
@@ -103,9 +86,7 @@ describe('DatasetSelector', () => {
10386
<DatasetSelector />
10487
</WidgetBuilderProvider>,
10588
{
106-
router,
10789
organization: organizationWithoutDeprecation,
108-
deprecatedRouterMocks: true,
10990
}
11091
);
11192

@@ -117,7 +98,6 @@ describe('DatasetSelector', () => {
11798

11899
expect(mockNavigate).toHaveBeenCalledWith(
119100
expect.objectContaining({
120-
...router.location,
121101
query: expect.objectContaining({dataset: 'transaction-like'}),
122102
}),
123103
expect.anything()

static/app/views/dashboards/widgetBuilder/components/groupBySelector.spec.tsx

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import {LocationFixture} from 'sentry-fixture/locationFixture';
21
import {OrganizationFixture} from 'sentry-fixture/organization';
3-
import {RouterFixture} from 'sentry-fixture/routerFixture';
42

53
import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
64

@@ -117,16 +115,17 @@ describe('WidgetBuilderGroupBySelector', () => {
117115
</TraceItemAttributeProvider>
118116
</WidgetBuilderProvider>,
119117
{
120-
organization: organizationWithFeature,
121-
router: RouterFixture({
122-
location: LocationFixture({
118+
initialRouterConfig: {
119+
route: '/organizations/:orgId/dashboard/:dashboardId/',
120+
location: {
121+
pathname: '/organizations/org-slug/dashboard/1/',
123122
query: {
124123
dataset: WidgetType.TRANSACTIONS,
125124
displayType: DisplayType.LINE,
126125
},
127-
}),
128-
}),
129-
deprecatedRouterMocks: true,
126+
},
127+
},
128+
organization: organizationWithFeature,
130129
}
131130
);
132131

@@ -150,16 +149,17 @@ describe('WidgetBuilderGroupBySelector', () => {
150149
</TraceItemAttributeProvider>
151150
</WidgetBuilderProvider>,
152151
{
153-
organization: organizationWithoutFeature,
154-
router: RouterFixture({
155-
location: LocationFixture({
152+
initialRouterConfig: {
153+
route: '/organizations/:orgId/dashboard/:dashboardId/',
154+
location: {
155+
pathname: '/organizations/org-slug/dashboard/1/',
156156
query: {
157157
dataset: WidgetType.TRANSACTIONS,
158158
displayType: DisplayType.LINE,
159159
},
160-
}),
161-
}),
162-
deprecatedRouterMocks: true,
160+
},
161+
},
162+
organization: organizationWithoutFeature,
163163
}
164164
);
165165

@@ -182,16 +182,17 @@ describe('WidgetBuilderGroupBySelector', () => {
182182
</TraceItemAttributeProvider>
183183
</WidgetBuilderProvider>,
184184
{
185-
organization: organizationWithFeature,
186-
router: RouterFixture({
187-
location: LocationFixture({
185+
initialRouterConfig: {
186+
route: '/organizations/:orgId/dashboard/:dashboardId/',
187+
location: {
188+
pathname: '/organizations/org-slug/dashboard/1/',
188189
query: {
189190
dataset: WidgetType.ERRORS,
190191
displayType: DisplayType.LINE,
191192
},
192-
}),
193-
}),
194-
deprecatedRouterMocks: true,
193+
},
194+
},
195+
organization: organizationWithFeature,
195196
}
196197
);
197198

static/app/views/dashboards/widgetBuilder/components/nameAndDescFields.spec.tsx

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,36 @@
1-
import {OrganizationFixture} from 'sentry-fixture/organization';
2-
import {RouterFixture} from 'sentry-fixture/routerFixture';
3-
41
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
52

6-
import {useNavigate} from 'sentry/utils/useNavigate';
73
import WidgetBuilderNameAndDescription from 'sentry/views/dashboards/widgetBuilder/components/nameAndDescFields';
84
import {WidgetBuilderProvider} from 'sentry/views/dashboards/widgetBuilder/contexts/widgetBuilderContext';
95

10-
jest.mock('sentry/utils/useNavigate', () => ({
11-
useNavigate: jest.fn(),
12-
}));
13-
14-
const mockUseNavigate = jest.mocked(useNavigate);
15-
166
describe('WidgetBuilder', () => {
17-
let router!: ReturnType<typeof RouterFixture>;
18-
let organization!: ReturnType<typeof OrganizationFixture>;
19-
beforeEach(() => {
20-
router = RouterFixture({
21-
location: {
22-
pathname: '/organizations/org-slug/dashboard/1/',
23-
query: {project: '-1'},
24-
},
25-
params: {},
26-
});
27-
organization = OrganizationFixture();
28-
});
7+
const initialRouterConfig = {
8+
route: '/organizations/:orgId/dashboard/:dashboardId/',
9+
location: {
10+
pathname: '/organizations/org-slug/dashboard/1/',
11+
query: {project: '-1'},
12+
},
13+
};
2914

3015
it('edits name and description', async () => {
31-
const mockNavigate = jest.fn();
32-
mockUseNavigate.mockReturnValue(mockNavigate);
33-
34-
render(
16+
const {router} = render(
3517
<WidgetBuilderProvider>
3618
<WidgetBuilderNameAndDescription />
3719
</WidgetBuilderProvider>,
3820
{
39-
router,
40-
organization,
41-
deprecatedRouterMocks: true,
21+
initialRouterConfig,
4222
}
4323
);
4424

4525
await userEvent.type(await screen.findByPlaceholderText('Name'), 'some name');
4626

4727
// trigger blur
4828
await userEvent.tab();
49-
expect(mockNavigate).toHaveBeenLastCalledWith(
29+
expect(router.location).toEqual(
5030
expect.objectContaining({
51-
...router.location,
31+
...initialRouterConfig.location,
5232
query: expect.objectContaining({title: 'some name'}),
53-
}),
54-
expect.anything()
33+
})
5534
);
5635

5736
await userEvent.click(await screen.findByTestId('add-description'));
@@ -63,12 +42,11 @@ describe('WidgetBuilder', () => {
6342

6443
// trigger blur
6544
await userEvent.tab();
66-
expect(mockNavigate).toHaveBeenLastCalledWith(
45+
expect(router.location).toEqual(
6746
expect.objectContaining({
68-
...router.location,
47+
...initialRouterConfig.location,
6948
query: expect.objectContaining({description: 'some description'}),
70-
}),
71-
expect.anything()
49+
})
7250
);
7351
});
7452

@@ -80,9 +58,7 @@ describe('WidgetBuilder', () => {
8058
/>
8159
</WidgetBuilderProvider>,
8260
{
83-
router,
84-
organization,
85-
deprecatedRouterMocks: true,
61+
initialRouterConfig,
8662
}
8763
);
8864

static/app/views/insights/browser/resources/views/resourcesLandingPage.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('ResourcesLandingPage', () => {
4646
});
4747

4848
it('renders a list of resources', async () => {
49-
render(<ResourcesLandingPage />, {organization, deprecatedRouterMocks: true});
49+
render(<ResourcesLandingPage />, {organization});
5050
await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
5151

5252
expect(
@@ -59,7 +59,7 @@ describe('ResourcesLandingPage', () => {
5959
});
6060

6161
it('fetches domain data', async () => {
62-
render(<ResourcesLandingPage />, {organization, deprecatedRouterMocks: true});
62+
render(<ResourcesLandingPage />, {organization});
6363
await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
6464

6565
expect(requestMocks.domainSelector!.mock.calls).toMatchInlineSnapshot(`
@@ -93,7 +93,7 @@ describe('ResourcesLandingPage', () => {
9393
});
9494

9595
it('contains correct query in charts', async () => {
96-
render(<ResourcesLandingPage />, {organization, deprecatedRouterMocks: true});
96+
render(<ResourcesLandingPage />, {organization});
9797
await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
9898

9999
expect(requestMocks.mainTable!.mock.calls).toMatchInlineSnapshot(`

0 commit comments

Comments
 (0)