-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[9.4] [Lens as code] Fix metric trendline (#264777) #264888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { spaceTest, tags } from '@kbn/scout'; | ||
| import { expect } from '@kbn/scout/ui'; | ||
| import type { KbnClient } from '@kbn/scout'; | ||
| import { testData } from '../fixtures'; | ||
|
|
||
| const DASHBOARD_API_PATH = '/api/dashboards'; | ||
| const DASHBOARD_API_VERSION = '2023-10-31'; | ||
|
|
||
| const LOGSTASH_TIME_RANGE = { | ||
| from: '2015-09-19T06:31:44.000Z', | ||
| to: '2015-09-23T18:31:44.000Z', | ||
| }; | ||
|
|
||
| function withSpace(path: string, spaceId: string): string { | ||
| return `/s/${spaceId}${path}`; | ||
| } | ||
|
|
||
| async function createDashboard(client: KbnClient, body: unknown, spaceId: string): Promise<string> { | ||
| const response = await client.request<unknown>({ | ||
| method: 'POST', | ||
| path: withSpace(DASHBOARD_API_PATH, spaceId), | ||
| body, | ||
| headers: { 'elastic-api-version': DASHBOARD_API_VERSION }, | ||
| }); | ||
|
|
||
| if (response.status !== 201) { | ||
| throw new Error( | ||
| `Expected dashboard create status 201, got ${response.status}: ${JSON.stringify( | ||
| response.data | ||
| )}` | ||
| ); | ||
| } | ||
|
|
||
| const { id } = response.data as Record<string, unknown>; | ||
| if (typeof id !== 'string' || id.length === 0) { | ||
| throw new Error('Dashboard create response: expected a non-empty string id'); | ||
| } | ||
| return id; | ||
| } | ||
|
|
||
| spaceTest.describe( | ||
| 'Lens metric trendline on dashboard (DSL)', | ||
| { tag: tags.stateful.classic }, | ||
| () => { | ||
| let storedDataViewId: string | undefined; | ||
|
|
||
| spaceTest.beforeAll(async ({ scoutSpace, apiServices }) => { | ||
| await scoutSpace.uiSettings.set({ | ||
| defaultIndex: testData.DATA_VIEW_ID.LOGSTASH, | ||
| 'dateFormat:tz': 'UTC', | ||
| 'timepicker:timeDefaults': JSON.stringify({ | ||
| from: testData.LOGSTASH_IN_RANGE_DATES.from, | ||
| to: testData.LOGSTASH_IN_RANGE_DATES.to, | ||
| }), | ||
| }); | ||
|
|
||
| const { data: dataView } = await apiServices.dataViews.create({ | ||
| title: testData.DATA_VIEW_ID.LOGSTASH, | ||
| name: `scout-metric-trendline-dv-${Date.now()}`, | ||
| timeFieldName: '@timestamp', | ||
| spaceId: scoutSpace.id, | ||
| }); | ||
| storedDataViewId = dataView.id; | ||
| }); | ||
|
|
||
| spaceTest.afterAll(async ({ scoutSpace, apiServices }) => { | ||
| if (storedDataViewId) { | ||
| await apiServices.dataViews.delete(storedDataViewId, scoutSpace.id); | ||
| } | ||
| await scoutSpace.uiSettings.unset('defaultIndex', 'dateFormat:tz', 'timepicker:timeDefaults'); | ||
| await scoutSpace.savedObjects.cleanStandardList(); | ||
| }); | ||
|
|
||
| spaceTest( | ||
| 'renders trendline when panel uses inline data view spec', | ||
| async ({ browserAuth, kbnClient, page, pageObjects, scoutSpace }) => { | ||
| const body = { | ||
| title: 'Metric trendline spec', | ||
| time_range: LOGSTASH_TIME_RANGE, | ||
| panels: [ | ||
| { | ||
| type: 'vis', | ||
| grid: { x: 0, y: 0, w: 12, h: 8 }, | ||
| config: { | ||
| type: 'metric', | ||
| title: 'Average bytes with trend', | ||
| data_source: { | ||
| type: 'data_view_spec', | ||
| index_pattern: testData.DATA_VIEW_ID.LOGSTASH, | ||
| time_field: '@timestamp', | ||
| }, | ||
| metrics: [ | ||
| { | ||
| type: 'primary', | ||
| operation: 'average', | ||
| field: 'bytes', | ||
| background_chart: { type: 'trend' }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const dashboardId = await createDashboard(kbnClient, body, scoutSpace.id); | ||
| await browserAuth.loginAsPrivilegedUser(); | ||
| await pageObjects.dashboard.openDashboardWithId(dashboardId); | ||
|
|
||
| await expect(page.getByTestId('mtrVis')).toBeVisible(); | ||
| await expect(page.locator('.echSingleMetricSparkline')).toBeVisible(); | ||
|
Comment on lines
+116
to
+117
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
See detailsThe existing FTR page object ( Consider scoping the CSS selector under the const metricVis = page.getByTestId('mtrVis');
await expect(metricVis).toBeVisible();
await expect(metricVis.locator('.echSingleMetricSparkline')).toBeVisible();Longer-term, a Posted via Macroscope — Scout Test Review |
||
| } | ||
| ); | ||
|
|
||
| spaceTest( | ||
| 'renders trendline when panel uses stored data view reference', | ||
| async ({ browserAuth, kbnClient, page, pageObjects, scoutSpace }) => { | ||
| spaceTest.fail(!storedDataViewId, 'Stored data view was not created in beforeAll'); | ||
|
|
||
| const body = { | ||
| title: 'Metric trendline ref', | ||
| time_range: LOGSTASH_TIME_RANGE, | ||
| panels: [ | ||
| { | ||
| type: 'vis', | ||
| grid: { x: 0, y: 0, w: 12, h: 8 }, | ||
| config: { | ||
| type: 'metric', | ||
| title: 'Average bytes with trend', | ||
| data_source: { | ||
| type: 'data_view_reference', | ||
| ref_id: storedDataViewId!, | ||
| }, | ||
| metrics: [ | ||
| { | ||
| type: 'primary', | ||
| operation: 'average', | ||
| field: 'bytes', | ||
| background_chart: { type: 'trend' }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const dashboardId = await createDashboard(kbnClient, body, scoutSpace.id); | ||
| await browserAuth.loginAsPrivilegedUser(); | ||
| await pageObjects.dashboard.openDashboardWithId(dashboardId); | ||
|
|
||
| await expect(page.getByTestId('mtrVis')).toBeVisible(); | ||
| await expect(page.locator('.echSingleMetricSparkline')).toBeVisible(); | ||
| } | ||
| ); | ||
| } | ||
| ); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
createDashboardhelper duplicates the dashboard-creation pattern already inesql_timeseries_dashboard_api.spec.ts(createDashboardWithLensPanel). Both hit the same API with the same version header.See details
Consider extracting a shared
createDashboard(client, body, spaceId)into the existingfixtures/helpers.tsso both spec files (and future ones) reuse the same helper. This keeps the API path, version header, and status assertion in one place.Then both spec files import
createDashboardfrom'../fixtures'.Posted via Macroscope — Scout Test Review