Skip to content

Commit

Permalink
useCheckOverflow Tests (#1909)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Apr 11, 2024
1 parent 36d4134 commit ae099ca
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions packages/react-hooks/src/useCheckOverflow.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { act, renderHook } from '@testing-library/react-hooks';
import type { DOMRefValue } from '@react-types/shared';
import { TestUtils } from '@deephaven/utils';
import { useCheckOverflow } from './useCheckOverflow';

const { createMockProxy } = TestUtils;

beforeEach(() => {
jest.clearAllMocks();
expect.hasAssertions();
});

describe('useCheckOverflow', () => {
const isOverflowing = createMockProxy<HTMLDivElement>({
scrollWidth: 101,
offsetWidth: 100,
});

const scrollWidthMatchesOffsetWidth = createMockProxy<HTMLDivElement>({
scrollWidth: 100,
offsetWidth: 100,
});

const offsetWidthGreaterThanScrollWidth = createMockProxy<HTMLDivElement>({
scrollWidth: 99,
offsetWidth: 100,
});

it.each([
[isOverflowing, true],
[scrollWidthMatchesOffsetWidth, false],
[offsetWidthGreaterThanScrollWidth, false],
])(
'should check if a Spectrum `DOMRefValue` is overflowing',
(el, expected) => {
const { result } = renderHook(() => useCheckOverflow());

const elRef = createMockProxy<DOMRefValue<HTMLDivElement>>({
UNSAFE_getDOMNode: () => createMockProxy<HTMLDivElement>(el),
});

act(() => {
result.current.checkOverflow(elRef);
});

expect(result.current.isOverflowing).toBe(expected);

act(() => {
result.current.resetIsOverflowing();
});

expect(result.current.isOverflowing).toBe(false);
}
);
});

0 comments on commit ae099ca

Please sign in to comment.