// SPDX-License-Identifier: AGPL-3.0-or-later import { describe, it, expect, vi } from 'vitest'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { CommandsViewer } from './CommandsViewer'; import type { CommandRow } from '../types'; const row = (overrides: Partial = {}): CommandRow => ({ service: 'ssh', decky: 'decoy-01', command: 'whoami', timestamp: '2026-05-09T11:00:00Z', ...overrides, }); describe('CommandsViewer', () => { it('renders the title with the unfiltered total when serviceFilter is null', () => { render( {}} serviceFilter={null} open={true} onToggle={() => {}} />, ); expect(screen.getByText(/COMMANDS \(5\)/)).toBeInTheDocument(); }); it('appends the filter to the title when serviceFilter is set', () => { render( {}} serviceFilter="ssh" open={true} onToggle={() => {}} />, ); expect(screen.getByText(/COMMANDS \(3 SSH\)/)).toBeInTheDocument(); }); it('shows the empty state when commands is []', () => { render( {}} serviceFilter={null} open={true} onToggle={() => {}} />, ); expect(screen.getByText('NO COMMANDS CAPTURED')).toBeInTheDocument(); }); it('hides pagination when total fits on one page', () => { render( {}} serviceFilter={null} open={true} onToggle={() => {}} />, ); expect(screen.queryByText(/Page 1 of/)).not.toBeInTheDocument(); }); it('paginates: prev/next buttons fire setCmdPage with the right delta', async () => { const user = userEvent.setup(); const setCmdPage = vi.fn(); render( {}} />, ); expect(screen.getByText('Page 3 of 5')).toBeInTheDocument(); const buttons = screen.getAllByRole('button'); await user.click(buttons[0]); // prev expect(setCmdPage).toHaveBeenLastCalledWith(2); await user.click(buttons[1]); // next expect(setCmdPage).toHaveBeenLastCalledWith(4); }); });