Skip to content

Commit

Permalink
add FTR tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Feb 11, 2021
1 parent 5076baf commit d4a9e69
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/core/public/application/navigation_confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ const windowConfirm: ConfirmHandler = (message: string, callback: ConfirmHandler

const getOverlayConfirmHandler = (overlay: OverlayStart): ConfirmHandler => {
return (message: string, callback: ConfirmHandlerCallback) => {
overlay.openConfirm(message, { title: ' ' }).then(
(confirmed) => {
callback(confirmed);
},
() => {
callback(false);
}
);
overlay
.openConfirm(message, { title: ' ', 'data-test-subj': 'navigationBlockConfirmModAl' })
.then(
(confirmed) => {
callback(confirmed);
},
() => {
callback(false);
}
);
};
};
8 changes: 8 additions & 0 deletions test/plugin_functional/plugins/core_history_block/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "core_history_block",
"version": "0.0.1",
"kibanaVersion": "kibana",
"server": false,
"ui": true,
"requiredBundles": ["kibanaReact"]
}
14 changes: 14 additions & 0 deletions test/plugin_functional/plugins/core_history_block/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "core_history_block",
"version": "1.0.0",
"main": "target/test/plugin_functional/plugins/core_history_block",
"kibana": {
"version": "kibana",
"templateVersion": "1.0.0"
},
"license": "SSPL-1.0 OR Elastic License 2.0",
"scripts": {
"kbn": "node ../../../../scripts/kbn.js",
"build": "rm -rf './target' && ../../../../node_modules/.bin/tsc"
}
}
83 changes: 83 additions & 0 deletions test/plugin_functional/plugins/core_history_block/public/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Switch, Route, Prompt } from 'react-router-dom';
import type { AppMountParameters, IBasePath, ApplicationStart } from 'kibana/public';
import { RedirectAppLinks } from '../../../../../src/plugins/kibana_react/public';

const HomePage = ({
basePath,
application,
}: {
basePath: IBasePath;
application: ApplicationStart;
}) => (
<div data-test-subj="page-home">
<Prompt message="Unsaved changes, are you sure you wanna leave?" />
<RedirectAppLinks application={application}>
<h1>HOME PAGE</h1>
<br /> <br />
<a data-test-subj="applink-intra-test" href={basePath.prepend(`/app/core_history_block/foo`)}>
Link to foo on the same app
</a>
<br /> <br />
<a data-test-subj="applink-external-test" href={basePath.prepend(`/app/home`)}>
Link to the home app
</a>
</RedirectAppLinks>
</div>
);

const FooPage = ({
basePath,
application,
}: {
basePath: IBasePath;
application: ApplicationStart;
}) => (
<div data-test-subj="page-home">
<RedirectAppLinks application={application}>
<h1>FOO PAGE</h1>
<br /> <br />
<a data-test-subj="applink-intra-test" href={basePath.prepend(`/app/history_block_test`)}>
Link to home on the same app
</a>
<br /> <br />
<a data-test-subj="applink-nested-test" href={basePath.prepend(`/app/home`)}>
Link to the home app
</a>
</RedirectAppLinks>
</div>
);

interface AppOptions {
basePath: IBasePath;
application: ApplicationStart;
}

export const renderApp = (
{ basePath, application }: AppOptions,
{ element, history }: AppMountParameters
) => {
ReactDOM.render(
<Router history={history}>
<Switch>
<Route path="/" exact={true}>
<HomePage basePath={basePath} application={application} />
</Route>
<Route path="/foo" exact={true}>
<FooPage basePath={basePath} application={application} />
</Route>
</Switch>
</Router>,
element
);
return () => ReactDOM.unmountComponentAtNode(element);
};
13 changes: 13 additions & 0 deletions test/plugin_functional/plugins/core_history_block/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { PluginInitializer } from 'kibana/public';
import { CoreAppLinkPlugin, CoreAppLinkPluginSetup, CoreAppLinkPluginStart } from './plugin';

