Skip to content

Commit

Permalink
fix: tooltip unit test (#532)
Browse files Browse the repository at this point in the history
* fix: tooltip unit test

* fix: satisfy git build

* fix: for git build

* fix: manage resetPdfWorker

* fix: pr feedback

---------

Co-authored-by: DORIAN MILLER <[email protected]>
  • Loading branch information
dorianmiller and drdorianm authored Sep 19, 2023
1 parent 8033a29 commit 288e429
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ import CIDocument from '../CIDocument';
import purchaseOrder from '../__fixtures__/po-index_op.json';
import invoice from '../__fixtures__/invoice-index_op.json';
import shortContract from '../__fixtures__/shortenedContract.json';
import { defineDOMRect, removeDOMRect } from 'setupTestsUtil';

beforeAll(() => {
defineDOMRect();
});
afterAll(() => {
removeDOMRect();
});

describe('<CIDocument />', () => {
describe('Invoice Document', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ import { screen, act, render } from '@testing-library/react';
import 'utils/test/createRange.mock';
import Section from '../Section';
import sectionData from '../__fixtures__/sectionData';
import { defineDOMRect, removeDOMRect } from 'setupTestsUtil';

describe('<Section />', () => {
beforeEach(() => {
defineDOMRect();
});
afterEach(() => {
removeDOMRect();
});
it('renders section HTML', async () => {
const data = {
html: '<p class="foobar">Here I am!</p>',
Expand Down
38 changes: 38 additions & 0 deletions packages/discovery-react-components/src/setupTestsUtil.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Helper functions to acount for DOMRect
// guidance https://stackoverflow.com/questions/71521976/referenceerror-domrect-is-not-defined
// globalThis https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
export function defineDOMRect() {
globalThis.DOMRect = class DOMRect {
x: number = 0;
y: number = 0;
bottom: number = 0;
left: number = 0;
right: number = 0;
top: number = 0;
width: number = 0;
height: number = 0;
constructor(
x: number | undefined = 0,
y: number | undefined = 0,
width: number | undefined = 0,
height: number | undefined = 0
) {
this.top = x;
this.bottom = y + height;
this.right = x + width;
this.left = x;
this.width = width;
this.height = height;
}
static fromRect(other: DOMRectInit): DOMRect {
return new DOMRect(other.x, other.y, other.width, other.height);
}
toJSON() {
return JSON.stringify(this);
}
};
}

export function removeDOMRect() {
delete globalThis.DOMRect;
}

0 comments on commit 288e429

Please sign in to comment.