|
1 | 1 | import React from 'react'; |
2 | 2 | import { render, screen, fireEvent } from '@testing-library/react'; |
3 | | -import { describe, it, expect, beforeEach, vi } from 'vitest'; |
| 3 | +import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'; |
4 | 4 | import InteractiveViewer, { formatDate } from './InteractiveViewer'; |
5 | 5 |
|
6 | 6 | // getBoundingClientRect is not implemented in jsdom — mock it so mouse-position |
@@ -553,4 +553,51 @@ describe('InteractiveViewer', () => { |
553 | 553 | expect(glow.style.left).toBe('75%'); |
554 | 554 | expect(glow.style.top).toBe('25%'); |
555 | 555 | }); |
| 556 | + |
| 557 | + describe('InteractiveViewer responsive rendering', () => { |
| 558 | + afterEach(() => { |
| 559 | + window.innerWidth = 1024; |
| 560 | + window.innerHeight = 768; |
| 561 | + }); |
| 562 | + |
| 563 | + const resizeWindow = (width: number, height: number) => { |
| 564 | + window.innerWidth = width; |
| 565 | + window.innerHeight = height; |
| 566 | + |
| 567 | + window.dispatchEvent(new Event('resize')); |
| 568 | + }; |
| 569 | + |
| 570 | + it('renders correctly on mobile viewport', () => { |
| 571 | + resizeWindow(375, 667); |
| 572 | + |
| 573 | + render( |
| 574 | + <InteractiveViewer> |
| 575 | + <div data-testid="mobile-content">Mobile Content</div> |
| 576 | + </InteractiveViewer> |
| 577 | + ); |
| 578 | + |
| 579 | + expect(screen.getByTestId('mobile-content')).toBeTruthy(); |
| 580 | + expect(screen.getByTestId('parallax-bg-layer')).toBeTruthy(); |
| 581 | + }); |
| 582 | + |
| 583 | + it('renders correctly on desktop viewport with pointer interactions', () => { |
| 584 | + resizeWindow(1440, 900); |
| 585 | + |
| 586 | + render( |
| 587 | + <InteractiveViewer> |
| 588 | + <div data-testid="desktop-content">Desktop Content</div> |
| 589 | + </InteractiveViewer> |
| 590 | + ); |
| 591 | + |
| 592 | + const glowLayer = screen.getByTestId('parallax-cursor-glow'); |
| 593 | + |
| 594 | + fireEvent.pointerMove(glowLayer, { |
| 595 | + clientX: 100, |
| 596 | + clientY: 100, |
| 597 | + }); |
| 598 | + |
| 599 | + expect(screen.getByTestId('desktop-content')).toBeTruthy(); |
| 600 | + expect(glowLayer).toBeTruthy(); |
| 601 | + }); |
| 602 | + }); |
556 | 603 | }); |
0 commit comments