|
| 1 | +import * as assert from 'assert'; |
| 2 | +import * as vscode from 'vscode'; |
| 3 | + |
| 4 | +import { resolveWorktreeArg } from '../../commands/utils/resolveWorktreeArg'; |
| 5 | + |
| 6 | +describe('resolveWorktreeArg', () => { |
| 7 | + it('passes through a plain string path', () => { |
| 8 | + assert.deepStrictEqual(resolveWorktreeArg('/repo/feature', '/repo'), { |
| 9 | + worktreePath: '/repo/feature', |
| 10 | + repositoryPath: '/repo', |
| 11 | + }); |
| 12 | + }); |
| 13 | + |
| 14 | + it('extracts fsPath from a Uri', () => { |
| 15 | + const uri = vscode.Uri.file('/repo/feature'); |
| 16 | + assert.deepStrictEqual(resolveWorktreeArg(uri, '/repo'), { |
| 17 | + worktreePath: '/repo/feature', |
| 18 | + repositoryPath: '/repo', |
| 19 | + }); |
| 20 | + }); |
| 21 | + |
| 22 | + it('extracts the path from a WorktreeTreeItem-shaped object, the argument VS Code actually sends for inline/context-menu commands', () => { |
| 23 | + const fakeTreeItem = { |
| 24 | + worktree: { path: '/repo/feature' }, |
| 25 | + repositoryPath: '/repo', |
| 26 | + contextValue: 'worktree linked clean', |
| 27 | + }; |
| 28 | + assert.deepStrictEqual(resolveWorktreeArg(fakeTreeItem), { |
| 29 | + worktreePath: '/repo/feature', |
| 30 | + repositoryPath: '/repo', |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + it('falls back to a separately passed repositoryPath when the tree item has none', () => { |
| 35 | + const fakeTreeItem = { worktree: { path: '/repo/feature' } }; |
| 36 | + assert.deepStrictEqual(resolveWorktreeArg(fakeTreeItem, '/repo'), { |
| 37 | + worktreePath: '/repo/feature', |
| 38 | + repositoryPath: '/repo', |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + it('returns undefined for unrecognized shapes', () => { |
| 43 | + assert.strictEqual(resolveWorktreeArg(undefined), undefined); |
| 44 | + assert.strictEqual(resolveWorktreeArg(null), undefined); |
| 45 | + assert.strictEqual(resolveWorktreeArg(''), undefined); |
| 46 | + assert.strictEqual(resolveWorktreeArg(42), undefined); |
| 47 | + assert.strictEqual(resolveWorktreeArg({}), undefined); |
| 48 | + assert.strictEqual(resolveWorktreeArg({ worktree: {} }), undefined); |
| 49 | + }); |
| 50 | +}); |
0 commit comments