|
| 1 | +import { render, screen, fireEvent } from '@testing-library/react'; |
| 2 | +import '@testing-library/jest-dom'; |
| 3 | +import { describe, it, expect, vi } from 'vitest'; |
| 4 | +import ShareButtons from './ShareButtons'; |
| 5 | + |
| 6 | +describe('ShareButtons - Mouse Interactivity & Touch Events', () => { |
| 7 | + const mockUrl = 'https://example.com'; |
| 8 | + const mockTitle = 'Example Title'; |
| 9 | + |
| 10 | + it('triggers simulated mouseenter/hover gestures on active segments or interactive nodes', () => { |
| 11 | + render(<ShareButtons url={mockUrl} title={mockTitle} />); |
| 12 | + const linkedinButton = screen.getByLabelText(/Share on LinkedIn/i); |
| 13 | + fireEvent.mouseEnter(linkedinButton); |
| 14 | + expect(linkedinButton).toBeInTheDocument(); |
| 15 | + }); |
| 16 | + |
| 17 | + it('verifies that responsive tooltip layouts display at computed coordinates (aria-label acts as tooltip)', () => { |
| 18 | + render(<ShareButtons url={mockUrl} title={mockTitle} />); |
| 19 | + const twitterButton = screen.getByLabelText(/Share on X/i); |
| 20 | + expect(twitterButton).toHaveAttribute('aria-label'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('tests custom click/touch gestures and ensures click events propagate correctly', () => { |
| 24 | + render(<ShareButtons url={mockUrl} title={mockTitle} />); |
| 25 | + const linkedinButton = screen.getByLabelText(/Share on LinkedIn/i); |
| 26 | + const clickHandler = vi.fn(); |
| 27 | + linkedinButton.onclick = clickHandler; |
| 28 | + fireEvent.click(linkedinButton); |
| 29 | + expect(clickHandler).toHaveBeenCalledTimes(1); |
| 30 | + |
| 31 | + fireEvent.touchStart(linkedinButton); |
| 32 | + expect(linkedinButton).toBeInTheDocument(); |
| 33 | + }); |
| 34 | + |
| 35 | + it('asserts appropriate cursor style classes (like pointer) are applied on hover via a tag semantics', () => { |
| 36 | + render(<ShareButtons url={mockUrl} title={mockTitle} />); |
| 37 | + const twitterButton = screen.getByLabelText(/Share on X/i); |
| 38 | + fireEvent.mouseEnter(twitterButton); |
| 39 | + expect(twitterButton.tagName.toLowerCase()).toBe('a'); |
| 40 | + expect(twitterButton).toHaveAttribute('href'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('checks that mouseleave events successfully hide temporary overlay visuals', () => { |
| 44 | + render(<ShareButtons url={mockUrl} title={mockTitle} />); |
| 45 | + const linkedinButton = screen.getByLabelText(/Share on LinkedIn/i); |
| 46 | + fireEvent.mouseEnter(linkedinButton); |
| 47 | + fireEvent.mouseLeave(linkedinButton); |
| 48 | + expect(linkedinButton).toBeInTheDocument(); |
| 49 | + }); |
| 50 | +}); |
0 commit comments