please analyse this module from an obsidian plugin and its unittests and suggest fixes and improvements. Current unitttests may have some wrong assumptions:
module:
import { normalizePath, Notice, type Vault } from "obsidian";
import { devError } from "./logging";

interface FileSystemError extends Error {
    code?: string;
}

export async function generateUniqueFilePath(
    vault: Vault,
    baseDir: string,
    fileName: string,
): Promise<string> {
    const normalizedBaseDir = normalizePath(baseDir);
    const originalFileName = normalizePath(fileName);

    let counter = 0;
    let currentPath = normalizePath(`${normalizedBaseDir}/${originalFileName}`);
    const extSeparator = originalFileName.includes(".") ? "." : ""; // Handle files with no extension
    const baseName = originalFileName.substring(
        0,
        originalFileName.lastIndexOf(extSeparator),
    );
    const ext = originalFileName.substring(
        originalFileName.lastIndexOf(extSeparator),
    );

    while (await vault.adapter.exists(currentPath)) {
        counter++;
        currentPath = normalizePath(
            `${normalizedBaseDir}/${baseName} (${counter})${ext}`,
        );
    }

    return currentPath;
}

export async function ensureParentDirectory(
    vault: Vault,
    filePath: string,
): Promise<void> {
    const dirPath = normalizePath(
        filePath.substring(0, filePath.lastIndexOf("/")),
    );
    const dirExists = vault.getFolderByPath(dirPath);

    if (!dirExists) {
        await vault.createFolder(dirPath);
    }
}

export function handleFileSystemError(
    operationDescription: string,
    filePath: string,
    error: unknown,
    options: {
        shouldThrow?: boolean;
        customNoticeMessage?: string;
    } = {},
): Error {
    const { shouldThrow = false, customNoticeMessage } = options;
    const baseError = error instanceof Error ? error : new Error(String(error));

    let userMessage = customNoticeMessage;
    let detailedMessage =
        `Error ${operationDescription} "${filePath}": ${baseError.message}`;

    const errorCode =
        typeof error === "object" && error !== null && "code" in error &&
            typeof error.code === "string"
            ? error.code
            : undefined;

    if (errorCode) {
        detailedMessage += ` (Code: ${errorCode})`;
        switch (errorCode) { 
            case "ENOENT":
                userMessage = userMessage ?? `Not found: ${filePath}`;
                detailedMessage =
                    `File/Directory not found: ${filePath}. Operation: ${operationDescription}.`;
                break;
            case "EPERM":
            case "EACCES":
                userMessage = userMessage ?? `Permission denied: ${filePath}`;
                detailedMessage =
                    `Permission/Access denied for ${filePath}. Operation: ${operationDescription}.`;
                break;
            case "EISDIR":
                userMessage = userMessage ??
                    `Expected a file but found a directory: ${filePath}`;
                detailedMessage =
                    `Path is a directory, but a file was expected: ${filePath}. Operation: ${operationDescription}.`;
                break;
            case "ENOTDIR":
                userMessage = userMessage ??
                    `Expected a directory but found a file: ${filePath}`;
                detailedMessage =
                    `Path is a file, but a directory was expected: ${filePath}. Operation: ${operationDescription}.`;
                break;
        }
    }

    userMessage = userMessage ??
        `Failed to ${
            operationDescription.split(" ")[0]
        } ${filePath}. Check console.`;

    devError(detailedMessage, baseError.stack);
    new Notice(userMessage, 7000);

    if (shouldThrow) {
        throw new Error(
            `Operation failed: ${operationDescription} for ${filePath}. Reason: ${baseError.message}`,
        );
    }
    return baseError;
}

unittests:
import {
generateUniqueFilePath,
ensureParentDirectory,
handleFileSystemError,
} from '../src/utils/fileUtils';
import { normalizePath } from 'obsidian'; // This is for potential use in mocks, not for testing normalizePath itself

// Mock Obsidian specific modules
jest.mock('obsidian', () => {
const originalObsidian = jest.requireActual('obsidian');
return {
    ...originalObsidian,
    Notice: jest.fn(),
    normalizePath: jest.fn((path) => path.replace(/\\/g, '/').replace(/\/{2,}/g, '/')), // Provide a basic mock implementation
};
});

