forked from janhq/jan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: mismatch between model json and path * chore: revert preserve model settings * test: add tests
- Loading branch information
Showing
35 changed files
with
878 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,4 @@ core/test_results.html | |
coverage | ||
.yarn | ||
.yarnrc | ||
*.tsbuildinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,109 @@ | ||
import { openExternalUrl } from './core'; | ||
import { joinPath } from './core'; | ||
import { openFileExplorer } from './core'; | ||
import { getJanDataFolderPath } from './core'; | ||
import { abortDownload } from './core'; | ||
import { getFileSize } from './core'; | ||
import { executeOnMain } from './core'; | ||
import { openExternalUrl } from './core' | ||
import { joinPath } from './core' | ||
import { openFileExplorer } from './core' | ||
import { getJanDataFolderPath } from './core' | ||
import { abortDownload } from './core' | ||
import { getFileSize } from './core' | ||
import { executeOnMain } from './core' | ||
|
||
it('should open external url', async () => { | ||
const url = 'http://example.com'; | ||
globalThis.core = { | ||
api: { | ||
openExternalUrl: jest.fn().mockResolvedValue('opened') | ||
describe('test core apis', () => { | ||
it('should open external url', async () => { | ||
const url = 'http://example.com' | ||
globalThis.core = { | ||
api: { | ||
openExternalUrl: jest.fn().mockResolvedValue('opened'), | ||
}, | ||
} | ||
}; | ||
const result = await openExternalUrl(url); | ||
expect(globalThis.core.api.openExternalUrl).toHaveBeenCalledWith(url); | ||
expect(result).toBe('opened'); | ||
}); | ||
const result = await openExternalUrl(url) | ||
expect(globalThis.core.api.openExternalUrl).toHaveBeenCalledWith(url) | ||
expect(result).toBe('opened') | ||
}) | ||
|
||
|
||
it('should join paths', async () => { | ||
const paths = ['/path/one', '/path/two']; | ||
globalThis.core = { | ||
api: { | ||
joinPath: jest.fn().mockResolvedValue('/path/one/path/two') | ||
it('should join paths', async () => { | ||
const paths = ['/path/one', '/path/two'] | ||
globalThis.core = { | ||
api: { | ||
joinPath: jest.fn().mockResolvedValue('/path/one/path/two'), | ||
}, | ||
} | ||
}; | ||
const result = await joinPath(paths); | ||
expect(globalThis.core.api.joinPath).toHaveBeenCalledWith(paths); | ||
expect(result).toBe('/path/one/path/two'); | ||
}); | ||
|
||
const result = await joinPath(paths) | ||
expect(globalThis.core.api.joinPath).toHaveBeenCalledWith(paths) | ||
expect(result).toBe('/path/one/path/two') | ||
}) | ||
|
||
it('should open file explorer', async () => { | ||
const path = '/path/to/open'; | ||
globalThis.core = { | ||
api: { | ||
openFileExplorer: jest.fn().mockResolvedValue('opened') | ||
it('should open file explorer', async () => { | ||
const path = '/path/to/open' | ||
globalThis.core = { | ||
api: { | ||
openFileExplorer: jest.fn().mockResolvedValue('opened'), | ||
}, | ||
} | ||
}; | ||
const result = await openFileExplorer(path); | ||
expect(globalThis.core.api.openFileExplorer).toHaveBeenCalledWith(path); | ||
expect(result).toBe('opened'); | ||
}); | ||
|
||
const result = await openFileExplorer(path) | ||
expect(globalThis.core.api.openFileExplorer).toHaveBeenCalledWith(path) | ||
expect(result).toBe('opened') | ||
}) | ||
|
||
it('should get jan data folder path', async () => { | ||
globalThis.core = { | ||
api: { | ||
getJanDataFolderPath: jest.fn().mockResolvedValue('/path/to/jan/data') | ||
it('should get jan data folder path', async () => { | ||
globalThis.core = { | ||
api: { | ||
getJanDataFolderPath: jest.fn().mockResolvedValue('/path/to/jan/data'), | ||
}, | ||
} | ||
}; | ||
const result = await getJanDataFolderPath(); | ||
expect(globalThis.core.api.getJanDataFolderPath).toHaveBeenCalled(); | ||
expect(result).toBe('/path/to/jan/data'); | ||
}); | ||
const result = await getJanDataFolderPath() | ||
expect(globalThis.core.api.getJanDataFolderPath).toHaveBeenCalled() | ||
expect(result).toBe('/path/to/jan/data') | ||
}) | ||
|
||
|
||
it('should abort download', async () => { | ||
const fileName = 'testFile'; | ||
globalThis.core = { | ||
api: { | ||
abortDownload: jest.fn().mockResolvedValue('aborted') | ||
it('should abort download', async () => { | ||
const fileName = 'testFile' | ||
globalThis.core = { | ||
api: { | ||
abortDownload: jest.fn().mockResolvedValue('aborted'), | ||
}, | ||
} | ||
}; | ||
const result = await abortDownload(fileName); | ||
expect(globalThis.core.api.abortDownload).toHaveBeenCalledWith(fileName); | ||
expect(result).toBe('aborted'); | ||
}); | ||
|
||
const result = await abortDownload(fileName) | ||
expect(globalThis.core.api.abortDownload).toHaveBeenCalledWith(fileName) | ||
expect(result).toBe('aborted') | ||
}) | ||
|
||
it('should get file size', async () => { | ||
const url = 'http://example.com/file'; | ||
globalThis.core = { | ||
api: { | ||
getFileSize: jest.fn().mockResolvedValue(1024) | ||
it('should get file size', async () => { | ||
const url = 'http://example.com/file' | ||
globalThis.core = { | ||
api: { | ||
getFileSize: jest.fn().mockResolvedValue(1024), | ||
}, | ||
} | ||
}; | ||
const result = await getFileSize(url); | ||
expect(globalThis.core.api.getFileSize).toHaveBeenCalledWith(url); | ||
expect(result).toBe(1024); | ||
}); | ||
const result = await getFileSize(url) | ||
expect(globalThis.core.api.getFileSize).toHaveBeenCalledWith(url) | ||
expect(result).toBe(1024) | ||
}) | ||
|
||
it('should execute function on main process', async () => { | ||
const extension = 'testExtension' | ||
const method = 'testMethod' | ||
const args = ['arg1', 'arg2'] | ||
globalThis.core = { | ||
api: { | ||
invokeExtensionFunc: jest.fn().mockResolvedValue('result'), | ||
}, | ||
} | ||
const result = await executeOnMain(extension, method, ...args) | ||
expect(globalThis.core.api.invokeExtensionFunc).toHaveBeenCalledWith(extension, method, ...args) | ||
expect(result).toBe('result') | ||
}) | ||
}) | ||
|
||
it('should execute function on main process', async () => { | ||
const extension = 'testExtension'; | ||
const method = 'testMethod'; | ||
const args = ['arg1', 'arg2']; | ||
globalThis.core = { | ||
api: { | ||
invokeExtensionFunc: jest.fn().mockResolvedValue('result') | ||
describe('dirName - just a pass thru api', () => { | ||
it('should retrieve the directory name from a file path', async () => { | ||
const mockDirName = jest.fn() | ||
globalThis.core = { | ||
api: { | ||
dirName: mockDirName.mockResolvedValue('/path/to'), | ||
}, | ||
} | ||
}; | ||
const result = await executeOnMain(extension, method, ...args); | ||
expect(globalThis.core.api.invokeExtensionFunc).toHaveBeenCalledWith(extension, method, ...args); | ||
expect(result).toBe('result'); | ||
}); | ||
// Normal file path with extension | ||
const path = '/path/to/file.txt' | ||
await globalThis.core.api.dirName(path) | ||
expect(mockDirName).toHaveBeenCalledWith(path) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,57 @@ | ||
import { App } from './app'; | ||
jest.mock('../../helper', () => ({ | ||
...jest.requireActual('../../helper'), | ||
getJanDataFolderPath: () => './app', | ||
})) | ||
import { dirname } from 'path' | ||
import { App } from './app' | ||
|
||
it('should call stopServer', () => { | ||
const app = new App(); | ||
const stopServerMock = jest.fn().mockResolvedValue('Server stopped'); | ||
const app = new App() | ||
const stopServerMock = jest.fn().mockResolvedValue('Server stopped') | ||
jest.mock('@janhq/server', () => ({ | ||
stopServer: stopServerMock | ||
})); | ||
const result = app.stopServer(); | ||
expect(stopServerMock).toHaveBeenCalled(); | ||
}); | ||
stopServer: stopServerMock, | ||
})) | ||
app.stopServer() | ||
expect(stopServerMock).toHaveBeenCalled() | ||
}) | ||
|
||
it('should correctly retrieve basename', () => { | ||
const app = new App(); | ||
const result = app.baseName('/path/to/file.txt'); | ||
expect(result).toBe('file.txt'); | ||
}); | ||
const app = new App() | ||
const result = app.baseName('/path/to/file.txt') | ||
expect(result).toBe('file.txt') | ||
}) | ||
|
||
it('should correctly identify subdirectories', () => { | ||
const app = new App(); | ||
const basePath = process.platform === 'win32' ? 'C:\\path\\to' : '/path/to'; | ||
const subPath = process.platform === 'win32' ? 'C:\\path\\to\\subdir' : '/path/to/subdir'; | ||
const result = app.isSubdirectory(basePath, subPath); | ||
expect(result).toBe(true); | ||
}); | ||
const app = new App() | ||
const basePath = process.platform === 'win32' ? 'C:\\path\\to' : '/path/to' | ||
const subPath = process.platform === 'win32' ? 'C:\\path\\to\\subdir' : '/path/to/subdir' | ||
const result = app.isSubdirectory(basePath, subPath) | ||
expect(result).toBe(true) | ||
}) | ||
|
||
it('should correctly join multiple paths', () => { | ||
const app = new App(); | ||
const result = app.joinPath(['path', 'to', 'file']); | ||
const expectedPath = process.platform === 'win32' ? 'path\\to\\file' : 'path/to/file'; | ||
expect(result).toBe(expectedPath); | ||
}); | ||
const app = new App() | ||
const result = app.joinPath(['path', 'to', 'file']) | ||
const expectedPath = process.platform === 'win32' ? 'path\\to\\file' : 'path/to/file' | ||
expect(result).toBe(expectedPath) | ||
}) | ||
|
||
it('should call correct function with provided arguments using process method', () => { | ||
const app = new App(); | ||
const mockFunc = jest.fn(); | ||
app.joinPath = mockFunc; | ||
app.process('joinPath', ['path1', 'path2']); | ||
expect(mockFunc).toHaveBeenCalledWith(['path1', 'path2']); | ||
}); | ||
const app = new App() | ||
const mockFunc = jest.fn() | ||
app.joinPath = mockFunc | ||
app.process('joinPath', ['path1', 'path2']) | ||
expect(mockFunc).toHaveBeenCalledWith(['path1', 'path2']) | ||
}) | ||
|
||
it('should retrieve the directory name from a file path (Unix/Windows)', async () => { | ||
const app = new App() | ||
const path = 'C:/Users/John Doe/Desktop/file.txt' | ||
expect(await app.dirName(path)).toBe('C:/Users/John Doe/Desktop') | ||
}) | ||
|
||
it('should retrieve the directory name when using file protocol', async () => { | ||
const app = new App() | ||
const path = 'file:/models/file.txt' | ||
expect(await app.dirName(path)).toBe(process.platform === 'win32' ? 'app\\models' : 'app/models') | ||
}) |
Oops, something went wrong.