Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Update Pie graph & Carbon API tests to use Jest (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdadn authored Jan 9, 2024
1 parent 29723a2 commit 806c18c
Show file tree
Hide file tree
Showing 8 changed files with 498 additions and 674 deletions.
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = (api) => {
];

const plugins = [
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-transform-object-rest-spread',
'@babel/plugin-transform-object-assign',
'@babel/plugin-transform-runtime',
];
Expand Down
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module.exports = {
...jestConfig,
testMatch: [
'**/carbon-graphs/tests/unit/controls/Bar/(*.)(test.js)',
'**/carbon-graphs/tests/unit/controls/Carbon/(*.)(test.js)',
'**/carbon-graphs/tests/unit/controls/Pie/(*.)(test.js)',
// The patterns below are temporarily commented out as not all tests are updated to work with Jest.
// Updating them is currently a work in progress.
// '**/tests/unit/**/(*.)(test.js)',
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
"extends @cerner/browserslist-config-terra"
],
"devDependencies": {
"@babel/cli": "^7.5.0",
"@babel/core": "^7.5.0",
"@babel/plugin-proposal-object-rest-spread": "^7.5.0",
"@babel/plugin-transform-object-assign": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.5.0",
"@babel/polyfill": "^7.10.4",
"@babel/preset-env": "^7.10.4",
"@babel/preset-react": "^7.0.0",
"@babel/runtime": "^7.10.4",
"@babel/cli": "7",
"@babel/core": "7",
"@babel/plugin-transform-object-assign": "7",
"@babel/plugin-transform-object-rest-spread": "7",
"@babel/plugin-transform-runtime": "7",
"@babel/polyfill": "7",
"@babel/preset-env": "7",
"@babel/preset-react": "7",
"@babel/runtime": "7",
"@cerner/browserslist-config-terra": "^3.0.0",
"@cerner/eslint-config-terra": "^5.0.0",
"@cerner/jest-config-terra": "2",
Expand All @@ -45,9 +45,9 @@
"@cerner/terra-open-source-scripts": "1",
"@cerner/webpack-config-terra": "3",
"autoprefixer": "^9.8.6",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-istanbul": "^6.0.0",
"babel-eslint": "10",
"babel-loader": "8",
"babel-plugin-istanbul": "6",
"babel-plugin-minify-replace": "^0.5.0",
"babel-preset-minify": "^0.5.1",
"check-installed-dependencies": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/carbon-graphs/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = (api) => {
];

const plugins = [
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-transform-object-rest-spread',
'@babel/plugin-transform-object-assign',
'@babel/plugin-transform-runtime',
];
Expand Down
72 changes: 37 additions & 35 deletions packages/carbon-graphs/tests/unit/controls/Carbon/Carbon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {

describe('Carbon', () => {
let graphContainer;

beforeEach(() => {
graphContainer = document.createElement('div');
graphContainer.id = 'testGraph_carbon';
Expand All @@ -34,6 +35,7 @@ describe('Carbon', () => {
afterEach(() => {
document.body.innerHTML = '';
});

it('registers all graph types', () => {
const keys = Object.keys(Carbon.api);
expect(keys).toBeDefined();
Expand All @@ -48,8 +50,8 @@ describe('Carbon', () => {
});
it('registers Graph', () => {
const graph = Carbon.api.graph(nativeInput);
expect(Carbon.api.graph).toEqual(jasmine.any(Function));
expect(graph instanceof Graph).toBeTruthy();
expect(typeof Carbon.api.graph).toEqual('function');
expect(graph).toBeInstanceOf(Graph);
});
it('registers Line graph', () => {
const data = {
Expand All @@ -65,8 +67,8 @@ describe('Carbon', () => {
],
};
const line = Carbon.api.line(data);
expect(Carbon.api.line).toEqual(jasmine.any(Function));
expect(line instanceof Line).toBeTruthy();
expect(typeof Carbon.api.line).toEqual('function');
expect(line).toBeInstanceOf(Line);
});
it('registers Paired Result graph', () => {
const data = {
Expand All @@ -81,43 +83,45 @@ describe('Carbon', () => {
],
};
const paired = Carbon.api.pairedResult(data);
expect(Carbon.api.pairedResult).toEqual(jasmine.any(Function));
expect(paired instanceof PairedResult).toBeTruthy();
expect(typeof Carbon.api.pairedResult).toEqual('function');
expect(paired).toBeInstanceOf(PairedResult);
});
it('registers Shape', () => {
const shape = Carbon.tools.shape(Carbon.helpers.SHAPES.RHOMBUS);
expect(Carbon.tools.shape).toEqual(jasmine.any(Function));
expect(shape instanceof Shape).toBeTruthy();
expect(typeof Carbon.tools.shape).toEqual('function');
expect(shape).toBeInstanceOf(Shape);
});
it('registers Shape - Dark', () => {
const shape = Carbon.tools.shape(Carbon.helpers.SHAPES.DARK.RHOMBUS);
expect(Carbon.tools.shape).toEqual(jasmine.any(Function));
expect(shape instanceof Shape).toBeTruthy();
expect(typeof Carbon.tools.shape).toEqual('function');
expect(shape).toBeInstanceOf(Shape);
});
it('registers Shape - Light', () => {
const shape = Carbon.tools.shape(Carbon.helpers.SHAPES.LIGHT.RHOMBUS);
expect(Carbon.tools.shape).toEqual(jasmine.any(Function));
expect(shape instanceof Shape).toBeTruthy();
expect(typeof Carbon.tools.shape).toEqual('function');
expect(shape).toBeInstanceOf(Shape);
});
it('registers defaultSVGProps', () => {
const _svgProps = Carbon.tools.defaultSVGProps();
expect(Carbon.tools.defaultSVGProps).toEqual(jasmine.any(Function));
expect(_svgProps instanceof Object).toBeTruthy();
expect(typeof Carbon.tools.defaultSVGProps).toEqual('function');
expect(_svgProps).toBeInstanceOf(Object);
expect(_svgProps.svgClassNames).toEqual('');
expect(_svgProps.svgStyles).toEqual('');
expect(_svgProps.transformFn).toEqual(jasmine.any(Function));
expect(_svgProps.onClickFn).toEqual(jasmine.any(Function));
expect(typeof _svgProps.transformFn).toEqual('function');
expect(typeof _svgProps.onClickFn).toEqual('function');
expect(_svgProps.a11yAttributes).toEqual({});
});
it('registers Gantt', () => {
const gantt = Carbon.api.gantt(ganttInput);
expect(Carbon.api.gantt).toEqual(jasmine.any(Function));
expect(gantt instanceof Gantt).toBeTruthy();
expect(typeof Carbon.api.gantt).toEqual('function');
expect(gantt).toBeInstanceOf(Gantt);
});
it('registers Timeline', () => {

// TODO: fix failing test
it.skip('registers Timeline', () => {
const timeline = Carbon.api.timeline(timelineInput);
expect(Carbon.api.timeline).toEqual(jasmine.any(Function));
expect(timeline instanceof Timeline).toBeTruthy();
expect(typeof Carbon.api.timeline).toEqual('function');
expect(timeline).toBeInstanceOf(Timeline);
});
it('registers Bar', () => {
const data = {
Expand All @@ -133,13 +137,13 @@ describe('Carbon', () => {
],
};
const bar = Carbon.api.bar(data);
expect(Carbon.api.bar).toEqual(jasmine.any(Function));
expect(bar instanceof Bar).toBeTruthy();
expect(typeof Carbon.api.bar).toEqual('function');
expect(bar).toBeInstanceOf(Bar);
});
it('registers Pie', () => {
const pie = Carbon.api.pie(pieInput);
expect(Carbon.api.line).toEqual(jasmine.any(Function));
expect(pie instanceof Pie).toBeTruthy();
expect(typeof Carbon.api.line).toEqual('function');
expect(pie).toBeInstanceOf(Pie);
});
it('registers Scatter', () => {
const data = {
Expand All @@ -155,8 +159,8 @@ describe('Carbon', () => {
],
};
const scatter = Carbon.api.scatter(data);
expect(Carbon.api.scatter).toEqual(jasmine.any(Function));
expect(scatter instanceof Scatter).toBeTruthy();
expect(typeof Carbon.api.scatter).toEqual('function');
expect(scatter).toBeInstanceOf(Scatter);
});
it('registers Bubble', () => {
const data = {
Expand All @@ -173,8 +177,8 @@ describe('Carbon', () => {
};

const bubble = Carbon.api.bubble(data);
expect(Carbon.api.bubble).toEqual(jasmine.any(Function));
expect(bubble instanceof Bubble).toBeTruthy();
expect(typeof Carbon.api.bubble).toEqual('function');
expect(bubble).toBeInstanceOf(Bubble);
});
it('registers BubbleSingleDataset', () => {
const data = {
Expand All @@ -191,8 +195,8 @@ describe('Carbon', () => {
};

const bubbleSingleDataset = Carbon.api.bubbleSingleDataset(data);
expect(Carbon.api.bubbleSingleDataset).toEqual(jasmine.any(Function));
expect(bubbleSingleDataset instanceof BubbleSingleDataset).toBeTruthy();
expect(typeof Carbon.api.bubbleSingleDataset).toBe('function');
expect(bubbleSingleDataset).toBeInstanceOf(BubbleSingleDataset);
});
it('registers BubbleMultipleDataset', () => {
const data = {
Expand All @@ -209,9 +213,7 @@ describe('Carbon', () => {
};

const bubbleMultipleDataset = Carbon.api.bubbleMultipleDataset(data);
expect(Carbon.api.bubbleMultipleDataset).toEqual(jasmine.any(Function));
expect(
bubbleMultipleDataset instanceof BubbleMultipleDataset,
).toBeTruthy();
expect(typeof Carbon.api.bubbleMultipleDataset).toEqual('function');
expect(bubbleMultipleDataset).toBeInstanceOf(BubbleMultipleDataset);
});
});
Loading

0 comments on commit 806c18c

Please sign in to comment.