|
| 1 | +/* eslint-disable @typescript-eslint/no-explicit-any */ |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; |
| 4 | +import ProfileOptimizerModal from './ProfileOptimizerModal'; |
| 5 | + |
| 6 | +vi.mock('framer-motion', () => ({ |
| 7 | + motion: { |
| 8 | + div: ({ children, className, ...props }: any) => { |
| 9 | + const clean = { ...props }; |
| 10 | + delete clean.initial; |
| 11 | + delete clean.animate; |
| 12 | + delete clean.exit; |
| 13 | + delete clean.transition; |
| 14 | + delete clean.onClick; |
| 15 | + return ( |
| 16 | + <div className={className} {...clean}> |
| 17 | + {children} |
| 18 | + </div> |
| 19 | + ); |
| 20 | + }, |
| 21 | + p: ({ children, className, ...props }: any) => { |
| 22 | + const clean = { ...props }; |
| 23 | + delete clean.initial; |
| 24 | + delete clean.animate; |
| 25 | + delete clean.exit; |
| 26 | + return ( |
| 27 | + <p className={className} {...clean}> |
| 28 | + {children} |
| 29 | + </p> |
| 30 | + ); |
| 31 | + }, |
| 32 | + }, |
| 33 | + AnimatePresence: ({ children }: any) => <>{children}</>, |
| 34 | +})); |
| 35 | + |
| 36 | +vi.mock('next/link', () => ({ |
| 37 | + default: ({ children, href }: any) => <a href={href}>{children}</a>, |
| 38 | +})); |
| 39 | + |
| 40 | +vi.mock('lucide-react', () => ({ |
| 41 | + X: () => <span data-testid="icon-x">X</span>, |
| 42 | + Download: () => <span>Download</span>, |
| 43 | + Copy: () => <span>Copy</span>, |
| 44 | + CheckCircle: () => <span>CheckCircle</span>, |
| 45 | + TrendingUp: () => <span>TrendingUp</span>, |
| 46 | + AlertCircle: () => <span>AlertCircle</span>, |
| 47 | +})); |
| 48 | + |
| 49 | +const mockUserData = { |
| 50 | + profile: { |
| 51 | + developerScore: 60, |
| 52 | + bio: 'Full-stack developer', |
| 53 | + stats: { repositories: 10, followers: 50 }, |
| 54 | + }, |
| 55 | + languages: [{ name: 'TypeScript' }, { name: 'Python' }], |
| 56 | + stats: { totalContributions: 200 }, |
| 57 | +}; |
| 58 | + |
| 59 | +describe('ProfileOptimizerModal — Responsive Multi-device Columns & Mobile Viewport Layouts', () => { |
| 60 | + const originalInnerWidth = window.innerWidth; |
| 61 | + |
| 62 | + beforeEach(() => { |
| 63 | + Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 375 }); |
| 64 | + window.dispatchEvent(new Event('resize')); |
| 65 | + }); |
| 66 | + |
| 67 | + afterEach(() => { |
| 68 | + Object.defineProperty(window, 'innerWidth', { |
| 69 | + writable: true, |
| 70 | + configurable: true, |
| 71 | + value: originalInnerWidth, |
| 72 | + }); |
| 73 | + }); |
| 74 | + |
| 75 | + it('renders modal container without fixed absolute widths that cause horizontal scroll', () => { |
| 76 | + const { container } = render( |
| 77 | + <ProfileOptimizerModal isOpen={true} onClose={vi.fn()} userData={mockUserData} /> |
| 78 | + ); |
| 79 | + const modalDiv = container.querySelector('.max-w-3xl'); |
| 80 | + expect(modalDiv).not.toBeNull(); |
| 81 | + expect(modalDiv?.className).toContain('w-full'); |
| 82 | + expect(modalDiv?.className).not.toContain('w-['); |
| 83 | + }); |
| 84 | + |
| 85 | + it('renders close button accessible on mobile viewport', () => { |
| 86 | + render(<ProfileOptimizerModal isOpen={true} onClose={vi.fn()} userData={mockUserData} />); |
| 87 | + const closeButton = screen.getByTestId('icon-x'); |
| 88 | + expect(closeButton).toBeDefined(); |
| 89 | + }); |
| 90 | + |
| 91 | + it('renders modal with vertical flex layout on small screens', () => { |
| 92 | + const { container } = render( |
| 93 | + <ProfileOptimizerModal isOpen={true} onClose={vi.fn()} userData={mockUserData} /> |
| 94 | + ); |
| 95 | + const flexModal = container.querySelector('.flex.flex-col'); |
| 96 | + expect(flexModal).not.toBeNull(); |
| 97 | + }); |
| 98 | + |
| 99 | + it('renders loading state with centered vertical layout on mobile', () => { |
| 100 | + const { container } = render( |
| 101 | + <ProfileOptimizerModal isOpen={true} onClose={vi.fn()} userData={mockUserData} /> |
| 102 | + ); |
| 103 | + const centered = container.querySelector('.flex-col.items-center.justify-center'); |
| 104 | + expect(centered).not.toBeNull(); |
| 105 | + }); |
| 106 | + |
| 107 | + it('does not render modal content when isOpen is false', () => { |
| 108 | + const { container } = render( |
| 109 | + <ProfileOptimizerModal isOpen={false} onClose={vi.fn()} userData={mockUserData} /> |
| 110 | + ); |
| 111 | + expect(container.firstChild).toBeNull(); |
| 112 | + }); |
| 113 | +}); |
0 commit comments