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

Update Pie & Carbon API tests to use Jest #325

Merged
merged 7 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
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",
Copy link

@kenk2 kenk2 Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Any reason why we're fixing these packages to a specific version instead of the carat notation? Unless I'm mistaken won't this actually be a downgrade (because we're fixing to a specific version in this case)?

Also I feel that we should probably keep the semver fully specified so that we know where our last working version is in case any upstream shenanigans (like babel stuff) happens and we need a reference point to easily downgrade to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't locking packages, it is just the shorter form of using the caret. We don't typically keep track of the minor versions of dev dependencies so this is just makes it clearer that we're using the "latest minor version of v7", especially with related dependencies that need to be on the same major version. It also makes future updates easier by needing to simply change the number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With caret:
CleanShot 2024-01-08 at 17 04 16

With only major version:
CleanShot 2024-01-08 at 17 04 03

"@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 @@

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

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

it('registers all graph types', () => {
const keys = Object.keys(Carbon.api);
expect(keys).toBeDefined();
Expand All @@ -48,8 +50,8 @@
});
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 @@
],
};
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 @@
],
};
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

Check failure on line 120 in packages/carbon-graphs/tests/unit/controls/Carbon/Carbon.test.js

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
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 @@
],
};
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 @@
],
};
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 @@
};

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 @@
};

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)

Check failure on line 199 in packages/carbon-graphs/tests/unit/controls/Carbon/Carbon.test.js

View workflow job for this annotation

GitHub Actions / build

Missing semicolon
});
it('registers BubbleMultipleDataset', () => {
const data = {
Expand All @@ -209,9 +213,7 @@
};

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
Loading