[TSVB] [AT] time series formatter duration (#38256)

* Add new tests for the duration formatter
This commit is contained in:
Vitali Haradkou 2019-06-13 15:31:26 +03:00 committed by GitHub
parent b2e0527735
commit a15b15aae3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 6 deletions

View file

@ -23,6 +23,7 @@ import { FtrProviderContext } from '../../ftr_provider_context';
export default function({ getPageObjects, getService }: FtrProviderContext) {
const { visualize, visualBuilder } = getPageObjects(['visualBuilder', 'visualize']);
const retry = getService('retry');
const log = getService('log');
describe('visual builder', function describeIndexTests() {
beforeEach(async () => {
@ -105,13 +106,22 @@ export default function({ getPageObjects, getService }: FtrProviderContext) {
expect(actualCount).to.be(expectedLegendValue);
});
it('should show the correct count in the legend with duration formatter', async () => {
const expectedLegendValue = '156.00';
it('should show the correct count in the legend with "Human readable" duration formatter', async () => {
await visualBuilder.clickSeriesOption();
await visualBuilder.changeDataFormatter('Duration');
const actualCount = await visualBuilder.getRhythmChartLegendValue();
expect(actualCount).to.be(expectedLegendValue);
await visualBuilder.setDurationFormatterSettings({ to: 'Human readable' });
const actualCountDefault = await visualBuilder.getRhythmChartLegendValue();
expect(actualCountDefault).to.be('a few seconds');
log.debug(`to: 'Human readable', from: 'Seconds'`);
await visualBuilder.setDurationFormatterSettings({ to: 'Human readable', from: 'Seconds' });
const actualCountSec = await visualBuilder.getRhythmChartLegendValue();
expect(actualCountSec).to.be('3 minutes');
log.debug(`to: 'Human readable', from: 'Minutes'`);
await visualBuilder.setDurationFormatterSettings({ to: 'Human readable', from: 'Minutes' });
const actualCountMin = await visualBuilder.getRhythmChartLegendValue();
expect(actualCountMin).to.be('3 hours');
});
});
});

View file

@ -28,6 +28,19 @@ export function VisualBuilderPageProvider({ getService, getPageObjects }: FtrPro
const comboBox = getService('comboBox');
const PageObjects = getPageObjects(['common', 'header', 'visualize', 'timePicker']);
type Duration =
| 'Milliseconds'
| 'Seconds'
| 'Minutes'
| 'Hours'
| 'Days'
| 'Weeks'
| 'Months'
| 'Years';
type FromDuration = Duration | 'Picoseconds' | 'Nanoseconds' | 'Microseconds';
type ToDuration = Duration | 'Human readable';
class VisualBuilderPage {
public async resetPage(
fromTime = '2015-09-19 06:31:44.000',
@ -225,10 +238,40 @@ export function VisualBuilderPageProvider({ getService, getPageObjects }: FtrPro
public async changeDataFormatter(
formatter: 'Bytes' | 'Number' | 'Percent' | 'Duration' | 'Custom'
) {
const [formatterEl] = await find.allByCssSelector('.euiComboBox');
const formatterEl = await find.byCssSelector('[id$="row"] .euiComboBox');
await comboBox.setElement(formatterEl, formatter);
}
/**
* set duration formatter additional settings
*
* @param from start format
* @param to end format
* @param decimalPlaces decimals count
*/
public async setDurationFormatterSettings({
from,
to,
decimalPlaces,
}: {
from?: FromDuration;
to?: ToDuration;
decimalPlaces?: string;
}) {
if (from) {
const fromCombobox = await find.byCssSelector('[id$="from-row"] .euiComboBox');
await comboBox.setElement(fromCombobox, from);
}
if (to) {
const toCombobox = await find.byCssSelector('[id$="to-row"] .euiComboBox');
await comboBox.setElement(toCombobox, to);
}
if (decimalPlaces) {
const decimalPlacesInput = await find.byCssSelector('[id$="decimal"]');
await decimalPlacesInput.type(decimalPlaces);
}
}
/**
* write template for aggregation row in the `option` tab
*