:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { Page } from '@playwright/test'
import { NodeKind } from '../../frontend/src/queries/schema/schema-general'
import { ChartDisplayType, InsightShortId } from '../../frontend/src/types'
import { expect, test, PlaywrightWorkspaceSetupResult } from '../utils/workspace-test-base'
async function goToSavedSqlInsight(page: Page, insightShortId: InsightShortId): Promise<void> {
await page.goto(`/sql#insight=${insightShortId}`, { waitUntil: 'domcontentloaded' })
await expect(page).toHaveURL(/\/sql#.*insight=/)
await expect(page.locator('.DataVisualization canvas[role="img"]').last()).toBeVisible({ timeout: 60_000 })
await expect(page.getByRole('button', { name: 'Update insight' })).toBeVisible({ timeout: 30_000 })
}
test.describe('SQL editor axis labels', () => {
test.setTimeout(120_000)
let workspace: PlaywrightWorkspaceSetupResult | null = null
test.beforeAll(async ({ playwrightSetup }) => {
workspace = await playwrightSetup.createWorkspace({
no_demo_data: true,
skip_onboarding: true,
insights: [
{
name: 'Axis labels SQL chart',
query: {
kind: NodeKind.DataVisualizationNode,
source: {
kind: NodeKind.HogQLQuery,
query: "SELECT 'sample' AS event, 10 AS events, 5 AS people",
},
display: ChartDisplayType.ActionsBar,
chartSettings: {
xAxis: {
column: 'event',
},
yAxis: [
{
column: 'events',
settings: {
display: {
yAxisPosition: 'left',
},
},
},
{
column: 'people',
settings: {
display: {
yAxisPosition: 'right',
},
},
},
],
},
tableSettings: {},
},
},
],
})
})
test.beforeEach(async ({ page, playwrightSetup }) => {
await playwrightSetup.login(page, workspace!)
})
test('adds axis labels to a saved SQL chart and persists them', async ({ page }) => {
const insightShortId = workspace!.created_insights![0].short_id as InsightShortId
await goToSavedSqlInsight(page, insightShortId)
await page.getByTestId('sql-editor-visualization-settings-button').click()
await page.getByRole('tab', { name: 'Display' }).click()
await page.getByText('X-axis', { exact: true }).click()
await page.getByText('Left Y-axis', { exact: true }).click()
await page.getByText('Right Y-axis', { exact: true }).click()
await page.getByTestId('data-visualization-x-axis-label-input').fill('Event name')
await page.getByTestId('data-visualization-left-y-axis-label-input').fill('Events')
await page.getByTestId('data-visualization-right-y-axis-label-input').fill('People')
// Labels save when the field loses focus.
await page.keyboard.press('Tab')
const saveRequestPromise = page.waitForResponse(
(response) =>
/\/api\/(?:projects|environments)\/\d+\/insights(?:\/\d+)?\/?(?:\?.*)?$/.test(response.url()) &&
response.request().method() === 'PATCH',
{ timeout: 60_000 }
)
await page.getByRole('button', { name: 'Update insight' }).click()
await expect((await saveRequestPromise).ok()).toBe(true)
await goToSavedSqlInsight(page, insightShortId)
await page.getByTestId('sql-editor-visualization-settings-button').click()
await page.getByRole('tab', { name: 'Display' }).click()
await page.getByText('X-axis', { exact: true }).click()
await page.getByText('Left Y-axis', { exact: true }).click()
await page.getByText('Right Y-axis', { exact: true }).click()
await expect(page.getByTestId('data-visualization-x-axis-label-input')).toHaveValue('Event name')
await expect(page.getByTestId('data-visualization-left-y-axis-label-input')).toHaveValue('Events')
await expect(page.getByTestId('data-visualization-right-y-axis-label-input')).toHaveValue('People')
})
})