managed-group-subscriptions.test.tsx 11 KB

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