start-free-trial-button.spec.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import StartFreeTrialButton from '../../../../frontend/js/shared/components/start-free-trial-button'
  2. import getMeta from '@/utils/meta'
  3. describe('start free trial button', function () {
  4. beforeEach(function () {
  5. cy.intercept('POST', '/event/paywall-prompt', {
  6. statusCode: 204,
  7. }).as('event-paywall-prompt')
  8. cy.intercept('POST', '/event/paywall-click', {
  9. statusCode: 204,
  10. }).as('event-paywall-click')
  11. getMeta('ol-ExposedSettings').isOverleaf = true
  12. })
  13. it('renders the button with default text', function () {
  14. cy.mount(<StartFreeTrialButton source="cypress-test" />)
  15. cy.wait('@event-paywall-prompt')
  16. .its('request.body.paywall-type')
  17. .should('eq', 'cypress-test')
  18. cy.get('button').contains('Start Free Trial!')
  19. })
  20. it('renders the button with custom text', function () {
  21. cy.mount(
  22. <StartFreeTrialButton source="cypress-test">
  23. Some Custom Text
  24. </StartFreeTrialButton>
  25. )
  26. cy.wait('@event-paywall-prompt')
  27. .its('request.body.paywall-type')
  28. .should('eq', 'cypress-test')
  29. cy.get('button').contains('Some Custom Text')
  30. })
  31. it('renders the button with styled button', function () {
  32. cy.mount(
  33. <StartFreeTrialButton
  34. source="cypress-test"
  35. buttonProps={{
  36. variant: 'danger',
  37. size: 'lg',
  38. }}
  39. />
  40. )
  41. cy.wait('@event-paywall-prompt')
  42. cy.get('button.btn.btn-danger.btn-lg').contains('Start Free Trial!')
  43. })
  44. it('renders the button with custom class', function () {
  45. cy.mount(
  46. <StartFreeTrialButton
  47. source="cypress-test"
  48. buttonProps={{ className: 'ct-test-class' }}
  49. />
  50. )
  51. cy.wait('@event-paywall-prompt')
  52. .its('request.body.paywall-type')
  53. .should('eq', 'cypress-test')
  54. cy.get('.ct-test-class').contains('Start Free Trial!')
  55. })
  56. it('calls onClick callback and opens a new tab to the subscription page on click', function () {
  57. const onClickStub = cy.stub()
  58. cy.mount(
  59. <StartFreeTrialButton source="cypress-test" handleClick={onClickStub} />
  60. )
  61. cy.wait('@event-paywall-prompt')
  62. cy.window().then(win => {
  63. cy.stub(win, 'open').as('Open')
  64. })
  65. cy.get('button.btn').contains('Start Free Trial!').click()
  66. cy.wrap(null).then(() => {
  67. cy.wait('@event-paywall-click')
  68. .its('request.body.paywall-type')
  69. .should('eq', 'cypress-test')
  70. cy.get('@Open').should(
  71. 'have.been.calledOnceWithExactly',
  72. '/user/subscription/choose-your-plan?itm_campaign=cypress-test'
  73. )
  74. expect(onClickStub).to.be.called
  75. })
  76. })
  77. })