Improve tests and add useGitOps hook test

This commit is contained in:
2025-05-27 21:33:02 +02:00
parent 942ff17c4f
commit 9cefe12872
6 changed files with 450 additions and 21 deletions

View File

@@ -157,8 +157,6 @@ describe('fileHelpers', () => {
});
it('uses the API base URL correctly', () => {
// Test that the function uses the expected API base URL
// Note: The API_BASE_URL is imported at module load time, so we test the expected behavior
const url = getFileUrl('test', 'file.md');
expect(url).toBe(
'http://localhost:8080/api/v1/workspaces/test/files/file.md'

View File

@@ -278,6 +278,7 @@ describe('remarkWikiLinks', () => {
expect(result.toString()).toContain('Spaces');
// Should not call API for empty/whitespace-only links
expect(fileApi.lookupFileByName).not.toHaveBeenCalled();
});
it('handles nested brackets', async () => {
@@ -319,19 +320,5 @@ describe('remarkWikiLinks', () => {
// Should not call API when workspace is empty
expect(fileApi.lookupFileByName).not.toHaveBeenCalled();
});
it('does not process links when workspace is not provided', async () => {
const processor = unified()
.use(remarkParse)
.use(remarkWikiLinks, '')
.use(remarkStringify);
const markdown = '[[test]]';
const result = await processor.process(markdown);
expect(result.toString()).toContain('test');
expect(fileApi.lookupFileByName).not.toHaveBeenCalled();
});
});
});

View File

@@ -233,6 +233,13 @@ export function remarkWikiLinks(workspaceName: string) {
}
try {
// Skip API call for empty or whitespace-only filenames
if (!match.fileName.trim()) {
newNodes.push(createTextNode(match.fullMatch));
lastIndex = match.index + match.fullMatch.length;
continue;
}
const lookupFileName: string = match.isImage
? match.fileName
: addMarkdownExtension(match.fileName);