Skip to content

Commit 6e9bc81

Browse files
authored
test(issues): Remove router mocks from tag components (#102052)
Swaps the test router mocks for our new test router
1 parent 6e307dd commit 6e9bc81

File tree

3 files changed

+47
-117
lines changed

3 files changed

+47
-117
lines changed

static/app/views/issueDetails/groupTags/groupTagValues.spec.tsx

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {ProjectFixture} from 'sentry-fixture/project';
33
import {TagsFixture} from 'sentry-fixture/tags';
44
import {TagValuesFixture} from 'sentry-fixture/tagvalues';
55

6-
import {initializeOrg} from 'sentry-test/initializeOrg';
76
import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
87

98
import ProjectsStore from 'sentry/stores/projectsStore';
@@ -14,19 +13,15 @@ describe('GroupTagValues', () => {
1413
const tags = TagsFixture();
1514
const project = ProjectFixture();
1615

17-
function init(tagKey: string, environment?: string[] | string) {
18-
return initializeOrg({
19-
router: {
20-
location: {
21-
query: {
22-
environment,
23-
},
24-
pathname: '/organizations/:orgId/issues/:groupId/tags/:tagKey/',
25-
},
26-
params: {orgId: 'org-slug', groupId: group.id, tagKey},
16+
const makeInitialRouterConfig = (tagKey: string, environment?: string[] | string) => ({
17+
location: {
18+
pathname: `/organizations/org-slug/issues/${group.id}/tags/${tagKey}/`,
19+
query: {
20+
...(environment && {environment}),
2721
},
28-
});
29-
}
22+
},
23+
route: '/organizations/:orgId/issues/:groupId/tags/:tagKey/',
24+
});
3025

3126
beforeEach(() => {
3227
ProjectsStore.init();
@@ -46,15 +41,12 @@ describe('GroupTagValues', () => {
4641
});
4742

4843
it('renders a list of tag values', async () => {
49-
const {router} = init('user');
50-
5144
MockApiClient.addMockResponse({
5245
url: '/organizations/org-slug/issues/1/tags/user/values/',
5346
body: TagValuesFixture(),
5447
});
5548
render(<GroupTagValues />, {
56-
router,
57-
deprecatedRouterMocks: true,
49+
initialRouterConfig: makeInitialRouterConfig('user'),
5850
});
5951

6052
// Special case for user tag - column title changes to Affected Users
@@ -69,8 +61,6 @@ describe('GroupTagValues', () => {
6961
});
7062

7163
it('can page through tag values', async () => {
72-
const {router} = init('user');
73-
7464
MockApiClient.addMockResponse({
7565
url: '/organizations/org-slug/issues/1/tags/user/values/',
7666
body: TagValuesFixture(),
@@ -80,9 +70,8 @@ describe('GroupTagValues', () => {
8070
'<https://sentry.io/api/0/organizations/sentry/user-feedback/?statsPeriod=14d&cursor=0:100:0>; rel="next"; results="true"; cursor="0:100:0"',
8171
},
8272
});
83-
render(<GroupTagValues />, {
84-
router,
85-
deprecatedRouterMocks: true,
73+
const {router} = render(<GroupTagValues />, {
74+
initialRouterConfig: makeInitialRouterConfig('user'),
8675
});
8776

8877
expect(await screen.findByRole('button', {name: 'Previous'})).toBeDisabled();
@@ -91,46 +80,38 @@ describe('GroupTagValues', () => {
9180
// Clicking next button loads page with query param ?cursor=0:100:0
9281
await userEvent.click(screen.getByRole('button', {name: 'Next'}));
9382
await waitFor(() => {
94-
expect(router.push).toHaveBeenCalledWith(
95-
expect.objectContaining({query: expect.objectContaining({cursor: '0:100:0'})})
96-
);
83+
expect(router.location.query.cursor).toBe('0:100:0');
9784
});
9885
});
9986

10087
it('navigates to issue details events tab with correct query params', async () => {
101-
const {router} = init('user');
102-
10388
MockApiClient.addMockResponse({
10489
url: '/organizations/org-slug/issues/1/tags/user/values/',
10590
body: TagValuesFixture(),
10691
});
107-
render(<GroupTagValues />, {
108-
router,
109-
deprecatedRouterMocks: true,
92+
const {router} = render(<GroupTagValues />, {
93+
initialRouterConfig: makeInitialRouterConfig('user'),
11094
});
11195

11296
await userEvent.click(await screen.findByRole('button', {name: 'More'}));
11397
await userEvent.click(
11498
screen.getByRole('menuitemradio', {name: 'Search All Issues with Tag Value'})
11599
);
116100

117-
expect(router.push).toHaveBeenCalledWith({
118-
pathname: '/organizations/org-slug/issues/',
119-
query: {query: 'user.username:david'},
101+
await waitFor(() => {
102+
expect(router.location.pathname).toBe('/organizations/org-slug/issues/');
120103
});
104+
expect(router.location.query.query).toBe('user.username:david');
121105
});
122106

123107
it('renders an error message if tag values request fails', async () => {
124-
const {router} = init('user', 'staging');
125-
126108
MockApiClient.addMockResponse({
127109
url: '/organizations/org-slug/issues/1/tags/user/values/',
128110
statusCode: 500,
129111
});
130112

131113
render(<GroupTagValues />, {
132-
router,
133-
deprecatedRouterMocks: true,
114+
initialRouterConfig: makeInitialRouterConfig('user', 'staging'),
134115
});
135116

136117
expect(
@@ -139,16 +120,13 @@ describe('GroupTagValues', () => {
139120
});
140121

141122
it('renders an error message if no tag values are returned because of environment selection', async () => {
142-
const {router} = init('user', 'staging');
143-
144123
MockApiClient.addMockResponse({
145124
url: '/organizations/org-slug/issues/1/tags/user/values/',
146125
body: [],
147126
});
148127

149128
render(<GroupTagValues />, {
150-
router,
151-
deprecatedRouterMocks: true,
129+
initialRouterConfig: makeInitialRouterConfig('user', 'staging'),
152130
});
153131

154132
expect(

static/app/views/issueDetails/groupTags/groupTagsTab.spec.tsx

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
import {GroupFixture} from 'sentry-fixture/group';
2+
import {OrganizationFixture} from 'sentry-fixture/organization';
23
import {TagsFixture} from 'sentry-fixture/tags';
34

4-
import {initializeOrg} from 'sentry-test/initializeOrg';
5-
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
5+
import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
66

77
import {GroupTagsTab} from './groupTagsTab';
88

99
describe('GroupTagsTab', () => {
1010
const group = GroupFixture();
11-
const {router, organization} = initializeOrg({
12-
router: {
13-
location: {
14-
query: {
15-
environment: 'dev',
16-
},
17-
},
18-
params: {
19-
orgId: 'org-slug',
20-
groupId: group.id,
11+
const organization = OrganizationFixture();
12+
let tagsMock: jest.Mock;
13+
14+
const makeInitialRouterConfig = () => ({
15+
location: {
16+
pathname: `/organizations/${organization.slug}/issues/${group.id}/tags/`,
17+
query: {
18+
environment: 'dev',
2119
},
2220
},
21+
route: '/organizations/:orgId/issues/:groupId/tags/',
2322
});
24-
let tagsMock: jest.Mock;
2523

2624
beforeEach(() => {
2725
MockApiClient.clearMockResponses();
@@ -36,10 +34,9 @@ describe('GroupTagsTab', () => {
3634
});
3735

3836
it('navigates to issue details events tab with correct query params', async () => {
39-
render(<GroupTagsTab />, {
40-
router,
37+
const {router} = render(<GroupTagsTab />, {
38+
initialRouterConfig: makeInitialRouterConfig(),
4139
organization,
42-
deprecatedRouterMocks: true,
4340
});
4441

4542
const headers = await screen.findAllByTestId('tag-title');
@@ -61,10 +58,11 @@ describe('GroupTagsTab', () => {
6158

6259
await userEvent.click(screen.getByText('david'));
6360

64-
expect(router.push).toHaveBeenCalledWith({
65-
pathname: '/organizations/org-slug/issues/1/events/',
66-
query: {query: 'user.username:david', environment: 'dev'},
61+
await waitFor(() => {
62+
expect(router.location.pathname).toBe('/organizations/org-slug/issues/1/events/');
6763
});
64+
expect(router.location.query.query).toBe('user.username:david');
65+
expect(router.location.query.environment).toBe('dev');
6866
});
6967

7068
it('shows an error message when the request fails', async () => {
@@ -74,9 +72,8 @@ describe('GroupTagsTab', () => {
7472
});
7573

7674
render(<GroupTagsTab />, {
77-
router,
75+
initialRouterConfig: makeInitialRouterConfig(),
7876
organization,
79-
deprecatedRouterMocks: true,
8077
});
8178

8279
expect(

0 commit comments

Comments
 (0)