organizationMembersWrapper.spec.tsx 3.6 KB

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