[Lens] Add more formatters tests (#160241)

## Summary

Adds formatters tests for the number fields.

Closes https://github.com/elastic/kibana/issues/147428

Flaky tests 50 times
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2449
This commit is contained in:
Stratoula Kalafateli 2023-06-22 17:09:57 +03:00 committed by GitHub
parent e19647821e
commit 807062835e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 166 additions and 82 deletions

View file

@ -13,6 +13,7 @@ export class FieldEditorService extends FtrService {
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly retry = this.ctx.getService('retry');
private readonly find = this.ctx.getService('find');
private readonly comboBox = this.ctx.getService('comboBox');
public async setName(name: string, clearFirst = false, typeCharByChar = false) {
await this.testSubjects.setValue('nameField > input', name, {
@ -90,6 +91,10 @@ export class FieldEditorService extends FtrService {
await this.testSubjects.setValue('truncateEditorLength', length);
}
public async setFieldType(type: string) {
await this.comboBox.set('typeField', type);
}
public async setFieldFormat(format: string) {
await this.find.clickByCssSelector(
'select[data-test-subj="editorSelectedFormatId"] > option[value="' + format + '"]'

View file

@ -22,100 +22,179 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const fieldEditor = getService('fieldEditor');
describe('lens fields formatters tests', () => {
before(async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickVisType('lens');
await PageObjects.lens.goToTimeRange();
await PageObjects.lens.switchToVisualization('lnsDatatable');
});
after(async () => {
await PageObjects.lens.clickField('runtimefield');
await PageObjects.lens.removeField('runtimefield');
await fieldEditor.confirmDelete();
await PageObjects.lens.waitForFieldMissing('runtimefield');
});
it('should display url formatter correctly', async () => {
await retry.try(async () => {
await PageObjects.lens.clickAddField();
await fieldEditor.setName('runtimefield');
await fieldEditor.enableValue();
await fieldEditor.typeScript("emit(doc['geo.dest'].value)");
await fieldEditor.setFormat(FIELD_FORMAT_IDS.URL);
await fieldEditor.setUrlFieldFormat('https://www.elastic.co?{{value}}');
await fieldEditor.save();
await fieldEditor.waitUntilClosed();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.lens.searchField('runtime');
await PageObjects.lens.waitForField('runtimefield');
await PageObjects.lens.dragFieldToWorkspace('runtimefield');
describe('keyword formatters', () => {
before(async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickVisType('lens');
await PageObjects.lens.goToTimeRange();
await PageObjects.lens.switchToVisualization('lnsDatatable');
});
await PageObjects.lens.waitForVisualization();
expect(await PageObjects.lens.getDatatableHeaderText(0)).to.equal(
'Top 5 values of runtimefield'
);
expect(await PageObjects.lens.getDatatableCellText(0, 0)).to.eql('https://www.elastic.co?CN');
});
it('should display static lookup formatter correctly', async () => {
await retry.try(async () => {
after(async () => {
await PageObjects.lens.clickField('runtimefield');
await PageObjects.lens.editField('runtimefield');
await fieldEditor.setFormat(FIELD_FORMAT_IDS.STATIC_LOOKUP);
await fieldEditor.setStaticLookupFormat('CN', 'China');
await fieldEditor.save();
await fieldEditor.waitUntilClosed();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.lens.removeField('runtimefield');
await fieldEditor.confirmDelete();
await PageObjects.lens.waitForFieldMissing('runtimefield');
});
it('should display url formatter correctly', async () => {
await retry.try(async () => {
await PageObjects.lens.clickAddField();
await fieldEditor.setName('runtimefield');
await fieldEditor.enableValue();
await fieldEditor.typeScript("emit(doc['geo.dest'].value)");
await fieldEditor.setFormat(FIELD_FORMAT_IDS.URL);
await fieldEditor.setUrlFieldFormat('https://www.elastic.co?{{value}}');
await fieldEditor.save();
await fieldEditor.waitUntilClosed();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.lens.searchField('runtime');
await PageObjects.lens.waitForField('runtimefield');
await PageObjects.lens.dragFieldToWorkspace('runtimefield');
});
await PageObjects.lens.waitForVisualization();
expect(await PageObjects.lens.getDatatableHeaderText(0)).to.equal(
'Top 5 values of runtimefield'
);
expect(await PageObjects.lens.getDatatableCellText(0, 0)).to.eql(
'https://www.elastic.co?CN'
);
});
it('should display static lookup formatter correctly', async () => {
await retry.try(async () => {
await PageObjects.lens.clickField('runtimefield');
await PageObjects.lens.editField('runtimefield');
await fieldEditor.setFormat(FIELD_FORMAT_IDS.STATIC_LOOKUP);
await fieldEditor.setStaticLookupFormat('CN', 'China');
await fieldEditor.save();
await fieldEditor.waitUntilClosed();
await PageObjects.header.waitUntilLoadingHasFinished();
});
await PageObjects.lens.waitForVisualization();
expect(await PageObjects.lens.getDatatableCellText(0, 0)).to.eql('China');
});
it('should display color formatter correctly', async () => {
await retry.try(async () => {
await PageObjects.lens.clickField('runtimefield');
await PageObjects.lens.editField('runtimefield');
await fieldEditor.setFormat(FIELD_FORMAT_IDS.COLOR);
await fieldEditor.setColorFormat('CN', '#ffffff', '#ff0000');
await fieldEditor.save();
await fieldEditor.waitUntilClosed();
await PageObjects.header.waitUntilLoadingHasFinished();
});
await PageObjects.lens.waitForVisualization();
const styleObj = await PageObjects.lens.getDatatableCellSpanStyle(0, 0);
expect(styleObj['background-color']).to.be('rgb(255, 0, 0)');
expect(styleObj.color).to.be('rgb(255, 255, 255)');
});
it('should display string formatter correctly', async () => {
await retry.try(async () => {
await PageObjects.lens.clickField('runtimefield');
await PageObjects.lens.editField('runtimefield');
await fieldEditor.setFormat(FIELD_FORMAT_IDS.STRING);
await fieldEditor.setStringFormat('lower');
await fieldEditor.save();
await fieldEditor.waitUntilClosed();
await PageObjects.header.waitUntilLoadingHasFinished();
});
await PageObjects.lens.waitForVisualization();
expect(await PageObjects.lens.getDatatableCellText(0, 0)).to.eql('cn');
});
it('should display truncate string formatter correctly', async () => {
await retry.try(async () => {
await PageObjects.lens.clickField('runtimefield');
await PageObjects.lens.editField('runtimefield');
await fieldEditor.clearScript();
await fieldEditor.typeScript("emit(doc['links.raw'].value)");
await fieldEditor.setFormat(FIELD_FORMAT_IDS.TRUNCATE);
await fieldEditor.setTruncateFormatLength('3');
await fieldEditor.save();
await fieldEditor.waitUntilClosed();
await PageObjects.header.waitUntilLoadingHasFinished();
});
await PageObjects.lens.waitForVisualization();
expect(await PageObjects.lens.getDatatableCellText(0, 0)).to.eql('dal...');
});
await PageObjects.lens.waitForVisualization();
expect(await PageObjects.lens.getDatatableCellText(0, 0)).to.eql('China');
});
it('should display color formatter correctly', async () => {
await retry.try(async () => {
await PageObjects.lens.clickField('runtimefield');
await PageObjects.lens.editField('runtimefield');
await fieldEditor.setFormat(FIELD_FORMAT_IDS.COLOR);
await fieldEditor.setColorFormat('CN', '#ffffff', '#ff0000');
await fieldEditor.save();
await fieldEditor.waitUntilClosed();
await PageObjects.header.waitUntilLoadingHasFinished();
describe('number formatters', () => {
before(async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickVisType('lens');
await PageObjects.lens.goToTimeRange();
await PageObjects.lens.switchToVisualization('lnsDatatable');
});
await PageObjects.lens.waitForVisualization();
const styleObj = await PageObjects.lens.getDatatableCellSpanStyle(0, 0);
expect(styleObj['background-color']).to.be('rgb(255, 0, 0)');
expect(styleObj.color).to.be('rgb(255, 255, 255)');
});
it('should display string formatter correctly', async () => {
await retry.try(async () => {
after(async () => {
await PageObjects.lens.clickField('runtimefield');
await PageObjects.lens.editField('runtimefield');
await fieldEditor.setFormat(FIELD_FORMAT_IDS.STRING);
await fieldEditor.setStringFormat('lower');
await fieldEditor.save();
await fieldEditor.waitUntilClosed();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.lens.removeField('runtimefield');
await fieldEditor.confirmDelete();
await PageObjects.lens.waitForFieldMissing('runtimefield');
});
it('should display bytes number formatter correctly', async () => {
await retry.try(async () => {
await PageObjects.lens.clickAddField();
await fieldEditor.setName('runtimefield');
await fieldEditor.setFieldType('long');
await fieldEditor.enableValue();
await fieldEditor.typeScript("emit(doc['bytes'].value)");
await fieldEditor.setFormat(FIELD_FORMAT_IDS.BYTES);
await fieldEditor.save();
await fieldEditor.waitUntilClosed();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.lens.configureDimension({
dimension: 'lnsDatatable_metrics > lns-empty-dimension',
operation: 'average',
field: 'runtimefield',
});
});
await PageObjects.lens.waitForVisualization();
expect(await PageObjects.lens.getDatatableCellText(0, 0)).to.eql('5.6KB');
});
await PageObjects.lens.waitForVisualization();
expect(await PageObjects.lens.getDatatableCellText(0, 0)).to.eql('cn');
});
it('should display truncate string formatter correctly', async () => {
await retry.try(async () => {
await PageObjects.lens.clickField('runtimefield');
await PageObjects.lens.editField('runtimefield');
await fieldEditor.clearScript();
await fieldEditor.typeScript("emit(doc['links.raw'].value)");
await fieldEditor.setFormat(FIELD_FORMAT_IDS.TRUNCATE);
await fieldEditor.setTruncateFormatLength('3');
await fieldEditor.save();
await fieldEditor.waitUntilClosed();
await PageObjects.header.waitUntilLoadingHasFinished();
it('should display currency number formatter correctly', async () => {
await retry.try(async () => {
await PageObjects.lens.clickField('runtimefield');
await PageObjects.lens.editField('runtimefield');
await fieldEditor.setFormat(FIELD_FORMAT_IDS.CURRENCY);
await fieldEditor.save();
await fieldEditor.waitUntilClosed();
await PageObjects.header.waitUntilLoadingHasFinished();
});
await PageObjects.lens.waitForVisualization();
expect(await PageObjects.lens.getDatatableCellText(0, 0)).to.eql('$5,727.32');
});
it('should display duration number formatter correctly', async () => {
await retry.try(async () => {
await PageObjects.lens.clickField('runtimefield');
await PageObjects.lens.editField('runtimefield');
await fieldEditor.setFormat(FIELD_FORMAT_IDS.DURATION);
await fieldEditor.save();
await fieldEditor.waitUntilClosed();
await PageObjects.header.waitUntilLoadingHasFinished();
});
await PageObjects.lens.waitForVisualization();
expect(await PageObjects.lens.getDatatableCellText(0, 0)).to.eql('2 hours');
});
it('should display percentage number formatter correctly', async () => {
await retry.try(async () => {
await PageObjects.lens.clickField('runtimefield');
await PageObjects.lens.editField('runtimefield');
await fieldEditor.setFormat(FIELD_FORMAT_IDS.PERCENT);
await fieldEditor.save();
await fieldEditor.waitUntilClosed();
await PageObjects.header.waitUntilLoadingHasFinished();
});
await PageObjects.lens.waitForVisualization();
expect(await PageObjects.lens.getDatatableCellText(0, 0)).to.eql('572,732.21%');
});
await PageObjects.lens.waitForVisualization();
expect(await PageObjects.lens.getDatatableCellText(0, 0)).to.eql('dal...');
});
});
}