|
| 1 | +import { render, screen, fireEvent } from '@testing-library/react'; |
| 2 | +import '@testing-library/jest-dom/vitest'; |
| 3 | +import { describe, expect, it, vi } from 'vitest'; |
| 4 | +import { DiscordButton } from './DiscordButton'; |
| 5 | +// Mock framer-motion |
| 6 | +vi.mock('framer-motion', () => ({ |
| 7 | + motion: { |
| 8 | + div: (props: React.ComponentProps<'div'>) => <div {...props} />, |
| 9 | + a: (props: React.ComponentProps<'a'>) => <a {...props} />, |
| 10 | + }, |
| 11 | +})); |
| 12 | + |
| 13 | +// Mock gsap |
| 14 | + |
| 15 | +vi.mock('gsap', () => ({ |
| 16 | + default: { |
| 17 | + to: vi.fn(), |
| 18 | + }, |
| 19 | +})); |
| 20 | + |
| 21 | +describe('DiscordButton', () => { |
| 22 | + it('renders discord invite link with correct href', () => { |
| 23 | + render(<DiscordButton />); |
| 24 | + |
| 25 | + const link = screen.getByRole('link'); |
| 26 | + |
| 27 | + expect(link).toHaveAttribute('href', 'https://discord.gg/Cb73bS79j'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('sets target and rel attributes for security', () => { |
| 31 | + render(<DiscordButton />); |
| 32 | + |
| 33 | + const link = screen.getByRole('link'); |
| 34 | + |
| 35 | + expect(link).toHaveAttribute('target', '_blank'); |
| 36 | + expect(link).toHaveAttribute('rel', 'noopener noreferrer'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('renders discord call-to-action text', () => { |
| 40 | + render(<DiscordButton />); |
| 41 | + |
| 42 | + expect(screen.getByText('Join the core community on Discord')).toBeInTheDocument(); |
| 43 | + }); |
| 44 | + |
| 45 | + it('renders svg icons', () => { |
| 46 | + const { container } = render(<DiscordButton />); |
| 47 | + |
| 48 | + const svgs = container.querySelectorAll('svg'); |
| 49 | + |
| 50 | + expect(svgs.length).toBeGreaterThanOrEqual(2); |
| 51 | + }); |
| 52 | + |
| 53 | + it('renders external link target', () => { |
| 54 | + render(<DiscordButton />); |
| 55 | + |
| 56 | + const link = screen.getByRole('link'); |
| 57 | + |
| 58 | + expect(link).toHaveAttribute('target', '_blank'); |
| 59 | + }); |
| 60 | +}); |
0 commit comments