From 40ae38a57aceaabc734182e8e3592c8df5d124c0 Mon Sep 17 00:00:00 2001 From: SANCHI GOYAL Date: Mon, 15 Jun 2026 07:04:02 +0000 Subject: [PATCH] test(aiinsights): add responsive breakpoint coverage --- ...AIInsights.responsive-breakpoints.test.tsx | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 components/dashboard/AIInsights.responsive-breakpoints.test.tsx diff --git a/components/dashboard/AIInsights.responsive-breakpoints.test.tsx b/components/dashboard/AIInsights.responsive-breakpoints.test.tsx new file mode 100644 index 000000000..b4d210f4f --- /dev/null +++ b/components/dashboard/AIInsights.responsive-breakpoints.test.tsx @@ -0,0 +1,92 @@ +import { render, screen } from '@testing-library/react'; +import { describe, expect, it, vi, beforeEach } from 'vitest'; +import AIInsights from './AIInsights'; +import type { ReactNode } from 'react'; + +vi.mock('framer-motion', () => ({ + motion: { + div: ({ children, className }: { children: ReactNode; className?: string }) => ( +
{children}
+ ), + }, +})); + +vi.mock('@/context/TranslationContext', () => ({ + useTranslation: () => ({ + t: (key: string) => key, + }), +})); + +vi.mock('lucide-react', () => ({ + Sparkles: () =>
SparklesIcon
, + Moon: () =>
MoonIcon
, + Sun: () =>
SunIcon
, + Zap: () =>
ZapIcon
, + Calendar: () =>
CalendarIcon
, + Flame: () =>
FlameIcon
, + Code: () =>
CodeIcon
, + Star: () =>
StarIcon
, +})); + +describe('AIInsights responsive breakpoints', () => { + const insights = Array.from({ length: 20 }, (_, index) => ({ + id: `${index}`, + icon: 'Zap', + text: `Insight item ${index + 1}`, + })); + + beforeEach(() => { + window.innerWidth = 375; + + Object.defineProperty(window, 'matchMedia', { + writable: true, + value: vi.fn().mockImplementation((query: string) => ({ + matches: query.includes('max-width'), + media: query, + onchange: null, + addListener: vi.fn(), + removeListener: vi.fn(), + addEventListener: vi.fn(), + removeEventListener: vi.fn(), + dispatchEvent: vi.fn(), + })), + }); + }); + + it('renders all insight cards correctly on mobile viewport widths', () => { + render(); + + expect(screen.getAllByText(/Insight item/i)).toHaveLength(20); + }); + + it('maintains vertical flex layout styling for mobile screens', () => { + const { container } = render(); + + const flexContainer = container.querySelector('.flex.flex-col.gap-6'); + + expect(flexContainer).toBeTruthy(); + }); + + it('does not apply fixed width classes that could cause horizontal overflow', () => { + const { container } = render(); + + const fixedWidthElements = container.querySelectorAll('[class*="w-["], [class*="min-w-["]'); + + expect(fixedWidthElements.length).toBe(0); + }); + + it('renders responsive content without clipping at narrow widths', () => { + render(); + + expect(screen.getByText('Insight item 1')).toBeTruthy(); + expect(screen.getByText('Insight item 20')).toBeTruthy(); + }); + + it('preserves readable stacked layout structure across mobile devices', () => { + const { container } = render(); + + const cards = container.querySelectorAll('.rounded-lg'); + + expect(cards.length).toBe(20); + }); +});