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

Added unit test cases to PlotlySchemaAdapter file #33552

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ff91b63
added component tests to Declarative chart
v-baambati Jan 2, 2025
2afa9e0
added change file
v-baambati Jan 2, 2025
4153c79
Merge branch 'master' of https://github.com/microsoft/fluentui into D…
v-baambati Jan 2, 2025
67c0bd9
updated snapshots
v-baambati Jan 2, 2025
2ddd260
resolved PR comments
v-baambati Jan 2, 2025
4dc949b
removed unwanted file
v-baambati Jan 2, 2025
aea52dc
update npmignore file
v-baambati Jan 2, 2025
e6c56e9
Merge branch 'master' of https://github.com/microsoft/fluentui into D…
v-baambati Jan 6, 2025
d44e38e
added unit test to plotly adapter
v-baambati Jan 6, 2025
10f0a3d
updated snapshots
v-baambati Jan 6, 2025
32f541d
Merge branch 'master' of https://github.com/microsoft/fluentui into D…
v-baambati Jan 6, 2025
4d31414
added new test
v-baambati Jan 6, 2025
84280c0
added test cases to string x axis values for line and area chart
v-baambati Jan 7, 2025
5625fad
Merge branch 'master' of https://github.com/microsoft/fluentui into D…
v-baambati Jan 8, 2025
da70915
Added new test cases for all invalid scenarios
v-baambati Jan 9, 2025
4fabe83
Merge branch 'master' of https://github.com/microsoft/fluentui into D…
v-baambati Jan 9, 2025
1bdc016
removed unwanted changes
v-baambati Jan 9, 2025
f6b475f
resolved eslint comments
v-baambati Jan 9, 2025
0b3af74
resolved eslint comments
v-baambati Jan 9, 2025
7869a25
updated snapshots
v-baambati Jan 9, 2025
05825c7
removed unwanted changes in this PR
v-baambati Jan 9, 2025
a7ff1ac
added failed test in declarative chart
v-baambati Jan 9, 2025
974b31f
added new test case
v-baambati Jan 10, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import {
v-baambati marked this conversation as resolved.
Show resolved Hide resolved
isDateArray,
isNumberArray,
isMonthArray,
updateXValues,
getColor,
transformPlotlyJsonToDonutProps,
transformPlotlyJsonToVSBCProps,
transformPlotlyJsonToGVBCProps,
transformPlotlyJsonToVBCProps,
transformPlotlyJsonToScatterChartProps,
transformPlotlyJsonToHorizontalBarWithAxisProps,
transformPlotlyJsonToHeatmapProps,
transformPlotlyJsonToSankeyProps,
transformPlotlyJsonToGaugeProps,
sanitizeJson,
} from '../src/components/DeclarativeChart/PlotlySchemaAdapter';

const colorMap = new Map<string, string>();
const env = require('../config/tests');
const runTest = env === 'TEST' ? describe : describe.skip;

runTest('isDate', () => {
test('Should return true when input array contains Date objects', () => {
var date = new Date();
v-baambati marked this conversation as resolved.
Show resolved Hide resolved
expect(isDateArray([date, date.getDate() + 1, date.getDate() + 2])).toBe(true);
});

test('Should return false when input array contains numeric data', () => {
expect(isDateArray([20, 30, 40])).toBe(false);
});

test('Should return false when input array contains string data', () => {
expect(isDateArray(['twenty', 'thirty', 'forty'])).toBe(false);
});
});

runTest('isNumberArray', () => {
test('Should return false when input array contains Date objects', () => {
var date = new Date();
expect(isNumberArray([date, date.getDate() + 1, date.getDate() + 2])).toBe(false);
});

test('Should return true when input array contains numeric data', () => {
expect(isNumberArray([20, 30, 40])).toBe(true);
});

test('Should return true when input array contains numaric data in string formatt', () => {
expect(isNumberArray(['20', '30', '40'])).toBe(true);
});

test('Should return false when input array contains string data', () => {
expect(isNumberArray(['twenty', 'thirty', 'forty'])).toBe(false);
});
});

runTest('isMonthArray', () => {
test('Should return false when input array contains Date objects', () => {
var date = new Date();
expect(isMonthArray([date, date.getDate() + 1, date.getDate() + 2])).toBe(false);
});

test('Should return true when input array contains months data', () => {
expect(isMonthArray([10, 11, 1])).toBe(true);
v-baambati marked this conversation as resolved.
Show resolved Hide resolved
});

test('Should return false when input array contains numeric data(apart from months 1 to 12)', () => {
expect(isMonthArray([20, 30, 40])).toBe(false);
});

test('Should return false when input array contains numaric data in string formatt', () => {
expect(isMonthArray(['20', '30', '40'])).toBe(false);
});

test('Should return false when input array contains string data', () => {
expect(isMonthArray(['One', 'Two', 'Three'])).toBe(false);
});
});

