0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-25 02:31:30 +01:00
posthog/cypress/e2e/dashboard.cy.ts
Paul D'Ambra 1de6d5c6fa
chore: throw runners at e2e CI (#17492)
* chore: throw runners at e2e CI

* add some files so we split even further

* more splitting

* more splitting
2023-09-18 13:00:03 +00:00

214 lines
8.8 KiB
TypeScript

import { randomString } from '../support/random'
import { insight, dashboards, dashboard } from '../productAnalytics'
describe('Dashboard', () => {
beforeEach(() => {
cy.intercept('GET', /api\/projects\/\d+\/insights\/\?.*/).as('loadInsightList')
cy.intercept('PATCH', /api\/projects\/\d+\/insights\/\d+\/.*/).as('patchInsight')
cy.intercept('POST', /\/api\/projects\/\d+\/dashboards/).as('createDashboard')
cy.clickNavMenu('dashboards')
cy.location('pathname').should('include', '/dashboard')
})
it('Dashboards loaded', () => {
cy.get('h1').should('contain', 'Dashboards')
// Breadcrumbs work
cy.get('[data-attr=breadcrumb-0]').should('contain', 'Hogflix')
cy.get('[data-attr=breadcrumb-1]').should('contain', 'Hogflix Demo App')
cy.get('[data-attr=breadcrumb-2]').should('have.text', 'Dashboards')
})
it('Adding new insight to dashboard works', () => {
const dashboardName = randomString('to add an insight to')
const insightName = randomString('insight to add to dashboard')
// create and visit a dashboard to get it into turbomode cache
dashboards.createAndGoToEmptyDashboard(dashboardName)
insight.create(insightName)
insight.addInsightToDashboard(dashboardName, { visitAfterAdding: true })
cy.get('.CardMeta h4').should('have.text', insightName)
})
it('Adding new insight to dashboard does not clear filters', () => {
const dashboardName = randomString('to add an insight to')
const firstInsight = randomString('insight to add to dashboard')
const secondInsight = randomString('another insight to add to dashboard')
// create and visit a dashboard to get it into turbomode cache
dashboards.createAndGoToEmptyDashboard(dashboardName)
dashboard.addInsightToEmptyDashboard(firstInsight)
dashboard.addAnyFilter()
dashboard.addInsightToEmptyDashboard(secondInsight)
cy.get('.PropertyFilterButton').should('have.length', 1)
cy.get('.CardMeta h4').should('contain.text', firstInsight)
cy.get('.CardMeta h4').should('contain.text', secondInsight)
})
it('Cannot see tags or description (non-FOSS feature)', () => {
cy.get('h1').should('contain', 'Dashboards')
cy.get('th').contains('Description').should('not.exist')
cy.get('th').contains('Tags').should('not.exist')
cy.get('[data-attr=dashboard-name]').contains('App Analytics').click()
cy.get('.InsightCard').should('exist')
cy.get('.dashboard-description').should('not.exist')
cy.get('[data-attr=dashboard-tags]').should('not.exist')
})
it('Pinned dashboards on menu', () => {
cy.clickNavMenu('events') // to make sure the dashboards menu item is not the active one
cy.get('[data-attr=menu-item-pinned-dashboards]').click()
cy.get('[data-attr=sidebar-pinned-dashboards]').should('be.visible')
cy.get('[data-attr=sidebar-pinned-dashboards] a').should('contain', 'App Analytics')
})
it('Share dashboard', () => {
dashboards.createDashboardFromDefaultTemplate('to be shared')
cy.get('.InsightCard').should('exist')
cy.get('[data-attr=dashboard-share-button]').click()
cy.get('[data-attr=sharing-switch]').click({ force: true })
cy.contains('Embed dashboard').should('be.visible')
cy.get('[data-attr=copy-code-button]').click()
cy.window()
.its('navigator.clipboard')
.then((c) => c.readText())
.should('contain', '<iframe')
cy.window()
.its('navigator.clipboard')
.then((c) => c.readText())
.should('contain', '/embedded/')
cy.contains('Copy public link').should('be.visible')
cy.get('[data-attr=sharing-link-button]').click()
cy.window()
.its('navigator.clipboard')
.then((c) => c.readText())
.should('contain', '/shared/')
})
it('Create an empty dashboard', () => {
const dashboardName = 'New Dashboard 2'
cy.get('[data-attr="new-dashboard"]').click()
cy.get('[data-attr="create-dashboard-blank"]').click()
cy.get('[data-attr="dashboard-name"]').should('exist')
cy.get('[data-attr="dashboard-name"] button').click()
cy.get('[data-attr="dashboard-name"] input').clear().type(dashboardName).blur()
cy.contains(dashboardName).should('exist')
cy.get('.EmptyDashboard').should('exist')
// Check that dashboard is not pinned by default
cy.get('.page-buttons [data-attr="dashboard-three-dots-options-menu"]').click()
cy.get('button').contains('Pin dashboard').should('exist')
})
it('Create dashboard from a template', () => {
const TEST_DASHBOARD_NAME = 'XDefault'
dashboards.createDashboardFromDefaultTemplate(TEST_DASHBOARD_NAME)
cy.get('.InsightCard').its('length').should('be.gte', 2)
// Breadcrumbs work
cy.get('[data-attr=breadcrumb-0]').should('contain', 'Hogflix')
cy.get('[data-attr=breadcrumb-1]').should('contain', 'Hogflix Demo App')
cy.get('[data-attr=breadcrumb-2]').should('have.text', 'Dashboards')
cy.get('[data-attr=breadcrumb-3]').should('have.text', TEST_DASHBOARD_NAME)
})
it('Click on a dashboard item dropdown and view graph', () => {
cy.get('[data-attr=dashboard-name]').contains('Web Analytics').click()
cy.get('.InsightCard [data-attr=more-button]').first().click()
cy.get('a').contains('View').click()
cy.location('pathname').should('include', '/insights')
})
it('Rename dashboard item', () => {
cy.get('[data-attr=dashboard-name]').contains('Web Analytics').click()
cy.get('.InsightCard [data-attr=more-button]').first().click()
cy.get('button').contains('Rename').click()
cy.get('[data-attr=modal-prompt]').clear().type('Test Name')
cy.contains('OK').click()
cy.contains('Test Name').should('exist')
})
it('Color dashboard item', () => {
cy.get('[data-attr=dashboard-name]').contains('Web Analytics').click()
cy.get('.InsightCard [data-attr=more-button]').first().click()
cy.get('button').contains('Set color').click()
cy.get('button').contains('Green').click()
cy.get('.InsightCard .CardMeta__ribbon').should('have.class', 'green')
})
it('Duplicate dashboard item', () => {
cy.get('[data-attr=dashboard-name]').contains('Web Analytics').click()
cy.get('.InsightCard [data-attr=more-button]').first().click()
cy.get('button').contains('Duplicate').click()
cy.get('[data-attr=success-toast]').contains('Insight duplicated').should('exist')
})
it('Move dashboard item', () => {
cy.intercept('PATCH', /api\/projects\/\d+\/dashboards\/\d+\/move_tile.*/).as('moveTile')
const sourceDashboard = randomString('source-dashboard')
const targetDashboard = randomString('target-dashboard')
const insightToMove = randomString('insight-to-move')
dashboards.createAndGoToEmptyDashboard(sourceDashboard)
const insightToLeave = randomString('insight-to-leave')
dashboard.addInsightToEmptyDashboard(insightToLeave)
dashboard.addInsightToEmptyDashboard(insightToMove)
cy.wait(200)
// create the target dashboard and get it cached by turbo-mode
cy.clickNavMenu('dashboards')
dashboards.createAndGoToEmptyDashboard(targetDashboard)
cy.clickNavMenu('dashboards')
dashboards.visitDashboard(sourceDashboard)
cy.contains('.InsightCard ', insightToMove).within(() => {
cy.get('[data-attr=more-button]').first().click({ force: true })
})
cy.get('button').contains('Move to').click()
cy.get('button').contains(targetDashboard).click()
cy.wait('@moveTile').then(() => {
cy.get('.CardMeta h4').should('have.text', insightToLeave)
cy.clickNavMenu('dashboards')
dashboards.visitDashboard(targetDashboard)
cy.get('.CardMeta h4').should('have.text', insightToMove)
})
})
it('Opens dashboard item in insights', () => {
cy.get('[data-attr=dashboard-name]').contains('App Analytics').click()
cy.get('.InsightCard [data-attr=insight-card-title]').first().click()
cy.location('pathname').should('include', '/insights')
cy.get('[data-attr=funnel-bar-graph]', { timeout: 30000 }).should('exist')
})
it('Add insight from empty dashboard', () => {
const dashboardName = randomString('dashboard-')
dashboards.createAndGoToEmptyDashboard(dashboardName)
dashboard.addInsightToEmptyDashboard(randomString('insight-'))
cy.wait(200)
cy.get('.page-title').contains(dashboardName).should('exist')
})
})