kibana/test/functional/apps/visualize/_tsvb_markdown.ts
Diana Derevyankina 33cfc4183a
[TSVB] Support custom field format (#101245)
* [TSVB] Support custom field format

Add format_label response processor for series vis data and bucket key formatting to process_bucket for table vis data

* Add ignore_field_formatting for series to support value formatting for all panel types except markdown

* Fix type issue for visData and rename getCustomFieldFormatter to createCustomFieldFormatter

* Update vis.test to cover custom field formats logic and add a migration script to set ignore_field_formatting to true for the series

* Move createCustomFieldFormatter to a separate file, make formatting respect only active metrics field name, refactor vis files and fix label formatting only for grouped by terms series

* Remove services, add getFieldFormatsService  to use it in format_label and get_table_data, replace getCustomFieldFormatter with createCustomFieldFormatter

* Update plugin.ts

* Update start for plugin.ts

* Add formatting for annotations and markdown values

* Refactor some code

* Update some naming and conditions

* Fix formatting of data type labels

* In process_bucket fix case for no getFieldFormatByName

* Add field formatting functional tests for all panel types

* Update tests to make them run correctly for firefox

* Update _tsvb_markdown test setup

* Move series ignoreFieldFormatting check to a separate file, change convertSeriesToVars signature, update migration script and refactor a bit functional tests

* Fix type check for timeseries_visualization.tsx

* Update migrations.js test expected version to 7.15

* Fix tests in _tsvb_chart.ts

* Fix merge conflict remove process_bucket.js

* Update process_bucket.test.ts

* Fix markdown labels formatting

* Add ignore_field_formatting for annotations, enhanced migration script to set that flag to true, refactor data_format_picker

* Fix migration script and add disabling for ignore component when string index pattern is used

* Add supporting URL and color formatters in tsvb table

* Fix eslint

* Remove ignore formatting component, add field formatting option to TSVB data format picker and make it default, remove migration script, update tests and refactor some files

* Fix failing tests, refactor create_field_formatter and add test to it, update some other files

* Fix series formatting for top hit when it has not numeric result

* Handle no fieldFormatMap case for table/vis.js

* Remove "Default" option form DataFormatPicker when index pattern is string, fix markdown variables issue and refactor some code

* Chore(TSVB): Replace aggregations lookup with map

* Fix types, update test expected data and remove unused translations

* Fix i18 check and useEffect in agg.tsx

* Handle aggregations field formatting case

* Fix agg_utils, vis and check_if_numeric_metric tests

* Correct typo and refactor condition in std_metric

* Fix type check

* Get rid of IFieldType

* Add URL and color formatting for topN and metric tabs, fix setting initial custom formatter and switching formatter in agg.tsx

* Update tsvb.asciidoc

* Remove link icon from Date format field help text, update click logic for top N in case of custom field format and fix CI

* Remove unused import

* Revert top N bar extra logic for click

* Refactor some code in agg.tsx

* Add URL and color formatting to Gauge

* Fix bug with terms formatting, refactor some code, update create_field_formatter

* Add comments to _gauge.scss

* Remove unnecessary await

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Uladzislau Lasitsa <Uladzislau_Lasitsa@epam.com>
2021-09-13 11:51:32 +03:00

177 lines
6.8 KiB
TypeScript

/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ getPageObjects, getService }: FtrProviderContext) {
const { visualBuilder, timePicker, visualize, visChart } = getPageObjects([
'visualBuilder',
'timePicker',
'visualize',
'visChart',
]);
const retry = getService('retry');
async function cleanupMarkdownData(variableName: 'variable' | 'label', checkedValue: string) {
await visualBuilder.markdownSwitchSubTab('data');
await visualBuilder.setMarkdownDataVariable('', variableName);
await visualBuilder.markdownSwitchSubTab('markdown');
const rerenderedTable = await visualBuilder.getMarkdownTableVariables();
rerenderedTable.forEach((row) => {
if (variableName === 'label') {
expect(row.key).to.include.string(checkedValue);
} else {
expect(row.key).to.not.include.string(checkedValue);
}
});
}
describe('visual builder', function describeIndexTests() {
describe('markdown', () => {
before(async () => {
await visualize.initTests();
await visualBuilder.resetPage();
await visualBuilder.clickMarkdown();
await timePicker.setAbsoluteRange(
'Sep 22, 2015 @ 06:00:00.000',
'Sep 22, 2015 @ 11:00:00.000'
);
await visualBuilder.markdownSwitchSubTab('options');
await visualBuilder.setMetricsDataTimerangeMode('Last value');
await visualBuilder.setDropLastBucket(true);
await visualBuilder.markdownSwitchSubTab('markdown');
});
it('should render subtabs and table variables markdown components', async () => {
const tabs = await visualBuilder.getSubTabs();
expect(tabs).to.have.length(3);
const variables = await visualBuilder.getMarkdownTableVariables();
expect(variables).not.to.be.empty();
expect(variables).to.have.length(5);
});
it('should allow printing raw timestamp of data', async () => {
await visualBuilder.enterMarkdown('{{ count.data.raw.[0].[0] }}');
const text = await visualBuilder.getMarkdownText();
expect(text).to.be('1442901600000');
});
it('should allow printing raw value of data', async () => {
await visualBuilder.enterMarkdown('{{ count.data.raw.[0].[1] }}');
const text = await visualBuilder.getMarkdownText();
expect(text).to.be('6');
});
it('should render html as plain text', async () => {
const html = '<h1>hello world</h1>';
await visualBuilder.enterMarkdown(html);
const markdownText = await visualBuilder.getMarkdownText();
expect(markdownText).to.be(html);
});
it('markdown variables should be clickable', async () => {
await visualBuilder.clearMarkdown();
const [firstVariable] = await visualBuilder.getMarkdownTableVariables();
await firstVariable.selector.click();
await visChart.waitForVisualizationRenderingStabilized();
const markdownText = await visualBuilder.getMarkdownText();
expect(markdownText).to.be('46');
});
it('should render mustache list', async () => {
const list = '{{#each _all}}\n{{ data.formatted.[0] }} {{ data.raw.[0] }}\n{{/each}}';
const expectedRenderer = 'Sep 22, 2015 @ 06:00:00.000,6 1442901600000,6';
await visualBuilder.enterMarkdown(list);
const markdownText = await visualBuilder.getMarkdownText();
expect(markdownText).to.be(expectedRenderer);
});
it('should render markdown table', async () => {
const TABLE =
'| raw | formatted |\n|-|-|\n| {{count.last.raw}} | {{count.last.formatted}} |';
const DATA = '46';
await visualBuilder.enterMarkdown(TABLE);
const text = await visualBuilder.getMarkdownText();
const tableValues = text.split('\n').map((row) => row.split(' '))[1]; // [46, 46]
tableValues.forEach((value) => {
expect(value).to.be.equal(DATA);
});
});
it('should change variable name', async () => {
const VARIABLE = 'variable';
await visualBuilder.markdownSwitchSubTab('data');
await visualBuilder.setMarkdownDataVariable(VARIABLE, VARIABLE);
await visualBuilder.markdownSwitchSubTab('markdown');
const table = await visualBuilder.getMarkdownTableVariables();
table.forEach((row, index) => {
// exception: last index for variable is always: {{count.label}}
if (index === table.length - 1) {
expect(row.key).to.not.include.string(VARIABLE);
} else {
expect(row.key).to.include.string(VARIABLE);
}
});
await cleanupMarkdownData(VARIABLE, VARIABLE);
});
it('series count should be 2 after cloning', async () => {
await visualBuilder.markdownSwitchSubTab('data');
await visualBuilder.cloneSeries();
await retry.try(async function seriesCountCheck() {
const seriesLength = (await visualBuilder.getSeries()).length;
expect(seriesLength).to.be.equal(2);
});
});
it('aggregation count should be 2 after cloning', async () => {
await visualBuilder.markdownSwitchSubTab('data');
await visualBuilder.createNewAgg();
await retry.try(async function aggregationCountCheck() {
const aggregationLength = await visualBuilder.getAggregationCount();
expect(aggregationLength).to.be.equal(2);
});
});
describe('applying field formats from Advanced Settings for values', () => {
before(async () => {
await visualBuilder.resetPage();
await visualBuilder.clickMarkdown();
await visualBuilder.markdownSwitchSubTab('markdown');
await visualBuilder.enterMarkdown('{{ average_of_bytes.last.formatted }}');
await visualBuilder.markdownSwitchSubTab('data');
await visualBuilder.selectAggType('Average');
await visualBuilder.setFieldForAggregation('bytes');
await visualBuilder.clickSeriesOption();
});
it('should apply field formatting by default', async () => {
const text = await visualBuilder.getMarkdownText();
expect(text).to.be('5.588KB');
});
it('should apply TSVB formatting', async () => {
await visualBuilder.changeDataFormatter('percent');
const text = await visualBuilder.getMarkdownText();
expect(text).to.be('572,241.265%');
});
});
});
});
}