Skip to content

Commit 240cc1e

Browse files
committed
Adds chart switcher test
Signed-off-by: Ashwin Pc <ashwinpc@amazon.com>
1 parent 3769a3a commit 240cc1e

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

src/plugins/wizard/public/application/components/right_nav.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const RightNav = () => {
3232
value: name,
3333
inputDisplay: <OptionItem icon={icon} title={title} />,
3434
dropdownDisplay: <OptionItem icon={icon} title={title} />,
35+
'data-test-subj': `visType-${name}`,
3536
}));
3637

3738
return (
@@ -44,6 +45,7 @@ export const RightNav = () => {
4445
setNewVisType(name);
4546
}}
4647
fullWidth
48+
data-test-subj="chartPicker"
4749
/>
4850
</div>
4951
<div className="wizSidenav__style">
@@ -72,6 +74,7 @@ export const RightNav = () => {
7274
setNewVisType(undefined);
7375
}}
7476
maxWidth="300px"
77+
data-test-subj="confirmVisChangeModal"
7578
>
7679
<p>
7780
<FormattedMessage

test/functional/apps/wizard/_base.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { FtrProviderContext } from '../../ftr_provider_context';
88

99
export default function ({ getService, getPageObjects }: FtrProviderContext) {
1010
const PageObjects = getPageObjects(['visualize', 'wizard', 'visChart']);
11+
const testSubjects = getService('testSubjects');
1112
const log = getService('log');
1213
const retry = getService('retry');
1314

@@ -27,21 +28,33 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
2728
});
2829

2930
it('should show visualization when a field is added', async () => {
30-
await PageObjects.wizard.addField('metric', 'Average', 'machine.ram');
31+
const expectedData = [2858, 2904, 2814, 1322, 2784];
32+
await PageObjects.wizard.addField('metric', 'Count');
33+
await PageObjects.wizard.addField('segment', 'Terms', 'machine.os.raw');
3134

32-
await retry.try(async () => {
33-
const data = await PageObjects.visChart.getBarChartData('Average machine.ram');
34-
expect(data).to.eql([13104038093]);
35-
});
35+
const data = await PageObjects.visChart.getBarChartData();
36+
expect(data).to.eql(expectedData);
3637
});
3738

3839
it('should clear visualization when field is deleted', async () => {
3940
await PageObjects.wizard.removeField('metric', 0);
4041

41-
await retry.try(async function tryingForTime() {
42-
const isEmptyWorkspace = await PageObjects.wizard.isEmptyWorkspace();
43-
expect(isEmptyWorkspace).to.be(true);
44-
});
42+
const isEmptyWorkspace = await PageObjects.wizard.isEmptyWorkspace();
43+
expect(isEmptyWorkspace).to.be(true);
44+
});
45+
46+
it('should show warning before changing visualization type', async () => {
47+
await PageObjects.wizard.selectVisType('metric', false);
48+
const confirmModalExists = await testSubjects.exists('confirmVisChangeModal');
49+
expect(confirmModalExists).to.be(true);
50+
51+
await testSubjects.click('confirmModalCancelButton');
52+
});
53+
54+
it('should change visualization type', async () => {
55+
const pickerValue = await PageObjects.wizard.selectVisType('metric');
56+
57+
expect(pickerValue).to.eql('Metric');
4558
});
4659
});
4760
}

test/functional/page_objects/wizard_page.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,35 @@ export function WizardPageProvider({ getService, getPageObjects }: FtrProviderCo
5050
return await dataSourceDropdown.getVisibleText();
5151
}
5252

53+
public async selectVisType(type: string, confirm = true) {
54+
const chartPicker = await testSubjects.find('chartPicker');
55+
await chartPicker.click();
56+
await testSubjects.click(`visType-${type}`);
57+
58+
if (confirm) {
59+
await testSubjects.click('confirmModalConfirmButton');
60+
}
61+
62+
return chartPicker.getVisibleText();
63+
}
64+
5365
public async addField(
5466
dropBoxId: string,
5567
aggValue: string,
56-
fieldValue: string,
68+
fieldValue?: string,
5769
returnToMainPanel = true
5870
) {
5971
await testSubjects.click(`dropBoxAddField-${dropBoxId} > dropBoxAddBtn`);
6072
await common.sleep(500);
6173
const aggComboBoxElement = await testSubjects.find('defaultEditorAggSelect');
6274
await comboBox.setElement(aggComboBoxElement, aggValue);
6375
await common.sleep(500);
64-
const fieldComboBoxElement = await testSubjects.find('visDefaultEditorField');
65-
await comboBox.setElement(fieldComboBoxElement, fieldValue);
66-
await common.sleep(500);
76+
77+
if (fieldValue) {
78+
const fieldComboBoxElement = await testSubjects.find('visDefaultEditorField');
79+
await comboBox.setElement(fieldComboBoxElement, fieldValue);
80+
await common.sleep(500);
81+
}
6782

6883
if (returnToMainPanel) {
6984
await testSubjects.click('panelCloseBtn');

0 commit comments

Comments
 (0)