managed-group-subscriptions.test.tsx 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. import { expect } from 'chai'
  2. import { screen } from '@testing-library/react'
  3. import ManagedGroupSubscriptions from '../../../../../../frontend/js/features/subscription/components/dashboard/managed-group-subscriptions'
  4. import { ManagedGroupSubscription } from '../../../../../../types/subscription/dashboard/subscription'
  5. import {
  6. cleanUpContext,
  7. renderWithSubscriptionDashContext,
  8. } from '../../helpers/render-with-subscription-dash-context'
  9. function getManagedGroupSubscriptions(
  10. groupSSO: boolean | null,
  11. managedUsers: boolean | null
  12. ): ManagedGroupSubscription[] {
  13. const subscriptionOne = {
  14. _id: 'bcd567',
  15. userIsGroupMember: true,
  16. planLevelName: 'Pro',
  17. admin_id: {
  18. email: 'you@example.com',
  19. },
  20. features: {
  21. groupSSO,
  22. managedUsers,
  23. },
  24. teamName: 'GAS',
  25. }
  26. const subscriptionTwo = {
  27. _id: 'def456',
  28. userIsGroupMember: false,
  29. planLevelName: 'Standard',
  30. admin_id: {
  31. email: 'someone@example.com',
  32. },
  33. features: {
  34. groupSSO,
  35. managedUsers,
  36. },
  37. teamName: 'GASWPLC',
  38. }
  39. const subscriptionMemberAndAdmin = {
  40. _id: 'group2abc',
  41. userIsGroupMember: true,
  42. planLevelName: 'Standard',
  43. admin_id: {
  44. email: 'admin@example.com',
  45. },
  46. features: {
  47. groupSSO,
  48. managedUsers,
  49. },
  50. teamName: 'Testing',
  51. }
  52. const subscriptionAdmin = {
  53. _id: 'group123abc',
  54. userIsGroupMember: false,
  55. planLevelName: 'Standard',
  56. admin_id: {
  57. email: 'admin@example.com',
  58. },
  59. features: {
  60. groupSSO,
  61. managedUsers,
  62. },
  63. teamName: 'Testing Another',
  64. }
  65. return [
  66. subscriptionOne,
  67. subscriptionTwo,
  68. subscriptionMemberAndAdmin,
  69. subscriptionAdmin,
  70. ]
  71. }
  72. const managedGroupSubscriptions: ManagedGroupSubscription[] =
  73. getManagedGroupSubscriptions(false, false)
  74. const managedGroupSubscriptions2: ManagedGroupSubscription[] =
  75. getManagedGroupSubscriptions(true, true)
  76. const managedGroupSubscriptions3: ManagedGroupSubscription[] =
  77. getManagedGroupSubscriptions(true, false)
  78. const managedGroupSubscriptions4: ManagedGroupSubscription[] =
  79. getManagedGroupSubscriptions(false, true)
  80. describe('<ManagedGroupSubscriptions />', function () {
  81. afterEach(function () {
  82. cleanUpContext()
  83. })
  84. it('renders all managed group subscriptions', async function () {
  85. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
  86. metaTags: [
  87. {
  88. name: 'ol-managedGroupSubscriptions',
  89. value: managedGroupSubscriptions,
  90. },
  91. { name: 'ol-usersEmail', value: 'admin@example.com' },
  92. ],
  93. })
  94. const elements = screen.getAllByText('You are a', {
  95. exact: false,
  96. })
  97. expect(elements.length).to.equal(4)
  98. expect(elements[0].textContent).to.equal(
  99. 'You are a manager and member of the Pro group subscription GAS administered by you@example.com.'
  100. )
  101. expect(elements[1].textContent).to.equal(
  102. 'You are a manager of the Standard group subscription GASWPLC administered by someone@example.com.'
  103. )
  104. expect(elements[2].textContent).to.equal(
  105. 'You are a manager and member of the Standard group subscription Testing administered by you (admin@example.com).'
  106. )
  107. expect(elements[3].textContent).to.equal(
  108. 'You are a manager of the Standard group subscription Testing Another administered by you (admin@example.com).'
  109. )
  110. const links = screen.getAllByRole('link')
  111. expect(links[1].getAttribute('href')).to.equal(
  112. '/manage/groups/bcd567/members'
  113. )
  114. expect(links[2].getAttribute('href')).to.equal(
  115. '/manage/groups/bcd567/managers'
  116. )
  117. expect(links[3].getAttribute('href')).to.equal('/metrics/groups/bcd567')
  118. expect(links[5].getAttribute('href')).to.equal(
  119. '/manage/groups/def456/members'
  120. )
  121. expect(links[6].getAttribute('href')).to.equal(
  122. '/manage/groups/def456/managers'
  123. )
  124. expect(links[7].getAttribute('href')).to.equal('/metrics/groups/def456')
  125. expect(links[9].getAttribute('href')).to.equal(
  126. '/manage/groups/group2abc/members'
  127. )
  128. expect(links[10].getAttribute('href')).to.equal(
  129. '/manage/groups/group2abc/managers'
  130. )
  131. expect(links[12].getAttribute('href')).to.equal('/metrics/groups/group2abc')
  132. expect(links[14].getAttribute('href')).to.equal(
  133. '/manage/groups/group123abc/members'
  134. )
  135. expect(links[15].getAttribute('href')).to.equal(
  136. '/manage/groups/group123abc/managers'
  137. )
  138. expect(links[17].getAttribute('href')).to.equal(
  139. '/metrics/groups/group123abc'
  140. )
  141. })
  142. it('renders nothing when there are no group memberships', function () {
  143. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />)
  144. const elements = screen.queryAllByText('You are a', {
  145. exact: false,
  146. })
  147. expect(elements.length).to.equal(0)
  148. })
  149. it('does not render the Manage group settings row when the user is not the group admin', function () {
  150. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
  151. metaTags: [
  152. {
  153. name: 'ol-managedGroupSubscriptions',
  154. value: managedGroupSubscriptions2,
  155. },
  156. {
  157. name: 'ol-groupSettingsEnabledFor',
  158. value: [],
  159. },
  160. ],
  161. })
  162. expect(screen.queryByText('Manage group settings')).to.be.null
  163. expect(screen.queryByText('Configure and manage SSO and Managed Users')).to
  164. .be.null
  165. })
  166. it('does not render the Group Audit Log settings row when the user is not the group admin', function () {
  167. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
  168. metaTags: [
  169. {
  170. name: 'ol-managedGroupSubscriptions',
  171. value: managedGroupSubscriptions2,
  172. },
  173. {
  174. name: 'ol-groupSettingsEnabledFor',
  175. value: [],
  176. },
  177. ],
  178. })
  179. expect(screen.queryByText('Audit logs')).to.be.null
  180. })
  181. it('renders the Group Audit Log settings row when the user is the group admin', async function () {
  182. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
  183. metaTags: [
  184. {
  185. name: 'ol-managedGroupSubscriptions',
  186. value: managedGroupSubscriptions,
  187. },
  188. { name: 'ol-usersEmail', value: 'admin@example.com' },
  189. ],
  190. })
  191. await screen.findAllByText('Audit logs')
  192. })
  193. it('does not render the Sharing Permissions settings row when the user is not the group admin', function () {
  194. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
  195. metaTags: [
  196. {
  197. name: 'ol-managedGroupSubscriptions',
  198. value: managedGroupSubscriptions2,
  199. },
  200. {
  201. name: 'ol-groupSettingsEnabledFor',
  202. value: [],
  203. },
  204. {
  205. name: 'ol-splitTestVariants',
  206. value: { 'sharing-updates': 'enabled' },
  207. },
  208. ],
  209. })
  210. expect(screen.queryByText(/sharing permissions/i)).to.be.null
  211. expect(screen.queryByText(/manage how group members share projects/i)).to.be
  212. .null
  213. })
  214. it('renders the Sharing Permissions settings row when the user is the group admin and plan is professional', async function () {
  215. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
  216. metaTags: [
  217. {
  218. name: 'ol-managedGroupSubscriptions',
  219. value: managedGroupSubscriptions,
  220. },
  221. { name: 'ol-usersEmail', value: 'you@example.com' },
  222. {
  223. name: 'ol-splitTestVariants',
  224. value: { 'sharing-updates': 'enabled' },
  225. },
  226. ],
  227. })
  228. await screen.findAllByText(/sharing permissions/i)
  229. await screen.findAllByText(/manage how group members share projects/i)
  230. })
  231. it('renders Managed Group / Group SSO settings row when both features are turned on', async function () {
  232. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
  233. metaTags: [
  234. {
  235. name: 'ol-managedGroupSubscriptions',
  236. value: managedGroupSubscriptions2,
  237. },
  238. {
  239. name: 'ol-groupSettingsEnabledFor',
  240. value: [managedGroupSubscriptions2[0]._id],
  241. },
  242. ],
  243. })
  244. await screen.findAllByText('Group settings')
  245. await screen.findAllByText('Configure and manage SSO and Managed Users')
  246. })
  247. it('does not render Group SSO settings when the feature is turned off', async function () {
  248. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
  249. metaTags: [
  250. {
  251. name: 'ol-managedGroupSubscriptions',
  252. value: managedGroupSubscriptions4,
  253. },
  254. {
  255. name: 'ol-groupSettingsEnabledFor',
  256. value: [managedGroupSubscriptions4[0]._id],
  257. },
  258. ],
  259. })
  260. await screen.findAllByText('Group settings')
  261. await screen.findAllByText('Turn on Managed Users')
  262. expect(screen.queryByText('Configure and manage SSO and Managed Users')).to
  263. .not.exist
  264. expect(screen.queryByText('Configure and manage SSO')).to.not.exist
  265. })
  266. it('does not render MAnaged Group settings when the feature is turned off', async function () {
  267. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
  268. metaTags: [
  269. {
  270. name: 'ol-managedGroupSubscriptions',
  271. value: managedGroupSubscriptions3,
  272. },
  273. {
  274. name: 'ol-groupSettingsEnabledFor',
  275. value: [managedGroupSubscriptions3[0]._id],
  276. },
  277. ],
  278. })
  279. await screen.findAllByText('Group settings')
  280. await screen.findAllByText('Configure and manage SSO')
  281. expect(screen.queryByText('Turn on Managed Users')).to.not.exist
  282. expect(screen.queryByText('Configure and manage SSO and Managed Users')).to
  283. .not.exist
  284. })
  285. })