Skip to content

Commit 3db7c5c

Browse files
committed
Add mocks; add test configs; add initial test
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
1 parent 454ee82 commit 3db7c5c

9 files changed

+142
-0
lines changed

babel.config.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
module.exports = {
7+
presets: [
8+
require('@babel/preset-env'),
9+
require('@babel/preset-react'),
10+
require('@babel/preset-typescript'),
11+
],
12+
plugins: [
13+
['@babel/plugin-transform-modules-commonjs', { allowTopLevelThis: true }],
14+
[require('@babel/plugin-transform-runtime'), { regenerator: true }],
15+
],
16+
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"opensearch": "../../scripts/use_node ../../scripts/opensearch",
1515
"lint:es": "../../scripts/use_node ../../scripts/eslint -c eslintrc.json",
1616
"lint:es:precommit": "yarn lint:es common/* public/* server/*",
17+
"test:jest": "../../node_modules/.bin/jest --config ./test/jest.config.js",
1718
"build": "yarn plugin-helpers build && echo Renaming artifact to $npm_package_config_plugin_zip_name-$npm_package_config_plugin_version.zip && mv ./build/$npm_package_config_plugin_name*.zip ./build/$npm_package_config_plugin_zip_name-$npm_package_config_plugin_version.zip"
1819
},
1920
"repository": {
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import React from 'react';
7+
import { render } from '@testing-library/react';
8+
import { Provider } from 'react-redux';
9+
10+
import {
11+
BrowserRouter as Router,
12+
RouteComponentProps,
13+
Route,
14+
Switch,
15+
} from 'react-router-dom';
16+
import { store } from '../../store';
17+
import { Workflows } from './workflows';
18+
19+
jest.mock('../../services', () => {
20+
const { mockCoreServices } = require('../../../test');
21+
return {
22+
...jest.requireActual('../../services'),
23+
...mockCoreServices,
24+
};
25+
});
26+
27+
const renderWithRouter = () => ({
28+
...render(
29+
<Provider store={store}>
30+
<Router>
31+
<Switch>
32+
<Route
33+
render={(props: RouteComponentProps) => <Workflows {...props} />}
34+
/>
35+
</Switch>
36+
</Router>
37+
</Provider>
38+
),
39+
});
40+
41+
describe('Workflows', () => {
42+
test('renders the page', () => {
43+
const { getByText } = renderWithRouter();
44+
expect(getByText('Workflows')).not.toBeNull();
45+
});
46+
});

test/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
export * from './mocks';

test/jest.config.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
module.exports = {
7+
rootDir: '../',
8+
roots: ['<rootDir>'],
9+
coverageDirectory: './coverage',
10+
moduleNameMapper: {
11+
'\\.(css|less|scss|sass)$': '<rootDir>/test/style_stub.js',
12+
},
13+
testEnvironment: 'jest-environment-jsdom',
14+
coverageReporters: ['lcov', 'text', 'cobertura'],
15+
testMatch: ['**/*.test.js', '**/*.test.jsx', '**/*.test.ts', '**/*.test.tsx'],
16+
collectCoverageFrom: [
17+
'**/*.ts',
18+
'**/*.tsx',
19+
'**/*.js',
20+
'**/*.jsx',
21+
'!**/models/**',
22+
'!**/node_modules/**',
23+
'!**/index.js',
24+
'!<rootDir>/public/app.js',
25+
'!<rootDir>/index.js',
26+
'!<rootDir>/babel.config.js',
27+
'!<rootDir>/test/**',
28+
'!<rootDir>/server/**',
29+
'!<rootDir>/coverage/**',
30+
'!<rootDir>/scripts/**',
31+
'!<rootDir>/build/**',
32+
'!**/vendor/**',
33+
],
34+
clearMocks: true,
35+
modulePathIgnorePatterns: ['<rootDir>/offline-module-cache/'],
36+
testPathIgnorePatterns: ['<rootDir>/build/', '<rootDir>/node_modules/'],
37+
transformIgnorePatterns: ['<rootDir>/node_modules'],
38+
};

test/mocks/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
export { mockCoreServices } from './mock_core_services';

test/mocks/mock_core_services.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
export const mockCoreServices = {
7+
getCore: () => {
8+
return {
9+
chrome: {
10+
setBreadcrumbs: jest.fn(),
11+
},
12+
};
13+
},
14+
getNotifications: () => {
15+
return {
16+
toasts: {
17+
addDanger: jest.fn().mockName('addDanger'),
18+
addSuccess: jest.fn().mockName('addSuccess'),
19+
},
20+
};
21+
},
22+
};

test/style_stub.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
module.exports = {};

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"public/**/*.ts",
5555
"public/**/*.tsx",
5656
"server/**/*.ts",
57+
"test/**/*",
5758
"../../typings/**/*"
5859
],
5960
"exclude": ["node_modules", "*/node_modules/"]

0 commit comments

Comments
 (0)