2022-11-08 16:50:58 +01:00
|
|
|
import { urls } from 'scenes/urls'
|
|
|
|
|
|
|
|
export const savedInsights = {
|
2022-12-30 11:23:09 +01:00
|
|
|
checkInsightIsInListView: (insightName: string): void => {
|
2022-11-08 16:50:58 +01:00
|
|
|
cy.visit(urls.savedInsights())
|
|
|
|
cy.contains('.saved-insights table tr', insightName).should('exist')
|
|
|
|
},
|
2022-12-30 11:23:09 +01:00
|
|
|
checkInsightIsNotInListView: (insightName: string): void => {
|
2022-11-08 16:50:58 +01:00
|
|
|
cy.visit(urls.savedInsights())
|
|
|
|
cy.contains('.saved-insights table tr', insightName).should('not.exist')
|
|
|
|
},
|
2022-12-30 11:23:09 +01:00
|
|
|
createNewInsightOfType: (insightType: string): void => {
|
2022-11-08 16:50:58 +01:00
|
|
|
cy.visit('/saved_insights/') // Should work with trailing slash just like without it
|
|
|
|
cy.get('[data-attr=saved-insights-new-insight-dropdown]').click()
|
|
|
|
cy.get(`[data-attr-insight-type="${insightType || 'TRENDS'}"`).click()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export const insight = {
|
2022-12-30 11:23:09 +01:00
|
|
|
applyFilter: (): void => {
|
2023-11-14 15:38:36 +01:00
|
|
|
cy.get('[data-attr$=add-filter-group]').click()
|
2022-11-08 16:50:58 +01:00
|
|
|
cy.get('[data-attr=property-select-toggle-0]').click()
|
|
|
|
cy.get('[data-attr=taxonomic-filter-searchfield]').click()
|
|
|
|
cy.get('[data-attr=prop-filter-event_properties-1]').click({ force: true })
|
|
|
|
cy.get('[data-attr=prop-val]').click()
|
2024-10-02 20:46:35 +02:00
|
|
|
cy.get('body').then(($body) => {
|
|
|
|
if ($body.find('[data-attr=prop-val-0]').length === 0) {
|
|
|
|
cy.get('[data-attr=taxonomic-value-select]').click()
|
|
|
|
}
|
|
|
|
})
|
2022-11-08 16:50:58 +01:00
|
|
|
},
|
2022-12-30 11:23:09 +01:00
|
|
|
editName: (insightName: string): void => {
|
2022-11-08 16:50:58 +01:00
|
|
|
if (insightName) {
|
2023-12-27 09:52:28 +01:00
|
|
|
cy.get('[data-attr="top-bar-name"] button').click()
|
|
|
|
cy.get('[data-attr="top-bar-name"] input').clear().type(insightName)
|
|
|
|
cy.get('[data-attr="top-bar-name"] [title="Save"]').click()
|
2022-11-08 16:50:58 +01:00
|
|
|
}
|
|
|
|
},
|
2022-12-30 11:23:09 +01:00
|
|
|
save: (): void => {
|
2022-11-08 16:50:58 +01:00
|
|
|
cy.get('[data-attr="insight-save-button"]').click()
|
|
|
|
// wait for save to complete and URL to change and include short id
|
|
|
|
cy.url().should('not.include', '/new')
|
|
|
|
},
|
2023-03-20 21:03:11 +01:00
|
|
|
clickTab: (tabName: string): void => {
|
2024-10-16 16:23:48 +02:00
|
|
|
cy.intercept('POST', /api\/environments\/\d+\/query\//).as('loadNewQueryInsight')
|
2023-03-20 21:03:11 +01:00
|
|
|
|
|
|
|
cy.get(`[data-attr="insight-${(tabName === 'PATHS' ? 'PATH' : tabName).toLowerCase()}-tab"]`).click()
|
2024-03-12 15:39:05 +01:00
|
|
|
if (tabName !== 'FUNNELS') {
|
|
|
|
// funnel insights require two steps before making an api call
|
2024-04-23 11:48:20 +02:00
|
|
|
cy.wait(`@loadNewQueryInsight`)
|
2024-03-12 15:39:05 +01:00
|
|
|
}
|
2023-03-20 21:03:11 +01:00
|
|
|
},
|
2023-03-21 00:44:56 +01:00
|
|
|
newInsight: (insightType: string = 'TRENDS'): void => {
|
2024-10-16 16:23:48 +02:00
|
|
|
cy.intercept('POST', /api\/environments\/\d+\/query\//).as('loadNewQueryInsight')
|
2023-03-18 18:38:11 +01:00
|
|
|
|
2023-03-22 10:36:09 +01:00
|
|
|
if (insightType === 'JSON') {
|
2023-03-24 10:11:59 +01:00
|
|
|
cy.clickNavMenu('savedinsights')
|
|
|
|
cy.get('[data-attr="saved-insights-new-insight-dropdown"]').click()
|
|
|
|
cy.get('[data-attr-insight-type="TRENDS"]').click()
|
2023-03-22 10:36:09 +01:00
|
|
|
insight.clickTab('JSON')
|
|
|
|
} else {
|
2023-03-24 10:11:59 +01:00
|
|
|
cy.clickNavMenu('savedinsights')
|
|
|
|
cy.get('[data-attr="saved-insights-new-insight-dropdown"]').click()
|
|
|
|
cy.get(`[data-attr-insight-type="${insightType}"]`).click()
|
2023-03-22 10:36:09 +01:00
|
|
|
}
|
2023-03-18 18:38:11 +01:00
|
|
|
|
2024-03-12 15:39:05 +01:00
|
|
|
if (insightType !== 'FUNNELS') {
|
|
|
|
// funnel insights require two steps before making an api call
|
2024-04-23 11:48:20 +02:00
|
|
|
cy.wait(`@loadNewQueryInsight`)
|
2024-03-12 15:39:05 +01:00
|
|
|
}
|
2023-03-18 18:38:11 +01:00
|
|
|
},
|
2024-03-07 15:44:57 +01:00
|
|
|
visitInsight: (insightName: string): void => {
|
|
|
|
cy.clickNavMenu('savedinsights')
|
2024-04-29 08:25:53 +02:00
|
|
|
cy.contains('.Link', insightName).click()
|
2024-03-07 15:44:57 +01:00
|
|
|
},
|
2023-03-21 00:44:56 +01:00
|
|
|
create: (insightName: string, insightType: string = 'TRENDS'): void => {
|
2023-03-24 10:11:59 +01:00
|
|
|
cy.clickNavMenu('savedinsights')
|
|
|
|
cy.get('[data-attr="saved-insights-new-insight-dropdown"]').click()
|
|
|
|
cy.get(`[data-attr-insight-type="${insightType}"]`).click()
|
2023-03-18 11:32:22 +01:00
|
|
|
|
2023-12-27 09:52:28 +01:00
|
|
|
cy.get('[data-attr="top-bar-name"] button').click()
|
|
|
|
cy.get('[data-attr="top-bar-name"] input').clear().type(insightName)
|
|
|
|
cy.get('[data-attr="top-bar-name"] [title="Save"]').click()
|
2024-03-07 15:44:57 +01:00
|
|
|
|
|
|
|
cy.get('[data-attr="insight-save-button"]').click() // Save the insight
|
|
|
|
cy.url().should('not.include', '/new') // wait for insight to complete and update URL
|
2023-01-25 14:09:58 +01:00
|
|
|
},
|
|
|
|
addInsightToDashboard: (dashboardName: string, options: { visitAfterAdding: boolean }): void => {
|
2024-10-16 16:23:48 +02:00
|
|
|
cy.intercept('PATCH', /api\/environments\/\d+\/insights\/\d+\/.*/).as('patchInsight')
|
2022-11-08 16:50:58 +01:00
|
|
|
|
|
|
|
cy.get('[data-attr="save-to-dashboard-button"]').click()
|
|
|
|
cy.get('[data-attr="dashboard-searchfield"]').type(dashboardName)
|
|
|
|
cy.contains('[data-attr="dashboard-list-item"]', dashboardName).within(() => {
|
|
|
|
// force clicks rather than mess around scrolling rows that exist into view
|
|
|
|
cy.contains('button', 'Add to dashboard').click({ force: true })
|
|
|
|
cy.wait('@patchInsight').then(() => {
|
2023-10-12 01:51:47 +02:00
|
|
|
cy.contains('Remove from dashboard').should('exist')
|
2023-01-25 14:09:58 +01:00
|
|
|
if (options?.visitAfterAdding) {
|
|
|
|
cy.contains('a', dashboardName).click({ force: true })
|
|
|
|
}
|
2022-11-08 16:50:58 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
2023-03-20 21:03:11 +01:00
|
|
|
updateQueryEditorText(query: string, selector: string = 'query-editor'): void {
|
|
|
|
// the default JSON query doesn't have any results, switch to one that does
|
|
|
|
|
2023-06-12 08:53:54 +02:00
|
|
|
// "obviously" we need to clear the text area multiple times
|
|
|
|
// monaco has elements in front of the text area that the human doesn't see
|
|
|
|
// so force: true is needed everywhere
|
|
|
|
cy.get(`[data-attr="${selector}"] textarea`).type('{selectall}', { force: true })
|
|
|
|
cy.get(`[data-attr="${selector}"] textarea`).type('{backspace}', { force: true })
|
|
|
|
cy.get(`[data-attr="${selector}"] textarea`).type('{selectall}', { force: true })
|
|
|
|
cy.get(`[data-attr="${selector}"] textarea`).type('{backspace}', { force: true })
|
|
|
|
cy.get(`[data-attr="${selector}"] textarea`).type('{selectall}', { force: true })
|
|
|
|
cy.get(`[data-attr="${selector}"] textarea`).type('{backspace}', { force: true })
|
|
|
|
cy.get(`[data-attr="${selector}"] textarea`).type('{selectall}', { force: true })
|
|
|
|
cy.get(`[data-attr="${selector}"] textarea`).type('{backspace}', { force: true })
|
2023-03-20 21:03:11 +01:00
|
|
|
|
2023-06-12 08:53:54 +02:00
|
|
|
cy.get(`[data-attr="${selector}"] textarea`).type(query, { force: true })
|
2023-03-20 21:03:11 +01:00
|
|
|
|
|
|
|
// monaco adds closing squares and curlies as we type,
|
|
|
|
// so, we need to delete any trailing characters to make valid JSON
|
|
|
|
// 😡
|
|
|
|
for (let i = 0; i < 10; i++) {
|
2023-06-12 08:53:54 +02:00
|
|
|
cy.get(`[data-attr="${selector}"] textarea`).type('{del}', { force: true })
|
2023-03-20 21:03:11 +01:00
|
|
|
}
|
|
|
|
|
2023-06-16 16:08:07 +02:00
|
|
|
cy.get(`[data-attr="${selector}-save"]`).click()
|
2023-03-20 21:03:11 +01:00
|
|
|
},
|
2022-11-08 16:50:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const dashboards = {
|
2022-12-30 11:23:09 +01:00
|
|
|
createDashboardFromDefaultTemplate: (dashboardName: string): void => {
|
2022-11-08 16:50:58 +01:00
|
|
|
cy.get('[data-attr="new-dashboard"]').click()
|
2023-03-14 14:31:38 +01:00
|
|
|
cy.get('[data-attr="create-dashboard-from-template"]').click()
|
2023-12-27 09:52:28 +01:00
|
|
|
cy.get('[data-attr="top-bar-name"]').contains('Product analytics').should('exist')
|
|
|
|
cy.get('[data-attr="top-bar-name"] button').click()
|
|
|
|
cy.get('[data-attr="top-bar-name"] input').clear().type(dashboardName).blur()
|
2022-11-08 16:50:58 +01:00
|
|
|
cy.contains(dashboardName).should('exist')
|
|
|
|
},
|
2022-12-30 11:23:09 +01:00
|
|
|
createAndGoToEmptyDashboard: (dashboardName: string): void => {
|
2022-11-08 16:50:58 +01:00
|
|
|
cy.get('[data-attr="new-dashboard"]').click()
|
2023-03-14 14:31:38 +01:00
|
|
|
cy.get('[data-attr="create-dashboard-blank"]').click()
|
2023-12-27 09:52:28 +01:00
|
|
|
cy.get('[data-attr="top-bar-name"]').should('exist')
|
|
|
|
cy.get('[data-attr="top-bar-name"] button').click()
|
|
|
|
cy.get('[data-attr="top-bar-name"] input').clear().type(dashboardName)
|
|
|
|
cy.get('[data-attr="top-bar-name"] [title="Save"]').click()
|
2023-03-14 14:31:38 +01:00
|
|
|
cy.contains(dashboardName).should('exist')
|
2022-11-08 16:50:58 +01:00
|
|
|
},
|
2022-12-30 11:23:09 +01:00
|
|
|
visitDashboard: (dashboardName: string): void => {
|
2023-01-25 14:09:58 +01:00
|
|
|
cy.get('[placeholder="Search for dashboards"]').clear().type(dashboardName)
|
2022-11-10 18:12:52 +01:00
|
|
|
|
|
|
|
cy.contains('[data-attr="dashboards-table"] tr', dashboardName).within(() => {
|
|
|
|
cy.get('a').click()
|
|
|
|
})
|
|
|
|
},
|
2022-11-08 16:50:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const dashboard = {
|
2022-12-30 11:23:09 +01:00
|
|
|
addInsightToEmptyDashboard: (insightName: string): void => {
|
2024-10-16 16:23:48 +02:00
|
|
|
cy.intercept('POST', /api\/environments\/\d+\/insights\//).as('postInsight')
|
2022-11-08 16:50:58 +01:00
|
|
|
|
|
|
|
cy.get('[data-attr=dashboard-add-graph-header]').contains('Add insight').click()
|
|
|
|
cy.get('[data-attr=toast-close-button]').click({ multiple: true })
|
|
|
|
|
|
|
|
if (insightName) {
|
2023-12-27 09:52:28 +01:00
|
|
|
cy.get('[data-attr="top-bar-name"] button').click()
|
|
|
|
cy.get('[data-attr="top-bar-name"] input').clear().type(insightName)
|
|
|
|
cy.get('[data-attr="top-bar-name"] [title="Save"]').click()
|
|
|
|
cy.get('[data-attr="top-bar-name"]').should('have.text', insightName)
|
2022-11-08 16:50:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cy.get('[data-attr=insight-save-button]').contains('Save & add to dashboard').click()
|
|
|
|
cy.wait('@postInsight')
|
|
|
|
},
|
2024-09-12 16:08:02 +02:00
|
|
|
addPropertyFilter(type: string = 'Browser', value: string = 'Chrome'): void {
|
2024-04-29 08:25:53 +02:00
|
|
|
cy.get('.PropertyFilterButton').should('have.length', 0)
|
|
|
|
cy.get('[data-attr="property-filter-0"]').click()
|
2024-09-12 16:08:02 +02:00
|
|
|
cy.get('[data-attr="taxonomic-filter-searchfield"]').click().type(type).wait(1000)
|
2024-06-05 12:42:00 +02:00
|
|
|
cy.get('[data-attr="prop-filter-event_properties-0"]').click({ force: true }).wait(1000)
|
2024-04-29 08:25:53 +02:00
|
|
|
cy.get('.LemonInput').type(value)
|
|
|
|
cy.contains('.LemonButton__content', value).click({ force: true })
|
2024-08-22 09:47:21 +02:00
|
|
|
cy.get('button').contains('Save').click()
|
2024-04-29 08:25:53 +02:00
|
|
|
},
|
2023-02-27 11:22:54 +01:00
|
|
|
addAnyFilter(): void {
|
|
|
|
cy.get('.PropertyFilterButton').should('have.length', 0)
|
|
|
|
cy.get('[data-attr="property-filter-0"]').click()
|
|
|
|
cy.get('[data-attr="taxonomic-filter-searchfield"]').click()
|
|
|
|
cy.get('[data-attr="prop-filter-event_properties-1"]').click({ force: true })
|
|
|
|
cy.get('[data-attr="prop-val"]').click()
|
|
|
|
cy.get('[data-attr="prop-val-0"]').click({ force: true })
|
2024-04-30 14:28:53 +02:00
|
|
|
// click .dashboard to blur
|
|
|
|
cy.get('.dashboard').click({ force: true })
|
2023-02-27 11:22:54 +01:00
|
|
|
cy.get('.PropertyFilterButton').should('have.length', 1)
|
2024-08-22 09:47:21 +02:00
|
|
|
cy.get('button').contains('Save').click()
|
2023-02-27 11:22:54 +01:00
|
|
|
},
|
2022-11-08 16:50:58 +01:00
|
|
|
}
|
|
|
|
|
2024-08-01 13:03:34 +02:00
|
|
|
export function createInsight(insightName: string): Cypress.Chainable<string> {
|
2022-11-08 16:50:58 +01:00
|
|
|
savedInsights.createNewInsightOfType('TRENDS')
|
|
|
|
insight.applyFilter()
|
|
|
|
insight.editName(insightName)
|
|
|
|
insight.save()
|
2024-08-01 13:03:34 +02:00
|
|
|
// return insight id from the url
|
|
|
|
return cy.url().then((url) => {
|
|
|
|
return url.split('/').at(-1)
|
|
|
|
})
|
2022-11-08 16:50:58 +01:00
|
|
|
}
|
2022-11-10 18:12:52 +01:00
|
|
|
|
2022-12-30 11:23:09 +01:00
|
|
|
export function duplicateDashboardFromMenu(duplicateTiles = false): void {
|
2022-11-10 18:12:52 +01:00
|
|
|
cy.contains('.LemonButton', 'Duplicate').click()
|
|
|
|
if (duplicateTiles) {
|
|
|
|
cy.contains('.LemonCheckbox', "Duplicate this dashboard's tiles").click()
|
|
|
|
}
|
|
|
|
cy.get('[data-attr="dashboard-submit-and-go"]').click()
|
|
|
|
}
|