Skip to content

Commit

Permalink
chore: add a test (#1299)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Jul 11, 2024
1 parent 2348606 commit 9e9191b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
36 changes: 7 additions & 29 deletions cypress/e2e/capture.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ describe('Event capture', () => {
})
})

describe('opting out of autocapture', () => {
it('captures pageviews, custom events', () => {
describe('when disabled', () => {
it('captures pageviews, custom events when autocapture disabled', () => {
start({ options: { autocapture: false }, waitForDecide: false })

cy.wait(50)
Expand All @@ -226,10 +226,8 @@ describe('Event capture', () => {
expect(captures['event']).to.equal('$pageview')
})
})
})

describe('opting out of pageviews', () => {
it('captures autocapture, custom events', () => {
it('captures autocapture, custom events when pageviews disabled', () => {
start({ options: { capture_pageview: false } })

cy.get('[data-cy-custom-event-button]').click()
Expand All @@ -239,35 +237,15 @@ describe('Event capture', () => {
cy.phCaptures().should('include', '$autocapture')
cy.phCaptures().should('include', 'custom-event')
})
})

describe('user opts out after start', () => {
it('does not send any autocapture/custom events after that', () => {
start({})

cy.posthog().invoke('opt_out_capturing')
it('does not capture things when multiple disabled', () => {
start({ options: { capture_pageview: false, capture_pageleave: false, autocapture: false } })

cy.get('[data-cy-custom-event-button]').click()
cy.get('[data-cy-feature-flag-button]').click()
cy.reload()

cy.phCaptures().should('deep.equal', ['$pageview'])
})

it('does not send session recording events', () => {
start({
decideResponseOverrides: {
sessionRecording: {
endpoint: '/ses/',
},
},
})

cy.posthog().invoke('opt_out_capturing')
cy.resetPhCaptures()

cy.get('[data-cy-custom-event-button]').click()
cy.phCaptures().should('deep.equal', [])
cy.phCaptures().should('have.length', 1)
cy.phCaptures().should('include', 'custom-event')
})
})

Expand Down
15 changes: 15 additions & 0 deletions cypress/e2e/opting-out.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assertWhetherPostHogRequestsWereCalled, pollPhCaptures } from '../support/assertions'
import { start } from '../support/setup'

function assertThatRecordingStarted() {
cy.phCaptures({ full: true }).then((captures) => {
Expand Down Expand Up @@ -188,4 +189,18 @@ describe('opting out', () => {
pollPhCaptures('$snapshot').then(assertThatRecordingStarted)
})
})

describe('user opts out after start', () => {
it('does not send any autocapture/custom events after that', () => {
start({})

cy.posthog().invoke('opt_out_capturing')

cy.get('[data-cy-custom-event-button]').click()
cy.get('[data-cy-feature-flag-button]').click()
cy.reload()

cy.phCaptures().should('deep.equal', ['$pageview'])
})
})
})

0 comments on commit 9e9191b

Please sign in to comment.