-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUG][Dashboard listing] push to history if dashboard otherwise nav (#…
…3922) History push will just to the current route. However, dashboardsProvider was implemented with the expectation that it was a different app. So when a plugin registered it was attempting to navigate to `app/dashboard#/app/{url}` Add tests and extra data test subject. Signed-off-by: Kawika Avilla <[email protected]>
- Loading branch information
Showing
11 changed files
with
239 additions
and
6 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
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
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
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
9 changes: 9 additions & 0 deletions
9
test/plugin_functional/plugins/dashboard_listing_test_plugin/opensearch_dashboards.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,9 @@ | ||
{ | ||
"id": "dashboard_listing_test_plugin", | ||
"version": "0.0.1", | ||
"opensearchDashboardsVersion": "opensearchDashboards", | ||
"configPath": ["dashboard_listing_test_plugin"], | ||
"server": false, | ||
"ui": true, | ||
"requiredPlugins": ["dashboard"] | ||
} |
17 changes: 17 additions & 0 deletions
17
test/plugin_functional/plugins/dashboard_listing_test_plugin/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,17 @@ | ||
{ | ||
"name": "dashboard_listing_test_plugin", | ||
"version": "1.0.0", | ||
"main": "target/test/plugin_functional/plugins/dashboard_listing_test_plugin", | ||
"opensearchDashboards": { | ||
"version": "opensearchDashboards", | ||
"templateVersion": "1.0.0" | ||
}, | ||
"license": "Apache-2.0", | ||
"scripts": { | ||
"osd": "../../../../scripts/use_node ../../../../scripts/osd.js", | ||
"build": "../../../../scripts/use_node ../../../../scripts/remove.js './target' && tsc" | ||
}, | ||
"devDependencies": { | ||
"typescript": "4.0.2" | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
test/plugin_functional/plugins/dashboard_listing_test_plugin/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,22 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Any modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import { PluginInitializer } from 'opensearch-dashboards/public'; | ||
import { | ||
DashboardListingTestPlugin, | ||
DashboardListingTestPluginSetup, | ||
DashboardListingTestPluginStart, | ||
} from './plugin'; | ||
|
||
export const plugin: PluginInitializer< | ||
DashboardListingTestPluginSetup, | ||
DashboardListingTestPluginStart | ||
> = () => new DashboardListingTestPlugin(); |
53 changes: 53 additions & 0 deletions
53
test/plugin_functional/plugins/dashboard_listing_test_plugin/public/plugin.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,53 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Any modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import { render, unmountComponentAtNode } from 'react-dom'; | ||
import { Router, Switch, Route, Link } from 'react-router-dom'; | ||
import { CoreSetup, Plugin } from 'opensearch-dashboards/public'; | ||
|
||
export class DashboardListingTestPlugin | ||
implements Plugin<DashboardListingTestPluginSetup, DashboardListingTestPluginStart> { | ||
public setup(core: CoreSetup, setupDeps: SetupDependencies) { | ||
const ID = 'dashboard_listing_test_plugin'; | ||
const BASE_URL = core.http.basePath.prepend(`/app/${ID}#`); | ||
setupDeps.dashboard.registerDashboardProvider({ | ||
appId: ID, | ||
savedObjectsType: 'dashboardTest', | ||
savedObjectsName: 'Dashboard Test', | ||
editUrlPathFn: (obj: SavedObject) => `${BASE_URL}/${obj.id}/edit`, | ||
viewUrlPathFn: (obj: SavedObject) => `${BASE_URL}/${obj.id}`, | ||
createLinkText: 'Test Dashboard', | ||
createSortText: 'Test Dashboard', | ||
createUrl: `${BASE_URL}/create`, | ||
}); | ||
|
||
core.application.register({ | ||
id: ID, | ||
title: 'Dashboard Listing Test Plugin', | ||
appRoute: `app/${ID}`, | ||
async mount(context, { element }) { | ||
render( | ||
<h1 data-test-subj="dashboardListingTestHeader">Dashboard Listing Test Header</h1>, | ||
element | ||
); | ||
|
||
return () => unmountComponentAtNode(element); | ||
}, | ||
}); | ||
} | ||
|
||
public start() {} | ||
public stop() {} | ||
} | ||
|
||
export type DashboardListingTestPluginSetup = ReturnType<DashboardListingTestPlugin['setup']>; | ||
export type DashboardListingTestPluginStart = ReturnType<DashboardListingTestPlugin['start']>; |
17 changes: 17 additions & 0 deletions
17
test/plugin_functional/plugins/dashboard_listing_test_plugin/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,17 @@ | ||
{ | ||
"extends": "../../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "./target", | ||
"skipLibCheck": true | ||
}, | ||
"include": [ | ||
"index.ts", | ||
"public/**/*.ts", | ||
"public/**/*.tsx", | ||
"../../../../typings/**/*", | ||
], | ||
"exclude": [], | ||
"references": [ | ||
{ "path": "../../../../src/core/tsconfig.json" } | ||
] | ||
} |
71 changes: 71 additions & 0 deletions
71
test/plugin_functional/test_suites/dashboard_listing_plugin/dashboard_listing_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,71 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Any modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import url from 'url'; | ||
import expect from '@osd/expect'; | ||
|
||
const getPathWithHash = (absoluteUrl: string) => { | ||
const parsed = url.parse(absoluteUrl); | ||
return `${parsed.path}${parsed.hash ?? ''}`; | ||
}; | ||
|
||
export default function ({ getService, getPageObjects }) { | ||
const testSubjects = getService('testSubjects'); | ||
const PageObjects = getPageObjects(['common', 'dashboard', 'header']); | ||
const browser = getService('browser'); | ||
const listingTable = getService('listingTable'); | ||
const find = getService('find'); | ||
|
||
describe('dashboard listing plugin', function describeIndexTests() { | ||
const dashboardName = 'Dashboard Test'; | ||
|
||
before(async () => { | ||
await PageObjects.dashboard.initTests({ | ||
opensearchDashboardsIndex: '../functional/fixtures/opensearch_archiver/dashboard/legacy', | ||
}); | ||
await PageObjects.dashboard.clickCreateDashboardPrompt(); | ||
await PageObjects.dashboard.saveDashboard('default'); | ||
await PageObjects.dashboard.gotoDashboardLandingPage(); | ||
}); | ||
|
||
it('should be able to navigate to create a dashboard', async () => { | ||
await testSubjects.click('createMenuDropdown'); | ||
await testSubjects.click('contextMenuItem-dashboard'); | ||
await PageObjects.dashboard.saveDashboard(dashboardName); | ||
|
||
await PageObjects.dashboard.gotoDashboardLandingPage(); | ||
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 1); | ||
}); | ||
|
||
it('should be able to navigate to view dashboard', async () => { | ||
await listingTable.clickItemLink('dashboard', dashboardName); | ||
await PageObjects.header.awaitGlobalLoadingIndicatorHidden(); | ||
await PageObjects.dashboard.getIsInViewMode(); | ||
await PageObjects.dashboard.gotoDashboardLandingPage(); | ||
}); | ||
|
||
it('should be able to navigate to edit dashboard', async () => { | ||
await listingTable.searchForItemWithName(dashboardName); | ||
const editBttn = await find.allByCssSelector('.euiToolTipAnchor'); | ||
await editBttn[0].click(); | ||
await PageObjects.dashboard.clickCancelOutOfEditMode(); | ||
await PageObjects.dashboard.gotoDashboardLandingPage(); | ||
}); | ||
|
||
it('should be able to navigate to create a test dashboard', async () => { | ||
await testSubjects.click('createMenuDropdown'); | ||
await testSubjects.click('contextMenuItem-dashboard_listing_test_plugin'); | ||
expect(getPathWithHash(await browser.getCurrentUrl())).to.eql( | ||
'/app/dashboard_listing_test_plugin#/create' | ||
); | ||
}); | ||
}); | ||
} |
35 changes: 35 additions & 0 deletions
35
test/plugin_functional/test_suites/dashboard_listing_plugin/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,35 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Any modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
export default function ({ getService, loadTestFile }) { | ||
const browser = getService('browser'); | ||
const opensearchArchiver = getService('opensearchArchiver'); | ||
|
||
async function loadLogstash() { | ||
await browser.setWindowSize(1200, 900); | ||
await opensearchArchiver.loadIfNeeded( | ||
'../functional/fixtures/opensearch_archiver/logstash_functional' | ||
); | ||
} | ||
|
||
async function unloadLogstash() { | ||
await opensearchArchiver.unload( | ||
'../functional/fixtures/opensearch_archiver/logstash_functional' | ||
); | ||
} | ||
|
||
describe('dashboard listing plugin', () => { | ||
before(loadLogstash); | ||
after(unloadLogstash); | ||
|
||
loadTestFile(require.resolve('./dashboard_listing_plugin')); | ||
}); | ||
} |