Skip to content

Commit

Permalink
add header display and capture tests
Browse files Browse the repository at this point in the history
  • Loading branch information
liyiy committed Jan 5, 2024
1 parent 1f2a0f0 commit 932c45b
Showing 1 changed file with 63 additions and 1 deletion.
64 changes: 63 additions & 1 deletion cypress/e2e/surveys.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference types="cypress" />
import { getBase64EncodedPayload } from '../support/compression'

function onPageLoad() {
cy.posthogInit(given.options)
Expand Down Expand Up @@ -26,7 +27,7 @@ describe('Surveys', () => {
active: true,
type: 'popover',
start_date: '2021-01-01T00:00:00Z',
questions: [{ type: 'open', question: 'What is your role?' }],
questions: [{ type: 'open', question: 'What is your role?', description: 'test description' }],
},
],
}).as('surveys')
Expand All @@ -35,6 +36,8 @@ describe('Surveys', () => {
cy.wait(500)
const survey = cy.get('.PostHogSurvey123').shadow()
survey.find('.survey-123-form').should('be.visible')
cy.get('.PostHogSurvey123').shadow().find('.survey-question').should('have.text', 'What is your role?')
cy.get('.PostHogSurvey123').shadow().find('.description').should('have.text', 'test description')
survey.find('.question-textarea-wrapper').type('product engineer')
cy.get('.PostHogSurvey123').shadow().find('.form-submit').click()
cy.phCaptures().should('include', 'survey sent')
Expand Down Expand Up @@ -119,4 +122,63 @@ describe('Surveys', () => {
cy.get('.PostHogSurvey12345').shadow().find('.form-submit').eq(3).click()
expect(cy.get('.PostHogSurvey12345').shadow().find('.thank-you-message').should('be.visible'))
})

describe('survey response capture', () => {
it('captures survey shown and survey dismissed events', () => {
cy.visit('./playground/cypress')
cy.intercept('GET', '**/surveys/*', {
surveys: [
{
id: '123',
name: 'Test survey',
description: 'description',
active: true,
type: 'popover',
start_date: '2021-01-01T00:00:00Z',
questions: [{ type: 'open', question: 'What is a survey event capture test?' }],
},
],
}).as('surveys')
cy.intercept('POST', '**/e/*').as('capture-assertion')
onPageLoad()
// first capture is $pageview
cy.wait('@capture-assertion')
cy.wait('@capture-assertion').then(async ({ request }) => {
const captures = await getBase64EncodedPayload(request)
expect(captures.map(({ event }) => event)).to.deep.equal(['survey shown'])
})
cy.get('.PostHogSurvey123').shadow().find('.cancel-btn-wrapper').click()
cy.wait('@capture-assertion').then(async ({ request }) => {
const captures = await getBase64EncodedPayload(request)
expect(captures.map(({ event }) => event)).to.deep.equal(['survey dismissed'])
})
})

it('captures survey sent event', () => {
cy.visit('./playground/cypress')
cy.intercept('GET', '**/surveys/*', {
surveys: [
{
id: '123',
name: 'Test survey',
description: 'description',
active: true,
type: 'popover',
start_date: '2021-01-01T00:00:00Z',
questions: [{ type: 'open', question: 'What is a survey event capture test?' }],
},
],
}).as('surveys')
cy.intercept('POST', '**/e/*').as('capture-assertion')
onPageLoad()
cy.get('.PostHogSurvey123').shadow().find('.question-textarea-wrapper').type('product engineer')
cy.get('.PostHogSurvey123').shadow().find('.form-submit').click()
cy.wait('@capture-assertion')
cy.wait('@capture-assertion').then(async ({ request }) => {
const captures = await getBase64EncodedPayload(request)
expect(captures.map(({ event }) => event)).to.deep.equal(['survey shown', 'survey sent'])
expect(captures[1].properties).to.contain({ $survey_id: '123', $survey_response: 'product engineer' })
})
})
})
})

0 comments on commit 932c45b

Please sign in to comment.