jest.mock('../src/utils/logging', () => ({
devError: jest.fn(),
devLog: jest.fn(),
devWarn: jest.fn(),
}));

describe('fileUtils', () => {
// Tests for generateUniqueFilePath will go here
// Tests for ensureParentDirectory will go here
// Tests for handleFileSystemError will go here
});

describe('generateUniqueFilePath', () => {
let mockVault: any;

beforeEach(() => {
    // Reset normalizePath mock calls and implementation for each test if needed
    (normalizePath as jest.Mock).mockImplementation((path) => path.replace(/\\/g, '/').replace(/\/{2,}/g, '/'));

    mockVault = {
        adapter: {
            exists: jest.fn(),
        },
    };
});

it('should return original path if it does not exist', async () => {
    mockVault.adapter.exists.mockResolvedValue(false);
    const filePath = await generateUniqueFilePath(mockVault, 'testDir', 'file.md');
    expect(filePath).toBe('testDir/file.md');
    expect(mockVault.adapter.exists).toHaveBeenCalledWith('testDir/file.md');
});

it('should return path with (1) if original exists', async () => {
    mockVault.adapter.exists.mockImplementation((path: string) => {
        if (path === 'testDir/file.md') return Promise.resolve(true);
        if (path === 'testDir/file (1).md') return Promise.resolve(false);
        return Promise.resolve(false);
    });
    const filePath = await generateUniqueFilePath(mockVault, 'testDir', 'file.md');
    expect(filePath).toBe('testDir/file (1).md');
    expect(mockVault.adapter.exists).toHaveBeenCalledWith('testDir/file.md');
    expect(mockVault.adapter.exists).toHaveBeenCalledWith('testDir/file (1).md');
});

it('should increment counter until a unique path is found', async () => {
    mockVault.adapter.exists.mockImplementation((path: string) => {
        if (path === 'testDir/file.md') return Promise.resolve(true);
        if (path === 'testDir/file (1).md') return Promise.resolve(true);
        if (path === 'testDir/file (2).md') return Promise.resolve(false);
        return Promise.resolve(false);
    });
    const filePath = await generateUniqueFilePath(mockVault, 'testDir', 'file.md');
    expect(filePath).toBe('testDir/file (2).md');
    expect(mockVault.adapter.exists).toHaveBeenCalledTimes(3);
});

it('should handle filenames without extensions', async () => {
    mockVault.adapter.exists.mockImplementation((path: string) => {
        if (path === 'testDir/file') return Promise.resolve(true);
        if (path === 'testDir/file (1)') return Promise.resolve(false);
        return Promise.resolve(false);
    });
    const filePath = await generateUniqueFilePath(mockVault, 'testDir', 'file');
    expect(filePath).toBe('testDir/file (1)');
});

it('should use normalizePath for baseDir and fileName inputs', async () => {
    (normalizePath as jest.Mock).mockImplementation(path => `normalized/${path}`);
    mockVault.adapter.exists.mockResolvedValue(false);

    await generateUniqueFilePath(mockVault, 'test\\Dir', 'file.md');
    
    expect(normalizePath).toHaveBeenCalledWith('test\\Dir');
    expect(normalizePath).toHaveBeenCalledWith('file.md');
    expect(mockVault.adapter.exists).toHaveBeenCalledWith('normalized/normalized/file.md');
});

it('should handle paths with multiple dots in filename correctly', async () => {
    mockVault.adapter.exists.mockImplementation((path: string) => {
        if (path === 'testDir/file.archive.tar.gz') return Promise.resolve(true);
        if (path === 'testDir/file.archive.tar (1).gz') return Promise.resolve(false);
        return Promise.resolve(false);
    });
    const filePath = await generateUniqueFilePath(mockVault, 'testDir', 'file.archive.tar.gz');
    expect(filePath).toBe('testDir/file.archive.tar (1).gz');
});
});

