|
| 1 | +import { render, screen } from '@testing-library/react'; |
| 2 | +import { beforeEach, describe, expect, it, vi } from 'vitest'; |
| 3 | + |
| 4 | +import CopyRepoButton from './CopyRepoButton'; |
| 5 | + |
| 6 | +vi.mock('lucide-react', () => ({ |
| 7 | + Copy: () => <svg data-testid="copy-icon" />, |
| 8 | +})); |
| 9 | + |
| 10 | +describe('CopyRepoButton - Responsive Breakpoints Layout Cohesion', () => { |
| 11 | + beforeEach(() => { |
| 12 | + window.innerWidth = 375; |
| 13 | + window.dispatchEvent(new Event('resize')); |
| 14 | + }); |
| 15 | + |
| 16 | + it('mocks standard mobile-width media coordinates correctly', () => { |
| 17 | + render(<CopyRepoButton />); |
| 18 | + expect(window.innerWidth).toBe(375); |
| 19 | + expect(screen.getByRole('button', { name: /copy url/i })).toBeDefined(); |
| 20 | + }); |
| 21 | + |
| 22 | + it('asserts that container layout reflows into a single vertical flex element or maintains appropriate inline-flex behavior on mobile', () => { |
| 23 | + render(<CopyRepoButton />); |
| 24 | + const button = screen.getByRole('button'); |
| 25 | + expect(button.className).toContain('inline-flex'); |
| 26 | + expect(button.className).toContain('items-center'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('verifies that styling values use flexible styles and padding rather than absolute widths to prevent horizontal scrollbars on smaller viewports', () => { |
| 30 | + render(<CopyRepoButton />); |
| 31 | + const button = screen.getByRole('button'); |
| 32 | + expect(button.className).toContain('px-8'); |
| 33 | + expect(button.className).toContain('py-4'); |
| 34 | + expect(button.className).not.toContain('w-[500px]'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('checks that button contents (icon and text) scale down gracefully on mobile screen sizes', () => { |
| 38 | + render(<CopyRepoButton />); |
| 39 | + const button = screen.getByRole('button'); |
| 40 | + expect(button.className).toContain('gap-2'); |
| 41 | + expect(screen.getByTestId('copy-icon')).toBeDefined(); |
| 42 | + }); |
| 43 | + |
| 44 | + it('asserts viewport changes do not affect state transitions of the copy action', async () => { |
| 45 | + render(<CopyRepoButton />); |
| 46 | + const button = screen.getByRole('button'); |
| 47 | + |
| 48 | + // Resize to desktop |
| 49 | + window.innerWidth = 1440; |
| 50 | + window.dispatchEvent(new Event('resize')); |
| 51 | + |
| 52 | + expect(window.innerWidth).toBe(1440); |
| 53 | + expect(button.className).toContain('transition-all'); |
| 54 | + }); |
| 55 | +}); |
0 commit comments