Skip to content

Commit 1b3f9b3

Browse files
authored
test(performance): Remove deprecated router mocks (#94830)
1 parent 2e3fa6b commit 1b3f9b3

File tree

5 files changed

+80
-107
lines changed

5 files changed

+80
-107
lines changed

static/app/views/performance/table.spec.tsx

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@ import ProjectsStore from 'sentry/stores/projectsStore';
88
import EventView from 'sentry/utils/discover/eventView';
99
import {MEPSettingProvider} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
1010
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
11-
import {useLocation} from 'sentry/utils/useLocation';
1211
import {OrganizationContext} from 'sentry/views/organizationContext';
1312
import Table from 'sentry/views/performance/table';
1413

1514
const FEATURES = ['performance-view'];
1615

17-
jest.mock('sentry/utils/useLocation');
18-
19-
const mockUseLocation = jest.mocked(useLocation);
20-
2116
const initializeData = (settings = {}, features: string[] = []) => {
2217
const projects = [
2318
ProjectFixture({id: '1', slug: '1'}),
@@ -37,7 +32,7 @@ function WrappedComponent({data, ...rest}: any) {
3732
<MEPSettingProvider>
3833
<Table
3934
organization={data.organization}
40-
location={data.router.location}
35+
location={LocationFixture({...data.initialRouterConfig.location})}
4136
setError={jest.fn()}
4237
summaryConditions=""
4338
{...data}
@@ -108,9 +103,6 @@ function mockEventView(data: ReturnType<typeof initializeData>) {
108103
describe('Performance > Table', function () {
109104
let eventsMock: jest.Mock;
110105
beforeEach(function () {
111-
mockUseLocation.mockReturnValue(
112-
LocationFixture({pathname: '/organizations/org-slug/insights/summary'})
113-
);
114106
MockApiClient.addMockResponse({
115107
url: '/organizations/org-slug/projects/',
116108
body: [],
@@ -201,7 +193,7 @@ describe('Performance > Table', function () {
201193

202194
ProjectsStore.loadInitialData(data.projects);
203195

204-
render(
196+
const {router} = render(
205197
<WrappedComponent
206198
data={data}
207199
eventView={mockEventView(data)}
@@ -210,10 +202,10 @@ describe('Performance > Table', function () {
210202
projects={data.projects}
211203
/>,
212204
{
213-
router: data.router,
214-
deprecatedRouterMocks: true,
205+
initialRouterConfig: data.initialRouterConfig,
215206
}
216207
);
208+
const initialLocation = router.location;
217209

218210
const rows = await screen.findAllByTestId('grid-body-row');
219211
const transactionCells = within(rows[0]!).getAllByTestId('grid-body-cell');
@@ -243,16 +235,15 @@ describe('Performance > Table', function () {
243235
expect(transactionCellTrigger).toBeInTheDocument();
244236
await userEvent.click(transactionCellTrigger);
245237

246-
expect(data.router.push).toHaveBeenCalledTimes(0);
238+
expect(router.location).toEqual(initialLocation);
247239
await userEvent.click(screen.getByRole('menuitemradio', {name: 'Add to filter'}));
248240

249-
expect(data.router.push).toHaveBeenCalledTimes(1);
250-
expect(data.router.push).toHaveBeenNthCalledWith(1, {
251-
pathname: undefined,
252-
query: expect.objectContaining({
241+
expect(router.location).not.toEqual(initialLocation);
242+
expect(router.location.query).toEqual(
243+
expect.objectContaining({
253244
query: 'transaction:/apple/cart',
254-
}),
255-
});
245+
})
246+
);
256247
});
257248

258249
it('hides cell actions when withStaticFilters is true', async function () {
@@ -268,10 +259,7 @@ describe('Performance > Table', function () {
268259
summaryConditions=""
269260
projects={data.projects}
270261
withStaticFilters
271-
/>,
272-
{
273-
deprecatedRouterMocks: true,
274-
}
262+
/>
275263
);
276264

277265
expect(await screen.findByTestId('grid-editable')).toBeInTheDocument();
@@ -299,10 +287,7 @@ describe('Performance > Table', function () {
299287
setError={jest.fn()}
300288
summaryConditions=""
301289
projects={data.projects}
302-
/>,
303-
{
304-
deprecatedRouterMocks: true,
305-
}
290+
/>
306291
);
307292

308293
const indicatorContainer = await screen.findByTestId('unparameterized-indicator');
@@ -360,10 +345,7 @@ describe('Performance > Table', function () {
360345
summaryConditions=""
361346
projects={data.projects}
362347
isMEPEnabled
363-
/>,
364-
{
365-
deprecatedRouterMocks: true,
366-
}
348+
/>
367349
);
368350

369351
expect(await screen.findByTestId('grid-editable')).toBeInTheDocument();

static/app/views/performance/transactionSummary/transactionEvents/index.spec.tsx

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,18 @@ import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
66

77
import ProjectsStore from 'sentry/stores/projectsStore';
88
import {MEPSettingProvider} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
9-
import {useLocation} from 'sentry/utils/useLocation';
109
import TransactionEvents from 'sentry/views/performance/transactionSummary/transactionEvents';
1110
import {
1211
EVENTS_TABLE_RESPONSE_FIELDS,
1312
MOCK_EVENTS_TABLE_DATA,
1413
} from 'sentry/views/performance/transactionSummary/transactionEvents/testUtils';
1514

16-
jest.mock('sentry/utils/useLocation');
17-
18-
const mockUseLocation = jest.mocked(useLocation);
19-
2015
function WrappedComponent({data}: {data: ReturnType<typeof initializeData>}) {
2116
return (
2217
<MEPSettingProvider>
2318
<TransactionEvents
2419
organization={data.organization}
25-
location={data.router.location}
20+
location={LocationFixture({...data.initialRouterConfig.location})}
2621
/>
2722
</MEPSettingProvider>
2823
);
@@ -139,12 +134,6 @@ const setupMockApiResponeses = () => {
139134
});
140135
};
141136

142-
const setupMocks = () => {
143-
mockUseLocation.mockReturnValue(
144-
LocationFixture({pathname: '/organizations/org-slug/insights/summary'})
145-
);
146-
};
147-
148137
const initializeData = (settings?: InitializeDataSettings) => {
149138
settings = {
150139
features: ['performance-view'],
@@ -159,7 +148,6 @@ const initializeData = (settings?: InitializeDataSettings) => {
159148
describe('Performance > Transaction Summary > Transaction Events > Index', () => {
160149
beforeEach(() => {
161150
setupMockApiResponeses();
162-
setupMocks();
163151
});
164152
afterEach(() => {
165153
MockApiClient.clearMockResponses();
@@ -170,8 +158,7 @@ describe('Performance > Transaction Summary > Transaction Events > Index', () =>
170158
const data = initializeData();
171159

172160
render(<WrappedComponent data={data} />, {
173-
router: data.router,
174-
deprecatedRouterMocks: true,
161+
initialRouterConfig: data.initialRouterConfig,
175162
});
176163
expect(await screen.findByText('uhoh@example.com')).toBeInTheDocument();
177164
expect(await screen.findByText('moreuhoh@example.com')).toBeInTheDocument();
@@ -183,8 +170,7 @@ describe('Performance > Transaction Summary > Transaction Events > Index', () =>
183170
});
184171

185172
render(<WrappedComponent data={data} />, {
186-
router: data.router,
187-
deprecatedRouterMocks: true,
173+
initialRouterConfig: data.initialRouterConfig,
188174
});
189175
expect(await screen.findByText('uhoh@example.com')).toBeInTheDocument();
190176
expect(screen.queryByText('moreuhoh@example.com')).not.toBeInTheDocument();
@@ -193,9 +179,8 @@ describe('Performance > Transaction Summary > Transaction Events > Index', () =>
193179
it('should update transaction percentile query if selected', async () => {
194180
const data = initializeData();
195181

196-
render(<WrappedComponent data={data} />, {
197-
router: data.router,
198-
deprecatedRouterMocks: true,
182+
const {router} = render(<WrappedComponent data={data} />, {
183+
initialRouterConfig: data.initialRouterConfig,
199184
});
200185
const percentileButton = await screen.findByRole('button', {
201186
name: /percentile p100/i,
@@ -208,8 +193,8 @@ describe('Performance > Transaction Summary > Transaction Events > Index', () =>
208193

209194
await userEvent.click(p50);
210195

211-
expect(data.router.push).toHaveBeenCalledWith(
212-
expect.objectContaining({query: expect.objectContaining({showTransactions: 'p50'})})
196+
expect(router.location.query).toEqual(
197+
expect.objectContaining({showTransactions: 'p50'})
213198
);
214199
});
215200
});

0 commit comments

Comments
 (0)