organizationMembersWrapper.spec.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import {openInviteMembersModal} from 'sentry/actionCreators/modal';
  4. import OrganizationMembersList from 'sentry/views/settings/organizationMembers/organizationMembersList';
  5. import OrganizationMembersWrapper from 'sentry/views/settings/organizationMembers/organizationMembersWrapper';
  6. jest.mock('sentry/utils/analytics');
  7. jest.mock('sentry/actionCreators/modal', () => ({
  8. openInviteMembersModal: jest.fn(),
  9. }));
  10. describe('OrganizationMembersWrapper', function () {
  11. const {routerProps} = initializeOrg();
  12. const member = TestStubs.Member();
  13. const organization = TestStubs.Organization({
  14. features: ['invite-members'],
  15. access: ['member:admin', 'org:admin', 'member:write'],
  16. status: {
  17. id: 'active',
  18. },
  19. });
  20. beforeEach(function () {
  21. jest.clearAllMocks();
  22. MockApiClient.clearMockResponses();
  23. MockApiClient.addMockResponse({
  24. url: '/organizations/org-slug/members/me/',
  25. method: 'GET',
  26. body: {roles: []},
  27. });
  28. MockApiClient.addMockResponse({
  29. url: '/organizations/org-slug/invite-requests/',
  30. method: 'GET',
  31. body: [],
  32. });
  33. MockApiClient.addMockResponse({
  34. url: '/organizations/org-slug/access-requests/',
  35. method: 'GET',
  36. body: [],
  37. });
  38. MockApiClient.addMockResponse({
  39. url: '/organizations/org-slug/members/',
  40. method: 'GET',
  41. body: [],
  42. });
  43. MockApiClient.addMockResponse({
  44. url: '/organizations/org-slug/auth-provider/',
  45. method: 'GET',
  46. body: {},
  47. });
  48. MockApiClient.addMockResponse({
  49. url: '/organizations/org-slug/missing-members/',
  50. method: 'GET',
  51. body: [],
  52. });
  53. });
  54. it('can invite member', async function () {
  55. render(<OrganizationMembersWrapper organization={organization} {...routerProps} />);
  56. await userEvent.click(screen.getByRole('button', {name: 'Invite Members'}));
  57. expect(openInviteMembersModal).toHaveBeenCalled();
  58. });
  59. it('can not invite members without the invite-members feature', function () {
  60. const org = TestStubs.Organization({
  61. features: [],
  62. access: ['member:admin', 'org:admin', 'member:write'],
  63. status: {
  64. id: 'active',
  65. },
  66. });
  67. render(<OrganizationMembersWrapper organization={org} {...routerProps} />);
  68. expect(screen.getByRole('button', {name: 'Invite Members'})).toBeDisabled();
  69. });
  70. it('can invite without permissions', async function () {
  71. const org = TestStubs.Organization({
  72. features: ['invite-members'],
  73. access: [],
  74. status: {
  75. id: 'active',
  76. },
  77. });
  78. render(<OrganizationMembersWrapper organization={org} {...routerProps} />);
  79. await userEvent.click(screen.getByRole('button', {name: 'Invite Members'}));
  80. expect(openInviteMembersModal).toHaveBeenCalled();
  81. });
  82. it('renders member list', async function () {
  83. MockApiClient.addMockResponse({
  84. url: '/organizations/org-slug/members/',
  85. method: 'GET',
  86. body: [member],
  87. });
  88. MockApiClient.addMockResponse({
  89. url: '/prompts-activity/',
  90. method: 'GET',
  91. body: {},
  92. });
  93. render(
  94. <OrganizationMembersWrapper organization={organization} {...routerProps}>
  95. <OrganizationMembersList {...routerProps} />
  96. </OrganizationMembersWrapper>
  97. );
  98. expect(await screen.findByText('Members')).toBeInTheDocument();
  99. expect(screen.getByText(member.name)).toBeInTheDocument();
  100. });
  101. });