0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-25 11:17:50 +01:00
posthog/cypress/support/e2e.ts
Eli Kinsey 27e183b765
feat(surveys): Improved survey creation flow (#17902)
* create edit survey components for feature flagging

* visual type picker

* organization

* move previews into tooltips

* targeting

* sync preview and accordion

* better presentation view

* Update UI snapshots for `chromium` (2)

* fix migration file lint

* Update UI snapshots for `chromium` (2)

* make collapse panel header easier to see

* label question index

* more fixes

* update

* surveys new creation flow flag

* fix linter spacing

* form appearance file

* Update UI snapshots for `chromium` (2)

* fix

* fix

* Update UI snapshots for `chromium` (2)

* fix targeting

* fix cypress tests

* black

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Li Yi Yu <li@posthog.com>
Co-authored-by: Neil Kakkar <neilkakkar@gmail.com>
2023-10-16 14:38:29 +00:00

87 lines
3.0 KiB
TypeScript

import 'givens/setup'
import './commands'
import 'cypress-axe'
import { decideResponse } from '../fixtures/api/decide'
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('cypress-terminal-report/src/installLogsCollector')()
// eslint-disable-next-line no-empty
} catch {}
const E2E_TESTING = Cypress.env('E2E_TESTING')
// Add console errors into cypress logs. This helps with failures in Github Actions which otherwise swallows them.
// From: https://github.com/cypress-io/cypress/issues/300#issuecomment-688915086
Cypress.on('window:before:load', (win) => {
cy.spy(win.console, 'error')
cy.spy(win.console, 'warn')
})
beforeEach(() => {
Cypress.env('POSTHOG_PROPERTY_CURRENT_TEST_TITLE', Cypress.currentTest.title)
Cypress.env('POSTHOG_PROPERTY_CURRENT_TEST_FULL_TITLE', Cypress.currentTest.titlePath.join(' > '))
Cypress.env('POSTHOG_PROPERTY_GITHUB_ACTION_RUN_URL', process.env.GITHUB_ACTION_RUN_URL)
cy.intercept('api/prompts/my_prompts/', { sequences: [], state: {} })
cy.intercept('https://app.posthog.com/decide/*', (req) =>
req.reply(
decideResponse({
// set feature flags here e.g.
// 'toolbar-launch-side-action': true,
'surveys-new-creation-flow': true,
'surveys-results-visualizations': true,
'auto-redirect': true,
notebooks: true,
})
)
)
// un-intercepted sometimes this doesn't work and the page gets stuck on the SpinnerOverlay
cy.intercept(/app.posthog.com\/api\/projects\/@current\/feature_flags\/my_flags.*/, (req) => req.reply([]))
cy.intercept('https://www.gravatar.com/avatar/**', (req) =>
req.reply({ statusCode: 404, body: 'Cypress forced 404' })
)
if (Cypress.spec.name.includes('Premium')) {
cy.intercept('/api/users/@me/', { fixture: 'api/user-enterprise' })
cy.request('POST', '/api/login/', {
email: 'test@posthog.com',
password: '12345678',
})
cy.visit('/?no-preloaded-app-context=true')
} else {
cy.intercept('GET', /\/api\/projects\/\d+\/insights\/?\?/).as('getInsights')
cy.request('POST', '/api/login/', {
email: 'test@posthog.com',
password: '12345678',
})
cy.visit('/insights')
cy.wait('@getInsights').then(() => {
cy.get('.saved-insights tr').should('exist')
})
}
})
afterEach(function () {
const { state, duration } = this.currentTest
const event = state === 'passed' ? 'e2e_testing_test_passed' : 'e2e_testing_test_failed'
if (E2E_TESTING) {
cy.window().then((win) => {
;(win as any).posthog?.capture(event, { state, duration })
})
}
})
const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/
Cypress.on('uncaught:exception', (err) => {
/* returning false here prevents Cypress from failing the test */
if (resizeObserverLoopErrRe.test(err.message)) {
return false
}
})