-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8aed197
commit 75a56ad
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
packages/hooks/src/__tests__/useSetContainerHeight.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { renderHook } from "@testing-library/react-hooks"; | ||
import useSetContainerHeight from "../useSetContainerHeight"; | ||
import { useReactiveHeight } from "../useReactiveSize"; | ||
|
||
|
||
describe("useSetContainerHeight", () => { | ||
const componentID = 'testComponent'; | ||
|
||
beforeAll(() => { | ||
const mockElement = document.createElement('div'); | ||
mockElement.id = componentID; | ||
|
||
mockElement.getBoundingClientRect = jest.fn().mockReturnValue({ top: 100 }); | ||
|
||
document.body.appendChild(mockElement); | ||
|
||
global.document.getElementById = jest.fn((id) => { | ||
if (id === componentID) { | ||
return mockElement; | ||
} | ||
return null; | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
const mockElement = document.getElementById(componentID); | ||
if (mockElement) { | ||
document.body.removeChild(mockElement); | ||
} | ||
}); | ||
|
||
it("calculates container height correctly based on window height", () => { | ||
const { result: windowHeightResult } = renderHook(() => | ||
useReactiveHeight(), | ||
); | ||
const windowHeight = windowHeightResult.current; | ||
|
||
const { result } = renderHook(() => useSetContainerHeight(componentID)); | ||
|
||
const expectedHeight = windowHeight - 100; | ||
|
||
expect(result.current.containerHeight).toBe(expectedHeight); | ||
}); | ||
}); |