From 527203c635f49cd5d806ab5972516797658b5181 Mon Sep 17 00:00:00 2001 From: m-tartari <37861893+m-tartari@users.noreply.github.com> Date: Mon, 9 Feb 2026 16:16:29 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test:=20fix=20failing=20unit=20test?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.test.tsx | 11 +- .../atoms/IconLinks/IconLinks.test.tsx | 4 +- src/components/atoms/IconLinks/index.tsx | 2 +- .../CookieConsent/CookieConsent.test.tsx | 2 - .../CookiePreferences.test.tsx | 89 ----------- .../molecules/CookiePreferences/index.tsx | 2 +- .../molecules/Footer/Footer.test.tsx | 12 +- .../PrivacyPolicy/PrivacyPolicy.test.tsx | 11 +- .../molecules/PrivacyPolicy/index.tsx | 146 +++++++++--------- .../BusinessCardPage.test.tsx | 24 ++- .../pages/ContactPage/ContactPage.test.tsx | 9 +- .../pages/ErrorPage/ErrorPage.test.tsx | 7 - .../pages/MainPage/MainPage.test.tsx | 17 +- src/components/pages/MainPage/MainPage.tsx | 4 +- .../pages/PeoplePage/PeoplePage.test.tsx | 19 +-- .../pages/PrivacyPage/PrivacyPage.test.tsx | 16 +- src/components/templates/Page/Page.test.tsx | 9 +- 17 files changed, 104 insertions(+), 280 deletions(-) delete mode 100644 src/components/molecules/CookiePreferences/CookiePreferences.test.tsx diff --git a/src/App.test.tsx b/src/App.test.tsx index 2710b73..0ae3b8b 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -1,20 +1,13 @@ import { render, screen } from '@testing-library/react' -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { useAnalytics } from 'use-analytics' -import App from './App' - -// Mock the analytics module -vi.mock('use-analytics', () => ({ - useAnalytics: () => ({ plugins: { enable: vi.fn(), disable: vi.fn() }, page: vi.fn() }), -})) +import App from './App.js' describe('App component', () => { test('renders MainPage without crashing', async () => { render() expect(screen.getByLabelText('loading-screen')).toBeInTheDocument() - expect(await screen.findByText('Robotics Engineer')).toBeInTheDocument() + expect(await screen.findByText("Compagnia d'Arme del Santo Luca")).toBeInTheDocument() expect(screen.queryByLabelText('loading-screen')).not.toBeInTheDocument() }) }) diff --git a/src/components/atoms/IconLinks/IconLinks.test.tsx b/src/components/atoms/IconLinks/IconLinks.test.tsx index efef427..bbaeee2 100644 --- a/src/components/atoms/IconLinks/IconLinks.test.tsx +++ b/src/components/atoms/IconLinks/IconLinks.test.tsx @@ -7,8 +7,8 @@ import * as IconLinks from './index.js' const labels: { [key: string]: string } = { DescriptionIconLink: 'Doc-button', EmailIconLink: 'Email-button', - GitHubIconLink: 'GitHub-button', - LinkedInIconLink: 'LinkedIn-button', + InstagramIconLink: 'Instagram-button', + FacebookIconLink: 'Facebook-button', AcademyIconLink: 'Academy-button', VideoIconLink: 'Video-button', ExternalIconLink: 'External-link-button', diff --git a/src/components/atoms/IconLinks/index.tsx b/src/components/atoms/IconLinks/index.tsx index 8cad0f6..e59f59b 100644 --- a/src/components/atoms/IconLinks/index.tsx +++ b/src/components/atoms/IconLinks/index.tsx @@ -56,7 +56,7 @@ const IconWrapper: React.FC = ({ index, fontSize, Icon, sx, .. export const DescriptionIconLink = (props: IconLinkProps) => export const EmailIconLink = (props: IconLinkProps) => export const InstagramIconLink = (props: IconLinkProps) => -export const FacebookIconLink = (props: IconLinkProps) => +export const FacebookIconLink = (props: IconLinkProps) => export const AcademyIconLink = (props: IconLinkProps) => export const VideoIconLink = (props: IconLinkProps) => export const ExternalIconLink = (props: IconLinkProps) => diff --git a/src/components/molecules/CookieConsent/CookieConsent.test.tsx b/src/components/molecules/CookieConsent/CookieConsent.test.tsx index 42e707c..e5e2ac9 100644 --- a/src/components/molecules/CookieConsent/CookieConsent.test.tsx +++ b/src/components/molecules/CookieConsent/CookieConsent.test.tsx @@ -1,6 +1,4 @@ import { render, screen, fireEvent } from '@testing-library/react' -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { useAnalytics } from 'use-analytics' import CookieConsent from './index.js' diff --git a/src/components/molecules/CookiePreferences/CookiePreferences.test.tsx b/src/components/molecules/CookiePreferences/CookiePreferences.test.tsx deleted file mode 100644 index ef3115b..0000000 --- a/src/components/molecules/CookiePreferences/CookiePreferences.test.tsx +++ /dev/null @@ -1,89 +0,0 @@ -import { screen, fireEvent } from '@testing-library/react' -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { useAnalytics } from 'use-analytics' - -import { renderWithRouter as render } from 'components/utils/tests/index.js' - -import CookiePreferences from './index.js' - -// Mock the analytics module -const analytics = { plugins: { enable: vi.fn(), disable: vi.fn() } } -vi.mock('use-analytics', () => ({ - useAnalytics: () => analytics, -})) - -// Mock localStorage -const localStorageMock = (() => { - let store: Record = {} - return { - getItem: vi.fn((key: string) => store[key] || null), - setItem: vi.fn((key: string, value: string) => { - store[key] = value - }), - clear: vi.fn(() => { - store = {} - }), - } -})() - -Object.defineProperty(window, 'localStorage', { value: localStorageMock }) - -describe('CookiePreferences', () => { - beforeEach(() => { - vi.clearAllMocks() - localStorageMock.clear() - }) - - it('accepts all cookies when clicking Accept All', () => { - render() - - expect(screen.getByText('Cookie Preferences')).toBeInTheDocument() - - fireEvent.click(screen.getByText('Accept All')) - fireEvent.click(screen.getByText('Save Preferences')) - - expect(localStorageMock.setItem).toHaveBeenCalledWith('m-tartari-cookie-consent', JSON.stringify({ necessary: true, analytics: true })) - expect(analytics.plugins.disable).not.toHaveBeenCalled() - expect(analytics.plugins.enable).toHaveBeenCalled() - }) - - it('rejects analytics cookies when clicking Reject All', () => { - render() - - expect(screen.getByText('Cookie Preferences')).toBeInTheDocument() - - fireEvent.click(screen.getByText('Reject All')) - fireEvent.click(screen.getByText('Save Preferences')) - - expect(localStorageMock.setItem).toHaveBeenCalledWith('m-tartari-cookie-consent', JSON.stringify({ necessary: true, analytics: false })) - expect(analytics.plugins.enable).not.toHaveBeenCalled() - expect(analytics.plugins.disable).toHaveBeenCalled() - }) - - it('toggles analytics cookies when clicking the Analytics button', () => { - render() - - expect(screen.getByText('Cookie Preferences')).toBeInTheDocument() - - fireEvent.click(screen.getByLabelText('analytics-cookies-toggle')) - fireEvent.click(screen.getByText('Save Preferences')) - - expect(localStorageMock.setItem).toHaveBeenCalledWith('m-tartari-cookie-consent', JSON.stringify({ necessary: true, analytics: true })) - expect(analytics.plugins.disable).not.toHaveBeenCalled() - expect(analytics.plugins.enable).toHaveBeenCalled() - }) - - it('renders the cookie consent in the right state when consent in local storage', () => { - localStorageMock.getItem.mockReturnValueOnce(JSON.stringify({ necessary: true, analytics: true })) - render() - - expect(screen.getByText('Cookie Preferences')).toBeInTheDocument() - - fireEvent.click(screen.getByLabelText('analytics-cookies-toggle')) - fireEvent.click(screen.getByText('Save Preferences')) - - expect(localStorageMock.setItem).toHaveBeenCalledWith('m-tartari-cookie-consent', JSON.stringify({ necessary: true, analytics: false })) - expect(analytics.plugins.enable).not.toHaveBeenCalled() - expect(analytics.plugins.disable).toHaveBeenCalled() - }) -}) diff --git a/src/components/molecules/CookiePreferences/index.tsx b/src/components/molecules/CookiePreferences/index.tsx index ea9cdba..840cd42 100644 --- a/src/components/molecules/CookiePreferences/index.tsx +++ b/src/components/molecules/CookiePreferences/index.tsx @@ -11,7 +11,7 @@ const CookieConsent: React.FC = () => { return ( - Cookie policy + Cookie Policy diff --git a/src/components/molecules/Footer/Footer.test.tsx b/src/components/molecules/Footer/Footer.test.tsx index ac1656a..1d40a27 100644 --- a/src/components/molecules/Footer/Footer.test.tsx +++ b/src/components/molecules/Footer/Footer.test.tsx @@ -1,24 +1,16 @@ import React from 'react' import { screen } from '@testing-library/react' -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import { useAnalytics } from 'use-analytics' import { renderWithRouter as render } from 'components/utils/tests/index.js' import Footer from './index.js' -// Mock the analytics module -const analytics = { plugins: { enable: vi.fn(), disable: vi.fn() } } -vi.mock('use-analytics', () => ({ - useAnalytics: () => analytics, -})) - describe('Footer', () => { it('renders the Footer', async () => { render(