diff --git a/frontend/src/components/HomeComponents/Footer/Footer.tsx b/frontend/src/components/HomeComponents/Footer/Footer.tsx
index 4c136e9e..57885deb 100644
--- a/frontend/src/components/HomeComponents/Footer/Footer.tsx
+++ b/frontend/src/components/HomeComponents/Footer/Footer.tsx
@@ -2,6 +2,7 @@ import { HighlightLink } from '@/components/ui/link-highlight';
import logo from '../../../assets/logo.png';
import logoLight from '../../../assets/logo_light.png';
import { url } from '@/components/utils/URLs';
+import { handleLogoClick } from '@/components/utils/utils';
export const Footer = () => {
return (
@@ -12,7 +13,8 @@ export const Footer = () => {
{
'logo-path');
jest.mock('../../../../assets/logo_light.png', () => 'logo-light-path');
@@ -29,3 +30,21 @@ describe('Footer component using Snapshot', () => {
expect(asFragment()).toMatchSnapshot();
});
});
+
+describe('Footer logo click handler', () => {
+ test('should call handleLogoClick when logo link is clicked', () => {
+ const handleLogoClickSpy = jest.spyOn(utils, 'handleLogoClick');
+ render();
+
+ const logoLinks = screen.getAllByRole('link');
+ const logoLink = logoLinks.find(
+ (link) => link.getAttribute('href') === '#'
+ );
+
+ expect(logoLink).toBeDefined();
+ fireEvent.click(logoLink!);
+ expect(handleLogoClickSpy).toHaveBeenCalledTimes(1);
+
+ handleLogoClickSpy.mockRestore();
+ });
+});
diff --git a/frontend/src/components/HomeComponents/Footer/__tests__/__snapshots__/Footer.test.tsx.snap b/frontend/src/components/HomeComponents/Footer/__tests__/__snapshots__/Footer.test.tsx.snap
index 486d842d..3905dec3 100644
--- a/frontend/src/components/HomeComponents/Footer/__tests__/__snapshots__/Footer.test.tsx.snap
+++ b/frontend/src/components/HomeComponents/Footer/__tests__/__snapshots__/Footer.test.tsx.snap
@@ -16,7 +16,7 @@ exports[`Footer component using Snapshot renders correctly 1`] = `
>
({
@@ -65,3 +66,21 @@ describe('Navbar component using snapshot', () => {
expect(asFragment()).toMatchSnapshot();
});
});
+
+describe('Navbar logo click handler', () => {
+ test('should call handleLogoClick when logo link is clicked', () => {
+ const handleLogoClickSpy = jest.spyOn(utils, 'handleLogoClick');
+ render();
+
+ const logoLinks = screen.getAllByRole('link');
+ const logoLink = logoLinks.find(
+ (link) => link.getAttribute('href') === '#'
+ );
+
+ expect(logoLink).toBeDefined();
+ fireEvent.click(logoLink!);
+ expect(handleLogoClickSpy).toHaveBeenCalledTimes(1);
+
+ handleLogoClickSpy.mockRestore();
+ });
+});
diff --git a/frontend/src/components/HomeComponents/Navbar/__tests__/__snapshots__/Navbar.test.tsx.snap b/frontend/src/components/HomeComponents/Navbar/__tests__/__snapshots__/Navbar.test.tsx.snap
index 8f6900e4..dfcdccf9 100644
--- a/frontend/src/components/HomeComponents/Navbar/__tests__/__snapshots__/Navbar.test.tsx.snap
+++ b/frontend/src/components/HomeComponents/Navbar/__tests__/__snapshots__/Navbar.test.tsx.snap
@@ -24,7 +24,7 @@ exports[`Navbar component using snapshot renders correctly 1`] = `
>
{
+ let mockEvent: Partial>;
+ let reloadMock: jest.Mock;
+
+ beforeEach(() => {
+ mockEvent = {
+ preventDefault: jest.fn(),
+ };
+
+ // Mock reload using Object.defineProperty
+ reloadMock = jest.fn();
+ Object.defineProperty(window, 'location', {
+ value: { reload: reloadMock },
+ writable: true,
+ });
+ });
+
+ it('should call preventDefault on the event', () => {
+ handleLogoClick(mockEvent as MouseEvent);
+
+ expect(mockEvent.preventDefault).toHaveBeenCalledTimes(1);
+ });
+
+ it('should reload the page', () => {
+ handleLogoClick(mockEvent as MouseEvent);
+
+ expect(reloadMock).toHaveBeenCalledTimes(1);
+ });
+
+ it('should call preventDefault before reloading', () => {
+ const callOrder: string[] = [];
+
+ mockEvent.preventDefault = jest.fn(() => {
+ callOrder.push('preventDefault');
+ });
+
+ reloadMock.mockImplementation(() => {
+ callOrder.push('reload');
+ });
+
+ handleLogoClick(mockEvent as MouseEvent);
+
+ expect(callOrder).toEqual(['preventDefault', 'reload']);
+ });
+});
diff --git a/frontend/src/components/utils/utils.ts b/frontend/src/components/utils/utils.ts
index a47bd6cb..612db1e3 100644
--- a/frontend/src/components/utils/utils.ts
+++ b/frontend/src/components/utils/utils.ts
@@ -1,4 +1,5 @@
import { type ClassValue, clsx } from 'clsx';
+import type { MouseEvent } from 'react';
import { twMerge } from 'tailwind-merge';
export function cn(...inputs: ClassValue[]) {
@@ -19,3 +20,8 @@ export function debounce void>(
export const getStartOfDay = (date: Date) => {
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
};
+
+export const handleLogoClick = (e: MouseEvent) => {
+ e.preventDefault();
+ window.location.reload();
+};