mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-22 17:24:15 +01:00
d1c75ab747
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
47 lines
2.0 KiB
TypeScript
47 lines
2.0 KiB
TypeScript
import { urls } from 'scenes/urls'
|
|
|
|
import { createInsight } from '../productAnalytics'
|
|
|
|
chai.Assertion.addMethod('neverHaveChild', function (childSelector) {
|
|
this._obj.on('DOMNodeInserted', () => {
|
|
const matchCount = cy.$$(childSelector, this._obj).length
|
|
if (matchCount > 0) {
|
|
throw new Error(
|
|
`Expected element to never have child ${childSelector}, but found ${matchCount} match${
|
|
matchCount > 1 ? 'es' : ''
|
|
}`
|
|
)
|
|
}
|
|
})
|
|
})
|
|
|
|
// For tests related to trends please check trendsElements.js
|
|
// insight tests were split up because Cypress was struggling with this many tests in one file🙈
|
|
describe('Insights - saved', () => {
|
|
// TODO: this test works locally, just not in CI
|
|
// also change 'neverHaveChild' check to start right after page loads
|
|
it.skip('Data is available immediately', () => {
|
|
createInsight('saved insight').then((newInsightId) => {
|
|
cy.get('[data-attr=trend-line-graph]').should('exist') // Results cached
|
|
cy.visit(urls.insightView(newInsightId)) // Full refresh
|
|
cy.get('.InsightViz').should('exist').should('neverHaveChild', '.insight-empty-state') // Only cached data
|
|
cy.get('[data-attr=trend-line-graph]').should('exist')
|
|
})
|
|
})
|
|
|
|
it('If cache empty, initiate async refresh', () => {
|
|
cy.intercept('GET', /\/api\/environments\/\d+\/insights\/?\?[^/]*?refresh=async/).as('getInsightsRefreshAsync')
|
|
let newInsightId: string
|
|
createInsight('saved insight').then((insightId) => {
|
|
newInsightId = insightId
|
|
})
|
|
cy.task('resetInsightCache').then(() => {
|
|
cy.visit(urls.insightView(newInsightId)) // Full refresh
|
|
cy.get('.insight-empty-state').should('exist') // There should be a loading state for a moment
|
|
cy.wait('@getInsightsRefreshAsync').then(() => {
|
|
cy.get('[data-attr=trend-line-graph]').should('exist')
|
|
})
|
|
})
|
|
})
|
|
})
|