describe('ensureParentDirectory', () => {
let mockVault: any;

beforeEach(() => {
    (normalizePath as jest.Mock).mockImplementation((path) => path.replace(/\\/g, '/').replace(/\/{2,}/g, '/'));
    mockVault = {
        getFolderByPath: jest.fn(),
        createFolder: jest.fn().mockResolvedValue(undefined),
    };
});

it('should do nothing if parent directory already exists', async () => {
    const filePath = 'parent/child/file.md';
    mockVault.getFolderByPath.mockReturnValue({}); // Simulate folder exists

    await ensureParentDirectory(mockVault, filePath);

    expect(normalizePath).toHaveBeenCalledWith('parent/child');
    expect(mockVault.getFolderByPath).toHaveBeenCalledWith('parent/child');
    expect(mockVault.createFolder).not.toHaveBeenCalled();
});

it('should create parent directory if it does not exist', async () => {
    const filePath = 'newParent/child/file.md';
    mockVault.getFolderByPath.mockReturnValue(null); // Simulate folder does not exist

    await ensureParentDirectory(mockVault, filePath);
    
    expect(normalizePath).toHaveBeenCalledWith('newParent/child');
    expect(mockVault.getFolderByPath).toHaveBeenCalledWith('newParent/child');
    expect(mockVault.createFolder).toHaveBeenCalledWith('newParent/child');
});

it('should handle file path in root directory (no parent)', async () => {
    const filePath = 'file_in_root.md';
    // normalizePath will be called with an empty string for the directory path
    // getFolderByPath will be called with an empty string

    mockVault.getFolderByPath.mockImplementation((path: string) => {
        if (path === '') return {}; // Root directory always exists conceptually
        return null;
    });
    
    await ensureParentDirectory(mockVault, filePath);

    expect(normalizePath).toHaveBeenCalledWith(''); 
    expect(mockVault.getFolderByPath).toHaveBeenCalledWith('');
    expect(mockVault.createFolder).not.toHaveBeenCalled();
});
});

describe('handleFileSystemError', () => {
const { Notice } = jest.requireActual('obsidian'); // Get the original Notice
const mockNotice = jest.fn();
const { devError } = require('../src/utils/logging');

beforeEach(() => {
    jest.clearAllMocks();
    // @ts-ignore
    global.Notice = mockNotice; // Replace global Notice with mock for this scope
});

afterEach(() => {
    // @ts-ignore
    global.Notice = Notice; // Restore original Notice
});

const testCases = [
    { code: 'ENOENT', expectedMsgPart: 'Not found', defaultNotice: 'Not found: test/path' },
    { code: 'EPERM', expectedMsgPart: 'Permission denied', defaultNotice: 'Permission denied: test/path' },
    { code: 'EACCES', expectedMsgPart: 'Permission denied', defaultNotice: 'Permission denied: test/path' },
    { code: 'EISDIR', expectedMsgPart: 'Expected a file but found a directory', defaultNotice: 'Expected a file but found a directory: test/path' },
    { code: 'ENOTDIR', expectedMsgPart: 'Expected a directory but found a file', defaultNotice: 'Expected a directory but found a file: test/path' },
    { code: 'UNKNOWN', expectedMsgPart: 'Failed to test operation test/path. Check console.', defaultNotice: 'Failed to test operation test/path. Check console.' },
];

testCases.forEach(({ code, expectedMsgPart, defaultNotice }) => {
    it(`should handle error code ${code}`, () => {
        const error: any = new Error(`Test ${code} error`);
        error.code = code !== 'UNKNOWN' ? code : undefined; // only add code if not UNKNOWN

        handleFileSystemError('test operation', 'test/path', error);

        expect(devError).toHaveBeenCalled();
        expect(devError.mock.calls[0][0]).toContain(code !== 'UNKNOWN' ? code : `Test ${code} error`);
        expect(mockNotice).toHaveBeenCalledWith(defaultNotice, 7000);
    });
});

it('should use customNoticeMessage if provided', () => {
    const error = new Error('Test error');
    handleFileSystemError('test op', 'test/path', error, { customNoticeMessage: 'Custom notice!' });
    expect(mockNotice).toHaveBeenCalledWith('Custom notice!', 7000);
});

it('should throw error if shouldThrow is true', () => {
    const error = new Error('Test error');
    expect(() => {
        handleFileSystemError('test op', 'test/path', error, { shouldThrow: true });
    }).toThrow('Operation failed: test op for test/path. Reason: Test error');
    expect(devError).toHaveBeenCalled();
    expect(mockNotice).toHaveBeenCalled(); // Notice is still shown
});

it('should handle non-Error objects as error input', () => {
    handleFileSystemError('test op', 'test/path', 'just a string error');
    expect(devError).toHaveBeenCalled();
    expect(devError.mock.calls[0][0]).toContain('Error test op "test/path": just a string error');
    expect(mockNotice).toHaveBeenCalledWith('Failed to test test/path. Check console.', 7000);
});
});

