From 7ccc48d85725682394eaac2214b6eae5c70d660b Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Thu, 5 Feb 2026 19:32:01 +0000 Subject: [PATCH] Initial upload with CI/CD workflow --- tests/unit/parsers.test.ts | 173 +++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 tests/unit/parsers.test.ts diff --git a/tests/unit/parsers.test.ts b/tests/unit/parsers.test.ts new file mode 100644 index 0000000..15a2e65 --- /dev/null +++ b/tests/unit/parsers.test.ts @@ -0,0 +1,173 @@ +import { TmuxParser, tmuxParser } from '../../src/parsers/tmuxParser'; +import { ScreenParser, screenParser } from '../../src/parsers/screenParser'; +import { iTerm2Parser, iterm2Parser } from '../../src/parsers/iterm2Parser'; +import { Layout, TerminalType } from '../../src/models/types'; + +describe('TmuxParser', () => { + describe('isAvailable', () => { + it('should check if tmux is available', async () => { + const available = await tmuxParser.isAvailable(); + expect(typeof available).toBe('boolean'); + }); + }); + + describe('listSessions', () => { + it('should return list of sessions', async () => { + const sessions = await tmuxParser.listSessions(); + expect(Array.isArray(sessions)).toBe(true); + }); + }); + + describe('generateRestoreCommands', () => { + it('should generate commands for layout restoration', async () => { + const layout: Layout = { + version: '1.0.0', + terminalType: 'tmux' as TerminalType, + createdAt: '2024-01-01T00:00:00.000Z', + updatedAt: '2024-01-01T00:00:00.000Z', + session: { + id: 's-test', + name: 'test-session', + windows: [ + { + id: 'w0', + index: 0, + name: 'main', + panes: [ + { + id: 'p0', + index: 0, + layout: { x: 0, y: 0, width: 80, height: 24 }, + cwd: '/home/user', + command: 'vim', + }, + ], + }, + ], + activeWindowIndex: 0, + }, + }; + + const commands = await tmuxParser.generateRestoreCommands(layout, 'test-session'); + expect(Array.isArray(commands)).toBe(true); + expect(commands.length).toBeGreaterThan(0); + expect(commands[0]).toContain('tmux new-session'); + }); + }); +}); + +describe('ScreenParser', () => { + describe('isAvailable', () => { + it('should check if screen is available', async () => { + const available = await screenParser.isAvailable(); + expect(typeof available).toBe('boolean'); + }); + }); + + describe('listSessions', () => { + it('should return list of sessions', async () => { + const sessions = await screenParser.listSessions(); + expect(Array.isArray(sessions)).toBe(true); + }); + }); + + describe('generateRestoreCommands', () => { + it('should generate commands for screen layout restoration', async () => { + const layout: Layout = { + version: '1.0.0', + terminalType: 'screen' as TerminalType, + createdAt: '2024-01-01T00:00:00.000Z', + updatedAt: '2024-01-01T00:00:00.000Z', + session: { + id: 's-test', + name: 'test-screen', + windows: [ + { + id: 'w0', + index: 0, + name: 'main', + panes: [ + { + id: 'p0', + index: 0, + layout: { x: 0, y: 0, width: 80, height: 24 }, + }, + ], + }, + ], + activeWindowIndex: 0, + }, + }; + + const commands = await screenParser.generateRestoreCommands(layout, 'test-screen'); + expect(Array.isArray(commands)).toBe(true); + expect(commands[0]).toContain('screen -dmS'); + }); + }); +}); + +describe('iTerm2Parser', () => { + describe('isAvailable', () => { + it('should check if iTerm2 is available', async () => { + const available = await iterm2Parser.isAvailable(); + expect(typeof available).toBe('boolean'); + }); + }); + + describe('listProfiles', () => { + it('should return list of profiles', async () => { + const profiles = await iterm2Parser.listProfiles(); + expect(Array.isArray(profiles)).toBe(true); + }); + }); + + describe('generateRestoreScript', () => { + it('should generate AppleScript for iTerm2', async () => { + const layout: Layout = { + version: '1.0.0', + terminalType: 'iterm2' as TerminalType, + createdAt: '2024-01-01T00:00:00.000Z', + updatedAt: '2024-01-01T00:00:00.000Z', + session: { + id: 's-iterm2', + name: 'iterm2', + windows: [ + { + id: 'w0', + index: 0, + name: 'main', + panes: [ + { + id: 'p0', + index: 0, + layout: { x: 0, y: 0, width: 80, height: 24 }, + cwd: '/Users/user', + }, + ], + }, + ], + activeWindowIndex: 0, + }, + }; + + const script = await iterm2Parser.generateRestoreScript(layout); + expect(typeof script).toBe('string'); + expect(script).toContain('osascript'); + }); + }); + + describe('captureCurrentLayout', () => { + it('should capture current iTerm2 layout', async () => { + const result = await iterm2Parser.captureCurrentLayout(); + if (process.platform === 'darwin') { + expect(result.success).toBe(true); + if (result.data) { + expect(result.data.terminalType).toBe('iterm2'); + } + } else { + expect(result.success).toBe(false); + expect(result.error).toContain('macOS'); + } + }); + }); +});