From 64f45f7c998babcd18ead93caf449abc1b2b4d08 Mon Sep 17 00:00:00 2001 From: anurag2787 Date: Sat, 2 Aug 2025 04:56:04 +0530 Subject: [PATCH 1/3] Added test for footer component --- .../__tests__/unit/components/Footer.test.tsx | 409 ++++++++++++++++++ 1 file changed, 409 insertions(+) create mode 100644 frontend/__tests__/unit/components/Footer.test.tsx diff --git a/frontend/__tests__/unit/components/Footer.test.tsx b/frontend/__tests__/unit/components/Footer.test.tsx new file mode 100644 index 0000000000..48dfd11496 --- /dev/null +++ b/frontend/__tests__/unit/components/Footer.test.tsx @@ -0,0 +1,409 @@ +/** + * @file Complete unit tests for the Footer component. + * @see {@link AutoScrollToTop.test.tsx} for structural reference. + */ +import { render, screen, fireEvent } from '@testing-library/react' +import '@testing-library/jest-dom' +import { ReactNode } from 'react' +import Footer from 'components/Footer' + +// Define proper types for mock props +interface MockLinkProps { + children: ReactNode + href: string + target?: string + rel?: string + className?: string + 'aria-label'?: string +} + +interface MockFontAwesomeIconProps { + icon: unknown + className?: string +} + +interface MockButtonProps { + children: ReactNode + onPress?: () => void + className?: string + disableAnimation?: boolean + 'aria-expanded'?: boolean + 'aria-controls'?: string +} + +jest.mock('next/link', () => { + return function MockedLink({ children, href, ...props }: MockLinkProps) { + return ( + + {children} + + ) + } +}) + +jest.mock('@fortawesome/react-fontawesome', () => ({ + FontAwesomeIcon: ({ icon, className }: MockFontAwesomeIconProps) => ( + + {String(icon)} + + ), +})) + +jest.mock('@heroui/button', () => ({ + Button: ({ children, onPress, className, disableAnimation, ...props }: MockButtonProps) => ( + + ), +})) + +jest.mock('utils/constants', () => ({ + footerSections: [ + { + title: 'OWASP Nest', + links: [ + { text: 'About', href: '/about' }, + { text: 'Contribute', href: 'https://github.com/OWASP/Nest/blob/main/CONTRIBUTING.md' }, + ], + }, + { + title: 'Resources', + links: [ + { text: 'Chapters', href: '/chapters/' }, + { text: 'Projects', href: '/projects/' }, + { text: 'Plain Text', isSpan: true }, + ], + }, + ], + footerIcons: [ + { + icon: 'faGithub', + href: 'https://github.com/owasp/nest', + label: 'GitHub', + }, + { + icon: 'faSlack', + href: 'https://owasp.slack.com/archives/project-nest', + label: 'Slack', + }, + ], +})) + +jest.mock('utils/credentials', () => ({ + ENVIRONMENT: 'production', + RELEASE_VERSION: '1.2.3', +})) + +describe('Footer', () => { + const mockFooterSections = [ + { + title: 'OWASP Nest', + links: [ + { text: 'About', href: '/about' }, + { text: 'Contribute', href: 'https://github.com/OWASP/Nest/blob/main/CONTRIBUTING.md' }, + ], + }, + { + title: 'Resources', + links: [ + { text: 'Chapters', href: '/chapters/' }, + { text: 'Projects', href: '/projects/' }, + { text: 'Plain Text', isSpan: true }, + ], + }, + ] + + const mockFooterIcons = [ + { + icon: 'faGithub', + href: 'https://github.com/owasp/nest', + label: 'GitHub', + }, + { + icon: 'faSlack', + href: 'https://owasp.slack.com/archives/project-nest', + label: 'Slack', + }, + ] + + const renderFooter = () => { + return render(