2026-01-14 10:22:21 -05:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
|
|
|
import { act } from 'react';
|
|
|
|
|
import { renderWithProviders } from '../../test-utils/render.js';
|
|
|
|
|
import { waitFor } from '../../test-utils/async.js';
|
|
|
|
|
import { RewindConfirmation, RewindOutcome } from './RewindConfirmation.js';
|
|
|
|
|
|
|
|
|
|
describe('RewindConfirmation', () => {
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
vi.restoreAllMocks();
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-18 16:46:50 -08:00
|
|
|
it('renders correctly with stats', async () => {
|
2026-01-14 10:22:21 -05:00
|
|
|
const stats = {
|
|
|
|
|
addedLines: 10,
|
|
|
|
|
removedLines: 5,
|
|
|
|
|
fileCount: 1,
|
|
|
|
|
details: [{ fileName: 'test.ts', diff: '' }],
|
|
|
|
|
};
|
|
|
|
|
const onConfirm = vi.fn();
|
2026-03-19 17:05:33 +00:00
|
|
|
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
|
2026-01-14 10:22:21 -05:00
|
|
|
<RewindConfirmation
|
|
|
|
|
stats={stats}
|
|
|
|
|
onConfirm={onConfirm}
|
|
|
|
|
terminalWidth={80}
|
|
|
|
|
/>,
|
|
|
|
|
{ width: 80 },
|
|
|
|
|
);
|
2026-02-18 16:46:50 -08:00
|
|
|
await waitUntilReady();
|
2026-01-14 10:22:21 -05:00
|
|
|
|
|
|
|
|
expect(lastFrame()).toMatchSnapshot();
|
|
|
|
|
expect(lastFrame()).toContain('Revert code changes');
|
2026-02-18 16:46:50 -08:00
|
|
|
unmount();
|
2026-01-14 10:22:21 -05:00
|
|
|
});
|
|
|
|
|
|
2026-02-18 16:46:50 -08:00
|
|
|
it('renders correctly without stats', async () => {
|
2026-01-14 10:22:21 -05:00
|
|
|
const onConfirm = vi.fn();
|
2026-03-19 17:05:33 +00:00
|
|
|
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
|
2026-01-14 10:22:21 -05:00
|
|
|
<RewindConfirmation
|
|
|
|
|
stats={null}
|
|
|
|
|
onConfirm={onConfirm}
|
|
|
|
|
terminalWidth={80}
|
|
|
|
|
/>,
|
|
|
|
|
{ width: 80 },
|
|
|
|
|
);
|
2026-02-18 16:46:50 -08:00
|
|
|
await waitUntilReady();
|
2026-01-14 10:22:21 -05:00
|
|
|
|
|
|
|
|
expect(lastFrame()).toMatchSnapshot();
|
|
|
|
|
expect(lastFrame()).not.toContain('Revert code changes');
|
|
|
|
|
expect(lastFrame()).toContain('Rewind conversation');
|
2026-02-18 16:46:50 -08:00
|
|
|
unmount();
|
2026-01-14 10:22:21 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('calls onConfirm with Cancel on Escape', async () => {
|
|
|
|
|
const onConfirm = vi.fn();
|
2026-03-19 17:05:33 +00:00
|
|
|
const { stdin, waitUntilReady, unmount } = await renderWithProviders(
|
2026-01-14 10:22:21 -05:00
|
|
|
<RewindConfirmation
|
|
|
|
|
stats={null}
|
|
|
|
|
onConfirm={onConfirm}
|
|
|
|
|
terminalWidth={80}
|
|
|
|
|
/>,
|
|
|
|
|
{ width: 80 },
|
|
|
|
|
);
|
2026-02-18 16:46:50 -08:00
|
|
|
await waitUntilReady();
|
2026-01-14 10:22:21 -05:00
|
|
|
|
|
|
|
|
await act(async () => {
|
|
|
|
|
stdin.write('\x1b');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
|
expect(onConfirm).toHaveBeenCalledWith(RewindOutcome.Cancel);
|
|
|
|
|
});
|
2026-02-18 16:46:50 -08:00
|
|
|
unmount();
|
2026-01-14 10:22:21 -05:00
|
|
|
});
|
|
|
|
|
|
2026-02-18 16:46:50 -08:00
|
|
|
it('renders timestamp when provided', async () => {
|
2026-01-14 10:22:21 -05:00
|
|
|
const onConfirm = vi.fn();
|
|
|
|
|
const timestamp = new Date().toISOString();
|
2026-03-19 17:05:33 +00:00
|
|
|
const { lastFrame, waitUntilReady, unmount } = await renderWithProviders(
|
2026-01-14 10:22:21 -05:00
|
|
|
<RewindConfirmation
|
|
|
|
|
stats={null}
|
|
|
|
|
onConfirm={onConfirm}
|
|
|
|
|
terminalWidth={80}
|
|
|
|
|
timestamp={timestamp}
|
|
|
|
|
/>,
|
|
|
|
|
{ width: 80 },
|
|
|
|
|
);
|
2026-02-18 16:46:50 -08:00
|
|
|
await waitUntilReady();
|
2026-01-14 10:22:21 -05:00
|
|
|
|
|
|
|
|
expect(lastFrame()).toMatchSnapshot();
|
|
|
|
|
expect(lastFrame()).not.toContain('Revert code changes');
|
2026-02-18 16:46:50 -08:00
|
|
|
unmount();
|
2026-01-14 10:22:21 -05:00
|
|
|
});
|
|
|
|
|
});
|