0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-12-01 04:12:23 +01:00
posthog/cypress/e2e/dashboard-shared.cy.ts

67 lines
2.3 KiB
TypeScript
Raw Normal View History

import { dashboards } from '../productAnalytics'
describe('Shared 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')
})
it('Dashboard sharing can be enabled', () => {
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('Insights load when cache is empty', () => {
cy.get('h1').should('contain', 'Dashboards')
dashboards.createDashboardFromDefaultTemplate('Foobar 3001')
cy.get('[data-attr=dashboard-share-button]').click()
cy.get('[data-attr=sharing-switch]').click({ force: true })
cy.contains('Copy public link').should('be.visible')
cy.get('[data-attr=sharing-link-button]').click()
cy.window()
.its('navigator.clipboard')
.then((clipboard) => {
cy.wrap(clipboard.readText()).as('clipboardText')
})
cy.task('resetInsightCache')
cy.window().then(async (win) => {
const text = await win.navigator.clipboard.readText()
cy.visit(text)
})
// Make sure no element with text "There are no matching events for this query" exists
cy.get('.InsightCard').should('have.length', 6)
cy.get('.insight-empty-state').should('not.exist')
})
})