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

Commit

Permalink
Update core tests to work with jest (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdadn authored Jan 10, 2024
1 parent e778263 commit cbd92cc
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 85 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
'**/carbon-graphs/tests/unit/controls/Carbon/(*.)(test.js)',
'**/carbon-graphs/tests/unit/controls/Scatter/(*.)(test.js)',
'**/carbon-graphs/tests/unit/controls/Pie/(*.)(test.js)',
'**/carbon-graphs/tests/unit/core/**/(*.)(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
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ describe('BaseConfig', () => {
beforeEach(() => {
config = new BaseConfig();
});
describe('when consumed', () => {
it('creates interfaces', () => {
expect(config.getConfig).toEqual(jasmine.any(Function));
expect(config.setInput).toEqual(jasmine.any(Function));
expect(config.validateInput).toEqual(jasmine.any(Function));
expect(config.clone).toEqual(jasmine.any(Function));
});
it('creates interfaces when consumed', () => {
expect(typeof config.getConfig).toEqual('function');
expect(typeof config.setInput).toEqual('function');
expect(typeof config.validateInput).toEqual('function');
expect(typeof config.clone).toEqual('function');
});
it('throws error when getInput is called without being implemented', () => {
expect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ describe('Construct', () => {
content = new Construct();
});
describe('when consumed', () => {
it('creates interfaces', () => {
expect(content.generate).toEqual(jasmine.any(Function));
expect(content.loadContent).toEqual(jasmine.any(Function));
expect(content.unloadContent).toEqual(jasmine.any(Function));
expect(content.resize).toEqual(jasmine.any(Function));
expect(content.destroy).toEqual(jasmine.any(Function));
it('creates interfaces when consumed', () => {
expect(typeof content.generate).toEqual('function');
expect(typeof content.loadContent).toEqual('function');
expect(typeof content.unloadContent).toEqual('function');
expect(typeof content.resize).toEqual('function');
expect(typeof content.destroy).toEqual('function');
});
it('throws error when generate is called without being implemented', () => {
expect(() => {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

import { GraphContent } from '../../../../src/js/core';
import errors from '../../../../src/js/helpers/errors';

describe('GraphContent - when consumed', () => {
let content = null;
beforeEach(() => {
content = new GraphContent();
});
it('creates interfaces', () => {
expect(typeof content.load).toEqual('function');
expect(typeof content.unload).toEqual('function');
expect(typeof content.resize).toEqual('function');
expect(typeof content.redraw).toEqual('function');
});
it('throws error when load is called without being implemented', () => {
expect(() => {
content.load();
}).toThrowError(errors.THROW_MSG_CONTENT_LOAD_NOT_IMPLEMENTED);
});
it('throws error when unload is called without being implemented', () => {
expect(() => {
content.unload();
}).toThrowError(errors.THROW_MSG_CONTENT_UNLOAD_NOT_IMPLEMENTED);
});
it('throws error when resize is called without being implemented', () => {
expect(() => {
content.resize();
}).toThrowError(errors.THROW_MSG_CONTENT_RESIZE_NOT_IMPLEMENTED);
});
it('throws error when redraw is called without being implemented', () => {
expect(() => {
content.redraw();
}).toThrowError(errors.THROW_MSG_CONTENT_REDRAW_NOT_IMPLEMENTED);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@ describe('Shape', () => {
const shapePath = groupSVG.firstChild;
expect(shapeSVG.nodeName === 'svg').toBeTruthy();
expect(toNumber(shapeSVG.getAttribute('x')) === SHAPES[i].options.x).toBeTruthy();
expect(
toNumber(shapeSVG.getAttribute('y')) === SHAPES[i].options.y,
).toBeTruthy();
expect(toNumber(shapeSVG.getAttribute('y')) === SHAPES[i].options.y).toBeTruthy();
expect(shapeSVG.classList.contains(styles.svgIcon)).toBeTruthy();
expect(shapeSVG.getAttribute('role') === 'img').toBeTruthy();
expect(shapePath.nodeName === 'path').toBeTruthy();
expect(
shapePath.getAttribute('d') === SHAPES[i].path.d,
).toBeTruthy();
expect(shapePath.getAttribute('d') === SHAPES[i].path.d).toBeTruthy();
});
});
it('returns path for Carbon Native shapes - Light', () => {
Expand All @@ -41,9 +37,7 @@ describe('Shape', () => {
expect(shapeSVG.classList.contains(styles.svgIcon)).toBeTruthy();
expect(shapeSVG.getAttribute('role') === 'img').toBeTruthy();
expect(shapePath.nodeName).toBeDefined();
expect(shapeSVG.querySelector('[fill]').getAttribute('fill')).toBe(
'#FFF',
);
expect(shapeSVG.querySelector('[fill]').getAttribute('fill')).toBe('#FFF');
});
});
it('returns path for custom shape', () => {
Expand Down Expand Up @@ -159,9 +153,7 @@ describe('Shape', () => {
],
options: { x: -15, y: -15, scale: 0.28 },
};
const shapeSVG = new Shape(customShape).getShapeElement(
getDefaultSVGProps({ transformFn: transformHandlerSpy }),
);
const shapeSVG = new Shape(customShape).getShapeElement(getDefaultSVGProps({ transformFn: transformHandlerSpy }));
expect(shapeSVG.nodeName === 'svg').toBeTruthy();
expect(shapeSVG.firstChild.getAttribute('transform')).toBeDefined();
expect(transformHandlerSpy.calledOnce).toBeTruthy();
Expand All @@ -170,30 +162,22 @@ describe('Shape', () => {
it('tear drop', () => {
const shapeSVG = new Shape(SHAPES.TEAR_DROP).getShapeElement();
const groupSVG = shapeSVG.firstChild;
expect(groupSVG.firstChild.getAttribute('d')).toBe(
SHAPES.TEAR_DROP.path.d,
);
expect(groupSVG.firstChild.getAttribute('d')).toBe(SHAPES.TEAR_DROP.path.d);
});
it('tear drop alternate', () => {
const shapeSVG = new Shape(SHAPES.TEAR_ALT).getShapeElement();
const groupSVG = shapeSVG.firstChild;
expect(groupSVG.firstChild.getAttribute('d')).toBe(
SHAPES.TEAR_ALT.path.d,
);
expect(groupSVG.firstChild.getAttribute('d')).toBe(SHAPES.TEAR_ALT.path.d);
});
it('triangle alternate', () => {
const shapeSVG = new Shape(SHAPES.TRIANGLE_DOWN).getShapeElement();
const groupSVG = shapeSVG.firstChild;
expect(groupSVG.firstChild.getAttribute('d')).toBe(
SHAPES.TRIANGLE_DOWN.path.d,
);
expect(groupSVG.firstChild.getAttribute('d')).toBe(SHAPES.TRIANGLE_DOWN.path.d);
});
it('triangle', () => {
const shapeSVG = new Shape(SHAPES.TRIANGLE).getShapeElement();
const groupSVG = shapeSVG.firstChild;
expect(groupSVG.firstChild.getAttribute('d')).toBe(
SHAPES.TRIANGLE.path.d,
);
expect(groupSVG.firstChild.getAttribute('d')).toBe(SHAPES.TRIANGLE.path.d);
});
it('x shape', () => {
const shapeSVG = new Shape(SHAPES.X).getShapeElement();
Expand All @@ -203,23 +187,17 @@ describe('Shape', () => {
it('rhombus shape', () => {
const shapeSVG = new Shape(SHAPES.RHOMBUS).getShapeElement();
const groupSVG = shapeSVG.firstChild;
expect(groupSVG.firstChild.getAttribute('d')).toBe(
SHAPES.RHOMBUS.path.d,
);
expect(groupSVG.firstChild.getAttribute('d')).toBe(SHAPES.RHOMBUS.path.d);
});
it('vertical bar shape', () => {
const shapeSVG = new Shape(SHAPES.VERTICAL_BAR).getShapeElement();
const groupSVG = shapeSVG.firstChild;
expect(groupSVG.firstChild.getAttribute('d')).toBe(
SHAPES.VERTICAL_BAR.path.d,
);
expect(groupSVG.firstChild.getAttribute('d')).toBe(SHAPES.VERTICAL_BAR.path.d);
});
it('square shape', () => {
const shapeSVG = new Shape(SHAPES.SQUARE).getShapeElement();
const groupSVG = shapeSVG.firstChild;
expect(groupSVG.firstChild.getAttribute('d')).toBe(
SHAPES.SQUARE.path.d,
);
expect(groupSVG.firstChild.getAttribute('d')).toBe(SHAPES.SQUARE.path.d);
});
});
describe('Validates a shape', () => {
Expand Down

0 comments on commit cbd92cc

Please sign in to comment.