organizationMembersWrapper.spec.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. });
  49. it('can invite member', async function () {
  50. render(<OrganizationMembersWrapper organization={organization} {...routerProps} />);
  51. await userEvent.click(screen.getByRole('button', {name: 'Invite Members'}));
  52. expect(openInviteMembersModal).toHaveBeenCalled();
  53. });
  54. it('can not invite members without the invite-members feature', function () {
  55. const org = TestStubs.Organization({
  56. features: [],
  57. access: ['member:admin', 'org:admin', 'member:write'],
  58. status: {
  59. id: 'active',
  60. },
  61. });
  62. render(<OrganizationMembersWrapper organization={org} {...routerProps} />);
  63. expect(screen.getByRole('button', {name: 'Invite Members'})).toBeDisabled();
  64. });
  65. it('can invite without permissions', async function () {
  66. const org = TestStubs.Organization({
  67. features: ['invite-members'],
  68. access: [],
  69. status: {
  70. id: 'active',
  71. },
  72. });
  73. render(<OrganizationMembersWrapper organization={org} {...routerProps} />);
  74. await userEvent.click(screen.getByRole('button', {name: 'Invite Members'}));
  75. expect(openInviteMembersModal).toHaveBeenCalled();
  76. });
  77. it('renders member list', function () {
  78. MockApiClient.addMockResponse({
  79. url: '/organizations/org-slug/members/',
  80. method: 'GET',
  81. body: [member],
  82. });
  83. render(
  84. <OrganizationMembersWrapper organization={organization} {...routerProps}>
  85. <OrganizationMembersList {...routerProps} />
  86. </OrganizationMembersWrapper>
  87. );
  88. expect(screen.getByText('Members')).toBeInTheDocument();
  89. expect(screen.getByText(member.name)).toBeInTheDocument();
  90. });
  91. });