managed-group-subscriptions.test.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { expect } from 'chai'
  2. import { render, screen } from '@testing-library/react'
  3. import ManagedGroupSubscriptions, {
  4. ManagedGroupSubscription,
  5. } from '../../../../../../frontend/js/features/subscription/components/dashboard/managed-group-subscriptions'
  6. import {
  7. groupActiveSubscription,
  8. groupActiveSubscriptionWithPendingLicenseChange,
  9. } from '../../fixtures/subscriptions'
  10. const managedGroupSubscriptions: ManagedGroupSubscription[] = [
  11. {
  12. ...groupActiveSubscription,
  13. userIsGroupMember: true,
  14. planLevelName: 'Professional',
  15. admin_id: {
  16. id: 'abc123abc123',
  17. email: 'you@example.com',
  18. },
  19. },
  20. {
  21. ...groupActiveSubscriptionWithPendingLicenseChange,
  22. userIsGroupMember: false,
  23. planLevelName: 'Collaborator',
  24. admin_id: {
  25. id: 'bcd456bcd456',
  26. email: 'someone@example.com',
  27. },
  28. },
  29. ]
  30. describe('<ManagedGroupSubscriptions />', function () {
  31. beforeEach(function () {
  32. window.metaAttributesCache = new Map()
  33. })
  34. afterEach(function () {
  35. window.metaAttributesCache = new Map()
  36. })
  37. it('renders all managed group subscriptions', function () {
  38. render(
  39. <ManagedGroupSubscriptions subscriptions={managedGroupSubscriptions} />
  40. )
  41. const elements = screen.getAllByText('You are a', {
  42. exact: false,
  43. })
  44. expect(elements.length).to.equal(2)
  45. expect(elements[0].textContent).to.equal(
  46. 'You are a manager and member of the Professional group subscription GAS administered by you@example.com'
  47. )
  48. expect(elements[1].textContent).to.equal(
  49. 'You are a manager of the Collaborator group subscription GASWPLC administered by someone@example.com'
  50. )
  51. const manageMembersLinks = screen.getAllByText('Manage members')
  52. expect(manageMembersLinks.length).to.equal(2)
  53. expect(manageMembersLinks[0].getAttribute('href')).to.equal(
  54. '/manage/groups/bcd567/members'
  55. )
  56. expect(manageMembersLinks[1].getAttribute('href')).to.equal(
  57. '/manage/groups/def456/members'
  58. )
  59. const manageGroupManagersLinks = screen.getAllByText(
  60. 'Manage group managers'
  61. )
  62. expect(manageGroupManagersLinks.length).to.equal(2)
  63. expect(manageGroupManagersLinks[0].getAttribute('href')).to.equal(
  64. '/manage/groups/bcd567/managers'
  65. )
  66. expect(manageGroupManagersLinks[1].getAttribute('href')).to.equal(
  67. '/manage/groups/def456/managers'
  68. )
  69. const viewMetricsLinks = screen.getAllByText('View metrics')
  70. expect(viewMetricsLinks.length).to.equal(2)
  71. expect(viewMetricsLinks[0].getAttribute('href')).to.equal(
  72. '/metrics/groups/bcd567'
  73. )
  74. expect(viewMetricsLinks[1].getAttribute('href')).to.equal(
  75. '/metrics/groups/def456'
  76. )
  77. })
  78. it('renders nothing when there are no group memberships', function () {
  79. render(<ManagedGroupSubscriptions subscriptions={undefined} />)
  80. const elements = screen.queryAllByText('You are a', {
  81. exact: false,
  82. })
  83. expect(elements.length).to.equal(0)
  84. })
  85. })