managed-group-subscriptions.test.tsx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. const managedGroupSubscriptions: ManagedGroupSubscription[] = [
  14. {
  15. ...groupActiveSubscription,
  16. userIsGroupMember: true,
  17. planLevelName: 'Professional',
  18. admin_id: {
  19. id: 'abc123abc123',
  20. email: 'you@example.com',
  21. },
  22. },
  23. {
  24. ...groupActiveSubscriptionWithPendingLicenseChange,
  25. userIsGroupMember: false,
  26. planLevelName: 'Collaborator',
  27. admin_id: {
  28. id: 'bcd456bcd456',
  29. email: 'someone@example.com',
  30. },
  31. },
  32. ]
  33. describe('<ManagedGroupSubscriptions />', function () {
  34. afterEach(function () {
  35. cleanUpContext()
  36. })
  37. it('renders all managed group subscriptions', function () {
  38. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />, {
  39. metaTags: [
  40. {
  41. name: 'ol-managedGroupSubscriptions',
  42. value: managedGroupSubscriptions,
  43. },
  44. ],
  45. })
  46. const elements = screen.getAllByText('You are a', {
  47. exact: false,
  48. })
  49. expect(elements.length).to.equal(2)
  50. expect(elements[0].textContent).to.equal(
  51. 'You are a manager and member of the Professional group subscription GAS administered by you@example.com'
  52. )
  53. expect(elements[1].textContent).to.equal(
  54. 'You are a manager of the Collaborator group subscription GASWPLC administered by someone@example.com'
  55. )
  56. const manageMembersLinks = screen.getAllByText('Manage members')
  57. expect(manageMembersLinks.length).to.equal(2)
  58. expect(manageMembersLinks[0].getAttribute('href')).to.equal(
  59. '/manage/groups/bcd567/members'
  60. )
  61. expect(manageMembersLinks[1].getAttribute('href')).to.equal(
  62. '/manage/groups/def456/members'
  63. )
  64. const manageGroupManagersLinks = screen.getAllByText(
  65. 'Manage group managers'
  66. )
  67. expect(manageGroupManagersLinks.length).to.equal(2)
  68. expect(manageGroupManagersLinks[0].getAttribute('href')).to.equal(
  69. '/manage/groups/bcd567/managers'
  70. )
  71. expect(manageGroupManagersLinks[1].getAttribute('href')).to.equal(
  72. '/manage/groups/def456/managers'
  73. )
  74. const viewMetricsLinks = screen.getAllByText('View metrics')
  75. expect(viewMetricsLinks.length).to.equal(2)
  76. expect(viewMetricsLinks[0].getAttribute('href')).to.equal(
  77. '/metrics/groups/bcd567'
  78. )
  79. expect(viewMetricsLinks[1].getAttribute('href')).to.equal(
  80. '/metrics/groups/def456'
  81. )
  82. })
  83. it('renders nothing when there are no group memberships', function () {
  84. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />)
  85. const elements = screen.queryAllByText('You are a', {
  86. exact: false,
  87. })
  88. expect(elements.length).to.equal(0)
  89. })
  90. })