Skip to content

Commit

Permalink
added functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomThomson committed Feb 3, 2021
1 parent 87e8386 commit 3f51874
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/plugins/visualize/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class VisualizePlugin
private appStateUpdater = new BehaviorSubject<AppUpdater>(() => ({}));
private stopUrlTracking: (() => void) | undefined = undefined;
private currentHistory: ScopedHistory | undefined = undefined;
private isLinkedToOriginatingApp: (() => boolean) | undefined = undefined;

private readonly visEditorsRegistry = createVisEditorsRegistry();

Expand Down Expand Up @@ -114,6 +115,12 @@ export class VisualizePlugin
},
],
getHistory: () => this.currentHistory!,
onBeforeNavLinkSaved: (urlToSave: string) => {
if (this.isLinkedToOriginatingApp?.()) {
return core.http.basePath.prepend('/app/visualize');
}
return urlToSave;
},
});
this.stopUrlTracking = () => {
stopUrlTracker();
Expand All @@ -134,6 +141,13 @@ export class VisualizePlugin
const [coreStart, pluginsStart] = await core.getStartServices();
this.currentHistory = params.history;

// allows the urlTracker to only save URLs that are not linked to an originatingApp
this.isLinkedToOriginatingApp = () => {
return Boolean(
pluginsStart.embeddable.getStateTransfer().getIncomingEditorState()?.originatingApp
);
};

// make sure the index pattern list is up to date
pluginsStart.data.indexPatterns.clearCache();
// make sure a default index pattern exists
Expand Down
30 changes: 26 additions & 4 deletions test/functional/apps/dashboard/edit_visualizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default function ({ getService, getPageObjects }) {
const PageObjects = getPageObjects(['dashboard', 'header', 'visualize', 'common', 'visEditor']);
const esArchiver = getService('esArchiver');
const testSubjects = getService('testSubjects');
const appsMenu = getService('appsMenu');
const kibanaServer = getService('kibanaServer');
const dashboardPanelActions = getService('dashboardPanelActions');
const dashboardVisualizations = getService('dashboardVisualizations');
Expand All @@ -25,10 +26,14 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.visualize.clickMarkdownWidget();
await PageObjects.visEditor.setMarkdownTxt(originalMarkdownText);
await PageObjects.visEditor.clickGo();
await PageObjects.visualize.saveVisualizationExpectSuccess(title, {
saveAsNew: true,
redirectToOrigin: true,
});
if (title) {
await PageObjects.visualize.saveVisualizationExpectSuccess(title, {
saveAsNew: true,
redirectToOrigin: true,
});
} else {
await PageObjects.visualize.saveVisualizationAndReturn();
}
};

const editMarkdownVis = async () => {
Expand Down Expand Up @@ -86,5 +91,22 @@ export default function ({ getService, getPageObjects }) {
const markdownText = await testSubjects.find('markdownBody');
expect(await markdownText.getVisibleText()).to.eql(originalMarkdownText);
});

it('visualize app menu navigates to the visualize listing page if the last opened visualization was by value', async () => {
await PageObjects.dashboard.gotoDashboardLandingPage();
await PageObjects.dashboard.clickNewDashboard();

// Create markdown by value.
await createMarkdownVis();

// Edit then save and return
await editMarkdownVis();
await PageObjects.visualize.saveVisualizationAndReturn();

await PageObjects.header.waitUntilLoadingHasFinished();
await appsMenu.clickLink('Visualize');
await PageObjects.common.clickConfirmOnModal();
expect(await testSubjects.exists('visualizationLandingPage')).to.be(true);
});
});
}

0 comments on commit 3f51874

Please sign in to comment.