|
| 1 | +import { render, screen } from '@testing-library/react'; |
| 2 | +import '@testing-library/jest-dom'; |
| 3 | +import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; |
| 4 | +import ShareButtons from './ShareButtons'; |
| 5 | +import React from 'react'; |
| 6 | + |
| 7 | +describe('ShareButtons - Responsive Multi-device & Viewports', () => { |
| 8 | + const originalInnerWidth = window.innerWidth; |
| 9 | + |
| 10 | + beforeEach(() => { |
| 11 | + Object.defineProperty(window, 'innerWidth', { |
| 12 | + writable: true, |
| 13 | + configurable: true, |
| 14 | + value: 1024, |
| 15 | + }); |
| 16 | + }); |
| 17 | + |
| 18 | + afterEach(() => { |
| 19 | + Object.defineProperty(window, 'innerWidth', { |
| 20 | + writable: true, |
| 21 | + configurable: true, |
| 22 | + value: originalInnerWidth, |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + it('verifies layouts adapt correctly to mobile viewport dimensions', () => { |
| 27 | + window.innerWidth = 375; // Mobile viewport |
| 28 | + render(<ShareButtons url="https://example.com" />); |
| 29 | + const container = screen.getByLabelText(/Share on X/i).parentElement; |
| 30 | + expect(container).toHaveClass('flex'); |
| 31 | + expect(container).toHaveClass('gap-3'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('tests responsive multi-device columns at tablet breakpoints', () => { |
| 35 | + window.innerWidth = 768; // Tablet viewport |
| 36 | + render(<ShareButtons url="https://example.com" />); |
| 37 | + const linkedinButton = screen.getByLabelText(/Share on LinkedIn/i); |
| 38 | + expect(linkedinButton).toBeInTheDocument(); |
| 39 | + }); |
| 40 | + |
| 41 | + it('ensures icons scale appropriately across different screen densities', () => { |
| 42 | + render(<ShareButtons url="https://example.com" />); |
| 43 | + const linkedinIcon = screen.getByLabelText(/Share on LinkedIn/i).querySelector('svg'); |
| 44 | + // Using standard size via props in ShareButtons component |
| 45 | + expect(linkedinIcon).toBeInTheDocument(); |
| 46 | + }); |
| 47 | + |
| 48 | + it('validates touch target sizing on compact mobile views', () => { |
| 49 | + window.innerWidth = 320; // Compact mobile |
| 50 | + render(<ShareButtons url="https://example.com" />); |
| 51 | + const twitterButton = screen.getByLabelText(/Share on X/i); |
| 52 | + expect(twitterButton).toHaveAttribute('href'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('confirms container classes provide necessary flex basis on desktop widths', () => { |
| 56 | + window.innerWidth = 1440; // Desktop viewport |
| 57 | + render(<ShareButtons url="https://example.com" />); |
| 58 | + const container = screen.getByLabelText(/Share on X/i).parentElement; |
| 59 | + expect(container).toHaveClass('flex'); |
| 60 | + }); |
| 61 | +}); |
0 commit comments