0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-24 18:07:17 +01:00
posthog/cypress/e2e/insights-unsaved-confirmation.cy.ts
Paul D'Ambra 5da50e633a
fix: throw error so test failures are not swallowed (#17926)
So obvious in retrospect

If you listen to the Cypress fail event without re-throwing then you swallow all test failures

"fun"

When reviewing #17919 I knew the Cypress tests would have to be failing which is what prompted me to check

Introduced in bbb7ed9 (July 10th!)
2023-10-12 00:51:47 +01:00

79 lines
2.7 KiB
TypeScript

import { urls } from 'scenes/urls'
import { randomString } from '../support/random'
import { decideResponse } from '../fixtures/api/decide'
import { insight } from '../productAnalytics'
// For tests related to trends please check trendsElements.js
describe('Insights', () => {
beforeEach(() => {
cy.intercept('https://app.posthog.com/decide/*', (req) =>
req.reply(
decideResponse({
hogql: true,
'data-exploration-insights': true,
})
)
)
// set window:confirm here to ensure previous tests can't block
cy.on('window:confirm', () => {
return true
})
cy.visit(urls.insightNew())
})
describe('unsaved insights confirmation', () => {
it('can move away from an unchanged new insight without confirm()', () => {
insight.newInsight()
cy.log('Navigate away')
cy.get('[data-attr="menu-item-featureflags"]').click()
cy.log('We should be on the Feature Flags page now')
cy.url().should('include', '/feature_flags')
})
it('Can navigate away from unchanged saved insight without confirm()', () => {
const insightName = randomString('to save and then navigate away from')
insight.create(insightName)
cy.get('[data-attr="menu-item-annotations"]').click()
// the annotations API call is made before the annotations page loads, so we can't wait for it
cy.get('[data-attr="annotations-content"]').should('exist')
cy.url().should('include', '/annotations')
})
it('Can keep editing changed new insight after navigating away with confirm() rejection (case 1)', () => {
cy.on('window:confirm', () => {
return false
})
insight.newInsight()
cy.log('Add series')
cy.get('[data-attr=add-action-event-button]').click()
cy.log('Navigate away')
cy.get('[data-attr="menu-item-featureflags"]').click()
cy.log('Save button should still be here because case 1 rejects confirm()')
cy.get('[data-attr="insight-save-button"]').should('exist')
})
it('Can navigate away from changed new insight with confirm() acceptance (case 2)', () => {
cy.on('window:confirm', () => {
return true
})
insight.newInsight()
cy.log('Add series')
cy.get('[data-attr=add-action-event-button]').click()
cy.log('Navigate away')
cy.get('[data-attr="menu-item-featureflags"]').click()
cy.url().should('include', '/feature_flags')
})
})
})