runTest('updateXValues', () => {
test('Should return true when input array contains months data', () => {
expect(updateXValues([10, 11, 1])).toStrictEqual(['10 01, 2024', '11 01, 2024', '1 01, 2025']);
});

test.skip('Should return true when input array contains months data', () => {
var date = new Date();
expect(updateXValues([10, 11, 16])).toStrictEqual(['10 01, 2024', '11 01, 2024', '1 01, 2025']);
});
});

runTest('getColor', () => {
test('Should return color code when we had legend title', () => {
expect(getColor('test', { current: colorMap }, true)).toBe('#e3008c');
});

test('Should return color code when we had legend title', () => {
expect(getColor('test', { current: colorMap }, false)).toBe('#e3008c');
});

test('Should return color code when we had legend title is empty', () => {
expect(getColor('', { current: colorMap }, false)).toBe('#2aa0a4');
});
});

runTest('transform Plotly Json To chart Props', () => {
test('transformPlotlyJsonToDonutProps - Should return donut chart props', () => {
const plotlySchema = require('../src/components/DeclarativeChart/tests/schema/fluent_donut_test.json');
expect(transformPlotlyJsonToDonutProps(plotlySchema, { current: colorMap }, true)).toMatchSnapshot();
});

test('transformPlotlyJsonToDonutProps - Should return pie chart props', () => {
const plotlySchema = require('../src/components/DeclarativeChart/tests/schema/fluent_pie_test.json');
expect(transformPlotlyJsonToDonutProps(plotlySchema, { current: colorMap }, true)).toMatchSnapshot();
});

test('transformPlotlyJsonToVSBCProps - Should return VSBC props', () => {
const plotlySchema = require('../src/components/DeclarativeChart/tests/schema/fluent_verticalstackedbarchart_test.json');
expect(transformPlotlyJsonToVSBCProps(plotlySchema, { current: colorMap }, true)).toMatchSnapshot();
});

test('transformPlotlyJsonToGVBCProps - Should return GVBC props', () => {
const plotlySchema = require('../src/components/DeclarativeChart/tests/schema/fluent_groupedverticalbarchart_test.json');
expect(transformPlotlyJsonToGVBCProps(plotlySchema, { current: colorMap }, true)).toMatchSnapshot();
});

test('transformPlotlyJsonToVBCProps - Should return VBC props', () => {
const plotlySchema = require('../src/components/DeclarativeChart/tests/schema/fluent_verticalbar_histogram_test.json');
expect(transformPlotlyJsonToVBCProps(plotlySchema, { current: colorMap }, true)).toMatchSnapshot();
});

test('transformPlotlyJsonToScatterChartProps - Should return line chart props', () => {
const plotlySchema = require('../src/components/DeclarativeChart/tests/schema/fluent_line_test.json');
expect(transformPlotlyJsonToScatterChartProps(plotlySchema, true, { current: colorMap }, true)).toMatchSnapshot();
});

test('transformPlotlyJsonToScatterChartProps - Should return area chart props', () => {
const plotlySchema = require('../src/components/DeclarativeChart/tests/schema/fluent_area_test.json');
expect(transformPlotlyJsonToScatterChartProps(plotlySchema, true, { current: colorMap }, true)).toMatchSnapshot();
});

test('transformPlotlyJsonToHorizontalBarWithAxisProps - Should return Horizontal bar chart with axis chart props', () => {
const plotlySchema = require('../src/components/DeclarativeChart/tests/schema/fluent_horizontalbar_test.json');
expect(
transformPlotlyJsonToHorizontalBarWithAxisProps(plotlySchema, { current: colorMap }, true),
).toMatchSnapshot();
});

test('transformPlotlyJsonToHeatmapProps - Should return heatmap chart props', () => {
const plotlySchema = require('../src/components/DeclarativeChart/tests/schema/fluent_heatmap_test.json');
expect(transformPlotlyJsonToHeatmapProps(plotlySchema)).toMatchSnapshot();
});

test('transformPlotlyJsonToSankeyProps - Should return sankey chart props', () => {
const plotlySchema = require('../src/components/DeclarativeChart/tests/schema/fluent_sankey_test.json');
expect(transformPlotlyJsonToSankeyProps(plotlySchema, { current: colorMap }, true)).toMatchSnapshot();
});

test('transformPlotlyJsonToGaugeProps - Should return gauge chart props', () => {
const plotlySchema = require('../src/components/DeclarativeChart/tests/schema/fluent_gauge_test.json');
expect(transformPlotlyJsonToGaugeProps(plotlySchema, { current: colorMap }, true)).toMatchSnapshot();
});
});

runTest('sanitizeJson', () => {
v-baambati marked this conversation as resolved.
Show resolved Hide resolved
test('Should return json object when depth inside the range', () => {
const plotlySchema = require('../src/components/DeclarativeChart/tests/schema/fluent_gauge_test.json');
expect(sanitizeJson(plotlySchema, 0)).toMatchSnapshot();
});
});
Loading
Loading