Skip to content

Commit

Permalink
Add visualize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
poffdeluxe committed Mar 15, 2021
1 parent d0fc0e2 commit 4ffb9ee
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ export function SaveModalDashboardSelector(props: SaveModalDashboardSelectorProp
</EuiPanel>
<EuiSpacer size="s" />
<EuiFlexGroup alignItems="center" gutterSize="s" responsive={false}>
<EuiFlexItem grow={false}>
<EuiFlexItem grow={false} data-test-subj="add-to-library-checkbox">
<EuiCheckbox
data-test-subj="add-to-library-checkbox"
id="add-to-library-option"
label={i18n.translate('presentationUtil.saveModalDashboard.libraryOptionLabel', {
defaultMessage: 'Add to library',
Expand Down
176 changes: 171 additions & 5 deletions test/functional/apps/visualize/_add_to_dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
]);

describe('Add to Dashboard', function describeIndexTests() {
it('adding a new metric to a new dashboard', async function () {
it('adding a new metric to a new dashboard by value', async function () {
await PageObjects.visualize.navigateToNewAggBasedVisualization();
await PageObjects.visualize.clickMetric();
await PageObjects.visualize.clickNewSearch();
Expand All @@ -36,17 +36,47 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

await PageObjects.timeToVisualize.saveFromModal('My New Vis 1', {
addToDashboard: 'new',
saveToLibrary: false,
});

await PageObjects.dashboard.waitForRenderComplete();
await dashboardExpect.metricValuesExist(['14,004']);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.eql(1);

const isLinked = await PageObjects.timeToVisualize.libraryNotificationExists('My New Vis 1');
expect(isLinked).to.be(false);

await PageObjects.timeToVisualize.resetNewDashboard();
});

it('adding a new metric to a new dashboard by reference', async function () {
await PageObjects.visualize.navigateToNewAggBasedVisualization();
await PageObjects.visualize.clickMetric();
await PageObjects.visualize.clickNewSearch();
await PageObjects.timePicker.setDefaultAbsoluteRange();

await testSubjects.click('visualizeSaveButton');

await PageObjects.timeToVisualize.saveFromModal('My Saved New Vis 1', {
addToDashboard: 'new',
saveToLibrary: true,
});

await PageObjects.dashboard.waitForRenderComplete();
await dashboardExpect.metricValuesExist(['14,004']);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.eql(1);

const isLinked = await PageObjects.timeToVisualize.libraryNotificationExists(
'My Saved New Vis 1'
);
expect(isLinked).to.be(true);

await PageObjects.timeToVisualize.resetNewDashboard();
});

it('adding a existing metric to a new dashboard', async function () {
it('adding a existing metric to a new dashboard by value', async function () {
await PageObjects.visualize.navigateToNewAggBasedVisualization();
await PageObjects.visualize.clickMetric();
await PageObjects.visualize.clickNewSearch();
Expand All @@ -57,6 +87,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
// Save this new viz to library
await PageObjects.timeToVisualize.saveFromModal('My New Vis 1', {
addToDashboard: null,
saveToLibrary: true,
});

await testSubjects.click('visualizeSaveButton');
Expand All @@ -68,17 +99,93 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.timeToVisualize.saveFromModal('My New Vis 1 Copy', {
addToDashboard: 'new',
saveAsNew: true,
saveToLibrary: false,
});

await PageObjects.dashboard.waitForRenderComplete();
await dashboardExpect.metricValuesExist(['14,004']);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.eql(1);

const isLinked = await PageObjects.timeToVisualize.libraryNotificationExists(
'My New Vis 1 Copy'
);
expect(isLinked).to.be(false);

await PageObjects.timeToVisualize.resetNewDashboard();
});

it('adding a existing metric to a new dashboard by reference', async function () {
await PageObjects.visualize.navigateToNewAggBasedVisualization();
await PageObjects.visualize.clickMetric();
await PageObjects.visualize.clickNewSearch();
await PageObjects.timePicker.setDefaultAbsoluteRange();

await testSubjects.click('visualizeSaveButton');

// Save this new viz to library
await PageObjects.timeToVisualize.saveFromModal('Another New Vis 1', {
addToDashboard: null,
saveToLibrary: true,
});

await testSubjects.click('visualizeSaveButton');

// All the options should be disabled
await PageObjects.timeToVisualize.ensureDashboardOptionsAreDisabled();

// Save a new copy of this viz to a new dashboard
await PageObjects.timeToVisualize.saveFromModal('Another New Vis 1 Copy', {
addToDashboard: 'new',
saveAsNew: true,
saveToLibrary: true,
});

await PageObjects.dashboard.waitForRenderComplete();
await dashboardExpect.metricValuesExist(['14,004']);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.eql(1);

const isLinked = await PageObjects.timeToVisualize.libraryNotificationExists(
'Another New Vis 1 Copy'
);
expect(isLinked).to.be(true);

await PageObjects.timeToVisualize.resetNewDashboard();
});

it('adding a new metric to an existing dashboard', async function () {
it('adding a new metric to an existing dashboard by value', async function () {
await PageObjects.common.navigateToApp('dashboard');

await PageObjects.dashboard.clickNewDashboard();
await PageObjects.dashboard.addVisualizations(['Visualization AreaChart']);
await PageObjects.dashboard.saveDashboard('My Excellent Dashboard');
await PageObjects.dashboard.gotoDashboardLandingPage();
await listingTable.searchAndExpectItemsCount('dashboard', 'My Excellent Dashboard', 1);

await PageObjects.visualize.navigateToNewAggBasedVisualization();
await PageObjects.visualize.clickMetric();
await PageObjects.visualize.clickNewSearch();
await PageObjects.timePicker.setDefaultAbsoluteRange();

await testSubjects.click('visualizeSaveButton');

await PageObjects.timeToVisualize.saveFromModal('My New Vis 2', {
addToDashboard: 'existing',
dashboardId: 'My Excellent Dashboard',
saveToLibrary: false,
});

await PageObjects.dashboard.waitForRenderComplete();
await dashboardExpect.metricValuesExist(['14,004']);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.eql(2);

const isLinked = await PageObjects.timeToVisualize.libraryNotificationExists('My New Vis 2');
expect(isLinked).to.be(false);
});

it('adding a new metric to an existing dashboard by reference', async function () {
await PageObjects.common.navigateToApp('dashboard');

await PageObjects.dashboard.clickNewDashboard();
Expand All @@ -94,18 +201,24 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

await testSubjects.click('visualizeSaveButton');

await PageObjects.timeToVisualize.saveFromModal('My New Vis 2', {
await PageObjects.timeToVisualize.saveFromModal('My Saved New Vis 2', {
addToDashboard: 'existing',
dashboardId: 'My Wonderful Dashboard',
saveToLibrary: true,
});

await PageObjects.dashboard.waitForRenderComplete();
await dashboardExpect.metricValuesExist(['14,004']);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.eql(2);

const isLinked = await PageObjects.timeToVisualize.libraryNotificationExists(
'My Saved New Vis 2'
);
expect(isLinked).to.be(true);
});

it('adding a existing metric to an existing dashboard', async function () {
it('adding a existing metric to an existing dashboard by value', async function () {
await PageObjects.common.navigateToApp('dashboard');

await PageObjects.dashboard.clickNewDashboard();
Expand All @@ -124,6 +237,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
// Save this new viz to library
await PageObjects.timeToVisualize.saveFromModal('My New Vis 2', {
addToDashboard: null,
saveToLibrary: true,
});

await testSubjects.click('visualizeSaveButton');
Expand All @@ -136,12 +250,64 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
addToDashboard: 'existing',
dashboardId: 'My Very Cool Dashboard',
saveAsNew: true,
saveToLibrary: false,
});

await PageObjects.dashboard.waitForRenderComplete();
await dashboardExpect.metricValuesExist(['14,004']);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.eql(2);

const isLinked = await PageObjects.timeToVisualize.libraryNotificationExists(
'My New Vis 2 Copy'
);
expect(isLinked).to.be(false);
});

it('adding a existing metric to an existing dashboard by reference', async function () {
await PageObjects.common.navigateToApp('dashboard');

await PageObjects.dashboard.clickNewDashboard();
await PageObjects.dashboard.addVisualizations(['Visualization AreaChart']);
await PageObjects.dashboard.saveDashboard('My Very Neat Dashboard');
await PageObjects.dashboard.gotoDashboardLandingPage();
await listingTable.searchAndExpectItemsCount('dashboard', 'My Very Neat Dashboard', 1);

await PageObjects.visualize.navigateToNewAggBasedVisualization();
await PageObjects.visualize.clickMetric();
await PageObjects.visualize.clickNewSearch();
await PageObjects.timePicker.setDefaultAbsoluteRange();

await testSubjects.click('visualizeSaveButton');

// Save this new viz to library
await PageObjects.timeToVisualize.saveFromModal('Neat Saved Vis 2', {
addToDashboard: null,
saveToLibrary: true,
});

await testSubjects.click('visualizeSaveButton');

// All the options should be disabled
await PageObjects.timeToVisualize.ensureDashboardOptionsAreDisabled();

// Save a new copy of this viz to an existing dashboard
await PageObjects.timeToVisualize.saveFromModal('Neat Saved Vis 2 Copy', {
addToDashboard: 'existing',
dashboardId: 'My Very Neat Dashboard',
saveAsNew: true,
saveToLibrary: true,
});

await PageObjects.dashboard.waitForRenderComplete();
await dashboardExpect.metricValuesExist(['14,004']);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.eql(2);

const isLinked = await PageObjects.timeToVisualize.libraryNotificationExists(
'Neat Saved Vis 2 Copy'
);
expect(isLinked).to.be(true);
});
});
}
42 changes: 27 additions & 15 deletions test/functional/page_objects/time_to_visualize_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export function TimeToVisualizePageProvider({ getService, getPageObjects }: FtrP
const dashboardSelector = await testSubjects.find('add-to-dashboard-options');
await dashboardSelector.findByCssSelector(`input[id="new-dashboard-option"]:disabled`);
await dashboardSelector.findByCssSelector(`input[id="existing-dashboard-option"]:disabled`);
await dashboardSelector.findByCssSelector(`input[id="add-to-library-option"]:disabled`);

const librarySelector = await testSubjects.find('add-to-library-checkbox');
await librarySelector.findByCssSelector(`input[id="add-to-library-option"]:disabled`);
}

public async resetNewDashboard() {
Expand Down Expand Up @@ -64,20 +66,6 @@ export function TimeToVisualizePageProvider({ getService, getPageObjects }: FtrP
await testSubjects.setEuiSwitch('saveAsNewCheckbox', state);
}

const hasSaveToLibrary = await testSubjects.exists('add-to-library-checkbox');
if (hasSaveToLibrary && saveToLibrary !== undefined) {
const state = saveToLibrary ? 'check' : 'uncheck';
log.debug('save to library checkbox exists. Setting its state to', state);
await testSubjects.setEuiSwitch('add-to-library-checkbox', state);
}

const hasRedirectToOrigin = await testSubjects.exists('returnToOriginModeSwitch');
if (hasRedirectToOrigin && redirectToOrigin !== undefined) {
const state = redirectToOrigin ? 'check' : 'uncheck';
log.debug('redirect to origin checkbox exists. Setting its state to', state);
await testSubjects.setEuiSwitch('returnToOriginModeSwitch', state);
}

const hasDashboardSelector = await testSubjects.exists('add-to-dashboard-options');
if (hasDashboardSelector && addToDashboard !== undefined) {
let option: DashboardPickerOption = 'no-dashboard-option';
Expand All @@ -94,6 +82,30 @@ export function TimeToVisualizePageProvider({ getService, getPageObjects }: FtrP
await find.clickByButtonText(dashboardId);
}
}

const hasSaveToLibrary = await testSubjects.exists('add-to-library-checkbox');
if (hasSaveToLibrary && saveToLibrary !== undefined) {
const libraryCheckbox = await find.byCssSelector('#add-to-library-option');
const isChecked = await libraryCheckbox.isSelected();

const needsClick = isChecked !== saveToLibrary;

const state = saveToLibrary ? 'check' : 'uncheck';
log.debug('save to library checkbox exists. Setting its state to', state);

if (needsClick) {
const selector = await testSubjects.find('add-to-library-checkbox');
const label = await selector.findByCssSelector(`label[for="add-to-library-option"]`);
await label.click();
}
}

const hasRedirectToOrigin = await testSubjects.exists('returnToOriginModeSwitch');
if (hasRedirectToOrigin && redirectToOrigin !== undefined) {
const state = redirectToOrigin ? 'check' : 'uncheck';
log.debug('redirect to origin checkbox exists. Setting its state to', state);
await testSubjects.setEuiSwitch('returnToOriginModeSwitch', state);
}
}

public async libraryNotificationExists(panelTitle: string) {
Expand Down

0 comments on commit 4ffb9ee

Please sign in to comment.