Improve test coverage for cli/src/ui/components (#13598)

This commit is contained in:
Megha Bansal
2025-11-22 08:17:29 +05:30
committed by GitHub
parent bdf80ea7c0
commit e205a468d9
48 changed files with 2897 additions and 51 deletions
@@ -0,0 +1,37 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { render } from '../../test-utils/render.js';
import { CopyModeWarning } from './CopyModeWarning.js';
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { useUIState, type UIState } from '../contexts/UIStateContext.js';
vi.mock('../contexts/UIStateContext.js');
describe('CopyModeWarning', () => {
const mockUseUIState = vi.mocked(useUIState);
beforeEach(() => {
vi.clearAllMocks();
});
it('renders nothing when copy mode is disabled', () => {
mockUseUIState.mockReturnValue({
copyModeEnabled: false,
} as unknown as UIState);
const { lastFrame } = render(<CopyModeWarning />);
expect(lastFrame()).toBe('');
});
it('renders warning when copy mode is enabled', () => {
mockUseUIState.mockReturnValue({
copyModeEnabled: true,
} as unknown as UIState);
const { lastFrame } = render(<CopyModeWarning />);
expect(lastFrame()).toContain('In Copy Mode');
expect(lastFrame()).toContain('Press any key to exit');
});
});