managed-group-subscriptions.test.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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', async 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 links = screen.getAllByRole('link')
  57. expect(links[1].getAttribute('href')).to.equal(
  58. '/manage/groups/bcd567/members'
  59. )
  60. expect(links[2].getAttribute('href')).to.equal(
  61. '/manage/groups/bcd567/managers'
  62. )
  63. expect(links[3].getAttribute('href')).to.equal('/metrics/groups/bcd567')
  64. expect(links[5].getAttribute('href')).to.equal(
  65. '/manage/groups/def456/members'
  66. )
  67. expect(links[6].getAttribute('href')).to.equal(
  68. '/manage/groups/def456/managers'
  69. )
  70. expect(links[7].getAttribute('href')).to.equal('/metrics/groups/def456')
  71. })
  72. it('renders nothing when there are no group memberships', function () {
  73. renderWithSubscriptionDashContext(<ManagedGroupSubscriptions />)
  74. const elements = screen.queryAllByText('You are a', {
  75. exact: false,
  76. })
  77. expect(elements.length).to.equal(0)
  78. })
  79. })