|
| 1 | +import '@testing-library/jest-dom' |
| 2 | +import { describe, expect, it } from 'vitest' |
| 3 | +import userEvent from '@testing-library/user-event' |
| 4 | +import { render, waitFor, screen } from '@testing-library/react' |
| 5 | +import { CapturedEventsList } from './index' |
| 6 | + |
| 7 | +describe('CapturedEventsList Component', () => { |
| 8 | + it('should render toggle button', () => { |
| 9 | + const component = render(<CapturedEventsList />) |
| 10 | + const toggleButton = |
| 11 | + component.container.getElementsByClassName('toggle-button')[0] |
| 12 | + expect(toggleButton).toBeInTheDocument() |
| 13 | + }) |
| 14 | + |
| 15 | + it('should open and close the debug window', async () => { |
| 16 | + render(<CapturedEventsList />) |
| 17 | + const toggleButton = screen.getByTestId('toggle-button') |
| 18 | + userEvent.click(toggleButton) |
| 19 | + |
| 20 | + const debugWindow = await waitFor(() => { |
| 21 | + const element = screen.getByTestId('debug-window') |
| 22 | + expect(element).not.toBeNull() |
| 23 | + return element |
| 24 | + }) |
| 25 | + |
| 26 | + expect(debugWindow).toBeVisible() |
| 27 | + userEvent.click(toggleButton) |
| 28 | + |
| 29 | + await waitFor(() => { |
| 30 | + expect(debugWindow).not.toBeVisible() |
| 31 | + }) |
| 32 | + }) |
| 33 | + |
| 34 | + it('should switch between individual and table view', async () => { |
| 35 | + render(<CapturedEventsList />) |
| 36 | + const toggleButton = screen.getByTestId('toggle-button') |
| 37 | + userEvent.click(toggleButton) |
| 38 | + |
| 39 | + const toggleViewButton = await waitFor(() => |
| 40 | + screen.getByTestId('toggle-view-button'), |
| 41 | + ) |
| 42 | + userEvent.click(toggleViewButton) |
| 43 | + |
| 44 | + const tableView = await waitFor(() => screen.getByTestId('table-view')) |
| 45 | + expect(tableView).toBeVisible() |
| 46 | + userEvent.click(toggleViewButton) |
| 47 | + |
| 48 | + const individualView = await waitFor(() => |
| 49 | + screen.getByTestId('individual-view'), |
| 50 | + ) |
| 51 | + expect(individualView).toBeVisible() |
| 52 | + }) |
| 53 | + |
| 54 | + it('should clear all events', async () => { |
| 55 | + render(<CapturedEventsList />) |
| 56 | + const toggleButton = screen.getByTestId('toggle-button') |
| 57 | + userEvent.click(toggleButton) |
| 58 | + |
| 59 | + const clearButton = await waitFor(() => screen.getByTestId('clear-button')) |
| 60 | + userEvent.click(clearButton) |
| 61 | + |
| 62 | + const noEventsText = await waitFor(() => screen.getByText('No events yet')) |
| 63 | + expect(noEventsText).toBeInTheDocument() |
| 64 | + }) |
| 65 | +}) |
0 commit comments