Skip to content

Commit 0980919

Browse files
authored
[Lens][TSVB] Functional tests for converting of Metric. (#143164)
* Added test for metric with params. * Added test for invalid model. * Added test for unsupported aggregation. * Added test for sibling pipeline agg. * Added parent pipeline agg tests. * Added functional tests for static value. * Added tests for converting metric with params, unsupported metrics and not valid panels. * Added tests for color ranges.
1 parent 17668d7 commit 0980919

3 files changed

Lines changed: 126 additions & 1 deletion

File tree

test/functional/page_objects/visual_builder_page.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,18 @@ export class VisualBuilderPageObject extends FtrService {
417417
});
418418
}
419419

420+
public async createColorRule(nth = 0) {
421+
await this.clickPanelOptions('metric');
422+
423+
const elements = await this.testSubjects.findAll('AddAddBtn');
424+
await elements[nth].click();
425+
await this.visChart.waitForVisualizationRenderingStabilized();
426+
await this.retry.waitFor('new color rule is added', async () => {
427+
const currentAddButtons = await this.testSubjects.findAll('AddAddBtn');
428+
return currentAddButtons.length > elements.length;
429+
});
430+
}
431+
420432
public async selectAggType(value: string, nth = 0) {
421433
const elements = await this.testSubjects.findAll('aggSelector');
422434
await this.comboBox.setElement(elements[nth], value);

x-pack/test/functional/apps/lens/group3/open_in_lens/tsvb/metric.ts

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ import expect from '@kbn/expect';
99
import { FtrProviderContext } from '../../../../../ftr_provider_context';
1010

1111
export default function ({ getPageObjects, getService }: FtrProviderContext) {
12-
const { visualize, visualBuilder, lens } = getPageObjects(['visualBuilder', 'visualize', 'lens']);
12+
const { visualize, visualBuilder, lens, header } = getPageObjects([
13+
'visualBuilder',
14+
'visualize',
15+
'lens',
16+
'header',
17+
]);
1318

1419
const testSubjects = getService('testSubjects');
20+
const retry = getService('retry');
21+
const find = getService('find');
1522

1623
describe('Metric', function describeIndexTests() {
1724
before(async () => {
@@ -40,5 +47,95 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
4047
const metricData = await lens.getMetricVisualizationData();
4148
expect(metricData[0].title).to.eql('Count of records');
4249
});
50+
51+
it('should draw static value', async () => {
52+
await visualBuilder.selectAggType('Static Value');
53+
await visualBuilder.setStaticValue(10);
54+
55+
await header.waitUntilLoadingHasFinished();
56+
57+
const button = await testSubjects.find('visualizeEditInLensButton');
58+
await button.click();
59+
await lens.waitForVisualization('mtrVis');
60+
await retry.try(async () => {
61+
const layers = await find.allByCssSelector(`[data-test-subj^="lns-layerPanel-"]`);
62+
expect(layers).to.have.length(1);
63+
64+
const dimensions = await testSubjects.findAll('lns-dimensionTrigger');
65+
expect(dimensions).to.have.length(1);
66+
expect(await dimensions[0].getVisibleText()).to.be('10');
67+
});
68+
});
69+
70+
it('should convert metric with params', async () => {
71+
await visualBuilder.selectAggType('Value Count');
72+
await visualBuilder.setFieldForAggregation('bytes');
73+
74+
await header.waitUntilLoadingHasFinished();
75+
76+
const button = await testSubjects.find('visualizeEditInLensButton');
77+
await button.click();
78+
await lens.waitForVisualization('mtrVis');
79+
await retry.try(async () => {
80+
const layers = await find.allByCssSelector(`[data-test-subj^="lns-layerPanel-"]`);
81+
expect(layers).to.have.length(1);
82+
83+
const dimensions = await testSubjects.findAll('lns-dimensionTrigger');
84+
expect(dimensions).to.have.length(1);
85+
expect(await dimensions[0].getVisibleText()).to.be('Count of bytes');
86+
});
87+
});
88+
89+
it('should not allow converting of unsupported metric', async () => {
90+
await visualBuilder.selectAggType('Counter Rate');
91+
await visualBuilder.setFieldForAggregation('machine.ram');
92+
93+
await header.waitUntilLoadingHasFinished();
94+
95+
const canEdit = await testSubjects.exists('visualizeEditInLensButton');
96+
expect(canEdit).to.be(false);
97+
});
98+
99+
it('should not allow converting of not valid panel', async () => {
100+
await visualBuilder.selectAggType('Value Count');
101+
await header.waitUntilLoadingHasFinished();
102+
const canEdit = await testSubjects.exists('visualizeEditInLensButton');
103+
expect(canEdit).to.be(false);
104+
});
105+
106+
it('should convert color ranges', async () => {
107+
await visualBuilder.clickPanelOptions('metric');
108+
await visualBuilder.setColorRuleOperator('>= greater than or equal');
109+
await visualBuilder.setColorRuleValue(10);
110+
await visualBuilder.setColorPickerValue('#54B399');
111+
112+
await header.waitUntilLoadingHasFinished();
113+
const button = await testSubjects.find('visualizeEditInLensButton');
114+
await button.click();
115+
116+
await lens.waitForVisualization('mtrVis');
117+
await retry.try(async () => {
118+
const closePalettePanels = await testSubjects.findAll(
119+
'lns-indexPattern-PalettePanelContainerBack'
120+
);
121+
if (closePalettePanels.length) {
122+
await lens.closePalettePanel();
123+
await lens.closeDimensionEditor();
124+
}
125+
126+
const dimensions = await testSubjects.findAll('lns-dimensionTrigger');
127+
expect(dimensions).to.have.length(1);
128+
129+
dimensions[0].click();
130+
131+
await lens.openPalettePanel('lnsMetric');
132+
const colorStops = await lens.getPaletteColorStops();
133+
134+
expect(colorStops).to.eql([
135+
{ stop: '10', color: 'rgba(84, 179, 153, 1)' },
136+
{ stop: '', color: undefined },
137+
]);
138+
});
139+
});
43140
});
44141
}

x-pack/test/functional/page_objects/lens_page.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,5 +1586,21 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont
15861586
throw new Error(`Warning with text "${warningText}" not found`);
15871587
}
15881588
},
1589+
1590+
async getPaletteColorStops() {
1591+
const stops = await find.allByCssSelector(
1592+
`[data-test-subj^="lnsPalettePanel_dynamicColoring_range_value_"]`
1593+
);
1594+
const colorsElements = await testSubjects.findAll('euiColorPickerAnchor');
1595+
const colors = await Promise.all(
1596+
colorsElements.map((c) => c.getComputedStyle('background-color'))
1597+
);
1598+
1599+
return await Promise.all(
1600+
stops.map(async (stop, index) => {
1601+
return { stop: await stop.getAttribute('value'), color: colors[index] };
1602+
})
1603+
);
1604+
},
15891605
});
15901606
}

0 commit comments

Comments
 (0)