Skip to content

Commit c4928be

Browse files
authored
test(issues): Migrate issue details components away from deprecatedRouterMocks (#103699)
1 parent f6d3d50 commit c4928be

File tree

3 files changed

+79
-46
lines changed

3 files changed

+79
-46
lines changed

static/app/views/issueDetails/groupSimilarIssues/similarIssuesDrawer.spec.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import {GroupFixture} from 'sentry-fixture/group';
22
import {OrganizationFixture} from 'sentry-fixture/organization';
33
import {ProjectFixture} from 'sentry-fixture/project';
4-
import {RouterFixture} from 'sentry-fixture/routerFixture';
54

6-
import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
5+
import {
6+
render,
7+
screen,
8+
waitFor,
9+
type RouterConfig,
10+
} from 'sentry-test/reactTestingLibrary';
711

812
import GroupStore from 'sentry/stores/groupStore';
913
import ProjectsStore from 'sentry/stores/projectsStore';
@@ -13,9 +17,12 @@ describe('SimilarIssuesDrawer', () => {
1317
const organization = OrganizationFixture();
1418
const project = ProjectFixture({features: ['similarity-view']});
1519
const group = GroupFixture();
16-
const router = RouterFixture({
17-
params: {groupId: group.id},
18-
});
20+
const initialRouterConfig: RouterConfig = {
21+
location: {
22+
pathname: `/organizations/${organization.slug}/issues/${group.id}/similar/`,
23+
},
24+
route: '/organizations/:orgId/issues/:groupId/similar/',
25+
};
1926
let mockSimilarIssues: jest.Mock;
2027

2128
beforeEach(() => {
@@ -53,8 +60,7 @@ describe('SimilarIssuesDrawer', () => {
5360
it('renders the content as expected', async () => {
5461
render(<SimilarIssuesDrawer group={group} project={project} />, {
5562
organization,
56-
router,
57-
deprecatedRouterMocks: true,
63+
initialRouterConfig,
5864
});
5965

6066
expect(

static/app/views/issueDetails/streamline/issueDetailsEventNavigation.spec.tsx

Lines changed: 65 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import {EventFixture} from 'sentry-fixture/event';
22
import {GroupFixture} from 'sentry-fixture/group';
3-
import {LocationFixture} from 'sentry-fixture/locationFixture';
4-
import {RouterFixture} from 'sentry-fixture/routerFixture';
3+
import {OrganizationFixture} from 'sentry-fixture/organization';
54

6-
import {initializeOrg} from 'sentry-test/initializeOrg';
7-
import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
5+
import {
6+
render,
7+
screen,
8+
userEvent,
9+
waitFor,
10+
type RouterConfig,
11+
} from 'sentry-test/reactTestingLibrary';
812

913
import {IssueDetailsEventNavigation} from './issueDetailsEventNavigation';
1014

1115
describe('IssueDetailsEventNavigation', () => {
12-
const {organization, router} = initializeOrg();
16+
const organization = OrganizationFixture();
1317
const group = GroupFixture({id: 'group-id'});
1418
const testEvent = EventFixture({
1519
id: 'event-id',
@@ -28,6 +32,24 @@ describe('IssueDetailsEventNavigation', () => {
2832
event: testEvent,
2933
group,
3034
};
35+
const routerConfigBase: Pick<RouterConfig, 'routes'> = {
36+
routes: [
37+
'/organizations/:orgId/issues/:groupId/events/',
38+
'/organizations/:orgId/issues/:groupId/events/:eventId/',
39+
],
40+
};
41+
const latestRouterConfig: RouterConfig = {
42+
...routerConfigBase,
43+
location: {
44+
pathname: `/organizations/${organization.slug}/issues/${group.id}/events/latest/`,
45+
},
46+
};
47+
const recommendedRouterConfig: RouterConfig = {
48+
...routerConfigBase,
49+
location: {
50+
pathname: `/organizations/${organization.slug}/issues/${group.id}/events/recommended/`,
51+
},
52+
};
3153

3254
beforeEach(() => {
3355
jest.resetAllMocks();
@@ -39,58 +61,63 @@ describe('IssueDetailsEventNavigation', () => {
3961

4062
describe('recommended event tabs', () => {
4163
it('can navigate to the oldest event', async () => {
42-
render(<IssueDetailsEventNavigation {...defaultProps} isSmallNav />, {
43-
router,
44-
deprecatedRouterMocks: true,
45-
});
64+
const {router} = render(
65+
<IssueDetailsEventNavigation {...defaultProps} isSmallNav />,
66+
{
67+
initialRouterConfig: latestRouterConfig,
68+
}
69+
);
4670

4771
await userEvent.click(await screen.findByRole('tab', {name: 'First'}));
4872

49-
expect(router.push).toHaveBeenCalledWith({
50-
pathname: '/organizations/org-slug/issues/group-id/events/oldest/',
51-
query: {referrer: 'oldest-event'},
52-
});
73+
await waitFor(() =>
74+
expect(router.location.pathname).toBe(
75+
'/organizations/org-slug/issues/group-id/events/oldest/'
76+
)
77+
);
78+
expect(router.location.query).toEqual({referrer: 'oldest-event'});
5379
});
5480

5581
it('can navigate to the latest event', async () => {
56-
render(<IssueDetailsEventNavigation {...defaultProps} isSmallNav />, {
57-
router,
58-
deprecatedRouterMocks: true,
59-
});
82+
const {router} = render(
83+
<IssueDetailsEventNavigation {...defaultProps} isSmallNav />,
84+
{
85+
initialRouterConfig: recommendedRouterConfig,
86+
}
87+
);
6088

6189
await userEvent.click(await screen.findByRole('tab', {name: 'Latest'}));
6290

63-
expect(router.push).toHaveBeenCalledWith({
64-
pathname: '/organizations/org-slug/issues/group-id/events/latest/',
65-
query: {referrer: 'latest-event'},
66-
});
91+
await waitFor(() =>
92+
expect(router.location.pathname).toBe(
93+
'/organizations/org-slug/issues/group-id/events/latest/'
94+
)
95+
);
96+
expect(router.location.query).toEqual({referrer: 'latest-event'});
6797
});
6898

6999
it('can navigate to the recommended event', async () => {
70-
const recommendedEventRouter = RouterFixture({
71-
params: {eventId: 'latest'},
72-
location: LocationFixture({
73-
pathname: `/organizations/org-slug/issues/group-id/events/latest/`,
74-
}),
75-
});
76-
77-
render(<IssueDetailsEventNavigation {...defaultProps} isSmallNav />, {
78-
router: recommendedEventRouter,
79-
deprecatedRouterMocks: true,
80-
});
100+
const {router} = render(
101+
<IssueDetailsEventNavigation {...defaultProps} isSmallNav />,
102+
{
103+
initialRouterConfig: latestRouterConfig,
104+
}
105+
);
81106

82107
await userEvent.click(await screen.findByRole('tab', {name: 'Rec.'}));
83108

84-
expect(recommendedEventRouter.push).toHaveBeenCalledWith({
85-
pathname: '/organizations/org-slug/issues/group-id/events/recommended/',
86-
query: {referrer: 'recommended-event'},
87-
});
109+
await waitFor(() =>
110+
expect(router.location.pathname).toBe(
111+
'/organizations/org-slug/issues/group-id/events/recommended/'
112+
)
113+
);
114+
expect(router.location.query).toEqual({referrer: 'recommended-event'});
88115
});
89116
});
90117

91118
it('can navigate next/previous events', async () => {
92119
render(<IssueDetailsEventNavigation {...defaultProps} />, {
93-
deprecatedRouterMocks: true,
120+
initialRouterConfig: latestRouterConfig,
94121
});
95122

96123
expect(await screen.findByRole('button', {name: 'Previous Event'})).toHaveAttribute(
@@ -117,7 +144,7 @@ describe('IssueDetailsEventNavigation', () => {
117144
body: EventFixture(),
118145
});
119146
render(<IssueDetailsEventNavigation {...defaultProps} event={event} />, {
120-
deprecatedRouterMocks: true,
147+
initialRouterConfig: latestRouterConfig,
121148
});
122149

123150
expect(mockNextEvent).not.toHaveBeenCalled();

static/app/views/issueList/issueViews/issueViewsList/issueViewsList.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('IssueViewsList', () => {
112112
],
113113
});
114114

115-
render(<IssueViewsList />, {organization, deprecatedRouterMocks: false});
115+
render(<IssueViewsList />, {organization});
116116

117117
// By default, sorts by popularity (desc) then visited (desc) then created (desc)
118118
await waitFor(() => {

0 commit comments

Comments
 (0)