organizationMembersWrapper.spec.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {openInviteMembersModal} from 'sentry/actionCreators/modal';
  3. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  4. import OrganizationMembersList from 'sentry/views/settings/organizationMembers/organizationMembersList';
  5. import OrganizationMembersWrapper from 'sentry/views/settings/organizationMembers/organizationMembersWrapper';
  6. jest.mock('sentry/utils/analytics/trackAdvancedAnalyticsEvent', () => jest.fn());
  7. jest.mock('sentry/actionCreators/modal', () => ({
  8. openInviteMembersModal: jest.fn(),
  9. }));
  10. describe('OrganizationMembersWrapper', function () {
  11. const member = TestStubs.Member();
  12. const organization = TestStubs.Organization({
  13. features: ['invite-members'],
  14. access: ['member:admin', 'org:admin', 'member:write'],
  15. status: {
  16. id: 'active',
  17. },
  18. });
  19. const defaultProps = {
  20. location: {query: {}},
  21. params: {orgId: organization.slug},
  22. };
  23. beforeEach(function () {
  24. trackAdvancedAnalyticsEvent.mockClear();
  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. });
  52. it('can invite member', function () {
  53. render(<OrganizationMembersWrapper organization={organization} {...defaultProps} />);
  54. userEvent.click(screen.getByRole('button', {name: 'Invite Members'}));
  55. expect(openInviteMembersModal).toHaveBeenCalled();
  56. });
  57. it('can not invite members without the invite-members feature', function () {
  58. const org = TestStubs.Organization({
  59. features: [],
  60. access: ['member:admin', 'org:admin', 'member:write'],
  61. status: {
  62. id: 'active',
  63. },
  64. });
  65. render(<OrganizationMembersWrapper organization={org} {...defaultProps} />);
  66. expect(screen.getByRole('button', {name: 'Invite Members'})).toBeDisabled();
  67. });
  68. it('can invite without permissions', function () {
  69. const org = TestStubs.Organization({
  70. features: ['invite-members'],
  71. access: [],
  72. status: {
  73. id: 'active',
  74. },
  75. });
  76. render(<OrganizationMembersWrapper organization={org} {...defaultProps} />);
  77. userEvent.click(screen.getByRole('button', {name: 'Invite Members'}));
  78. expect(openInviteMembersModal).toHaveBeenCalled();
  79. });
  80. it('renders member list', function () {
  81. MockApiClient.addMockResponse({
  82. url: '/organizations/org-slug/members/',
  83. method: 'GET',
  84. body: [member],
  85. });
  86. render(
  87. <OrganizationMembersWrapper organization={organization} {...defaultProps}>
  88. <OrganizationMembersList {...defaultProps} router={{routes: []}} />
  89. </OrganizationMembersWrapper>
  90. );
  91. expect(screen.getByText('Members')).toBeInTheDocument();
  92. expect(screen.getByText(member.name)).toBeInTheDocument();
  93. });
  94. });