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

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