From cbd4f418f6e7ba231a54ebf17c76b7fbb9d9019d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 09:03:09 +0000 Subject: [PATCH] test: Add tests for expandNotesPath function - Added comprehensive test cases for tilde expansion - Added tests for relative path expansion - Added tests for absolute path handling - Added tests for edge cases and custom base paths Co-authored-by: DeJeune <67425183+DeJeune@users.noreply.github.com> --- src/main/utils/__tests__/file.test.ts | 59 +++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/main/utils/__tests__/file.test.ts b/src/main/utils/__tests__/file.test.ts index f6f6d2c40e..d6abefd729 100644 --- a/src/main/utils/__tests__/file.test.ts +++ b/src/main/utils/__tests__/file.test.ts @@ -10,6 +10,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { readTextFileWithAutoEncoding } from '../file' import { + expandNotesPath, getAllFiles, getAppConfigDir, getConfigDir, @@ -331,6 +332,64 @@ describe('file', () => { }) }) + describe('expandNotesPath', () => { + beforeEach(() => { + // Mock path.isAbsolute + vi.mocked(path.isAbsolute).mockImplementation((p) => { + return p.startsWith('/') || /^[A-Za-z]:/.test(p) + }) + + // Mock path.resolve + vi.mocked(path.resolve).mockImplementation((...args) => { + const joined = args.join('/') + return joined.startsWith('/') ? joined : `/${joined}` + }) + + // Mock path.normalize + vi.mocked(path.normalize).mockImplementation((p) => p.replace(/\/+/g, '/')) + }) + + it('should expand tilde paths to home directory', () => { + const result = expandNotesPath('~/Notes') + expect(result).toBe('/mock/home/Notes') + }) + + it('should expand relative paths using userData as base', () => { + const result = expandNotesPath('./Notes') + expect(result).toContain('userData') + }) + + it('should return absolute paths unchanged', () => { + const result = expandNotesPath('/absolute/path/Notes') + expect(result).toBe('/absolute/path/Notes') + }) + + it('should handle Windows absolute paths', () => { + const result = expandNotesPath('C:\\Users\\Notes') + expect(result).toBe('C:\\Users\\Notes') + }) + + it('should handle empty string', () => { + const result = expandNotesPath('') + expect(result).toBe('') + }) + + it('should expand parent directory paths', () => { + const result = expandNotesPath('../Notes') + expect(result).toContain('userData') + }) + + it('should use custom base path when provided', () => { + const result = expandNotesPath('./Notes', '/custom/base') + expect(result).toContain('/custom/base') + }) + + it('should handle complex relative paths', () => { + const result = expandNotesPath('../../Notes') + expect(result).toContain('userData') + }) + }) + describe('isPathInside', () => { beforeEach(() => { // Mock path.resolve to simulate path resolution