diff --git a/cypress/e2e/insights-reload-query.ts b/cypress/e2e/insights-reload-query.ts index 44e0a82bc520d..b2b0236810d99 100644 --- a/cypress/e2e/insights-reload-query.ts +++ b/cypress/e2e/insights-reload-query.ts @@ -8,25 +8,10 @@ describe('ReloadInsight component', () => { // Visit the new insight creation page cy.visit('/insights/new') - // Interact with the page to change the query - // For this example, we'll select the "Trends" insight and add an event - cy.get('[data-attr="insight-type-selector"]').click() - cy.contains('Trends').click() + cy.wait(1000) - // Ensure the trends tab is active - cy.get('[data-attr="insight-type-tab"]').should('have.class', 'active').and('contain', 'Trends') - - // Add an event to the query - cy.get('[data-attr="add-event-button"]').click() - cy.get('[data-attr="event-name-input"]').type('Pageview{enter}') - - // Wait for the query to run and results to load - cy.get('.insights-graph-container').should('exist') - - // Verify that the URL contains the updated query in the hash parameters (e.g., 'q=') - cy.location().then((location) => { - expect(location.hash).to.contain('q=') - }) + cy.get('[data-attr="math-selector-0"]').click({ force: true }) + cy.get('[data-attr="math-dau-0"]').click({ force: true }) // Check that the 'draft-query' item is stored in localStorage cy.window().then((window) => { @@ -36,10 +21,13 @@ describe('ReloadInsight component', () => { const draftQueryObj = JSON.parse(draftQuery) expect(draftQueryObj).to.have.property('query') - // Optional: Verify the content of the query matches the changes made - expect(draftQueryObj.query).to.deep.include({ - kind: 'TrendsQuery', - events: [{ id: 'Pageview' }], + expect(draftQueryObj).to.have.property('query') + + const firstSeries = draftQueryObj.query.source.series[0] + + expect(firstSeries).to.include({ + event: '$pageview', + math: 'dau', }) }) @@ -52,14 +40,6 @@ describe('ReloadInsight component', () => { // Click the link to reload the unsaved insight cy.contains('Click here').click() - // Confirm that we are redirected back to the insight creation page - cy.location('pathname').should('eq', '/insights/new') - - // Verify that the query editor has restored the previous query - // Check that "Pageview" is selected in the events - cy.get('[data-attr="event-name"]').should('contain', 'Pageview') - - // Verify that the insights graph is displayed based on the restored query - cy.get('.insights-graph-container').should('exist') + cy.get('[data-attr="math-selector-0"]').should('contain', 'Unique users') }) }) diff --git a/frontend/src/scenes/insights/insightSceneLogic.tsx b/frontend/src/scenes/insights/insightSceneLogic.tsx index 43eb639c2cc54..1bb424de8e522 100644 --- a/frontend/src/scenes/insights/insightSceneLogic.tsx +++ b/frontend/src/scenes/insights/insightSceneLogic.tsx @@ -27,6 +27,9 @@ import { insightDataLogicType } from './insightDataLogicType' import type { insightSceneLogicType } from './insightSceneLogicType' import { summarizeInsight } from './summarizeInsight' +const NEW_INSIGHT = 'new' as const +export type InsightId = InsightShortId | typeof NEW_INSIGHT | null + export const insightSceneLogic = kea([ path(['scenes', 'insights', 'insightSceneLogic']), connect(() => ({ @@ -77,7 +80,7 @@ export const insightSceneLogic = kea([ }), reducers({ insightId: [ - null as null | 'new' | InsightShortId, + null as null | InsightId, { setSceneState: (_, { insightId }) => insightId, },