Skip to content

Commit 288e429

Browse files
fix: tooltip unit test (#532)
* fix: tooltip unit test * fix: satisfy git build * fix: for git build * fix: manage resetPdfWorker * fix: pr feedback --------- Co-authored-by: DORIAN MILLER <millerbd@us.ibm.com>
1 parent 8033a29 commit 288e429

4 files changed

Lines changed: 53 additions & 0 deletions

File tree

packages/discovery-react-components/src/components/CIDocument/components/CIDocument/__tests__/CIDocument.spec.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ import CIDocument from '../CIDocument';
1616
import purchaseOrder from '../__fixtures__/po-index_op.json';
1717
import invoice from '../__fixtures__/invoice-index_op.json';
1818
import shortContract from '../__fixtures__/shortenedContract.json';
19+
import { defineDOMRect, removeDOMRect } from 'setupTestsUtil';
20+
21+
beforeAll(() => {
22+
defineDOMRect();
23+
});
24+
afterAll(() => {
25+
removeDOMRect();
26+
});
1927

2028
describe('<CIDocument />', () => {
2129
describe('Invoice Document', () => {

packages/discovery-react-components/src/components/CIDocument/components/Section/__tests__/Section.spec.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@ import { screen, act, render } from '@testing-library/react';
33
import 'utils/test/createRange.mock';
44
import Section from '../Section';
55
import sectionData from '../__fixtures__/sectionData';
6+
import { defineDOMRect, removeDOMRect } from 'setupTestsUtil';
67

78
describe('<Section />', () => {
9+
beforeEach(() => {
10+
defineDOMRect();
11+
});
12+
afterEach(() => {
13+
removeDOMRect();
14+
});
815
it('renders section HTML', async () => {
916
const data = {
1017
html: '<p class="foobar">Here I am!</p>',

packages/discovery-react-components/src/setupTests.ts renamed to packages/discovery-react-components/src/setupTests.tsx

File renamed without changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Helper functions to acount for DOMRect
2+
// guidance https://stackoverflow.com/questions/71521976/referenceerror-domrect-is-not-defined
3+
// globalThis https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
4+
export function defineDOMRect() {
5+
globalThis.DOMRect = class DOMRect {
6+
x: number = 0;
7+
y: number = 0;
8+
bottom: number = 0;
9+
left: number = 0;
10+
right: number = 0;
11+
top: number = 0;
12+
width: number = 0;
13+
height: number = 0;
14+
constructor(
15+
x: number | undefined = 0,
16+
y: number | undefined = 0,
17+
width: number | undefined = 0,
18+
height: number | undefined = 0
19+
) {
20+
this.top = x;
21+
this.bottom = y + height;
22+
this.right = x + width;
23+
this.left = x;
24+
this.width = width;
25+
this.height = height;
26+
}
27+
static fromRect(other: DOMRectInit): DOMRect {
28+
return new DOMRect(other.x, other.y, other.width, other.height);
29+
}
30+
toJSON() {
31+
return JSON.stringify(this);
32+
}
33+
};
34+
}
35+
36+
export function removeDOMRect() {
37+
delete globalThis.DOMRect;
38+
}

0 commit comments

Comments
 (0)