mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-10-01 09:19:34 +05:30
The explorer panel's explorerCurrentDir is hardcoded to null, so the Quick Switcher's workspace toggle was a no-op. Rather than fix the broken explorer flow, derive the workspace from the active tab's filePath's parent directory — the most reliable source we have without restructuring that panel. deriveWorkspaceDir() handles POSIX and Windows paths (including mixed separators and trailing separators), returns null for untitled / empty inputs so the workspace toggle silently stays off in those cases. 10 new tests cover POSIX, Windows, mixed-separator, trailing separator, UNC, and invalid input paths. Amit Haridas
55 lines
1.8 KiB
JavaScript
55 lines
1.8 KiB
JavaScript
/**
|
|
* @jest-environment node
|
|
*
|
|
* Workspace dir resolver — derive parent dir from a file path.
|
|
*/
|
|
|
|
const { deriveWorkspaceDir } = require('../src/quick-switcher/workspace-dir-resolver');
|
|
|
|
describe('deriveWorkspaceDir', () => {
|
|
test('returns parent dir for a POSIX path', () => {
|
|
expect(deriveWorkspaceDir('/home/user/notes/readme.md')).toBe('/home/user/notes');
|
|
});
|
|
|
|
test('returns parent dir for a Windows path', () => {
|
|
expect(deriveWorkspaceDir('C:\\Users\\me\\notes\\readme.md')).toBe('C:\\Users\\me\\notes');
|
|
});
|
|
|
|
test('returns parent dir for a nested POSIX path', () => {
|
|
expect(deriveWorkspaceDir('/a/b/c/d/e.md')).toBe('/a/b/c/d');
|
|
});
|
|
|
|
test('auto-detects separator when path contains both', () => {
|
|
// A path with both — backslash takes precedence (Windows convention)
|
|
expect(deriveWorkspaceDir('C:\\foo/bar.txt')).toBe('C:\\foo');
|
|
});
|
|
|
|
test('returns null for a root-level POSIX file', () => {
|
|
expect(deriveWorkspaceDir('readme.md')).toBeNull();
|
|
});
|
|
|
|
test('returns null for an empty string', () => {
|
|
expect(deriveWorkspaceDir('')).toBeNull();
|
|
});
|
|
|
|
test('returns null for null / undefined / non-string', () => {
|
|
expect(deriveWorkspaceDir(null)).toBeNull();
|
|
expect(deriveWorkspaceDir(undefined)).toBeNull();
|
|
expect(deriveWorkspaceDir(42)).toBeNull();
|
|
expect(deriveWorkspaceDir({})).toBeNull();
|
|
});
|
|
|
|
test('returns null for a single-character filename', () => {
|
|
expect(deriveWorkspaceDir('/x')).toBeNull();
|
|
expect(deriveWorkspaceDir('\\x')).toBeNull();
|
|
});
|
|
|
|
test('preserves trailing separators', () => {
|
|
expect(deriveWorkspaceDir('/home/user/notes/')).toBe('/home/user');
|
|
});
|
|
|
|
test('handles UNC-style Windows path', () => {
|
|
expect(deriveWorkspaceDir('\\\\server\\share\\file.md')).toBe('\\\\server\\share');
|
|
});
|
|
});
|