0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-25 11:17:50 +01:00
posthog/cypress/e2e/insights-unsaved-confirmation.cy.ts

79 lines
2.6 KiB
TypeScript

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('/insights')
cy.wait('@getInsights').then(() => {
cy.get('.saved-insights tr').should('exist')
})
})
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-dashboards"]').click()
cy.url().should('include', '/dashboard')
})
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')
})
})
})