organizationMembersWrapper.spec.tsx 4.1 KB

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