-
Notifications
You must be signed in to change notification settings - Fork 303
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
29bff33
commit d77bb7e
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
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,38 @@ | ||
import { updateHeaderHeight } from 'app/shared/util/navbar.util'; | ||
|
||
describe('updateHeaderHeight', () => { | ||
document.querySelector = jest.fn(); | ||
const setPropertyMock = jest.fn(); | ||
document.documentElement.style.setProperty = setPropertyMock; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should update the --header-height variable based on the navbar height', () => { | ||
const mockNavbar = { | ||
getBoundingClientRect: jest.fn(() => ({ height: 80 })), | ||
}; | ||
document.querySelector.mockReturnValue(mockNavbar); | ||
Check failure on line 16 in src/test/javascript/spec/util/shared/navbar.util.spec.ts GitHub Actions / client-tests
Check failure on line 16 in src/test/javascript/spec/util/shared/navbar.util.spec.ts GitHub Actions / client-tests-selected
|
||
jest.useFakeTimers(); | ||
|
||
updateHeaderHeight(); | ||
|
||
jest.runAllTimers(); | ||
expect(document.querySelector).toHaveBeenCalledWith('jhi-navbar'); | ||
expect(mockNavbar.getBoundingClientRect).toHaveBeenCalled(); | ||
expect(setPropertyMock).toHaveBeenCalledWith('--header-height', '80px'); | ||
jest.useRealTimers(); | ||
}); | ||
|
||
it('should not update --header-height if navbar is not found', () => { | ||
document.querySelector.mockReturnValue(null); | ||
Check failure on line 29 in src/test/javascript/spec/util/shared/navbar.util.spec.ts GitHub Actions / client-tests
Check failure on line 29 in src/test/javascript/spec/util/shared/navbar.util.spec.ts GitHub Actions / client-tests-selected
|
||
jest.useFakeTimers(); | ||
|
||
updateHeaderHeight(); | ||
|
||
jest.runAllTimers(); | ||
expect(setPropertyMock).not.toHaveBeenCalled(); | ||
jest.useRealTimers(); | ||
}); | ||
}); |