mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-05 15:44:21 +00:00
Add test for handling empty file path in saveLastOpenedFile function
This commit is contained in:
@@ -183,6 +183,22 @@ describe('useLastOpenedFile', () => {
|
||||
expect(fileApi.updateLastOpenedFile).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does nothing when file path is empty', async () => {
|
||||
const mockUpdateLastOpenedFile = vi.mocked(fileApi.updateLastOpenedFile);
|
||||
mockUpdateLastOpenedFile.mockResolvedValue(undefined);
|
||||
|
||||
const { result } = renderHook(() => useLastOpenedFile());
|
||||
|
||||
await act(async () => {
|
||||
await result.current.saveLastOpenedFile('');
|
||||
});
|
||||
|
||||
expect(mockUpdateLastOpenedFile).not.toHaveBeenCalledWith(
|
||||
'test-workspace',
|
||||
''
|
||||
);
|
||||
});
|
||||
|
||||
it('handles different file path formats', async () => {
|
||||
const mockUpdateLastOpenedFile = vi.mocked(fileApi.updateLastOpenedFile);
|
||||
mockUpdateLastOpenedFile.mockResolvedValue(undefined);
|
||||
@@ -211,22 +227,6 @@ describe('useLastOpenedFile', () => {
|
||||
|
||||
expect(mockUpdateLastOpenedFile).toHaveBeenCalledTimes(testCases.length);
|
||||
});
|
||||
|
||||
it('handles empty file path', async () => {
|
||||
const mockUpdateLastOpenedFile = vi.mocked(fileApi.updateLastOpenedFile);
|
||||
mockUpdateLastOpenedFile.mockResolvedValue(undefined);
|
||||
|
||||
const { result } = renderHook(() => useLastOpenedFile());
|
||||
|
||||
await act(async () => {
|
||||
await result.current.saveLastOpenedFile('');
|
||||
});
|
||||
|
||||
expect(mockUpdateLastOpenedFile).toHaveBeenCalledWith(
|
||||
'test-workspace',
|
||||
''
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('workspace dependency', () => {
|
||||
|
||||
@@ -24,7 +24,7 @@ export const useLastOpenedFile = (): UseLastOpenedFileResult => {
|
||||
|
||||
const saveLastOpenedFile = useCallback(
|
||||
async (filePath: string): Promise<void> => {
|
||||
if (!currentWorkspace) return;
|
||||
if (!currentWorkspace || !filePath.trim()) return;
|
||||
|
||||
try {
|
||||
await updateLastOpenedFile(currentWorkspace.name, filePath);
|
||||
|
||||
Reference in New Issue
Block a user