From ae099ca0864c02e53311a8087bfae5e57369c3e3 Mon Sep 17 00:00:00 2001 From: Brian Ingles Date: Wed, 10 Apr 2024 15:51:46 -0500 Subject: [PATCH] useCheckOverflow Tests (#1909) --- .../react-hooks/src/useCheckOverflow.test.ts | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 packages/react-hooks/src/useCheckOverflow.test.ts diff --git a/packages/react-hooks/src/useCheckOverflow.test.ts b/packages/react-hooks/src/useCheckOverflow.test.ts new file mode 100644 index 0000000000..35c2eb38df --- /dev/null +++ b/packages/react-hooks/src/useCheckOverflow.test.ts @@ -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({ + scrollWidth: 101, + offsetWidth: 100, + }); + + const scrollWidthMatchesOffsetWidth = createMockProxy({ + scrollWidth: 100, + offsetWidth: 100, + }); + + const offsetWidthGreaterThanScrollWidth = createMockProxy({ + 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>({ + UNSAFE_getDOMNode: () => createMockProxy(el), + }); + + act(() => { + result.current.checkOverflow(elRef); + }); + + expect(result.current.isOverflowing).toBe(expected); + + act(() => { + result.current.resetIsOverflowing(); + }); + + expect(result.current.isOverflowing).toBe(false); + } + ); +});