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

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