managed-group-subscriptions.test.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 getManagedGroupSubscription(groupSSO: boolean, managedUsers: boolean) {
  15. const subscriptionOne = {
  16. ...groupActiveSubscription,
  17. userIsGroupMember: true,
  18. planLevelName: 'Professional',
  19. admin_id: {
  20. id: 'abc123abc123' as UserId,
  21. email: 'you@example.com',
  22. },
  23. features: {
  24. groupSSO,
  25. managedUsers,
  26. },
  27. }
  28. const subscriptionTwo = {
  29. ...groupActiveSubscriptionWithPendingLicenseChange,
  30. userIsGroupMember: false,
  31. planLevelName: 'Collaborator',
  32. admin_id: {
  33. id: 'bcd456bcd456' as UserId,
  34. email: 'someone@example.com',
  35. },
  36. features: {
  37. groupSSO,
  38. managedUsers,
  39. },
  40. }
  41. return [subscriptionOne, subscriptionTwo]
  42. }
  43. const managedGroupSubscriptions: ManagedGroupSubscription[] =
  44. getManagedGroupSubscription(false, false)
  45. const managedGroupSubscriptions2: ManagedGroupSubscription[] =
  46. getManagedGroupSubscription(true, true)
  47. const managedGroupSubscriptions3: ManagedGroupSubscription[] =
  48. getManagedGroupSubscription(true, false)
  49. const managedGroupSubscriptions4: ManagedGroupSubscription[] =
  50. getManagedGroupSubscription(false, true)
  51. describe('<ManagedGroupSubscriptions />', function () {
  52. afterEach(function () {
  53. cleanUpContext()
  54. })
  55. it('renders all managed group subscriptions', async function () {
  56. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
  57. metaTags: [
  58. {
  59. name: 'ol-managedGroupSubscriptions',
  60. value: managedGroupSubscriptions,
  61. },
  62. ],
  63. })
  64. const elements = screen.getAllByText('You are a', {
  65. exact: false,
  66. })
  67. expect(elements.length).to.equal(2)
  68. expect(elements[0].textContent).to.equal(
  69. 'You are a manager and member of the Professional group subscription GAS administered by you@example.com'
  70. )
  71. expect(elements[1].textContent).to.equal(
  72. 'You are a manager of the Collaborator group subscription GASWPLC administered by someone@example.com'
  73. )
  74. const links = screen.getAllByRole('link')
  75. expect(links[1].getAttribute('href')).to.equal(
  76. '/manage/groups/bcd567/members'
  77. )
  78. expect(links[2].getAttribute('href')).to.equal(
  79. '/manage/groups/bcd567/managers'
  80. )
  81. expect(links[3].getAttribute('href')).to.equal('/metrics/groups/bcd567')
  82. expect(links[5].getAttribute('href')).to.equal(
  83. '/manage/groups/def456/members'
  84. )
  85. expect(links[6].getAttribute('href')).to.equal(
  86. '/manage/groups/def456/managers'
  87. )
  88. expect(links[7].getAttribute('href')).to.equal('/metrics/groups/def456')
  89. })
  90. it('renders nothing when there are no group memberships', function () {
  91. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />)
  92. const elements = screen.queryAllByText('You are a', {
  93. exact: false,
  94. })
  95. expect(elements.length).to.equal(0)
  96. })
  97. it('does not render the Manage group settings row when the user is not the group admin', function () {
  98. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
  99. metaTags: [
  100. {
  101. name: 'ol-managedGroupSubscriptions',
  102. value: managedGroupSubscriptions2,
  103. },
  104. {
  105. name: 'ol-groupSettingsEnabledFor',
  106. value: [],
  107. },
  108. ],
  109. })
  110. expect(screen.queryByText('Manage group settings')).to.be.null
  111. expect(screen.queryByText('Configure and manage SSO and Managed Users')).to
  112. .be.null
  113. })
  114. it('renders the Manage group settings row when feature is turned on', async function () {
  115. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
  116. metaTags: [
  117. {
  118. name: 'ol-managedGroupSubscriptions',
  119. value: managedGroupSubscriptions2,
  120. },
  121. {
  122. name: 'ol-groupSettingsEnabledFor',
  123. value: [managedGroupSubscriptions2[0]._id],
  124. },
  125. ],
  126. })
  127. await screen.findAllByText('Manage group settings')
  128. await screen.findAllByText('Configure and manage SSO and Managed Users')
  129. })
  130. it('renders the the correct subText for Manage Group settings row', async function () {
  131. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
  132. metaTags: [
  133. {
  134. name: 'ol-managedGroupSubscriptions',
  135. value: managedGroupSubscriptions2,
  136. },
  137. {
  138. name: 'ol-groupSettingsEnabledFor',
  139. value: [managedGroupSubscriptions2[0]._id],
  140. },
  141. ],
  142. })
  143. await screen.findAllByText('Configure and manage SSO and Managed Users')
  144. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
  145. metaTags: [
  146. {
  147. name: 'ol-managedGroupSubscriptions',
  148. value: managedGroupSubscriptions3,
  149. },
  150. {
  151. name: 'ol-groupSettingsEnabledFor',
  152. value: [managedGroupSubscriptions3[0]._id],
  153. },
  154. ],
  155. })
  156. await screen.findAllByText('Configure and manage SSO')
  157. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
  158. metaTags: [
  159. {
  160. name: 'ol-managedGroupSubscriptions',
  161. value: managedGroupSubscriptions4,
  162. },
  163. {
  164. name: 'ol-groupSettingsEnabledFor',
  165. value: [managedGroupSubscriptions4[0]._id],
  166. },
  167. ],
  168. })
  169. await screen.findAllByText('Turn on Managed Users')
  170. })
  171. })