Skip to content

Commit

Permalink
Jest test cases (#985)
Browse files Browse the repository at this point in the history
* gauge chart test case added, event-anlytics utils test case added

Signed-off-by: Ramneet Chopra <ramneet_chopra@persistent.com>

* build error resolve: updated snapshots

Signed-off-by: Ramneet Chopra <ramneet_chopra@persistent.com>

Signed-off-by: Ramneet Chopra <ramneet_chopra@persistent.com>
  • Loading branch information
ramneet-persistent authored Sep 13, 2022
1 parent a37542d commit a1490cc
Show file tree
Hide file tree
Showing 13 changed files with 1,376 additions and 203 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

import {
hexToRgb,
lightenColor,
formatError,
isValidTraceId,
rangeNumDocs,
getHeaders,
} from '../utils';

describe('Utils event analytics helper functions', () => {
configure({ adapter: new Adapter() });

it('validates hexToRgb function', () => {
expect(hexToRgb()).toBe('rgba(60,161,199,1)');
expect(hexToRgb('test', 1, true)).toBe('rgba(96,353,409,1)');
expect(hexToRgb('#000000', 1, true)).toBe('rgba(0,0,0,1)');
});

it('validates lightenColor function', () => {
expect(lightenColor('#00000', 10)).toBe('#1a1a1a');
});

it('validates formatError function', () => {
expect(formatError('Warning', 'This is a warning', 'Test warning description')).toStrictEqual({
body: {
attributes: { error: { caused_by: { reason: 'Test warning description', type: '' } } },
},
message: 'This is a warning',
name: 'Warning',
});
});

it('validates isValidTraceId function', () => {
expect(isValidTraceId('#00000')).toBe(false);
expect(isValidTraceId('abcdefghijklmnopqrstuvwxyzabcdef')).toBe(true);
});

it('validates rangeNumDocs function', () => {
expect(rangeNumDocs(11000)).toBe(10000);
expect(rangeNumDocs(-200)).toBe(0);
expect(rangeNumDocs(2000)).toBe(2000);
});

it('validates getHeaders function', () => {
expect(
getHeaders(
[
{
name: 'host',
type: 'text',
},
{
name: 'ip_count',
type: 'integer',
},
{
name: 'per_ip_bytes',
type: 'long',
},
{
name: 'resp_code',
type: 'text',
},
{
name: 'sum_bytes',
type: 'long',
},
],
['', 'Time', '_source'],
undefined
)
).toBeTruthy();
expect(getHeaders([], ['', 'Time', '_source'], undefined)).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,27 @@ exports[`Bar component Renders bar component 1`] = `
"status": 200,
},
},
"userConfigs": Object {},
"userConfigs": Object {
"dataConfig": Object {
"valueOptions": Object {
"dimensions": Array [
Object {
"label": "tags",
"name": "tags",
"type": "text",
},
],
"metrics": Array [
Object {
"label": "count()",
"name": "count()",
"side": "left",
"type": "integer",
},
],
},
},
},
},
"vis": Object {
"barwidth": 0.97,
Expand Down
Loading

0 comments on commit a1490cc

Please sign in to comment.