-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5076baf
commit d4a9e69
Showing
9 changed files
with
239 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
test/plugin_functional/plugins/core_history_block/kibana.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
test/plugin_functional/plugins/core_history_block/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
83
test/plugin_functional/plugins/core_history_block/public/app.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
test/plugin_functional/plugins/core_history_block/public/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
40
test/plugin_functional/plugins/core_history_block/public/plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
test/plugin_functional/plugins/core_history_block/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
57
test/plugin_functional/test_suites/core_plugins/history_block.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters