managed-group-subscriptions.test.tsx 5.7 KB

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