Skip to content

Commit

Permalink
Add tests for navbar.util.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-glombik committed Nov 8, 2024
1 parent 29bff33 commit d77bb7e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/test/javascript/spec/util/shared/navbar.util.spec.ts
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

View workflow job for this annotation

GitHub Actions / client-tests

Property 'mockReturnValue' does not exist on type '{ <K extends keyof HTMLElementTagNameMap>(selectors: K): HTMLElementTagNameMap[K] | null; <K extends keyof SVGElementTagNameMap>(selectors: K): SVGElementTagNameMap[K] | null; <K extends keyof MathMLElementTagNameMap>(selectors: K): MathMLElementTagNameMap[K] | null; <K extends keyof HTMLElementDeprecatedTagNameMap>...'.

Check failure on line 16 in src/test/javascript/spec/util/shared/navbar.util.spec.ts

View workflow job for this annotation

GitHub Actions / client-tests-selected

Property 'mockReturnValue' does not exist on type '{ <K extends keyof HTMLElementTagNameMap>(selectors: K): HTMLElementTagNameMap[K] | null; <K extends keyof SVGElementTagNameMap>(selectors: K): SVGElementTagNameMap[K] | null; <K extends keyof MathMLElementTagNameMap>(selectors: K): MathMLElementTagNameMap[K] | null; <K extends keyof HTMLElementDeprecatedTagNameMap>...'.
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

View workflow job for this annotation

GitHub Actions / client-tests

Property 'mockReturnValue' does not exist on type '{ <K extends keyof HTMLElementTagNameMap>(selectors: K): HTMLElementTagNameMap[K] | null; <K extends keyof SVGElementTagNameMap>(selectors: K): SVGElementTagNameMap[K] | null; <K extends keyof MathMLElementTagNameMap>(selectors: K): MathMLElementTagNameMap[K] | null; <K extends keyof HTMLElementDeprecatedTagNameMap>...'.

Check failure on line 29 in src/test/javascript/spec/util/shared/navbar.util.spec.ts

View workflow job for this annotation

GitHub Actions / client-tests-selected

Property 'mockReturnValue' does not exist on type '{ <K extends keyof HTMLElementTagNameMap>(selectors: K): HTMLElementTagNameMap[K] | null; <K extends keyof SVGElementTagNameMap>(selectors: K): SVGElementTagNameMap[K] | null; <K extends keyof MathMLElementTagNameMap>(selectors: K): MathMLElementTagNameMap[K] | null; <K extends keyof HTMLElementDeprecatedTagNameMap>...'.
jest.useFakeTimers();

updateHeaderHeight();

jest.runAllTimers();
expect(setPropertyMock).not.toHaveBeenCalled();
jest.useRealTimers();
});
});

0 comments on commit d77bb7e

Please sign in to comment.