-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Expand file tree
/
Copy pathSessionRetentionWarningDialog.test.tsx
More file actions
119 lines (102 loc) · 3.5 KB
/
SessionRetentionWarningDialog.test.tsx
File metadata and controls
119 lines (102 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*
* @license
*/
import { describe, it, expect, vi, afterEach } from 'vitest';
import { renderWithProviders } from '../../test-utils/render.js';
import { SessionRetentionWarningDialog } from './SessionRetentionWarningDialog.js';
import { waitFor } from '../../test-utils/async.js';
import { act } from 'react';
// Helper to write to stdin
const writeKey = (stdin: { write: (data: string) => void }, key: string) => {
act(() => {
stdin.write(key);
});
};
describe('SessionRetentionWarningDialog', () => {
afterEach(() => {
vi.restoreAllMocks();
});
it('renders correctly with warning message and session count', async () => {
const { lastFrame, waitUntilReady } = renderWithProviders(
<SessionRetentionWarningDialog
onKeep120Days={vi.fn()}
onKeep30Days={vi.fn()}
sessionsToDeleteCount={42}
/>,
);
await waitUntilReady();
expect(lastFrame()).toContain('Keep chat history');
expect(lastFrame()).toContain(
'introducing a limit on how long chat sessions are stored',
);
expect(lastFrame()).toContain('Keep for 30 days (Recommended)');
expect(lastFrame()).toContain('42 sessions will be deleted');
expect(lastFrame()).toContain('Keep for 120 days');
expect(lastFrame()).toContain('No sessions will be deleted at this time');
});
it('handles pluralization correctly for 1 session', async () => {
const { lastFrame, waitUntilReady } = renderWithProviders(
<SessionRetentionWarningDialog
onKeep120Days={vi.fn()}
onKeep30Days={vi.fn()}
sessionsToDeleteCount={1}
/>,
);
await waitUntilReady();
expect(lastFrame()).toContain('1 session will be deleted');
});
it('defaults to "Keep for 120 days" when there are sessions to delete', async () => {
const onKeep120Days = vi.fn();
const onKeep30Days = vi.fn();
const { stdin, waitUntilReady } = renderWithProviders(
<SessionRetentionWarningDialog
onKeep120Days={onKeep120Days}
onKeep30Days={onKeep30Days}
sessionsToDeleteCount={10}
/>,
);
await waitUntilReady();
// Initial selection should be "Keep for 120 days" (index 1) because count > 0
// Pressing Enter immediately should select it.
writeKey(stdin, '\r');
await waitFor(() => {
expect(onKeep120Days).toHaveBeenCalled();
expect(onKeep30Days).not.toHaveBeenCalled();
});
});
it('calls onKeep30Days when "Keep for 30 days" is explicitly selected (from 120 days default)', async () => {
const onKeep120Days = vi.fn();
const onKeep30Days = vi.fn();
const { stdin, waitUntilReady } = renderWithProviders(
<SessionRetentionWarningDialog
onKeep120Days={onKeep120Days}
onKeep30Days={onKeep30Days}
sessionsToDeleteCount={10}
/>,
);
await waitUntilReady();
// Default is index 1 (120 days). Move UP to index 0 (30 days).
writeKey(stdin, '\x1b[A'); // Up arrow
writeKey(stdin, '\r');
await waitFor(() => {
expect(onKeep30Days).toHaveBeenCalled();
expect(onKeep120Days).not.toHaveBeenCalled();
});
});
it('should match snapshot', async () => {
const { lastFrame, waitUntilReady } = renderWithProviders(
<SessionRetentionWarningDialog
onKeep120Days={vi.fn()}
onKeep30Days={vi.fn()}
sessionsToDeleteCount={123}
/>,
);
await waitUntilReady();
// Initial render
expect(lastFrame()).toMatchSnapshot();
});
});