Skip to content

Commit

Permalink
Visualize Save with Dashboard Picker
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomThomson committed Jan 15, 2021
1 parent f041bad commit 676f971
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ export function SavedObjectSaveModalDashboard(props: DashboardSaveModalProps) {
}
hasChildLabel={false}
>
<EuiPanel color="subdued" hasShadow={false}>
<EuiPanel color="subdued" hasShadow={false} data-test-subj="add-to-dashboard-options">
<div>
<EuiRadio
checked={dashboardOption === 'existing'}
id="existing"
id="existing-dashboard-option"
name="dashboard-option"
label={i18n.translate(
'presentationUtil.saveModalDashboard.existingDashboardOptionLabel',
Expand All @@ -129,7 +129,7 @@ export function SavedObjectSaveModalDashboard(props: DashboardSaveModalProps) {

<EuiRadio
checked={dashboardOption === 'new'}
id="new"
id="new-dashboard-option"
name="dashboard-option"
label={i18n.translate(
'presentationUtil.saveModalDashboard.newDashboardOptionLabel',
Expand All @@ -145,7 +145,7 @@ export function SavedObjectSaveModalDashboard(props: DashboardSaveModalProps) {

<EuiRadio
checked={dashboardOption === null}
id="library"
id="add-to-library-option"
name="dashboard-option"
label={i18n.translate('presentationUtil.saveModalDashboard.libraryOptionLabel', {
defaultMessage: 'No dashboard, but add to library',
Expand Down
34 changes: 31 additions & 3 deletions test/functional/page_objects/visualize_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
import { FtrProviderContext } from '../ftr_provider_context';
import { VisualizeConstants } from '../../../src/plugins/visualize/public/application/visualize_constants';

interface VisualizeSaveModalArgs {
saveAsNew?: boolean;
redirectToOrigin?: boolean;
addToDashboard?: boolean;
dashboardId?: string;
}

export function VisualizePageProvider({ getService, getPageObjects }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const retry = getService('retry');
Expand Down Expand Up @@ -348,7 +355,7 @@ export function VisualizePageProvider({ getService, getPageObjects }: FtrProvide

public async saveVisualization(
vizName: string,
{ saveAsNew = false, redirectToOrigin = false } = {}
{ saveAsNew, redirectToOrigin, addToDashboard, dashboardId }: VisualizeSaveModalArgs = {}
) {
await this.ensureSavePanelOpen();
await testSubjects.setValue('savedObjectTitle', vizName);
Expand All @@ -366,6 +373,22 @@ export function VisualizePageProvider({ getService, getPageObjects }: FtrProvide
log.debug('redirect to origin checkbox exists. Setting its state to', state);
await testSubjects.setEuiSwitch('returnToOriginModeSwitch', state);
}

const dashboardSelectorExists = await testSubjects.exists('add-to-dashboard-options');
if (dashboardSelectorExists) {
const dashboardSelector = await testSubjects.find('add-to-dashboard-options');
let optionSelector = 'add-to-library-option';
if (addToDashboard) {
optionSelector = dashboardId ? 'existing-dashboard-option' : 'new-dashboard-option';
}
log.debug('dashboard selector exists, choosing option:', optionSelector);
const label = await dashboardSelector.findByCssSelector(`label[for="${optionSelector}"]`);
await label.click();

if (dashboardId) {
// TODO - selecting an existing dashboard
}
}
log.debug('Click Save Visualization button');

await testSubjects.click('confirmSaveSavedObjectButton');
Expand All @@ -381,9 +404,14 @@ export function VisualizePageProvider({ getService, getPageObjects }: FtrProvide

public async saveVisualizationExpectSuccess(
vizName: string,
{ saveAsNew = false, redirectToOrigin = false } = {}
{ saveAsNew, redirectToOrigin, addToDashboard, dashboardId }: VisualizeSaveModalArgs = {}
) {
const saveMessage = await this.saveVisualization(vizName, { saveAsNew, redirectToOrigin });
const saveMessage = await this.saveVisualization(vizName, {
saveAsNew,
redirectToOrigin,
addToDashboard,
dashboardId,
});
if (!saveMessage) {
throw new Error(
`Expected saveVisualization to respond with the saveMessage from the toast, got ${saveMessage}`
Expand Down

0 comments on commit 676f971

Please sign in to comment.