2023-03-18 11:32:22 +01:00
|
|
|
|
import { urls } from 'scenes/urls'
|
|
|
|
|
import { insight } from '../productAnalytics'
|
|
|
|
|
import { decideResponse } from '../fixtures/api/decide'
|
2023-03-21 18:10:10 +01:00
|
|
|
|
import { randomString } from '../support/random'
|
2023-03-18 11:32:22 +01:00
|
|
|
|
|
2023-03-20 21:03:11 +01:00
|
|
|
|
const hogQLQuery = `select event,
|
|
|
|
|
count()
|
|
|
|
|
from events
|
|
|
|
|
group by event,
|
|
|
|
|
properties.$browser,
|
|
|
|
|
person.properties.email
|
|
|
|
|
order by count() desc
|
|
|
|
|
limit 2`
|
|
|
|
|
|
2023-03-18 11:32:22 +01:00
|
|
|
|
// For tests related to trends please check trendsElements.js
|
|
|
|
|
describe('Insights (with data exploration on)', () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
cy.intercept('https://app.posthog.com/decide/*', (req) =>
|
|
|
|
|
req.reply(
|
|
|
|
|
decideResponse({
|
|
|
|
|
'data-exploration-query-tab': true,
|
|
|
|
|
'data-exploration-insights': true,
|
2023-03-22 20:27:37 +01:00
|
|
|
|
'data-exploration-live-events': true,
|
2023-03-18 11:32:22 +01:00
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
)
|
2023-03-20 21:03:11 +01:00
|
|
|
|
|
2023-03-18 11:32:22 +01:00
|
|
|
|
cy.visit(urls.insightNew())
|
|
|
|
|
})
|
|
|
|
|
|
2023-03-20 21:03:11 +01:00
|
|
|
|
it('can open the query editor', () => {
|
2023-03-21 00:44:56 +01:00
|
|
|
|
insight.newInsight('TRENDS')
|
|
|
|
|
cy.get('[aria-label="Edit as JSON"]').click()
|
2023-03-18 18:38:11 +01:00
|
|
|
|
cy.get('[data-attr="query-editor"]').should('exist')
|
2023-03-18 11:32:22 +01:00
|
|
|
|
})
|
2023-03-20 21:03:11 +01:00
|
|
|
|
|
2023-03-22 10:36:09 +01:00
|
|
|
|
it('can save and load and edit a SQL insight', () => {
|
2023-03-21 18:10:10 +01:00
|
|
|
|
insight.newInsight('SQL')
|
|
|
|
|
const insightName = randomString('SQL insight')
|
|
|
|
|
insight.editName(insightName)
|
|
|
|
|
insight.save()
|
|
|
|
|
cy.visit(urls.savedInsights())
|
|
|
|
|
cy.contains('.row-name a', insightName).click()
|
|
|
|
|
|
|
|
|
|
cy.get('[data-attr="hogql-query-editor"]').should('not.exist')
|
|
|
|
|
cy.get('tr.DataTable__row').should('have.length.gte', 2)
|
2023-03-22 10:36:09 +01:00
|
|
|
|
|
|
|
|
|
cy.get('[data-attr="insight-edit-button"]').click()
|
|
|
|
|
insight.clickTab('RETENTION')
|
|
|
|
|
|
|
|
|
|
cy.get('[data-attr="insight-save-button"]').click()
|
|
|
|
|
|
|
|
|
|
cy.get('.RetentionContainer canvas').should('exist')
|
|
|
|
|
cy.get('.RetentionTable__Tab').should('have.length', 66)
|
2023-03-21 18:10:10 +01:00
|
|
|
|
})
|
|
|
|
|
|
2023-03-20 21:03:11 +01:00
|
|
|
|
describe('opening a new insight directly', () => {
|
|
|
|
|
it('can open a new trends insight', () => {
|
2023-03-21 00:44:56 +01:00
|
|
|
|
insight.newInsight('TRENDS')
|
2023-03-20 21:03:11 +01:00
|
|
|
|
cy.get('.trends-insights-container canvas').should('exist')
|
2023-03-21 00:44:56 +01:00
|
|
|
|
cy.get('tr').should('have.length.gte', 2)
|
2023-03-20 21:03:11 +01:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('can open a new funnels insight', () => {
|
2023-03-21 00:44:56 +01:00
|
|
|
|
insight.newInsight('FUNNELS')
|
2023-03-20 21:03:11 +01:00
|
|
|
|
cy.get('.funnels-empty-state__title').should('exist')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('can open a new retention insight', () => {
|
2023-03-21 00:44:56 +01:00
|
|
|
|
insight.newInsight('RETENTION')
|
2023-03-20 21:03:11 +01:00
|
|
|
|
cy.get('.RetentionContainer canvas').should('exist')
|
|
|
|
|
cy.get('.RetentionTable__Tab').should('have.length', 66)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('can open a new paths insight', () => {
|
2023-03-21 00:44:56 +01:00
|
|
|
|
insight.newInsight('PATHS')
|
2023-03-20 21:03:11 +01:00
|
|
|
|
cy.get('.Paths g').should('have.length.gte', 5) // not a fixed value unfortunately
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('can open a new stickiness insight', () => {
|
2023-03-21 00:44:56 +01:00
|
|
|
|
insight.newInsight('STICKINESS')
|
2023-03-20 21:03:11 +01:00
|
|
|
|
cy.get('.trends-insights-container canvas').should('exist')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('can open a new lifecycle insight', () => {
|
2023-03-21 00:44:56 +01:00
|
|
|
|
insight.newInsight('LIFECYCLE')
|
2023-03-20 21:03:11 +01:00
|
|
|
|
cy.get('.trends-insights-container canvas').should('exist')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('can open a new SQL insight', () => {
|
2023-03-21 00:44:56 +01:00
|
|
|
|
insight.newInsight('SQL')
|
2023-03-20 21:03:11 +01:00
|
|
|
|
insight.updateQueryEditorText(hogQLQuery, 'hogql-query-editor')
|
|
|
|
|
cy.get('[data-attr="hogql-query-editor"]').should('exist')
|
2023-03-21 00:44:56 +01:00
|
|
|
|
cy.get('tr.DataTable__row').should('have.length.gte', 2)
|
2023-03-20 21:03:11 +01:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('opening a new insight after opening a new SQL insight', () => {
|
|
|
|
|
// TRICKY: these tests have identical assertions to the ones above, but we need to open a SQL insight first
|
|
|
|
|
// and then click a different tab to switch to that insight.
|
|
|
|
|
// this is because we had a bug where doing that would mean after starting to load the new insight,
|
|
|
|
|
// the SQL insight would be unexpectedly re-selected and the page would switch back to it
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-03-21 00:44:56 +01:00
|
|
|
|
insight.newInsight('SQL')
|
2023-03-20 21:03:11 +01:00
|
|
|
|
insight.updateQueryEditorText(hogQLQuery, 'hogql-query-editor')
|
|
|
|
|
cy.get('[data-attr="hogql-query-editor"]').should('exist')
|
2023-03-21 00:44:56 +01:00
|
|
|
|
cy.get('tr.DataTable__row').should('have.length.gte', 2)
|
2023-03-20 21:03:11 +01:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('can open a new trends insight', () => {
|
|
|
|
|
insight.clickTab('TRENDS')
|
|
|
|
|
cy.get('.trends-insights-container canvas').should('exist')
|
2023-03-21 00:44:56 +01:00
|
|
|
|
cy.get('tr').should('have.length.gte', 2)
|
2023-03-20 21:03:11 +01:00
|
|
|
|
cy.contains('tr', 'No insight results').should('not.exist')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('can open a new funnels insight', () => {
|
|
|
|
|
insight.clickTab('FUNNELS')
|
|
|
|
|
cy.get('.funnels-empty-state__title').should('exist')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('can open a new retention insight', () => {
|
|
|
|
|
insight.clickTab('RETENTION')
|
|
|
|
|
cy.get('.RetentionContainer canvas').should('exist')
|
|
|
|
|
cy.get('.RetentionTable__Tab').should('have.length', 66)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('can open a new paths insight', () => {
|
|
|
|
|
insight.clickTab('PATH')
|
|
|
|
|
cy.get('.Paths g').should('have.length.gte', 5) // not a fixed value unfortunately
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('can open a new stickiness insight', () => {
|
|
|
|
|
insight.clickTab('STICKINESS')
|
|
|
|
|
cy.get('.trends-insights-container canvas').should('exist')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('can open a new lifecycle insight', () => {
|
|
|
|
|
insight.clickTab('LIFECYCLE')
|
|
|
|
|
cy.get('.trends-insights-container canvas').should('exist')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('can open a new SQL insight', () => {
|
|
|
|
|
insight.clickTab('SQL')
|
|
|
|
|
insight.updateQueryEditorText(hogQLQuery, 'hogql-query-editor')
|
|
|
|
|
cy.get('[data-attr="hogql-query-editor"]').should('exist')
|
2023-03-21 00:44:56 +01:00
|
|
|
|
cy.get('tr.DataTable__row').should('have.length.gte', 2)
|
2023-03-20 21:03:11 +01:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('can open a new SQL insight and navigate to a different one, then back to SQL, and back again', () => {
|
|
|
|
|
/**
|
|
|
|
|
* This is here as a regression test. We had a bug where navigating to a new query based insight,
|
|
|
|
|
* then clicking on the trends tab, then on SQL, and again on trends would mean that the trends
|
|
|
|
|
* tab would be selected, but no data loaded for it 🤷♀️
|
|
|
|
|
*/
|
|
|
|
|
|
2023-03-21 00:44:56 +01:00
|
|
|
|
insight.newInsight('SQL')
|
2023-03-20 21:03:11 +01:00
|
|
|
|
cy.get('[data-attr="hogql-query-editor"]').should('exist')
|
|
|
|
|
insight.updateQueryEditorText(hogQLQuery, 'hogql-query-editor')
|
|
|
|
|
|
2023-03-21 00:44:56 +01:00
|
|
|
|
cy.get('.DataTable tr').should('have.length.gte', 2)
|
2023-03-20 21:03:11 +01:00
|
|
|
|
|
|
|
|
|
insight.clickTab('TRENDS')
|
|
|
|
|
cy.get('.trends-insights-container canvas').should('exist')
|
2023-03-21 00:44:56 +01:00
|
|
|
|
cy.get('tr').should('have.length.gte', 2)
|
2023-03-20 21:03:11 +01:00
|
|
|
|
cy.contains('tr', 'No insight results').should('not.exist')
|
|
|
|
|
|
|
|
|
|
insight.clickTab('SQL')
|
|
|
|
|
cy.get('[data-attr="hogql-query-editor"]').should('exist')
|
|
|
|
|
insight.updateQueryEditorText(hogQLQuery, 'hogql-query-editor')
|
|
|
|
|
|
2023-03-21 00:44:56 +01:00
|
|
|
|
cy.get('.DataTable tr').should('have.length.gte', 2)
|
2023-03-20 21:03:11 +01:00
|
|
|
|
|
|
|
|
|
insight.clickTab('TRENDS')
|
|
|
|
|
cy.get('.trends-insights-container canvas').should('exist')
|
2023-03-21 00:44:56 +01:00
|
|
|
|
cy.get('tr').should('have.length.gte', 2)
|
2023-03-20 21:03:11 +01:00
|
|
|
|
cy.contains('tr', 'No insight results').should('not.exist')
|
|
|
|
|
})
|
2023-03-22 20:27:37 +01:00
|
|
|
|
|
|
|
|
|
it('can open event explorer as an insight', () => {
|
|
|
|
|
cy.clickNavMenu('events')
|
|
|
|
|
cy.get('[data-attr="open-json-editor-button"]').click()
|
|
|
|
|
cy.get('[data-attr="insight-json-tab"]').should('exist')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('does not show the json tab usually', () => {
|
|
|
|
|
cy.clickNavMenu('savedinsights')
|
|
|
|
|
cy.get('[data-attr="insight-json-tab"]').should('not.exist')
|
|
|
|
|
})
|
2023-03-18 11:32:22 +01:00
|
|
|
|
})
|