-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add unit tests and dependencies Signed-off-by: Joshua Li <[email protected]> * Add codecov and badges Signed-off-by: Joshua Li <[email protected]> * Add color picker test Signed-off-by: Joshua Li <[email protected]> * Fix codecov badge link Signed-off-by: Joshua Li <[email protected]>
- Loading branch information
1 parent
57a4780
commit f13317f
Showing
26 changed files
with
4,690 additions
and
71 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
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" | ||
] | ||
} |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
node_modules/ | ||
build/ | ||
target/ | ||
coverage/ | ||
.cypress/screenshots | ||
.cypress/videos | ||
.cypress/videos |
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
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'); | ||
}); | ||
}); |
73 changes: 73 additions & 0 deletions
73
gantt-chart/public/components/__tests__/__snapshots__/gantt_chart.test.tsx.snap
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,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%;" | ||
/> | ||
`; |
Oops, something went wrong.