: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
test(trends): restore unit coverage for buildTrendsYAxisConfig + schemaGoalLinesToConfigs (#57693)
Sam Pennington7ac08f93e79a
diff --git a/frontend/src/scenes/trends/viz/trends-line-chart/goalLinesAdapter.test.ts b/frontend/src/scenes/trends/viz/trends-line-chart/goalLinesAdapter.test.tsindex f051946ac590..16f60bfe18ee 100644--- a/frontend/src/scenes/trends/viz/trends-line-chart/goalLinesAdapter.test.ts+++ b/frontend/src/scenes/trends/viz/trends-line-chart/goalLinesAdapter.test.ts@@ -3,7 +3,11 @@ import type { Series } from 'lib/hog-charts'import type { GoalLine as SchemaGoalLine } from '~/queries/schema/schema-general'-import { alertThresholdsToReferenceLines, goalLinesToReferenceLines } from './goalLinesAdapter'+import {+ alertThresholdsToReferenceLines,+ goalLinesToReferenceLines,+ schemaGoalLinesToConfigs,+} from './goalLinesAdapter'const makeSeries = (data: number[], overrides: Partial<Series> = {}): Series => ({key: 'a',@@ -120,4 +124,46 @@ describe('goalLinesAdapter', () => {expect(alertThresholdsToReferenceLines(lines).map((r) => r.label)).toEqual(['Crossed', 'Above'])})})++ describe('schemaGoalLinesToConfigs', () => {+ it.each<[string, SchemaGoalLine[] | null | undefined]>([+ ['null', null],+ ['undefined', undefined],+ ['empty array', []],+ ])('returns undefined for %s input', (_, input) => {+ expect(schemaGoalLinesToConfigs(input)).toBeUndefined()+ })++ it('produces one GoalLineConfig per schema goal line, mapping every field', () => {+ const lines: SchemaGoalLine[] = [+ {+ label: 'Target',+ value: 100,+ displayLabel: true,+ borderColor: '#ff0000',+ position: 'end',+ displayIfCrossed: true,+ },+ { label: 'Floor', value: 10 },+ ]+ expect(schemaGoalLinesToConfigs(lines)).toEqual([+ {+ label: 'Target',+ value: 100,+ displayLabel: true,+ color: '#ff0000',+ labelPosition: 'end',+ displayIfCrossed: true,+ },+ {+ label: 'Floor',+ value: 10,+ displayLabel: undefined,+ color: undefined,+ labelPosition: undefined,+ displayIfCrossed: undefined,+ },+ ])+ })+ })})diff --git a/frontend/src/scenes/trends/viz/trends-line-chart/trendsAxisFormat.test.ts b/frontend/src/scenes/trends/viz/trends-line-chart/trendsAxisFormat.test.tsindex 5513eef1d9af..e34a17a73f9e 100644--- a/frontend/src/scenes/trends/viz/trends-line-chart/trendsAxisFormat.test.ts+++ b/frontend/src/scenes/trends/viz/trends-line-chart/trendsAxisFormat.test.ts@@ -3,7 +3,7 @@ import { AggregationAxisFormat } from 'scenes/insights/aggregationAxisFormat'import { CurrencyCode, TrendsFilter } from '~/queries/schema/schema-general'-import { trendsFilterToYFormatterConfig } from './trendsAxisFormat'+import { buildTrendsYAxisConfig, trendsFilterToYFormatterConfig } from './trendsAxisFormat'const NBSP = ' '@@ -75,3 +75,35 @@ describe('trends y-tick formatter end-to-end', () => {expect(fmt(50)).toBe('50%')})})++describe('buildTrendsYAxisConfig', () => {+ it.each([+ ['log10', 'log'],+ ['linear', 'linear'],+ ['auto', 'linear'],+ [undefined, 'linear'],+ [null, 'linear'],+ ] as const)('translates yAxisScaleType "%s" to scale "%s"', (input, expected) => {+ expect(buildTrendsYAxisConfig(null, false, undefined, { yAxisScaleType: input }).scale).toBe(expected)+ })++ it('passes showGrid through from extras', () => {+ expect(buildTrendsYAxisConfig(null, false, undefined, { showGrid: true }).showGrid).toBe(true)+ expect(buildTrendsYAxisConfig(null, false, undefined, {}).showGrid).toBeUndefined()+ })++ it('spreads the formatter config from trendsFilterToYFormatterConfig', () => {+ const trendsFilter: TrendsFilter = {+ aggregationAxisFormat: 'duration',+ aggregationAxisPrefix: '~',+ decimalPlaces: 2,+ }+ const cfg = buildTrendsYAxisConfig(trendsFilter, false, 'USD' as CurrencyCode)+ expect(cfg).toMatchObject({ format: 'duration', prefix: '~', decimalPlaces: 2, currency: 'USD' })+ })++ it('forces percentage format when isPercentStackView is true', () => {+ const trendsFilter: TrendsFilter = { aggregationAxisFormat: 'currency', aggregationAxisPrefix: '$' }+ expect(buildTrendsYAxisConfig(trendsFilter, true, 'USD' as CurrencyCode).format).toBe('percentage')+ })+})