institution-memberships.test.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { expect } from 'chai'
  2. import { screen } from '@testing-library/react'
  3. import InstitutionMemberships from '../../../../../../frontend/js/features/subscription/components/dashboard/institution-memberships'
  4. import {
  5. cleanUpContext,
  6. renderWithSubscriptionDashContext,
  7. } from '../../helpers/render-with-subscription-dash-context'
  8. import { Institution } from '../../../../../../types/institution'
  9. const memberships: Institution[] = [
  10. {
  11. id: 9258,
  12. name: 'Test University',
  13. commonsAccount: true,
  14. isUniversity: true,
  15. confirmed: true,
  16. ssoBeta: false,
  17. ssoEnabled: false,
  18. maxConfirmationMonths: 6,
  19. writefullCommonsAccount: false,
  20. },
  21. {
  22. id: 9259,
  23. name: 'Example Institution',
  24. commonsAccount: true,
  25. isUniversity: true,
  26. confirmed: true,
  27. ssoBeta: false,
  28. ssoEnabled: true,
  29. maxConfirmationMonths: 12,
  30. writefullCommonsAccount: false,
  31. },
  32. ]
  33. describe('<InstitutionMemberships />', function () {
  34. afterEach(function () {
  35. cleanUpContext()
  36. })
  37. it('renders all insitutions with license', function () {
  38. renderWithSubscriptionDashContext(<InstitutionMemberships />, {
  39. metaTags: [
  40. { name: 'ol-currentInstitutionsWithLicence', value: memberships },
  41. ],
  42. })
  43. const elements = screen.getAllByText('You are on our', {
  44. exact: false,
  45. })
  46. expect(elements.length).to.equal(2)
  47. expect(elements[0].textContent).to.equal(
  48. 'You are on our Professional plan as a confirmed member of Test University'
  49. )
  50. expect(elements[1].textContent).to.equal(
  51. 'You are on our Professional plan as a confirmed member of Example Institution'
  52. )
  53. })
  54. it('renders error message when failed to check commons licenses', function () {
  55. renderWithSubscriptionDashContext(<InstitutionMemberships />)
  56. screen.getByText(
  57. 'Sorry, something went wrong. Subscription information related to institutional affiliations may not be displayed. Please try again later.'
  58. )
  59. })
  60. })