inviteBanner.spec.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. import moment from 'moment';
  2. import {MemberFixture} from 'sentry-fixture/member';
  3. import {MissingMembersFixture} from 'sentry-fixture/missingMembers';
  4. import {OrganizationFixture} from 'sentry-fixture/organization';
  5. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  6. import {DEFAULT_SNOOZE_PROMPT_DAYS} from 'sentry/utils/promptIsDismissed';
  7. import {InviteBanner} from 'sentry/views/settings/organizationMembers/inviteBanner';
  8. const missingMembers = {
  9. integration: 'github',
  10. users: MissingMembersFixture(),
  11. };
  12. const noMissingMembers = {
  13. integration: 'github',
  14. users: [],
  15. };
  16. describe('inviteBanner', function () {
  17. beforeEach(function () {
  18. MockApiClient.clearMockResponses();
  19. MockApiClient.addMockResponse({
  20. url: '/organizations/org-slug/missing-members/',
  21. method: 'GET',
  22. body: [missingMembers],
  23. });
  24. MockApiClient.addMockResponse({
  25. url: '/organizations/org-slug/prompts-activity/',
  26. method: 'GET',
  27. body: {
  28. dismissed_ts: undefined,
  29. snoozed_ts: undefined,
  30. },
  31. });
  32. });
  33. it('render banners with feature flag', async function () {
  34. const org = OrganizationFixture({
  35. features: ['integrations-gh-invite'],
  36. githubNudgeInvite: true,
  37. });
  38. render(
  39. <InviteBanner
  40. onSendInvite={() => {}}
  41. organization={org}
  42. allowedRoles={[]}
  43. onModalClose={() => {}}
  44. />
  45. );
  46. expect(
  47. await screen.findByRole('heading', {
  48. name: 'Bring your full GitHub team on board in Sentry',
  49. })
  50. ).toBeInTheDocument();
  51. expect(screen.queryAllByTestId('invite-missing-member')).toHaveLength(5);
  52. expect(screen.getByText('See all 5 missing members')).toBeInTheDocument();
  53. });
  54. it('does not render banner if no feature flag', function () {
  55. const org = OrganizationFixture({
  56. features: [],
  57. });
  58. const {container} = render(
  59. <InviteBanner
  60. onSendInvite={() => {}}
  61. organization={org}
  62. allowedRoles={[]}
  63. onModalClose={() => {}}
  64. />
  65. );
  66. expect(container).toBeEmptyDOMElement();
  67. });
  68. it('does not render banner if no option', function () {
  69. const org = OrganizationFixture({
  70. features: ['integrations-gh-invite'],
  71. });
  72. const {container} = render(
  73. <InviteBanner
  74. onSendInvite={() => {}}
  75. organization={org}
  76. allowedRoles={[]}
  77. onModalClose={() => {}}
  78. />
  79. );
  80. expect(container).toBeEmptyDOMElement();
  81. });
  82. it('does not render banner if no missing members', async function () {
  83. const org = OrganizationFixture({
  84. features: ['integrations-gh-invite'],
  85. githubNudgeInvite: true,
  86. });
  87. const mock = MockApiClient.addMockResponse({
  88. url: '/organizations/org-slug/missing-members/',
  89. method: 'GET',
  90. body: [noMissingMembers],
  91. });
  92. const {container} = render(
  93. <InviteBanner
  94. onSendInvite={() => {}}
  95. organization={org}
  96. allowedRoles={[]}
  97. onModalClose={() => {}}
  98. />
  99. );
  100. await waitFor(() => expect(mock).toHaveBeenCalledTimes(1));
  101. expect(container).toBeEmptyDOMElement();
  102. });
  103. it('does not render banner if no integration', async function () {
  104. const org = OrganizationFixture({
  105. features: ['integrations-gh-invite'],
  106. githubNudgeInvite: true,
  107. });
  108. const mock = MockApiClient.addMockResponse({
  109. url: '/organizations/org-slug/missing-members/',
  110. method: 'GET',
  111. body: [],
  112. });
  113. const {container} = render(
  114. <InviteBanner
  115. onSendInvite={() => {}}
  116. organization={org}
  117. allowedRoles={[]}
  118. onModalClose={() => {}}
  119. />
  120. );
  121. await waitFor(() => expect(mock).toHaveBeenCalledTimes(1));
  122. expect(container).toBeEmptyDOMElement();
  123. });
  124. it('does not render banner if lacking org:write', function () {
  125. const org = OrganizationFixture({
  126. features: ['integrations-gh-invite'],
  127. access: [],
  128. githubNudgeInvite: true,
  129. });
  130. const {container} = render(
  131. <InviteBanner
  132. onSendInvite={() => {}}
  133. organization={org}
  134. allowedRoles={[]}
  135. onModalClose={() => {}}
  136. />
  137. );
  138. expect(container).toBeEmptyDOMElement();
  139. });
  140. it('renders banner if snoozed_ts days is longer than threshold', async function () {
  141. const org = OrganizationFixture({
  142. features: ['integrations-gh-invite'],
  143. githubNudgeInvite: true,
  144. });
  145. const promptResponse = {
  146. dismissed_ts: undefined,
  147. snoozed_ts: moment
  148. .utc()
  149. .subtract(DEFAULT_SNOOZE_PROMPT_DAYS + 1, 'days')
  150. .unix(),
  151. };
  152. MockApiClient.addMockResponse({
  153. url: `/organizations/${org.slug}/prompts-activity/`,
  154. method: 'GET',
  155. body: {data: promptResponse},
  156. });
  157. render(
  158. <InviteBanner
  159. onSendInvite={() => {}}
  160. organization={org}
  161. allowedRoles={[]}
  162. onModalClose={() => {}}
  163. />
  164. );
  165. expect(
  166. await screen.findByRole('heading', {
  167. name: 'Bring your full GitHub team on board in Sentry',
  168. })
  169. ).toBeInTheDocument();
  170. });
  171. it('does not render banner if snoozed_ts days is shorter than threshold', async function () {
  172. const org = OrganizationFixture({
  173. features: ['integrations-gh-invite'],
  174. githubNudgeInvite: true,
  175. });
  176. const promptResponse = {
  177. dismissed_ts: undefined,
  178. snoozed_ts: moment
  179. .utc()
  180. .subtract(DEFAULT_SNOOZE_PROMPT_DAYS - 1, 'days')
  181. .unix(),
  182. };
  183. const mockPrompt = MockApiClient.addMockResponse({
  184. url: `/organizations/${org.slug}/prompts-activity/`,
  185. method: 'GET',
  186. body: {data: promptResponse},
  187. });
  188. const {container} = render(
  189. <InviteBanner
  190. onSendInvite={() => {}}
  191. organization={org}
  192. allowedRoles={[]}
  193. onModalClose={() => {}}
  194. />
  195. );
  196. await waitFor(() => expect(mockPrompt).toHaveBeenCalled());
  197. expect(container).toBeEmptyDOMElement();
  198. });
  199. it('invites member from banner', async function () {
  200. const newMember = MemberFixture({
  201. id: '6',
  202. email: 'hello@sentry.io',
  203. teams: [],
  204. teamRoles: [],
  205. flags: {
  206. 'idp:provisioned': false,
  207. 'idp:role-restricted': false,
  208. 'member-limit:restricted': false,
  209. 'partnership:restricted': false,
  210. 'sso:invalid': false,
  211. 'sso:linked': true,
  212. },
  213. });
  214. MockApiClient.addMockResponse({
  215. url: '/organizations/org-slug/missing-members/',
  216. method: 'GET',
  217. body: [
  218. {
  219. integration: 'github',
  220. users: MissingMembersFixture().slice(0, 5),
  221. },
  222. ],
  223. });
  224. MockApiClient.addMockResponse({
  225. url: '/organizations/org-slug/members/?referrer=github_nudge_invite',
  226. method: 'POST',
  227. body: newMember,
  228. });
  229. const org = OrganizationFixture({
  230. features: ['integrations-gh-invite'],
  231. githubNudgeInvite: true,
  232. });
  233. render(
  234. <InviteBanner
  235. onSendInvite={() => {}}
  236. organization={org}
  237. allowedRoles={[]}
  238. onModalClose={() => {}}
  239. />
  240. );
  241. expect(
  242. await screen.findByRole('heading', {
  243. name: 'Bring your full GitHub team on board in Sentry',
  244. })
  245. ).toBeInTheDocument();
  246. expect(screen.queryAllByTestId('invite-missing-member')).toHaveLength(5);
  247. expect(screen.getByText('See all 5 missing members')).toBeInTheDocument();
  248. const inviteButton = screen.queryAllByTestId('invite-missing-member')[0];
  249. await userEvent.click(inviteButton);
  250. expect(screen.queryAllByTestId('invite-missing-member')).toHaveLength(4);
  251. expect(screen.getByText('See all 4 missing members')).toBeInTheDocument();
  252. });
  253. });