premium-features-link.test.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { expect } from 'chai'
  2. import sinon from 'sinon'
  3. import { fireEvent, render, screen, within } from '@testing-library/react'
  4. import * as eventTracking from '../../../../../../frontend/js/infrastructure/event-tracking'
  5. import PremiumFeaturesLink from '../../../../../../frontend/js/features/subscription/components/dashboard/premium-features-link'
  6. describe('<PremiumFeaturesLink />', function () {
  7. const originalLocation = window.location
  8. let sendMBSpy: sinon.SinonSpy
  9. const variants = [
  10. { name: 'default', link: '/learn/how-to/Overleaf_premium_features' },
  11. { name: 'new', link: '/about/features-overview' },
  12. ]
  13. beforeEach(function () {
  14. window.metaAttributesCache = new Map()
  15. sendMBSpy = sinon.spy(eventTracking, 'sendMB')
  16. })
  17. afterEach(function () {
  18. window.metaAttributesCache = new Map()
  19. sendMBSpy.restore()
  20. Object.defineProperty(window, 'location', {
  21. value: originalLocation,
  22. })
  23. })
  24. for (const variant of variants) {
  25. describe(`${variant.name} variant`, function () {
  26. beforeEach(function () {
  27. window.metaAttributesCache.set('ol-splitTestVariants', {
  28. 'features-page': variant.name,
  29. })
  30. })
  31. afterEach(function () {
  32. window.metaAttributesCache.delete('ol-splitTestVariants')
  33. })
  34. it('renders the premium features link and sends analytics event', function () {
  35. render(<PremiumFeaturesLink />)
  36. const premiumText = screen.getByText('Get the most out of your', {
  37. exact: false,
  38. })
  39. const link = within(premiumText).getByRole('link')
  40. fireEvent.click(link)
  41. expect(sendMBSpy).to.be.calledOnce
  42. expect(sendMBSpy).calledWith('features-page-link', {
  43. splitTest: 'features-page',
  44. splitTestVariant: variant.name,
  45. page: originalLocation.pathname,
  46. })
  47. })
  48. })
  49. }
  50. })