fails:
tests/fileUtils.test.ts
  generateUniqueFilePath
    √ should return original path if it does not exist (3 ms)
    √ should return path with (1) if original exists (1 ms)
    √ should increment counter until a unique path is found (1 ms)
    √ should handle filenames without extensions (1 ms)
    × should use normalizePath for baseDir and fileName inputs (3 ms)
    √ should handle paths with multiple dots in filename correctly (1 ms)
  ensureParentDirectory
    √ should do nothing if parent directory already exists (1 ms)
    √ should create parent directory if it does not exist
    √ should handle file path in root directory (no parent)
  handleFileSystemError
    × should handle error code ENOENT (5 ms)
    × should handle error code EPERM
    × should handle error code EACCES
    × should handle error code EISDIR (1 ms)
    × should handle error code ENOTDIR
    × should handle error code UNKNOWN (3 ms)
    × should use customNoticeMessage if provided (1 ms)
    × should throw error if shouldThrow is true (15 ms)
    × should handle non-Error objects as error input

  ● generateUniqueFilePath › should use normalizePath for baseDir and fileName inputs

    expect(jest.fn()).toHaveBeenCalledWith(...expected)

    Expected: "normalized/normalized/file.md"
    Received: "normalized/normalized/test\\Dir/normalized/file.md"

    Number of calls: 1

      91 |     expect(normalizePath).toHaveBeenCalledWith('test\\Dir');
      92 |     expect(normalizePath).toHaveBeenCalledWith('file.md');
    > 93 |     expect(mockVault.adapter.exists).toHaveBeenCalledWith('normalized/normalized/file.md');
         |                                      ^
      94 | });
      95 |
      96 | it('should handle paths with multiple dots in filename correctly', async () => {

      at Object.<anonymous> (tests/fileUtils.test.ts:93:38)

  ● handleFileSystemError › should handle error code ENOENT

    expect(received).toContain(expected) // indexOf

    Expected substring: "ENOENT"
    Received string:    "File/Directory not found: test/path. Operation: test operation."

      189 |
      190 |         expect(devError).toHaveBeenCalled();
    > 191 |         expect(devError.mock.calls[0][0]).toContain(code !== 'UNKNOWN' ? code : `Test ${code} error`);
          |                                           ^
      192 |         expect(mockNotice).toHaveBeenCalledWith(defaultNotice, 7000);
      193 |     });
      194 | });

      at Object.<anonymous> (tests/fileUtils.test.ts:191:43)

  ● handleFileSystemError › should handle error code EPERM

    expect(received).toContain(expected) // indexOf

    Expected substring: "EPERM"
    Received string:    "Permission/Access denied for test/path. Operation: test operation."

      189 |
      190 |         expect(devError).toHaveBeenCalled();
    > 191 |         expect(devError.mock.calls[0][0]).toContain(code !== 'UNKNOWN' ? code : `Test ${code} error`);
          |                                           ^
      192 |         expect(mockNotice).toHaveBeenCalledWith(defaultNotice, 7000);
      193 |     });
      194 | });

      at Object.<anonymous> (tests/fileUtils.test.ts:191:43)

  ● handleFileSystemError › should handle error code EACCES

    expect(received).toContain(expected) // indexOf

    Expected substring: "EACCES"
    Received string:    "Permission/Access denied for test/path. Operation: test operation."

      189 |
      190 |         expect(devError).toHaveBeenCalled();
    > 191 |         expect(devError.mock.calls[0][0]).toContain(code !== 'UNKNOWN' ? code : `Test ${code} error`);
          |                                           ^
      192 |         expect(mockNotice).toHaveBeenCalledWith(defaultNotice, 7000);
      193 |     });
      194 | });

      at Object.<anonymous> (tests/fileUtils.test.ts:191:43)

  ● handleFileSystemError › should handle error code EISDIR

    expect(received).toContain(expected) // indexOf

    Expected substring: "EISDIR"
    Received string:    "Path is a directory, but a file was expected: test/path. Operation: test operation."

      189 |
      190 |         expect(devError).toHaveBeenCalled();
    > 191 |         expect(devError.mock.calls[0][0]).toContain(code !== 'UNKNOWN' ? code : `Test ${code} error`);
          |                                           ^
      192 |         expect(mockNotice).toHaveBeenCalledWith(defaultNotice, 7000);
      193 |     });
      194 | });

      at Object.<anonymous> (tests/fileUtils.test.ts:191:43)

  ● handleFileSystemError › should handle error code ENOTDIR

    expect(received).toContain(expected) // indexOf

    Expected substring: "ENOTDIR"
    Received string:    "Path is a file, but a directory was expected: test/path. Operation: test operation."

      189 |
      190 |         expect(devError).toHaveBeenCalled();
    > 191 |         expect(devError.mock.calls[0][0]).toContain(code !== 'UNKNOWN' ? code : `Test ${code} error`);
          |                                           ^
      192 |         expect(mockNotice).toHaveBeenCalledWith(defaultNotice, 7000);
      193 |     });
      194 | });

      at Object.<anonymous> (tests/fileUtils.test.ts:191:43)

  ● handleFileSystemError › should handle error code UNKNOWN

    expect(jest.fn()).toHaveBeenCalledWith(...expected)

    Expected: "Failed to test operation test/path. Check console.", 7000

    Number of calls: 0

      190 |         expect(devError).toHaveBeenCalled();
      191 |         expect(devError.mock.calls[0][0]).toContain(code !== 'UNKNOWN' ? code : `Test ${code} error`);
    > 192 |         expect(mockNotice).toHaveBeenCalledWith(defaultNotice, 7000);
          |                            ^
      193 |     });
      194 | });
      195 |

      at Object.<anonymous> (tests/fileUtils.test.ts:192:28)

  ● handleFileSystemError › should use customNoticeMessage if provided

    expect(jest.fn()).toHaveBeenCalledWith(...expected)

    Expected: "Custom notice!", 7000

    Number of calls: 0

      197 |     const error = new Error('Test error');
      198 |     handleFileSystemError('test op', 'test/path', error, { customNoticeMessage: 'Custom notice!' });
    > 199 |     expect(mockNotice).toHaveBeenCalledWith('Custom notice!', 7000);
          |                        ^
      200 | });
      201 |
      202 | it('should throw error if shouldThrow is true', () => {

      at Object.<anonymous> (tests/fileUtils.test.ts:199:24)

  ● handleFileSystemError › should throw error if shouldThrow is true

    expect(jest.fn()).toHaveBeenCalled()

    Expected number of calls: >= 1
    Received number of calls:    0

      206 |     }).toThrow('Operation failed: test op for test/path. Reason: Test error');
      207 |     expect(devError).toHaveBeenCalled();
    > 208 |     expect(mockNotice).toHaveBeenCalled(); // Notice is still shown
          |                        ^
      209 | });
      210 |
      211 | it('should handle non-Error objects as error input', () => {

      at Object.<anonymous> (tests/fileUtils.test.ts:208:24)

  ● handleFileSystemError › should handle non-Error objects as error input

    expect(jest.fn()).toHaveBeenCalledWith(...expected)

    Expected: "Failed to test test/path. Check console.", 7000

    Number of calls: 0

      213 |     expect(devError).toHaveBeenCalled();
      214 |     expect(devError.mock.calls[0][0]).toContain('Error test op "test/path": just a string error');
    > 215 |     expect(mockNotice).toHaveBeenCalledWith('Failed to test test/path. Check console.', 7000);
          |                        ^
      216 | });
      217 | });

      at Object.<anonymous> (tests/fileUtils.test.ts:215:24)