| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import { render } from 'ink-testing-library'; |
| import { waitFor } from '@testing-library/react'; |
| import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; |
| import { SettingsDialog } from './SettingsDialog.js'; |
| import { LoadedSettings } from '../../config/settings.js'; |
| import { VimModeProvider } from '../contexts/VimModeContext.js'; |
| import { KeypressProvider } from '../contexts/KeypressContext.js'; |
|
|
| |
| const mockToggleVimEnabled = vi.fn(); |
| const mockSetVimMode = vi.fn(); |
|
|
| const createMockSettings = ( |
| userSettings = {}, |
| systemSettings = {}, |
| workspaceSettings = {}, |
| ) => |
| new LoadedSettings( |
| { |
| settings: { ui: { customThemes: {} }, mcpServers: {}, ...systemSettings }, |
| path: '/system/settings.json', |
| }, |
| { |
| settings: {}, |
| path: '/system/system-defaults.json', |
| }, |
| { |
| settings: { |
| ui: { customThemes: {} }, |
| mcpServers: {}, |
| ...userSettings, |
| }, |
| path: '/user/settings.json', |
| }, |
| { |
| settings: { |
| ui: { customThemes: {} }, |
| mcpServers: {}, |
| ...workspaceSettings, |
| }, |
| path: '/workspace/settings.json', |
| }, |
| [], |
| true, |
| new Set(), |
| ); |
|
|
| vi.mock('../contexts/SettingsContext.js', async () => { |
| const actual = await vi.importActual('../contexts/SettingsContext.js'); |
| let settings = createMockSettings({ 'a.string.setting': 'initial' }); |
| return { |
| ...actual, |
| useSettings: () => ({ |
| settings, |
| setSetting: (key: string, value: string) => { |
| settings = createMockSettings({ [key]: value }); |
| }, |
| getSettingDefinition: (key: string) => { |
| if (key === 'a.string.setting') { |
| return { |
| type: 'string', |
| description: 'A string setting', |
| }; |
| } |
| return undefined; |
| }, |
| }), |
| }; |
| }); |
|
|
| vi.mock('../contexts/VimModeContext.js', async () => { |
| const actual = await vi.importActual('../contexts/VimModeContext.js'); |
| return { |
| ...actual, |
| useVimMode: () => ({ |
| vimEnabled: false, |
| vimMode: 'INSERT' as const, |
| toggleVimEnabled: mockToggleVimEnabled, |
| setVimMode: mockSetVimMode, |
| }), |
| }; |
| }); |
|
|
| vi.mock('../../utils/settingsUtils.js', async () => { |
| const actual = await vi.importActual('../../utils/settingsUtils.js'); |
| return { |
| ...actual, |
| saveModifiedSettings: vi.fn(), |
| }; |
| }); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
|
|
| describe('SettingsDialog', () => { |
| const wait = (ms = 50) => new Promise((resolve) => setTimeout(resolve, ms)); |
|
|
| beforeEach(() => { |
| vi.clearAllMocks(); |
| |
| |
| |
| |
| |
| mockToggleVimEnabled.mockResolvedValue(true); |
| }); |
|
|
| afterEach(() => { |
| |
| |
| |
| |
| |
| }); |
|
|
| const createMockSettings = ( |
| userSettings = {}, |
| systemSettings = {}, |
| workspaceSettings = {}, |
| ) => |
| new LoadedSettings( |
| { |
| settings: { |
| ui: { customThemes: {} }, |
| mcpServers: {}, |
| ...systemSettings, |
| }, |
| path: '/system/settings.json', |
| }, |
| { |
| settings: {}, |
| path: '/system/system-defaults.json', |
| }, |
| { |
| settings: { |
| ui: { customThemes: {} }, |
| mcpServers: {}, |
| ...userSettings, |
| }, |
| path: '/user/settings.json', |
| }, |
| { |
| settings: { |
| ui: { customThemes: {} }, |
| mcpServers: {}, |
| ...workspaceSettings, |
| }, |
| path: '/workspace/settings.json', |
| }, |
| [], |
| true, |
| new Set(), |
| ); |
|
|
| describe('Initial Rendering', () => { |
| it('should render the settings dialog with default state', () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { lastFrame } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| const output = lastFrame(); |
| expect(output).toContain('Settings'); |
| expect(output).toContain('Apply To'); |
| expect(output).toContain('Use Enter to select, Tab to change focus'); |
| }); |
|
|
| it('should show settings list with default values', () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { lastFrame } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| const output = lastFrame(); |
| |
| expect(output).toContain('●'); |
| }); |
|
|
| it('should highlight first setting by default', () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { lastFrame } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| const output = lastFrame(); |
| |
| expect(output).toContain('●'); |
| }); |
| }); |
|
|
| describe('Settings Navigation', () => { |
| it('should navigate down with arrow key', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('\u001B[B'); |
| await wait(); |
|
|
| |
| unmount(); |
| }); |
|
|
| it('should navigate up with arrow key', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('\u001B[B'); |
| await wait(); |
| stdin.write('\u001B[A'); |
| await wait(); |
|
|
| unmount(); |
| }); |
|
|
| it('should navigate with vim keys (j/k)', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('j'); |
| await wait(); |
| stdin.write('k'); |
| await wait(); |
|
|
| unmount(); |
| }); |
|
|
| it('should not navigate beyond bounds', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('\u001B[A'); |
| await wait(); |
|
|
| |
| unmount(); |
| }); |
| }); |
|
|
| describe('Settings Toggling', () => { |
| it('should toggle setting with Enter key', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('\u000D'); |
| await wait(); |
|
|
| unmount(); |
| }); |
|
|
| it('should toggle setting with Space key', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write(' '); |
| await wait(); |
|
|
| unmount(); |
| }); |
|
|
| it('should handle vim mode setting specially', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| |
| stdin.write('\u000D'); |
| await wait(); |
|
|
| |
| unmount(); |
| }); |
| }); |
|
|
| describe('Scope Selection', () => { |
| it('should switch between scopes', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('\t'); |
| await wait(); |
|
|
| |
| stdin.write('2'); |
| await wait(); |
|
|
| unmount(); |
| }); |
|
|
| it('should reset to settings focus when scope is selected', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { lastFrame, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| await waitFor(() => { |
| expect(lastFrame()).toContain('Vim Mode'); |
| }); |
|
|
| |
| expect(lastFrame()).toContain('● Vim Mode'); |
| expect(lastFrame()).toContain(' Apply To'); |
|
|
| |
| |
|
|
| unmount(); |
| }); |
| }); |
|
|
| describe('Restart Prompt', () => { |
| it('should show restart prompt for restart-required settings', async () => { |
| const settings = createMockSettings(); |
| const onRestartRequest = vi.fn(); |
|
|
| const { unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog |
| settings={settings} |
| onSelect={() => {}} |
| onRestartRequest={onRestartRequest} |
| /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| |
| await wait(); |
|
|
| unmount(); |
| }); |
|
|
| it('should handle restart request when r is pressed', async () => { |
| const settings = createMockSettings(); |
| const onRestartRequest = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog |
| settings={settings} |
| onSelect={() => {}} |
| onRestartRequest={onRestartRequest} |
| /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('r'); |
| await wait(); |
|
|
| |
| unmount(); |
| }); |
| }); |
|
|
| describe('Escape Key Behavior', () => { |
| it('should call onSelect with undefined when Escape is pressed', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { lastFrame, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| await waitFor(() => { |
| expect(lastFrame()).toContain('Hide Window Title'); |
| }); |
|
|
| |
| expect(lastFrame()).toContain('Settings'); |
| expect(lastFrame()).toContain('Apply To'); |
|
|
| |
| |
|
|
| unmount(); |
| }); |
| }); |
|
|
| describe('Settings Persistence', () => { |
| it('should persist settings across scope changes', async () => { |
| const settings = createMockSettings({ vimMode: true }); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('\t'); |
| await wait(); |
|
|
| |
| stdin.write('2'); |
| await wait(); |
|
|
| |
| unmount(); |
| }); |
|
|
| it('should show different values for different scopes', () => { |
| const settings = createMockSettings( |
| { vimMode: true }, |
| { vimMode: false }, |
| { autoUpdate: false }, |
| ); |
| const onSelect = vi.fn(); |
|
|
| const { lastFrame } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| const output = lastFrame(); |
| expect(output).toContain('Settings'); |
| }); |
| }); |
|
|
| describe('Error Handling', () => { |
| it('should handle vim mode toggle errors gracefully', async () => { |
| mockToggleVimEnabled.mockRejectedValue(new Error('Toggle failed')); |
|
|
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('\u000D'); |
| await wait(); |
|
|
| |
| unmount(); |
| }); |
| }); |
|
|
| describe('Complex State Management', () => { |
| it('should track modified settings correctly', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('\u000D'); |
| await wait(); |
|
|
| |
| stdin.write('\u001B[B'); |
| await wait(); |
| stdin.write('\u000D'); |
| await wait(); |
|
|
| |
| unmount(); |
| }); |
|
|
| it('should handle scrolling when there are many settings', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| for (let i = 0; i < 10; i++) { |
| stdin.write('\u001B[B'); |
| await wait(10); |
| } |
|
|
| unmount(); |
| }); |
| }); |
|
|
| describe('VimMode Integration', () => { |
| it('should sync with VimModeContext when vim mode is toggled', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <VimModeProvider settings={settings}> |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider> |
| </VimModeProvider>, |
| ); |
|
|
| |
| |
| stdin.write('\u000D'); |
| await wait(); |
|
|
| unmount(); |
| }); |
| }); |
|
|
| describe('Specific Settings Behavior', () => { |
| it('should show correct display values for settings with different states', () => { |
| const settings = createMockSettings( |
| { vimMode: true, hideTips: false }, |
| { hideWindowTitle: true }, |
| { ideMode: false }, |
| ); |
| const onSelect = vi.fn(); |
|
|
| const { lastFrame } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| const output = lastFrame(); |
| |
| expect(output).toContain('Settings'); |
| }); |
|
|
| it('should handle immediate settings save for non-restart-required settings', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('\u000D'); |
| await wait(); |
|
|
| |
| unmount(); |
| }); |
|
|
| it('should show restart prompt for restart-required settings', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { lastFrame, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| |
| await wait(); |
|
|
| |
| expect(lastFrame()).not.toContain( |
| 'To see changes, Gemini CLI must be restarted', |
| ); |
|
|
| unmount(); |
| }); |
|
|
| it('should clear restart prompt when switching scopes', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| unmount(); |
| }); |
| }); |
|
|
| describe('Settings Display Values', () => { |
| it('should show correct values for inherited settings', () => { |
| const settings = createMockSettings( |
| {}, |
| { vimMode: true, hideWindowTitle: false }, |
| {}, |
| ); |
| const onSelect = vi.fn(); |
|
|
| const { lastFrame } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| const output = lastFrame(); |
| |
| expect(output).toContain('Settings'); |
| }); |
|
|
| it('should show override indicator for overridden settings', () => { |
| const settings = createMockSettings( |
| { vimMode: false }, |
| { vimMode: true }, |
| {}, |
| ); |
| const onSelect = vi.fn(); |
|
|
| const { lastFrame } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| const output = lastFrame(); |
| |
| expect(output).toContain('Settings'); |
| }); |
| }); |
|
|
| describe('Keyboard Shortcuts Edge Cases', () => { |
| it('should handle rapid key presses gracefully', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| for (let i = 0; i < 5; i++) { |
| stdin.write('\u001B[B'); |
| stdin.write('\u001B[A'); |
| } |
| await wait(100); |
|
|
| |
| unmount(); |
| }); |
|
|
| it('should handle Ctrl+C to reset current setting to default', async () => { |
| const settings = createMockSettings({ vimMode: true }); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('\u0003'); |
| await wait(); |
|
|
| |
| unmount(); |
| }); |
|
|
| it('should handle Ctrl+L to reset current setting to default', async () => { |
| const settings = createMockSettings({ vimMode: true }); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('\u000C'); |
| await wait(); |
|
|
| |
| unmount(); |
| }); |
|
|
| it('should handle navigation when only one setting exists', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('\u001B[B'); |
| await wait(); |
| stdin.write('\u001B[A'); |
| await wait(); |
|
|
| unmount(); |
| }); |
|
|
| it('should properly handle Tab navigation between sections', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { lastFrame, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| await waitFor(() => { |
| expect(lastFrame()).toContain('Vim Mode'); |
| }); |
|
|
| |
| expect(lastFrame()).toContain('● Vim Mode'); |
| expect(lastFrame()).toContain(' Apply To'); |
|
|
| |
| |
|
|
| unmount(); |
| }); |
| }); |
|
|
| describe('Error Recovery', () => { |
| it('should handle malformed settings gracefully', () => { |
| |
| const settings = createMockSettings( |
| { vimMode: null as unknown as boolean }, |
| {}, |
| {}, |
| ); |
| const onSelect = vi.fn(); |
|
|
| const { lastFrame } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| expect(lastFrame()).toContain('Settings'); |
| }); |
|
|
| it('should handle missing setting definitions gracefully', () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| |
| const { lastFrame } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| expect(lastFrame()).toContain('Settings'); |
| }); |
| }); |
|
|
| describe('Complex User Interactions', () => { |
| it('should handle complete user workflow: navigate, toggle, change scope, exit', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { lastFrame, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| await waitFor(() => { |
| expect(lastFrame()).toContain('Vim Mode'); |
| }); |
|
|
| |
| expect(lastFrame()).toContain('Settings'); |
| expect(lastFrame()).toContain('● Vim Mode'); |
| expect(lastFrame()).toContain('Apply To'); |
| expect(lastFrame()).toContain('1. User Settings'); |
| expect(lastFrame()).toContain( |
| '(Use Enter to select, Tab to change focus)', |
| ); |
|
|
| |
| |
|
|
| unmount(); |
| }); |
|
|
| it('should allow changing multiple settings without losing pending changes', async () => { |
| const settings = createMockSettings(); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('\u000D'); |
| await wait(); |
|
|
| |
| stdin.write('\u001B[B'); |
| await wait(); |
| stdin.write('\u000D'); |
| await wait(); |
|
|
| |
| stdin.write('\u001B[B'); |
| await wait(); |
| stdin.write('\u000D'); |
| await wait(); |
|
|
| |
| |
| unmount(); |
| }); |
|
|
| it('should maintain state consistency during complex interactions', async () => { |
| const settings = createMockSettings({ vimMode: true }); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('\t'); |
| await wait(); |
| stdin.write('2'); |
| await wait(); |
| stdin.write('\t'); |
| await wait(); |
| stdin.write('\t'); |
| await wait(); |
| stdin.write('1'); |
| await wait(); |
|
|
| |
| unmount(); |
| }); |
|
|
| it('should handle restart workflow correctly', async () => { |
| const settings = createMockSettings(); |
| const onRestartRequest = vi.fn(); |
|
|
| const { stdin, unmount } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog |
| settings={settings} |
| onSelect={() => {}} |
| onRestartRequest={onRestartRequest} |
| /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| stdin.write('r'); |
| await wait(); |
|
|
| |
| expect(onRestartRequest).not.toHaveBeenCalled(); |
|
|
| unmount(); |
| }); |
| }); |
|
|
| describe('String Settings Editing', () => { |
| it('should allow editing and committing a string setting', async () => { |
| let settings = createMockSettings({ 'a.string.setting': 'initial' }); |
| const onSelect = vi.fn(); |
|
|
| const { stdin, unmount, rerender } = render( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
|
|
| |
| await wait(); |
|
|
| |
| for (let i = 0; i < 20; i++) { |
| stdin.write('j'); |
| await wait(10); |
| } |
|
|
| |
| stdin.write('\r'); |
| await wait(); |
|
|
| |
| stdin.write('new value'); |
| await wait(); |
|
|
| |
| stdin.write('\r'); |
| await wait(); |
|
|
| settings = createMockSettings( |
| { 'a.string.setting': 'new value' }, |
| {}, |
| {}, |
| ); |
| rerender( |
| <KeypressProvider kittyProtocolEnabled={false}> |
| <SettingsDialog settings={settings} onSelect={onSelect} /> |
| </KeypressProvider>, |
| ); |
| await wait(); |
|
|
| |
| stdin.write('\u001B'); |
| await wait(); |
|
|
| expect(onSelect).toHaveBeenCalledWith(undefined, 'User'); |
|
|
| unmount(); |
| }); |
| }); |
| }); |
|
|