-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
[Lens] Add more chart editor tests based on the debug state #86750
Changes from all commits
2197202
beec4a1
7489291
69c5dfc
a1ff774
011d1cb
ea276aa
0d5b6c4
afa3904
a6b13b0
110791b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { DebugState } from '@elastic/charts'; | ||
import expect from '@kbn/expect'; | ||
import { range } from 'lodash'; | ||
import { FtrProviderContext } from '../../ftr_provider_context'; | ||
|
||
export default function ({ getService, getPageObjects }: FtrProviderContext) { | ||
const PageObjects = getPageObjects(['visualize', 'lens', 'common', 'header']); | ||
const elasticChart = getService('elasticChart'); | ||
|
||
describe('lens chart data', () => { | ||
before(async () => { | ||
await PageObjects.visualize.navigateToNewVisualization(); | ||
await PageObjects.visualize.clickVisType('lens'); | ||
await elasticChart.setNewChartUiDebugFlag(true); | ||
await PageObjects.lens.goToTimeRange(); | ||
|
||
await PageObjects.lens.configureDimension({ | ||
dimension: 'lnsXY_xDimensionPanel > lns-empty-dimension', | ||
operation: 'terms', | ||
field: 'ip', | ||
}); | ||
|
||
await PageObjects.lens.configureDimension({ | ||
dimension: 'lnsXY_yDimensionPanel > lns-empty-dimension', | ||
operation: 'avg', | ||
field: 'bytes', | ||
}); | ||
|
||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
}); | ||
|
||
const expectedData = [ | ||
{ x: '0.53.251.53', y: 4624.75 }, | ||
{ x: '0.108.3.2', y: 7359.41 }, | ||
{ x: '0.209.80.244', y: 6169.9 }, | ||
{ x: '0.228.1.71', y: 7092.8 }, | ||
{ x: '0.254.91.215', y: 3835.58 }, | ||
{ x: '__other__', y: 5727.24 }, | ||
]; | ||
|
||
function assertMatchesExpectedData(state: DebugState) { | ||
expect( | ||
state.bars![0].bars.map((bar) => ({ | ||
x: bar.x, | ||
y: Math.round(bar.y * 100) / 100, | ||
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. Could you comment on why this rounding is needed? Or maybe the 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. it's because the data table rounds numbers to two decimal points, but the xy chart does not |
||
})) | ||
).to.eql(expectedData); | ||
} | ||
|
||
it('should render xy chart', async () => { | ||
const data = await PageObjects.lens.getCurrentChartDebugState(); | ||
assertMatchesExpectedData(data!); | ||
}); | ||
|
||
// Partition chart tests have to be skipped until | ||
// https://github.com/elastic/elastic-charts/issues/917 gets fixed | ||
it.skip('should render pie chart', async () => { | ||
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. Please comment on the skipped tests |
||
await PageObjects.lens.switchToVisualization('pie'); | ||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
const data = await PageObjects.lens.getCurrentChartDebugState(); | ||
assertMatchesExpectedData(data!); | ||
}); | ||
|
||
it.skip('should render donut chart', async () => { | ||
await PageObjects.lens.switchToVisualization('donut'); | ||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
const data = await PageObjects.lens.getCurrentChartDebugState(); | ||
assertMatchesExpectedData(data!); | ||
}); | ||
|
||
it.skip('should render treemap chart', async () => { | ||
await PageObjects.lens.switchToVisualization('treemap'); | ||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
const data = await PageObjects.lens.getCurrentChartDebugState(); | ||
assertMatchesExpectedData(data!); | ||
}); | ||
|
||
it('should render datatable', async () => { | ||
await PageObjects.lens.switchToVisualization('lnsDatatable'); | ||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
const terms = await Promise.all( | ||
range(0, 6).map((index) => PageObjects.lens.getDatatableCellText(index, 0)) | ||
); | ||
const values = await Promise.all( | ||
range(0, 6).map((index) => PageObjects.lens.getDatatableCellText(index, 1)) | ||
); | ||
expect(terms.map((term) => (term === 'Other' ? '__other__' : term))).to.eql( | ||
expectedData.map(({ x }) => x) | ||
); | ||
expect(values.map((value) => Math.round(100 * Number(value.replace(',', ''))) / 100)).to.eql( | ||
expectedData.map(({ y }) => y) | ||
); | ||
}); | ||
|
||
it('should render metric', async () => { | ||
await PageObjects.lens.switchToVisualization('lnsMetric'); | ||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
await PageObjects.lens.assertMetric('Average of bytes', '5,727.322'); | ||
}); | ||
}); | ||
} |
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.
Could you load one of the existing pre-saved visualizations that are used by the other charts? Does it need to be the Terms agg?