Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 60 additions & 8 deletions static/app/components/issues/groupList.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import * as qs from 'query-string';
import {GroupFixture} from 'sentry-fixture/group';
import {MemberFixture} from 'sentry-fixture/member';
import {OrganizationFixture} from 'sentry-fixture/organization';
import {ProjectFixture} from 'sentry-fixture/project';
import {TeamFixture} from 'sentry-fixture/team';
import {UserFixture} from 'sentry-fixture/user';

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

import GroupStore from 'sentry/stores/groupStore';
import MemberListStore from 'sentry/stores/memberListStore';
import TeamStore from 'sentry/stores/teamStore';
import {RELATED_ISSUES_BOOLEAN_QUERY_ERROR} from 'sentry/views/alerts/rules/metric/details/relatedIssuesNotAvailable';

import GroupList from './groupList';
Expand All @@ -16,7 +20,6 @@ describe('GroupList', () => {
const membersUrl = `/organizations/${organization.slug}/users/`;
const issuesUrl = `/organizations/${organization.slug}/issues/`;
const defaultQueryParams = {query: '', sort: 'new', limit: '50'};
const issuesUrlWithDefaultQuery = `${issuesUrl}?${qs.stringify(defaultQueryParams)}`;
const initialRouterConfig = {
location: {
pathname: `/organizations/${organization.slug}/issues/`,
Expand All @@ -31,14 +34,16 @@ describe('GroupList', () => {

MockApiClient.addMockResponse({url: membersUrl, body: [MemberFixture()]});
MockApiClient.addMockResponse({
url: issuesUrlWithDefaultQuery,
url: issuesUrl,
method: 'GET',
body: [group],
});
});

afterEach(() => {
GroupStore.reset();
TeamStore.reset();
MemberListStore.reset();
});

it('renders the group list', async () => {
Expand All @@ -59,7 +64,7 @@ describe('GroupList', () => {
it('renders empty state when no groups are returned', async () => {
MockApiClient.addMockResponse({url: membersUrl, body: []});
MockApiClient.addMockResponse({
url: issuesUrlWithDefaultQuery,
url: issuesUrl,
method: 'GET',
body: [],
});
Expand All @@ -77,7 +82,7 @@ describe('GroupList', () => {
it('renders custom error when query has boolean logic', async () => {
const renderErrorMessage = jest.fn(() => <div>custom error</div>);
const issuesRequest = MockApiClient.addMockResponse({
url: `${issuesUrl}?${qs.stringify({...defaultQueryParams, query: 'issue.id:1'})}`,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the file changes here are simplifying the mocks.

/organizations/org-slug/issues/?query=foo&cursor=bar -> /organizations/org-slug/issues/

url: issuesUrl,
method: 'GET',
body: [],
});
Expand Down Expand Up @@ -113,7 +118,7 @@ describe('GroupList', () => {
MockApiClient.addMockResponse({url: membersUrl, body: []});
const linkHeader = '<https://sentry.io/?cursor=next>; rel="next"';
MockApiClient.addMockResponse({
url: issuesUrlWithDefaultQuery,
url: issuesUrl,
method: 'GET',
body: [group],
headers: {Link: linkHeader},
Expand All @@ -140,7 +145,7 @@ describe('GroupList', () => {
groups: [group],
loading: false,
pageLinks: linkHeader,
memberList: undefined,
memberList: {},
}),
expect.any(Function)
)
Expand All @@ -154,7 +159,7 @@ describe('GroupList', () => {

MockApiClient.addMockResponse({url: membersUrl, body: []});
MockApiClient.addMockResponse({
url: issuesUrlWithDefaultQuery,
url: issuesUrl,
method: 'GET',
body: [GroupFixture()],
headers: {Link: pageLinks},
Expand Down Expand Up @@ -182,4 +187,51 @@ describe('GroupList', () => {

expect(router.location.query.page).toBe('1');
});

it('updates the assignee when changed', async () => {
const user = UserFixture({id: '2', name: 'Jane Doe', email: 'jane@example.com'});
const team = TeamFixture({id: '1', slug: 'cool-team'});
const project = ProjectFixture({teams: [team]});
const groupWithProject = GroupFixture({project, assignedTo: null});

TeamStore.loadInitialData([team]);
MemberListStore.loadInitialData([user]);

MockApiClient.addMockResponse({url: membersUrl, body: [MemberFixture({user})]});
MockApiClient.addMockResponse({
url: issuesUrl,
method: 'GET',
body: [groupWithProject],
});

const assignMock = MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/issues/${groupWithProject.id}/`,
method: 'PUT',
body: {...groupWithProject, assignedTo: {...user, type: 'user'}},
});

render(<GroupList numPlaceholderRows={1} queryParams={defaultQueryParams} />, {
organization,
initialRouterConfig,
});

expect(await screen.findByText('RequestError')).toBeInTheDocument();

// Open the assignee dropdown and select a user
await userEvent.click(
await screen.findByRole('button', {name: 'Modify issue assignee'})
);
await userEvent.click(await screen.findByRole('option', {name: /Jane Doe/}));

// Should make the API call and display the new assignee
await waitFor(() => {
expect(assignMock).toHaveBeenCalledWith(
`/organizations/${organization.slug}/issues/${groupWithProject.id}/`,
expect.objectContaining({
data: {assignedTo: 'user:2', assignedBy: 'assignee_selector'},
})
);
});
expect(await screen.findByTestId('assigned-avatar')).toBeInTheDocument();
});
});
Loading
Loading