|
| 1 | +import React from 'react'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import '@testing-library/jest-dom/vitest'; |
| 4 | +import { describe, expect, it, vi, beforeAll } from 'vitest'; |
| 5 | +import { WallOfLove } from './WallOfLove'; |
| 6 | + |
| 7 | +/* ───────────────────────────────────────────────────────── |
| 8 | + MOCKS — same pattern as the existing WallOfLove test file |
| 9 | + ───────────────────────────────────────────────────────── */ |
| 10 | + |
| 11 | +vi.mock('framer-motion', () => ({ |
| 12 | + motion: { |
| 13 | + p: (props: React.ComponentProps<'p'>) => <p {...props} />, |
| 14 | + }, |
| 15 | + useReducedMotion: () => true, |
| 16 | +})); |
| 17 | + |
| 18 | +vi.mock('gsap', () => { |
| 19 | + const timeline = () => ({ |
| 20 | + to: vi.fn().mockReturnThis(), |
| 21 | + fromTo: vi.fn().mockReturnThis(), |
| 22 | + kill: vi.fn(), |
| 23 | + }); |
| 24 | + |
| 25 | + return { |
| 26 | + default: { |
| 27 | + registerPlugin: vi.fn(), |
| 28 | + context: (cb: () => void) => { |
| 29 | + cb(); |
| 30 | + return { revert: vi.fn() }; |
| 31 | + }, |
| 32 | + timeline, |
| 33 | + to: vi.fn(), |
| 34 | + set: vi.fn(), |
| 35 | + fromTo: vi.fn(), |
| 36 | + }, |
| 37 | + }; |
| 38 | +}); |
| 39 | + |
| 40 | +vi.mock('gsap/ScrollTrigger', () => ({ |
| 41 | + ScrollTrigger: {}, |
| 42 | +})); |
| 43 | + |
| 44 | +/* ───────────────────────────────────────────────────────── |
| 45 | + IntersectionObserver stub (not available in jsdom) |
| 46 | + ───────────────────────────────────────────────────────── */ |
| 47 | +beforeAll(() => { |
| 48 | + class MockIntersectionObserver { |
| 49 | + observe = vi.fn(); |
| 50 | + unobserve = vi.fn(); |
| 51 | + disconnect = vi.fn(); |
| 52 | + |
| 53 | + constructor(callback: IntersectionObserverCallback) { |
| 54 | + callback( |
| 55 | + [ |
| 56 | + { |
| 57 | + isIntersecting: true, |
| 58 | + target: document.createElement('p'), |
| 59 | + boundingClientRect: {} as DOMRectReadOnly, |
| 60 | + intersectionRatio: 1, |
| 61 | + intersectionRect: {} as DOMRectReadOnly, |
| 62 | + rootBounds: null, |
| 63 | + time: Date.now(), |
| 64 | + } as IntersectionObserverEntry, |
| 65 | + ], |
| 66 | + this as unknown as IntersectionObserver |
| 67 | + ); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + global.IntersectionObserver = MockIntersectionObserver as unknown as typeof IntersectionObserver; |
| 72 | +}); |
| 73 | + |
| 74 | +/* ═══════════════════════════════════════════════════════════════════════════ |
| 75 | + WallOfLove — Massive Data Sets and Extreme High Bounds Scaling (Variation 2) |
| 76 | + ═══════════════════════════════════════════════════════════════════════════ */ |
| 77 | + |
| 78 | +describe('WallOfLove — Massive Scaling', () => { |
| 79 | + /* ─────────────────────────────────────────────────────────────────────── |
| 80 | + TEST 1 |
| 81 | + All 12 testimonial names from both rows are present in the DOM. |
| 82 | + MarqueeRow duplicates each array ([...t, ...t]), so every name must |
| 83 | + appear at least twice — verifying the duplication logic at scale. |
| 84 | + ─────────────────────────────────────────────────────────────────────── */ |
| 85 | + it('renders all 12 unique testimonial author names, each duplicated by MarqueeRow', () => { |
| 86 | + render(<WallOfLove />); |
| 87 | + |
| 88 | + const allNames = [ |
| 89 | + // ROW 1 |
| 90 | + 'Alex Chen', |
| 91 | + 'Priya Sharma', |
| 92 | + 'Marcus Johnson', |
| 93 | + 'Yuki Tanaka', |
| 94 | + 'Jordan Rivers', |
| 95 | + 'Emma Rodriguez', |
| 96 | + // ROW 2 |
| 97 | + 'David Kim', |
| 98 | + 'Sarah Mitchell', |
| 99 | + 'Raj Patel', |
| 100 | + 'Lisa Wong', |
| 101 | + 'Omar Hassan', |
| 102 | + 'Chloe Nguyen', |
| 103 | + ]; |
| 104 | + |
| 105 | + allNames.forEach((name) => { |
| 106 | + const nodes = screen.getAllByText(name); |
| 107 | + // MarqueeRow duplicates: at least 2 occurrences of every card |
| 108 | + expect(nodes.length).toBeGreaterThanOrEqual(2); |
| 109 | + }); |
| 110 | + }); |
| 111 | + |
| 112 | + /* ─────────────────────────────────────────────────────────────────────── |
| 113 | + TEST 2 |
| 114 | + All 12 handles from both rows appear in the DOM, each at least twice |
| 115 | + (duplicated by MarqueeRow), validating high-volume node rendering. |
| 116 | + ─────────────────────────────────────────────────────────────────────── */ |
| 117 | + it('renders all 12 unique testimonial handles, each duplicated at least twice', () => { |
| 118 | + render(<WallOfLove />); |
| 119 | + |
| 120 | + const allHandles = [ |
| 121 | + '@alexcodes', |
| 122 | + '@priyabuilds', |
| 123 | + '@marcusdev', |
| 124 | + '@yukicodes', |
| 125 | + '@jordandev', |
| 126 | + '@emmacodes', |
| 127 | + '@davidkim', |
| 128 | + '@sarahcodes', |
| 129 | + '@rajbuilds', |
| 130 | + '@lisawong', |
| 131 | + '@omardev', |
| 132 | + '@chloedev', |
| 133 | + ]; |
| 134 | + |
| 135 | + allHandles.forEach((handle) => { |
| 136 | + const nodes = screen.getAllByText(handle); |
| 137 | + expect(nodes.length).toBeGreaterThanOrEqual(2); |
| 138 | + }); |
| 139 | + }); |
| 140 | + |
| 141 | + /* ─────────────────────────────────────────────────────────────────────── |
| 142 | + TEST 3 |
| 143 | + All 12 testimonial messages render in full without truncation. |
| 144 | + Long strings (100+ chars) must survive the DOM without being cut off — |
| 145 | + this is the core text-wrapping / overflow correctness check at scale. |
| 146 | + ─────────────────────────────────────────────────────────────────────── */ |
| 147 | + it('renders full-length testimonial messages without truncation', () => { |
| 148 | + render(<WallOfLove />); |
| 149 | + |
| 150 | + const messageSnippets: string[] = [ |
| 151 | + '3D monolith looks absolutely insane', // Alex Chen |
| 152 | + 'went from boring to absolutely premium', // Priya Sharma |
| 153 | + 'real-time sync with GitHub is flawless', // Marcus Johnson |
| 154 | + 'contribution graph into art', // Yuki Tanaka |
| 155 | + "Dracula theme is *chef's kiss*", // Jordan Rivers |
| 156 | + 'want to code every single day', // Emma Rodriguez |
| 157 | + 'tweaking every little detail', // David Kim |
| 158 | + '3D monolith on my profile gets so many', // Sarah Mitchell |
| 159 | + '3D masterpiece in seconds', // Raj Patel |
| 160 | + 'SVG output is remarkable', // Lisa Wong |
| 161 | + 'like a AAA game UI', // Omar Hassan |
| 162 | + 'beautiful 3D view is incredibly motivating', // Chloe Nguyen |
| 163 | + ]; |
| 164 | + |
| 165 | + messageSnippets.forEach((snippet) => { |
| 166 | + // getAllByText with exact:false matches partial text inside the element |
| 167 | + const nodes = screen.getAllByText((_content, element) => |
| 168 | + (element?.textContent ?? '').includes(snippet) |
| 169 | + ); |
| 170 | + expect(nodes.length).toBeGreaterThan(0); |
| 171 | + }); |
| 172 | + }); |
| 173 | + |
| 174 | + /* ─────────────────────────────────────────────────────────────────────── |
| 175 | + TEST 4 |
| 176 | + Stat bar renders correct extreme-looking production values. |
| 177 | + Verifies that large formatted strings ("50K+") and decimal values |
| 178 | + ("4.9") are not mangled, rounded, or clipped by the DOM at scale. |
| 179 | + ─────────────────────────────────────────────────────────────────────── */ |
| 180 | + it('renders all three stat values and labels exactly as specified', () => { |
| 181 | + render(<WallOfLove />); |
| 182 | + |
| 183 | + // Values |
| 184 | + expect(screen.getByText('2K+')).toBeInTheDocument(); |
| 185 | + expect(screen.getByText('50K+')).toBeInTheDocument(); |
| 186 | + expect(screen.getByText('4.9')).toBeInTheDocument(); |
| 187 | + |
| 188 | + // Labels |
| 189 | + expect(screen.getByText('Happy Developers')).toBeInTheDocument(); |
| 190 | + expect(screen.getByText('Badges Generated')).toBeInTheDocument(); |
| 191 | + expect(screen.getByText('Average Rating')).toBeInTheDocument(); |
| 192 | + }); |
| 193 | + |
| 194 | + /* ─────────────────────────────────────────────────────────────────────── |
| 195 | + TEST 5 |
| 196 | + Total card count in the DOM equals 24 (12 unique × 2 MarqueeRow rows |
| 197 | + × 2 duplication per row). Ensures the grid does not break, collapse, |
| 198 | + or silently drop nodes under the full combined data set load. |
| 199 | + ─────────────────────────────────────────────────────────────────────── */ |
| 200 | + it('renders exactly 24 avatar images — 12 cards × 2 rows, each duplicated once', () => { |
| 201 | + render(<WallOfLove />); |
| 202 | + |
| 203 | + // Every TestimonialCard renders one <img> with alt = testimonial.name. |
| 204 | + // 6 cards in Row1 × 2 (duplicate) = 12 images |
| 205 | + // 6 cards in Row2 × 2 (duplicate) = 12 images |
| 206 | + // Total = 24 |
| 207 | + const avatars = screen.getAllByRole('img'); |
| 208 | + expect(avatars.length).toBe(24); |
| 209 | + |
| 210 | + // Every image must have a non-empty src (no broken blank images) |
| 211 | + avatars.forEach((img) => { |
| 212 | + expect(img).toHaveAttribute('src'); |
| 213 | + expect((img as HTMLImageElement).src.length).toBeGreaterThan(0); |
| 214 | + }); |
| 215 | + }); |
| 216 | +}); |
0 commit comments