2025-07-27 02:00:26 -04:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-08-15 10:54:00 -07:00
|
|
|
import { renderWithProviders } from '../../test-utils/render.js';
|
2025-07-27 02:00:26 -04:00
|
|
|
import { describe, it, expect, vi } from 'vitest';
|
|
|
|
|
import { ShellConfirmationDialog } from './ShellConfirmationDialog.js';
|
|
|
|
|
|
|
|
|
|
describe('ShellConfirmationDialog', () => {
|
|
|
|
|
const onConfirm = vi.fn();
|
|
|
|
|
|
|
|
|
|
const request = {
|
|
|
|
|
commands: ['ls -la', 'echo "hello"'],
|
|
|
|
|
onConfirm,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
it('renders correctly', () => {
|
2025-08-15 10:54:00 -07:00
|
|
|
const { lastFrame } = renderWithProviders(
|
|
|
|
|
<ShellConfirmationDialog request={request} />,
|
2025-10-31 07:43:12 -07:00
|
|
|
{ width: 101 },
|
2025-08-15 10:54:00 -07:00
|
|
|
);
|
2025-07-27 02:00:26 -04:00
|
|
|
expect(lastFrame()).toMatchSnapshot();
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-18 16:38:53 -08:00
|
|
|
it('calls onConfirm with ProceedOnce when "Allow once" is selected', () => {
|
2025-08-15 10:54:00 -07:00
|
|
|
const { lastFrame } = renderWithProviders(
|
|
|
|
|
<ShellConfirmationDialog request={request} />,
|
|
|
|
|
);
|
2025-07-27 02:00:26 -04:00
|
|
|
const select = lastFrame()!.toString();
|
|
|
|
|
// Simulate selecting the first option
|
|
|
|
|
// This is a simplified way to test the selection
|
2025-12-18 16:38:53 -08:00
|
|
|
expect(select).toContain('Allow once');
|
2025-07-27 02:00:26 -04:00
|
|
|
});
|
|
|
|
|
|
2025-12-18 16:38:53 -08:00
|
|
|
it('calls onConfirm with ProceedAlways when "Allow for this session" is selected', () => {
|
2025-08-15 10:54:00 -07:00
|
|
|
const { lastFrame } = renderWithProviders(
|
|
|
|
|
<ShellConfirmationDialog request={request} />,
|
|
|
|
|
);
|
2025-07-27 02:00:26 -04:00
|
|
|
const select = lastFrame()!.toString();
|
|
|
|
|
// Simulate selecting the second option
|
2025-12-18 16:38:53 -08:00
|
|
|
expect(select).toContain('Allow for this session');
|
2025-07-27 02:00:26 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('calls onConfirm with Cancel when "No (esc)" is selected', () => {
|
2025-08-15 10:54:00 -07:00
|
|
|
const { lastFrame } = renderWithProviders(
|
|
|
|
|
<ShellConfirmationDialog request={request} />,
|
2025-10-31 07:43:12 -07:00
|
|
|
{ width: 100 },
|
2025-08-15 10:54:00 -07:00
|
|
|
);
|
2025-07-27 02:00:26 -04:00
|
|
|
const select = lastFrame()!.toString();
|
|
|
|
|
// Simulate selecting the third option
|
|
|
|
|
expect(select).toContain('No (esc)');
|
|
|
|
|
});
|
|
|
|
|
});
|