Browse Source

ref: Change toast message for assigning issue to non-team member (#40854)

Change toast message from "Unable to change assignee. Please try again."
to "Cannot assign to non-team member" when assigning issue to non-team
member.

Fixes WOR-2064
Jodi Jang 2 years ago
parent
commit
d128b6b16c
2 changed files with 50 additions and 4 deletions
  1. 42 1
      static/app/components/assigneeSelector.spec.jsx
  2. 8 3
      static/app/stores/groupStore.tsx

+ 42 - 1
static/app/components/assigneeSelector.spec.jsx

@@ -6,6 +6,7 @@ import AssigneeSelectorComponent from 'sentry/components/assigneeSelector';
 import {putSessionUserFirst} from 'sentry/components/assigneeSelectorDropdown';
 import ConfigStore from 'sentry/stores/configStore';
 import GroupStore from 'sentry/stores/groupStore';
+import IndicatorStore from 'sentry/stores/indicatorStore';
 import MemberListStore from 'sentry/stores/memberListStore';
 import ProjectsStore from 'sentry/stores/projectsStore';
 import TeamStore from 'sentry/stores/teamStore';
@@ -17,7 +18,7 @@ jest.mock('sentry/actionCreators/modal', () => ({
 describe('AssigneeSelector', () => {
   let assignMock;
   let assignGroup2Mock;
-  let USER_1, USER_2, USER_3;
+  let USER_1, USER_2, USER_3, USER_4;
   let TEAM_1;
   let PROJECT_1;
   let GROUP_1;
@@ -39,6 +40,12 @@ describe('AssigneeSelector', () => {
       name: 'J J',
       email: 'jj@example.com',
     });
+    USER_4 = TestStubs.Member({
+      id: '4',
+      name: 'Jane Doe',
+      email: 'janedoe@example.com',
+      team_slug: 'cool-team2',
+    });
 
     TEAM_1 = TestStubs.Team({
       id: '3',
@@ -317,6 +324,40 @@ describe('AssigneeSelector', () => {
     expect(screen.getByTestId('assignee-selector')).toHaveTextContent('JB');
   });
 
+  it('shows the correct toast for assigning to a non-team member', async () => {
+    jest.spyOn(GroupStore, 'get').mockImplementation(() => GROUP_2);
+    const addMessageSpy = jest.spyOn(IndicatorStore, 'addMessage');
+
+    render(<AssigneeSelectorComponent id={GROUP_2.id} />);
+    act(() => MemberListStore.loadInitialData([USER_1, USER_2, USER_3, USER_4]));
+
+    assignMock = Client.addMockResponse({
+      method: 'PUT',
+      url: `/issues/${GROUP_2.id}/`,
+      statusCode: 400,
+      body: {detail: 'Cannot assign to non-team member'},
+    });
+
+    expect(screen.getByTestId('suggested-avatar-stack')).toBeInTheDocument();
+
+    await openMenu();
+    expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument();
+    expect(screen.getByText(`#${TEAM_1.slug}`)).toBeInTheDocument();
+    expect(await screen.findByText('Suggested')).toBeInTheDocument();
+
+    const options = screen.getAllByTestId('assignee-option');
+    expect(options[4]).toHaveTextContent('JD');
+    act(() => userEvent.click(options[4]));
+
+    await waitFor(() => {
+      expect(addMessageSpy).toHaveBeenCalledWith(
+        'Cannot assign to non-team member',
+        'error',
+        {duration: 4000}
+      );
+    });
+  });
+
   it('successfully shows suggested assignees', async () => {
     jest.spyOn(GroupStore, 'get').mockImplementation(() => GROUP_2);
     const onAssign = jest.fn();

+ 8 - 3
static/app/stores/groupStore.tsx

@@ -11,6 +11,7 @@ import {
   GroupRelease,
   GroupStats,
 } from 'sentry/types';
+import RequestError from 'sentry/utils/requestError/requestError';
 
 import SelectedGroupStore from './selectedGroupStore';
 import {CommonStoreDefinition} from './types';
@@ -60,7 +61,7 @@ interface GroupStoreDefinition extends CommonStoreDefinition<Item[]>, InternalDe
   loadInitialData: (items: Item[]) => void;
 
   onAssignTo: (changeId: string, itemId: string, data: any) => void;
-  onAssignToError: (changeId: string, itemId: string, error: Error) => void;
+  onAssignToError: (changeId: string, itemId: string, error: RequestError) => void;
   onAssignToSuccess: (changeId: string, itemId: string, response: any) => void;
 
   onDelete: (changeId: string, itemIds: ItemIds) => void;
@@ -315,9 +316,13 @@ const storeConfig: GroupStoreDefinition = {
   },
 
   // TODO(dcramer): This is not really the best place for this
-  onAssignToError(_changeId, itemId, _error) {
+  onAssignToError(_changeId, itemId, error) {
     this.clearStatus(itemId, 'assignTo');
-    showAlert(t('Unable to change assignee. Please try again.'), 'error');
+    if (error.responseJSON?.detail === 'Cannot assign to non-team member') {
+      showAlert(t('Cannot assign to non-team member'), 'error');
+    } else {
+      showAlert(t('Unable to change assignee. Please try again.'), 'error');
+    }
   },
 
   onAssignToSuccess(_changeId, itemId, response) {