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

Jest test cases #985

Merged
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

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