diff --git a/components/KonamiEasterEgg.massive-scaling.test.tsx b/components/KonamiEasterEgg.massive-scaling.test.tsx new file mode 100644 index 000000000..26a10cac0 --- /dev/null +++ b/components/KonamiEasterEgg.massive-scaling.test.tsx @@ -0,0 +1,153 @@ +import React from 'react'; +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { render, screen, fireEvent, act, cleanup } from '@testing-library/react'; +import type { ReactNode, HTMLAttributes } from 'react'; +import KonamiEasterEgg from './KonamiEasterEgg'; + +vi.useFakeTimers(); + +vi.mock('framer-motion', () => ({ + AnimatePresence: ({ children }: { children: ReactNode }) => <>{children}, + motion: new Proxy( + {}, + { + get: + () => + ({ + children, + ...props + }: { + children?: ReactNode; + } & HTMLAttributes) =>
{children}
, + } + ), +})); + +describe('KonamiEasterEgg', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + afterEach(() => { + cleanup(); + vi.clearAllTimers(); + }); + + function triggerSecretCode() { + 'commit'.split('').forEach((key) => { + fireEvent.keyDown(window, { key }); + }); + } + + it('activates when the secret code is entered', () => { + render(); + + triggerSecretCode(); + + expect(screen.getByText('You Found It!')).toBeInTheDocument(); + expect(screen.getByText(/git commit -m/i)).toBeInTheDocument(); + }); + + it('does not activate for an incorrect sequence', () => { + render(); + + 'commix'.split('').forEach((key) => { + fireEvent.keyDown(window, { key }); + }); + + expect(screen.queryByText('You Found It!')).not.toBeInTheDocument(); + }); + + it('matches only the complete secret code', () => { + render(); + + 'commi'.split('').forEach((key) => { + fireEvent.keyDown(window, { key }); + }); + + expect(screen.queryByText('You Found It!')).not.toBeInTheDocument(); + + fireEvent.keyDown(window, { key: 't' }); + + expect(screen.getByText('You Found It!')).toBeInTheDocument(); + }); + + it('ignores keyboard events from input elements', () => { + render( + <> + + + + ); + + const input = screen.getByTestId('input'); + + 'commit'.split('').forEach((key) => { + fireEvent.keyDown(input, { key }); + }); + + expect(screen.queryByText('You Found It!')).not.toBeInTheDocument(); + }); + + it('ignores keyboard events from textarea elements', () => { + render( + <> +