From cb9a5677d5375856a514fd07e7c0278388987c53 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 6 Apr 2022 10:30:11 +0200 Subject: [PATCH] catalog-graph: move SVG mocks to test setup Signed-off-by: Patrik Oldsberg --- .../CatalogGraphCard/CatalogGraphCard.test.tsx | 7 ------- .../CatalogGraphPage/CatalogGraphPage.test.tsx | 15 --------------- .../EntityRelationsGraph/CustomNode.test.tsx | 7 ------- .../EntityRelationsGraph.test.tsx | 7 ------- plugins/catalog-graph/src/setupTests.ts | 14 ++++++++++++++ 5 files changed, 14 insertions(+), 36 deletions(-) diff --git a/plugins/catalog-graph/src/components/CatalogGraphCard/CatalogGraphCard.test.tsx b/plugins/catalog-graph/src/components/CatalogGraphCard/CatalogGraphCard.test.tsx index eb65f77242..f3717f8b70 100644 --- a/plugins/catalog-graph/src/components/CatalogGraphCard/CatalogGraphCard.test.tsx +++ b/plugins/catalog-graph/src/components/CatalogGraphCard/CatalogGraphCard.test.tsx @@ -39,13 +39,6 @@ describe('', () => { let catalog: jest.Mocked; let apis: TestApiRegistry; - beforeAll(() => { - Object.defineProperty(window.SVGElement.prototype, 'getBBox', { - value: () => ({ width: 100, height: 100 }), - configurable: true, - }); - }); - beforeEach(() => { entity = { apiVersion: 'a', diff --git a/plugins/catalog-graph/src/components/CatalogGraphPage/CatalogGraphPage.test.tsx b/plugins/catalog-graph/src/components/CatalogGraphPage/CatalogGraphPage.test.tsx index fc5676e7c9..eb31e07a65 100644 --- a/plugins/catalog-graph/src/components/CatalogGraphPage/CatalogGraphPage.test.tsx +++ b/plugins/catalog-graph/src/components/CatalogGraphPage/CatalogGraphPage.test.tsx @@ -40,21 +40,6 @@ describe('', () => { let wrapper: JSX.Element; let catalog: jest.Mocked; - beforeAll(() => { - Object.defineProperty(window.SVGElement.prototype, 'getBBox', { - value: () => ({ width: 100, height: 100 }), - configurable: true, - }); - Object.defineProperty(window.SVGElement.prototype, 'viewBox', { - value: { baseVal: { x: 0, y: 0, width: 100, height: 100 } }, - configurable: true, - }); - Object.defineProperty(window.MouseEvent.prototype, 'view', { - value: window, - configurable: true, - }); - }); - beforeEach(() => { const entityC = { apiVersion: 'a', diff --git a/plugins/catalog-graph/src/components/EntityRelationsGraph/CustomNode.test.tsx b/plugins/catalog-graph/src/components/EntityRelationsGraph/CustomNode.test.tsx index 7602f4558d..6e034db2b6 100644 --- a/plugins/catalog-graph/src/components/EntityRelationsGraph/CustomNode.test.tsx +++ b/plugins/catalog-graph/src/components/EntityRelationsGraph/CustomNode.test.tsx @@ -19,13 +19,6 @@ import { CustomNode } from './CustomNode'; import userEvent from '@testing-library/user-event'; describe('', () => { - beforeAll(() => { - Object.defineProperty(window.SVGElement.prototype, 'getBBox', { - value: () => ({ width: 100, height: 100 }), - configurable: true, - }); - }); - test('renders node', async () => { const { getByText } = await renderInTestApp( diff --git a/plugins/catalog-graph/src/components/EntityRelationsGraph/EntityRelationsGraph.test.tsx b/plugins/catalog-graph/src/components/EntityRelationsGraph/EntityRelationsGraph.test.tsx index 8c8898a734..187c23f967 100644 --- a/plugins/catalog-graph/src/components/EntityRelationsGraph/EntityRelationsGraph.test.tsx +++ b/plugins/catalog-graph/src/components/EntityRelationsGraph/EntityRelationsGraph.test.tsx @@ -33,13 +33,6 @@ describe('', () => { let catalog: jest.Mocked; const CUSTOM_TEST_ID = 'custom-test-id'; - beforeAll(() => { - Object.defineProperty(window.SVGElement.prototype, 'getBBox', { - value: () => ({ width: 100, height: 100 }), - configurable: true, - }); - }); - beforeEach(() => { const entities: { [ref: string]: Entity } = { 'b:d/c': { diff --git a/plugins/catalog-graph/src/setupTests.ts b/plugins/catalog-graph/src/setupTests.ts index 7435872609..ef0d01c64c 100644 --- a/plugins/catalog-graph/src/setupTests.ts +++ b/plugins/catalog-graph/src/setupTests.ts @@ -14,3 +14,17 @@ * limitations under the License. */ import '@testing-library/jest-dom'; + +// Common mocks needed for SVG and D3 rendering +Object.defineProperty(window.SVGElement.prototype, 'getBBox', { + value: () => ({ width: 100, height: 100 }), + configurable: true, +}); +Object.defineProperty(window.SVGElement.prototype, 'viewBox', { + value: { baseVal: { x: 0, y: 0, width: 100, height: 100 } }, + configurable: true, +}); +Object.defineProperty(window.MouseEvent.prototype, 'view', { + value: window, + configurable: true, +});