Skip to content

Commit 4746724

Browse files
committed
add listing test plugin
Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
1 parent f05d4b4 commit 4746724

File tree

8 files changed

+201
-0
lines changed

8 files changed

+201
-0
lines changed

test/plugin_functional/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
5252
require.resolve('./test_suites/doc_views_links'),
5353
require.resolve('./test_suites/application_links'),
5454
require.resolve('./test_suites/data_plugin'),
55+
require.resolve('./test_suites?dashboard_listing_plugin'),
5556
],
5657
services: {
5758
...functionalConfig.get('services'),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"id": "dashboard_listing_test_plugin",
3+
"version": "0.0.1",
4+
"opensearchDashboardsVersion": "opensearchDashboards",
5+
"configPath": ["dashboard_listing_test_plugin"],
6+
"server": false,
7+
"ui": true,
8+
"requiredPlugins": ["dashboard"]
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "dashboard_listing_test_plugin",
3+
"version": "1.0.0",
4+
"main": "target/test/plugin_functional/plugins/dashboard_listing_test_plugin",
5+
"opensearchDashboards": {
6+
"version": "opensearchDashboards",
7+
"templateVersion": "1.0.0"
8+
},
9+
"license": "Apache-2.0",
10+
"scripts": {
11+
"osd": "../../../../scripts/use_node ../../../../scripts/osd.js",
12+
"build": "../../../../scripts/use_node ../../../../scripts/remove.js './target' && tsc"
13+
},
14+
"devDependencies": {
15+
"typescript": "4.0.2"
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*
8+
* Any modifications Copyright OpenSearch Contributors. See
9+
* GitHub history for details.
10+
*/
11+
12+
import { PluginInitializer } from 'opensearch-dashboards/public';
13+
import {
14+
DashboardListingTestPlugin,
15+
DashboardListingTestPluginSetup,
16+
DashboardListingTestPluginStart,
17+
} from './plugin';
18+
19+
export const plugin: PluginInitializer<
20+
DashboardListingTestPluginSetup,
21+
DashboardListingTestPluginStart
22+
> = () => new DashboardListingTestPlugin();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*
8+
* Any modifications Copyright OpenSearch Contributors. See
9+
* GitHub history for details.
10+
*/
11+
12+
import * as React from 'react';
13+
import { render, unmountComponentAtNode } from 'react-dom';
14+
import { Router, Switch, Route, Link } from 'react-router-dom';
15+
import { CoreSetup, Plugin } from 'opensearch-dashboards/public';
16+
17+
export class DashboardListingTestPlugin
18+
implements Plugin<DashboardListingTestPluginSetup, DashboardListingTestPluginStart> {
19+
public setup(core: CoreSetup, setupDeps: SetupDependencies) {
20+
const ID = 'dashboard_listing_test_plugin';
21+
const BASE_URL = core.http.basePath.prepend(`/app/${ID}#`);
22+
setupDeps.dashboard.registerDashboardProvider({
23+
appId: ID,
24+
savedObjectsType: 'dashboardTest',
25+
savedObjectsName: 'Dashboard Test',
26+
editUrlPathFn: (obj: SavedObject) => `${BASE_URL}/${obj.id}/edit`,
27+
viewUrlPathFn: (obj: SavedObject) => `${BASE_URL}/${obj.id}`,
28+
createLinkText: 'Test Dashboard',
29+
createSortText: 'Test Dashboard',
30+
createUrl: `${BASE_URL}/create`,
31+
});
32+
33+
core.application.register({
34+
id: ID,
35+
title: 'Dashboard Listing Test Plugin',
36+
appRoute: `app/${ID}`,
37+
async mount(context, { element }) {
38+
render(
39+
<h1 data-test-subj="dashboardListingTestHeader">Dashboard Listing Test Header</h1>,
40+
element
41+
);
42+
43+
return () => unmountComponentAtNode(element);
44+
},
45+
});
46+
}
47+
48+
public start() {}
49+
public stop() {}
50+
}
51+
52+
export type DashboardListingTestPluginSetup = ReturnType<DashboardListingTestPlugin['setup']>;
53+
export type DashboardListingTestPluginStart = ReturnType<DashboardListingTestPlugin['start']>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": "../../../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"outDir": "./target",
5+
"skipLibCheck": true
6+
},
7+
"include": [
8+
"index.ts",
9+
"public/**/*.ts",
10+
"public/**/*.tsx",
11+
"../../../../typings/**/*",
12+
],
13+
"exclude": [],
14+
"references": [
15+
{ "path": "../../../../src/core/tsconfig.json" }
16+
]
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*
8+
* Any modifications Copyright OpenSearch Contributors. See
9+
* GitHub history for details.
10+
*/
11+
12+
import url from 'url';
13+
import expect from '@osd/expect';
14+
15+
const getPathWithHash = (absoluteUrl: string) => {
16+
const parsed = url.parse(absoluteUrl);
17+
return `${parsed.path}${parsed.hash ?? ''}`;
18+
};
19+
20+
export default function ({ getService, getPageObjects }) {
21+
const testSubjects = getService('testSubjects');
22+
const PageObjects = getPageObjects(['common', 'dashboard']);
23+
const browser = getService('browser');
24+
const listingTable = getService('listingTable');
25+
const find = getService('find');
26+
27+
describe('dashboard listing plugin', function describeIndexTests() {
28+
const dashboardName = 'Dashboard Test';
29+
30+
before(async () => {
31+
await PageObjects.dashboard.initTests();
32+
});
33+
34+
it('should be able to navigate to create a dashboard', async () => {
35+
await testSubjects.click('createMenuDropdown');
36+
await testSubjects.click('contextMenuItem-dashboard');
37+
await PageObjects.dashboard.saveDashboard(dashboardName);
38+
39+
await PageObjects.dashboard.gotoDashboardLandingPage();
40+
await listingTable.searchAndExpectItemsCount('dashboard', dashboardName, 1);
41+
});
42+
43+
it('should be able to navigate to view dashboard', async () => {
44+
await listingTable.clickItemLink('dashboard', dashboardName);
45+
await PageObjects.header.awaitGlobalLoadingIndicatorHidden();
46+
await PageObjects.dashboard.getIsInViewMode();
47+
await PageObjects.dashboard.gotoDashboardLandingPage();
48+
});
49+
50+
it('should be able to navigate to edit dashboard', async () => {
51+
await listingTable.searchForItemWithName(dashboardName);
52+
const editBttn = await find.allByCssSelector('.euiToolTipAnchor');
53+
await editBttn.click();
54+
await PageObjects.dashboard.clickCancelOutOfEditMode();
55+
await PageObjects.dashboard.gotoDashboardLandingPage();
56+
});
57+
58+
it('should be able to navigate to create a test dashboard', async () => {
59+
await testSubjects.click('createMenuDropdown');
60+
await testSubjects.click('contextMenuItem-dashboard_listing_test_plugin');
61+
expect(getPathWithHash(await browser.getCurrentUrl())).to.eql(
62+
'/app/dashboard_listing_test_plugin#/create'
63+
);
64+
});
65+
});
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*
8+
* Any modifications Copyright OpenSearch Contributors. See
9+
* GitHub history for details.
10+
*/
11+
12+
export default function ({ loadTestFile }) {
13+
describe('dashboard listing plugin', () => {
14+
loadTestFile(require.resolve('./dashboard_listing_plugin'));
15+
});
16+
}

0 commit comments

Comments
 (0)