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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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').contains('Start Free Trial!').click()
  61. cy.wrap(null).then(() => {
  62. cy.wait('@event-paywall-click')
  63. .its('request.body.paywall-type')
  64. .should('eq', 'cypress-test')
  65. cy.get('@Open').should(
  66. 'have.been.calledOnceWithExactly',
  67. '/user/subscription/choose-your-plan?itm_campaign=cypress-test'
  68. )
  69. expect(onClickStub).to.be.called
  70. })
  71. })
  72. })