organizationMembersWrapper.spec.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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('can invite without permissions', async function () {
  75. const org = OrganizationFixture({
  76. features: ['invite-members'],
  77. access: [],
  78. status: {
  79. id: 'active',
  80. name: 'active',
  81. },
  82. });
  83. render(<OrganizationMembersWrapper organization={org} {...routerProps} />);
  84. await userEvent.click(screen.getByRole('button', {name: 'Invite Members'}));
  85. expect(openInviteMembersModal).toHaveBeenCalled();
  86. });
  87. it('renders member list', async function () {
  88. MockApiClient.addMockResponse({
  89. url: '/organizations/org-slug/members/',
  90. method: 'GET',
  91. body: [member],
  92. });
  93. MockApiClient.addMockResponse({
  94. url: '/organizations/org-slug/prompts-activity/',
  95. method: 'GET',
  96. body: {},
  97. });
  98. render(
  99. <OrganizationMembersWrapper organization={organization} {...routerProps}>
  100. <OrganizationMembersList {...routerProps} />
  101. </OrganizationMembersWrapper>
  102. );
  103. expect(await screen.findByText('Members')).toBeInTheDocument();
  104. expect(screen.getByText(member.name)).toBeInTheDocument();
  105. });
  106. });