2025-11-22 08:17:29 +05:30
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { render } from '../../test-utils/render.js';
|
|
|
|
|
import { ExitWarning } from './ExitWarning.js';
|
|
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
|
|
import { useUIState, type UIState } from '../contexts/UIStateContext.js';
|
|
|
|
|
|
|
|
|
|
vi.mock('../contexts/UIStateContext.js');
|
|
|
|
|
|
|
|
|
|
describe('ExitWarning', () => {
|
|
|
|
|
const mockUseUIState = vi.mocked(useUIState);
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.clearAllMocks();
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-18 16:46:50 -08:00
|
|
|
it('renders nothing by default', async () => {
|
2025-11-22 08:17:29 +05:30
|
|
|
mockUseUIState.mockReturnValue({
|
|
|
|
|
dialogsVisible: false,
|
|
|
|
|
ctrlCPressedOnce: false,
|
|
|
|
|
ctrlDPressedOnce: false,
|
|
|
|
|
} as unknown as UIState);
|
2026-03-20 20:08:29 +00:00
|
|
|
const { lastFrame, unmount } = await render(<ExitWarning />);
|
2026-02-18 16:46:50 -08:00
|
|
|
expect(lastFrame({ allowEmpty: true })).toBe('');
|
|
|
|
|
unmount();
|
2025-11-22 08:17:29 +05:30
|
|
|
});
|
|
|
|
|
|
2026-02-18 16:46:50 -08:00
|
|
|
it('renders Ctrl+C warning when pressed once and dialogs visible', async () => {
|
2025-11-22 08:17:29 +05:30
|
|
|
mockUseUIState.mockReturnValue({
|
|
|
|
|
dialogsVisible: true,
|
|
|
|
|
ctrlCPressedOnce: true,
|
|
|
|
|
ctrlDPressedOnce: false,
|
|
|
|
|
} as unknown as UIState);
|
2026-03-20 20:08:29 +00:00
|
|
|
const { lastFrame, unmount } = await render(<ExitWarning />);
|
2025-11-22 08:17:29 +05:30
|
|
|
expect(lastFrame()).toContain('Press Ctrl+C again to exit');
|
2026-02-18 16:46:50 -08:00
|
|
|
unmount();
|
2025-11-22 08:17:29 +05:30
|
|
|
});
|
|
|
|
|
|
2026-02-18 16:46:50 -08:00
|
|
|
it('renders Ctrl+D warning when pressed once and dialogs visible', async () => {
|
2025-11-22 08:17:29 +05:30
|
|
|
mockUseUIState.mockReturnValue({
|
|
|
|
|
dialogsVisible: true,
|
|
|
|
|
ctrlCPressedOnce: false,
|
|
|
|
|
ctrlDPressedOnce: true,
|
|
|
|
|
} as unknown as UIState);
|
2026-03-20 20:08:29 +00:00
|
|
|
const { lastFrame, unmount } = await render(<ExitWarning />);
|
2025-11-22 08:17:29 +05:30
|
|
|
expect(lastFrame()).toContain('Press Ctrl+D again to exit');
|
2026-02-18 16:46:50 -08:00
|
|
|
unmount();
|
2025-11-22 08:17:29 +05:30
|
|
|
});
|
|
|
|
|
|
2026-02-18 16:46:50 -08:00
|
|
|
it('renders nothing if dialogs are not visible', async () => {
|
2025-11-22 08:17:29 +05:30
|
|
|
mockUseUIState.mockReturnValue({
|
|
|
|
|
dialogsVisible: false,
|
|
|
|
|
ctrlCPressedOnce: true,
|
|
|
|
|
ctrlDPressedOnce: true,
|
|
|
|
|
} as unknown as UIState);
|
2026-03-20 20:08:29 +00:00
|
|
|
const { lastFrame, unmount } = await render(<ExitWarning />);
|
2026-02-18 16:46:50 -08:00
|
|
|
expect(lastFrame({ allowEmpty: true })).toBe('');
|
|
|
|
|
unmount();
|
2025-11-22 08:17:29 +05:30
|
|
|
});
|
|
|
|
|
});
|