export const plugin: PluginInitializer<CoreAppLinkPluginSetup, CoreAppLinkPluginStart> = () =>
new CoreAppLinkPlugin();
40 changes: 40 additions & 0 deletions test/plugin_functional/plugins/core_history_block/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { Plugin, CoreSetup, AppMountParameters } from 'kibana/public';
import { renderApp } from './app';

export class CoreAppLinkPlugin implements Plugin<CoreAppLinkPluginSetup, CoreAppLinkPluginStart> {
public setup(core: CoreSetup, deps: {}) {
core.application.register({
id: 'core_history_block',
title: 'History block test',
mount: async (params: AppMountParameters) => {
const [{ application }] = await core.getStartServices();
return renderApp(
{
basePath: core.http.basePath,
application,
},
params
);
},
});

return {};
}

public start() {
return {};
}

public stop() {}
}

export type CoreAppLinkPluginSetup = ReturnType<CoreAppLinkPlugin['setup']>;
export type CoreAppLinkPluginStart = ReturnType<CoreAppLinkPlugin['start']>;
13 changes: 13 additions & 0 deletions test/plugin_functional/plugins/core_history_block/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./target",
"skipLibCheck": true
},
"include": ["index.ts", "public/**/*.ts", "public/**/*.tsx", "../../../../typings/**/*"],
"exclude": [],
"references": [
{ "path": "../../../../src/core/tsconfig.json" },
{ "path": "../../../../src/plugins/kibana_react/tsconfig.json" }
]
}
57 changes: 57 additions & 0 deletions test/plugin_functional/test_suites/core_plugins/history_block.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import expect from '@kbn/expect';
import { PluginFunctionalProviderContext } from '../../services';

export default function ({ getService, getPageObjects }: PluginFunctionalProviderContext) {
const PageObjects = getPageObjects(['common']);
const browser = getService('browser');
const testSubjects = getService('testSubjects');

describe('application using `ScopedHistory.block`', () => {
beforeEach(async () => {
await PageObjects.common.navigateToApp('core_history_block');
});

describe('when navigating to another app', () => {
it('prevents navigation if user click cancel on the confirmation dialog', async () => {
await testSubjects.click('applink-external-test');

await testSubjects.existOrFail('navigationBlockConfirmModAl');
await PageObjects.common.clickCancelOnModal(false);
expect(await browser.getCurrentUrl()).to.contain('/app/core_history_block');
});
it('allows navigation if user click confirm on the confirmation dialog', async () => {
await testSubjects.click('applink-external-test');

await testSubjects.existOrFail('navigationBlockConfirmModAl');
await PageObjects.common.clickConfirmOnModal();
expect(await browser.getCurrentUrl()).to.contain('/app/home');
});
});

describe('when navigating to another app', () => {
it('prevents navigation if user click cancel on the confirmation dialog', async () => {
await testSubjects.click('applink-intra-test');

await testSubjects.existOrFail('navigationBlockConfirmModAl');
await PageObjects.common.clickCancelOnModal(false);
expect(await browser.getCurrentUrl()).to.contain('/app/core_history_block');
expect(await browser.getCurrentUrl()).not.to.contain('/foo');
});
it('allows navigation if user click confirm on the confirmation dialog', async () => {
await testSubjects.click('applink-intra-test');

await testSubjects.existOrFail('navigationBlockConfirmModAl');
await PageObjects.common.clickConfirmOnModal();
expect(await browser.getCurrentUrl()).to.contain('/app/core_history_block/foo');
});
});
});
}
1 change: 1 addition & 0 deletions test/plugin_functional/test_suites/core_plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export default function ({ loadTestFile }: PluginFunctionalProviderContext) {
loadTestFile(require.resolve('./application_status'));
loadTestFile(require.resolve('./rendering'));
loadTestFile(require.resolve('./chrome_help_menu_links'));
loadTestFile(require.resolve('./history_block'));
});
}

0 comments on commit d4a9e69

Please sign in to comment.