Skip to content

Commit

Permalink
fix: reload cyprus and tsc issue
Browse files Browse the repository at this point in the history
  • Loading branch information
k11kirky committed Dec 16, 2024
1 parent ecc7186 commit 8e54242
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 32 deletions.
42 changes: 11 additions & 31 deletions cypress/e2e/insights-reload-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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',
})
})

Expand All @@ -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')
})
})
5 changes: 4 additions & 1 deletion frontend/src/scenes/insights/insightSceneLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<insightSceneLogicType>([
path(['scenes', 'insights', 'insightSceneLogic']),
connect(() => ({
Expand Down Expand Up @@ -77,7 +80,7 @@ export const insightSceneLogic = kea<insightSceneLogicType>([
}),
reducers({
insightId: [
null as null | 'new' | InsightShortId,
null as null | InsightId,
{
setSceneState: (_, { insightId }) => insightId,
},
Expand Down

0 comments on commit 8e54242

Please sign in to comment.