Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests and codecov #19

Merged
merged 4 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/test-and-build-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ jobs:
run: |
cd OpenSearch-Dashboards/plugins/gantt-chart
yarn osd bootstrap
- name: Test
run: |
cd OpenSearch-Dashboards/plugins/gantt-chart
yarn test --coverage
- name: Upload coverage
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Build Artifact
run: |
cd OpenSearch-Dashboards/plugins/gantt-chart
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[![Dashboards Visualizations CI](https://github.com/opensearch-project/dashboards-visualizations/actions/workflows/test-and-build-workflow.yml/badge.svg)](https://github.com/opensearch-project/dashboards-visualizations/actions/workflows/test-and-build-workflow.yml)
[![codecov](https://codecov.io/gh/opensearch-project/dashboards-visualizations/branch/main/graphs/badge.svg)](https://codecov.io/gh/opensearch-project/dashboards-visualizations)

# OpenSearch Dashboards Visualizations

The OpenSearch Dashboards Visualizations enables you to use additional types of visualizations inside OpenSearch Dashboards Visualize and integrate them in Dashboard.
Expand Down
18 changes: 18 additions & 0 deletions gantt-chart/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": { "node": "10" }
}
],
"@babel/preset-react",
"@babel/preset-typescript"
],
"plugins": [
"@babel/plugin-transform-modules-commonjs",
["@babel/plugin-transform-runtime", { "regenerator": true }],
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread"
]
}
3 changes: 2 additions & 1 deletion gantt-chart/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/
build/
target/
coverage/
.cypress/screenshots
.cypress/videos
.cypress/videos
8 changes: 7 additions & 1 deletion gantt-chart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@
"lint": "eslint .",
"build": "yarn plugin-helpers build",
"plugin-helpers": "node ../../scripts/plugin_helpers",
"test": "../../node_modules/.bin/jest --config ./test/jest.config.js",
"test:cypress": "cypress run"
},
"dependencies": {
"plotly.js-dist": "^1.57.1",
"react-plotly.js": "^2.4.0"
},
"devDependencies": {
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/react-plotly.js": "^2.2.4",
"@types/showdown": "^1.9.3",
"cypress": "^5.0.0",
"eslint": "^6.8.0"
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^6.8.0",
"jest": "^26.4.2",
"jest-dom": "^4.0.0"
},
"engines": {
"node": "10.23.1",
Expand Down
82 changes: 82 additions & 0 deletions gantt-chart/public/__tests__/gantt_vis_type.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

import { MockStateParams } from '../../test/mocks/mockData';
import { getGanttVisDefinition } from '../gantt_vis_type';
import { GanttVisDependencies } from '../plugin';

describe('Test vis type', () => {
const MOCK_RESPONSE = {
total: 25,
hits: [
{
_source: { field: 'test' },
_index: 'test-index',
_type: 'test-type',
_id: 'test-id',
_score: 0,
},
],
};
const httpClient = jest.fn() as any;
httpClient.post = jest.fn(() => Promise.resolve(MOCK_RESPONSE));

it('returns vis type', async () => {
const dependencies = ({
uiSettings: jest.fn(),
http: httpClient,
} as unknown) as GanttVisDependencies;
const ganttVisDefinition = getGanttVisDefinition(dependencies);

const request = await ganttVisDefinition.requestHandler({
timeRange: { from: 'now-15m', to: 'now' },
filters: [],
index: jest.fn() as any,
query: [] as any,
visParams: MockStateParams,
});
expect(request).toEqual(MOCK_RESPONSE);
expect(httpClient.post).toBeCalledWith('../api/gantt_vis/query', {
body:
'{"size":10,"body":{"sort":[{"startTime":{"order":"desc"}}],"query":{"bool":{"must":[{"range":"test-range"}]}}}}',
});

const response = await ganttVisDefinition.responseHandler(MOCK_RESPONSE);
expect(response).toEqual({
source: [
{
field: 'test',
},
],
total: 25,
});
});

it('catches errors', async () => {
httpClient.post = jest.fn(() => Promise.reject('test-error'));
console.error = jest.fn();
const dependencies = ({
uiSettings: jest.fn(),
http: httpClient,
} as unknown) as GanttVisDependencies;
const ganttVisDefinition = getGanttVisDefinition(dependencies);

const request = await ganttVisDefinition.requestHandler({
timeRange: { from: 'now-15m', to: 'now' },
filters: [],
index: jest.fn() as any,
query: [] as any,
visParams: MockStateParams,
});
expect(request).toEqual(undefined);
expect(console.error).toBeCalledWith('test-error');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<GanttChart /> spec renders empty prompt when no data is returned 1`] = `
<div
class="euiEmptyPrompt"
>
<span
class="euiTextColor euiTextColor--subdued"
>
<h2
class="euiTitle euiTitle--medium"
>
No data
</h2>
<div
class="euiSpacer euiSpacer--m"
/>
<div
class="euiText euiText--medium"
>
<div
class="euiText euiText--medium"
>
No data matching the selected filter.
</div>
</div>
</span>
</div>
`;

exports[`<GanttChart /> spec renders empty prompt when no field is selected 1`] = `
<div
class="euiEmptyPrompt"
>
<span
class="euiTextColor euiTextColor--subdued"
>
<h2
class="euiTitle euiTitle--medium"
>
No data
</h2>
<div
class="euiSpacer euiSpacer--m"
/>
<div
class="euiText euiText--medium"
>
<div
class="euiText euiText--medium"
>
Specify data to plot the chart using the Data & Options panel
<br />
on the right.
</div>
</div>
</span>
</div>
`;

exports[`<GanttChart /> spec renders the component 1`] = `
<div
id="plotly-gantt-chart"
style="width: 100%; height: 100%;"
/>
`;

exports[`<GanttChart /> spec renders the component with different props 1`] = `
<div
id="plotly-gantt-chart"
style="width: 100%; height: 100%;"
/>
`;
Loading