From 99a0f63df9799100f4b50f2468e870937983a913 Mon Sep 17 00:00:00 2001 From: Saad <38024451+sdadn@users.noreply.github.com> Date: Wed, 10 Jan 2024 16:21:18 -0600 Subject: [PATCH] updated tests --- jest.config.js | 1 + .../tests/unit/core/Config/Config.test.js | 12 ++--- .../unit/core/Construct/Construct.test.js | 12 ++--- .../core/GraphContent/GraphContent.test.js | 54 +++++++++---------- .../tests/unit/core/Shape/Shape.test.js | 44 ++++----------- 5 files changed, 49 insertions(+), 74 deletions(-) diff --git a/jest.config.js b/jest.config.js index 927e4dc6b..4f477a72e 100644 --- a/jest.config.js +++ b/jest.config.js @@ -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)', diff --git a/packages/carbon-graphs/tests/unit/core/Config/Config.test.js b/packages/carbon-graphs/tests/unit/core/Config/Config.test.js index bfd2fe02a..74aa98036 100644 --- a/packages/carbon-graphs/tests/unit/core/Config/Config.test.js +++ b/packages/carbon-graphs/tests/unit/core/Config/Config.test.js @@ -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(() => { diff --git a/packages/carbon-graphs/tests/unit/core/Construct/Construct.test.js b/packages/carbon-graphs/tests/unit/core/Construct/Construct.test.js index 11e38be6e..1e2757c5b 100644 --- a/packages/carbon-graphs/tests/unit/core/Construct/Construct.test.js +++ b/packages/carbon-graphs/tests/unit/core/Construct/Construct.test.js @@ -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(() => { diff --git a/packages/carbon-graphs/tests/unit/core/GraphContent/GraphContent.test.js b/packages/carbon-graphs/tests/unit/core/GraphContent/GraphContent.test.js index 8fbefc29a..62338b730 100644 --- a/packages/carbon-graphs/tests/unit/core/GraphContent/GraphContent.test.js +++ b/packages/carbon-graphs/tests/unit/core/GraphContent/GraphContent.test.js @@ -3,37 +3,35 @@ import { GraphContent } from '../../../../src/js/core'; import errors from '../../../../src/js/helpers/errors'; -describe('GraphContent', () => { +describe('GraphContent - when consumed', () => { let content = null; beforeEach(() => { content = new GraphContent(); }); - describe('when consumed', () => { - it('creates interfaces', () => { - expect(content.load).toEqual(jasmine.any(Function)); - expect(content.unload).toEqual(jasmine.any(Function)); - expect(content.resize).toEqual(jasmine.any(Function)); - expect(content.redraw).toEqual(jasmine.any(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); - }); + 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); }); }); diff --git a/packages/carbon-graphs/tests/unit/core/Shape/Shape.test.js b/packages/carbon-graphs/tests/unit/core/Shape/Shape.test.js index f0618c9ab..db5f7e739 100644 --- a/packages/carbon-graphs/tests/unit/core/Shape/Shape.test.js +++ b/packages/carbon-graphs/tests/unit/core/Shape/Shape.test.js @@ -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', () => { @@ -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', () => { @@ -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(); @@ -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(); @@ -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', () => {