inviteBanner.spec.tsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. import moment from 'moment';
  2. import {Member} from 'sentry-fixture/member';
  3. import {MissingMembers} from 'sentry-fixture/missingMembers';
  4. import {Organization} from 'sentry-fixture/organization';
  5. import {act, render, screen, userEvent} 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: MissingMembers(),
  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: '/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 = Organization({
  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 = Organization({
  56. features: [],
  57. });
  58. render(
  59. <InviteBanner
  60. onSendInvite={() => {}}
  61. organization={org}
  62. allowedRoles={[]}
  63. onModalClose={() => {}}
  64. />
  65. );
  66. expect(
  67. screen.queryByRole('heading', {
  68. name: 'Bring your full GitHub team on board in Sentry',
  69. })
  70. ).not.toBeInTheDocument();
  71. });
  72. it('does not render banner if no option', function () {
  73. const org = Organization({
  74. features: ['integrations-gh-invite'],
  75. });
  76. render(
  77. <InviteBanner
  78. onSendInvite={() => {}}
  79. organization={org}
  80. allowedRoles={[]}
  81. onModalClose={() => {}}
  82. />
  83. );
  84. expect(
  85. screen.queryByRole('heading', {
  86. name: 'Bring your full GitHub team on board in Sentry',
  87. })
  88. ).not.toBeInTheDocument();
  89. });
  90. it('does not render banner if no missing members', async function () {
  91. const org = Organization({
  92. features: ['integrations-gh-invite'],
  93. githubNudgeInvite: true,
  94. });
  95. MockApiClient.addMockResponse({
  96. url: '/organizations/org-slug/missing-members/',
  97. method: 'GET',
  98. body: [noMissingMembers],
  99. });
  100. await act(async () => {
  101. await render(
  102. <InviteBanner
  103. onSendInvite={() => {}}
  104. organization={org}
  105. allowedRoles={[]}
  106. onModalClose={() => {}}
  107. />
  108. );
  109. });
  110. expect(
  111. screen.queryByRole('heading', {
  112. name: 'Bring your full GitHub team on board in Sentry',
  113. })
  114. ).not.toBeInTheDocument();
  115. });
  116. it('does not render banner if no integration', async function () {
  117. const org = Organization({
  118. features: ['integrations-gh-invite'],
  119. githubNudgeInvite: true,
  120. });
  121. MockApiClient.addMockResponse({
  122. url: '/organizations/org-slug/missing-members/',
  123. method: 'GET',
  124. body: [],
  125. });
  126. await act(async () => {
  127. await render(
  128. <InviteBanner
  129. onSendInvite={() => {}}
  130. organization={org}
  131. allowedRoles={[]}
  132. onModalClose={() => {}}
  133. />
  134. );
  135. });
  136. expect(
  137. screen.queryByRole('heading', {
  138. name: 'Bring your full GitHub team on board in Sentry',
  139. })
  140. ).not.toBeInTheDocument();
  141. });
  142. it('does not render banner if lacking org:write', async function () {
  143. const org = Organization({
  144. features: ['integrations-gh-invite'],
  145. access: [],
  146. githubNudgeInvite: true,
  147. });
  148. await act(async () => {
  149. await render(
  150. <InviteBanner
  151. onSendInvite={() => {}}
  152. organization={org}
  153. allowedRoles={[]}
  154. onModalClose={() => {}}
  155. />
  156. );
  157. });
  158. expect(
  159. screen.queryByRole('heading', {
  160. name: 'Bring your full GitHub team on board in Sentry',
  161. })
  162. ).not.toBeInTheDocument();
  163. });
  164. it('renders banner if snoozed_ts days is longer than threshold', async function () {
  165. const org = Organization({
  166. features: ['integrations-gh-invite'],
  167. githubNudgeInvite: true,
  168. });
  169. const promptResponse = {
  170. dismissed_ts: undefined,
  171. snoozed_ts: moment
  172. .utc()
  173. .subtract(DEFAULT_SNOOZE_PROMPT_DAYS + 1, 'days')
  174. .unix(),
  175. };
  176. MockApiClient.addMockResponse({
  177. url: '/prompts-activity/',
  178. method: 'GET',
  179. body: {data: promptResponse},
  180. });
  181. render(
  182. <InviteBanner
  183. onSendInvite={() => {}}
  184. organization={org}
  185. allowedRoles={[]}
  186. onModalClose={() => {}}
  187. />
  188. );
  189. expect(
  190. await screen.findByRole('heading', {
  191. name: 'Bring your full GitHub team on board in Sentry',
  192. })
  193. ).toBeInTheDocument();
  194. });
  195. it('does not render banner if snoozed_ts days is shorter than threshold', async function () {
  196. const org = Organization({
  197. features: ['integrations-gh-invite'],
  198. githubNudgeInvite: true,
  199. });
  200. const promptResponse = {
  201. dismissed_ts: undefined,
  202. snoozed_ts: moment
  203. .utc()
  204. .subtract(DEFAULT_SNOOZE_PROMPT_DAYS - 1, 'days')
  205. .unix(),
  206. };
  207. const mockPrompt = MockApiClient.addMockResponse({
  208. url: '/prompts-activity/',
  209. method: 'GET',
  210. body: {data: promptResponse},
  211. });
  212. await act(async () => {
  213. await render(
  214. <InviteBanner
  215. onSendInvite={() => {}}
  216. organization={org}
  217. allowedRoles={[]}
  218. onModalClose={() => {}}
  219. />
  220. );
  221. });
  222. expect(mockPrompt).toHaveBeenCalled();
  223. expect(
  224. screen.queryByRole('heading', {
  225. name: 'Bring your full GitHub team on board in Sentry',
  226. })
  227. ).not.toBeInTheDocument();
  228. });
  229. it('invites member from banner', async function () {
  230. const newMember = Member({
  231. id: '6',
  232. email: 'hello@sentry.io',
  233. teams: [],
  234. teamRoles: [],
  235. flags: {
  236. 'idp:provisioned': false,
  237. 'idp:role-restricted': false,
  238. 'member-limit:restricted': false,
  239. 'partnership:restricted': false,
  240. 'sso:invalid': false,
  241. 'sso:linked': true,
  242. },
  243. });
  244. MockApiClient.addMockResponse({
  245. url: '/organizations/org-slug/missing-members/',
  246. method: 'GET',
  247. body: [
  248. {
  249. integration: 'github',
  250. users: MissingMembers().slice(0, 5),
  251. },
  252. ],
  253. });
  254. MockApiClient.addMockResponse({
  255. url: '/organizations/org-slug/members/?referrer=github_nudge_invite',
  256. method: 'POST',
  257. body: newMember,
  258. });
  259. const org = Organization({
  260. features: ['integrations-gh-invite'],
  261. githubNudgeInvite: true,
  262. });
  263. render(
  264. <InviteBanner
  265. onSendInvite={() => {}}
  266. organization={org}
  267. allowedRoles={[]}
  268. onModalClose={() => {}}
  269. />
  270. );
  271. expect(
  272. await screen.findByRole('heading', {
  273. name: 'Bring your full GitHub team on board in Sentry',
  274. })
  275. ).toBeInTheDocument();
  276. expect(screen.queryAllByTestId('invite-missing-member')).toHaveLength(5);
  277. expect(screen.getByText('See all 5 missing members')).toBeInTheDocument();
  278. const inviteButton = screen.queryAllByTestId('invite-missing-member')[0];
  279. await userEvent.click(inviteButton);
  280. expect(screen.queryAllByTestId('invite-missing-member')).toHaveLength(4);
  281. expect(screen.getByText('See all 4 missing members')).toBeInTheDocument();
  282. });
  283. });