mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-13 20:42:29 +08:00
test(services/data_dir): simplify getPlatformAppDataDir
use the new available mocks to make tests a tiny bit more simpler :-)
This commit is contained in:
parent
3090233078
commit
0ccf91721d
@ -61,27 +61,28 @@ describe("data_dir.ts unit tests", async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe("#getPlatformAppDataDir()", () => {
|
describe("#getPlatformAppDataDir()", () => {
|
||||||
type TestCaseGetPlatformAppDataDir = [description: string, fnValue: Parameters<typeof getPlatformAppDataDir>, expectedValueFn: (val: ReturnType<typeof getPlatformAppDataDir>) => boolean];
|
type TestCaseGetPlatformAppDataDir = [description: string, fnValue: Parameters<typeof getPlatformAppDataDir>, expectedValue: string | null, osHomedirMockValue: string | null];
|
||||||
|
|
||||||
const testCases: TestCaseGetPlatformAppDataDir[] = [
|
const testCases: TestCaseGetPlatformAppDataDir[] = [
|
||||||
["w/ unsupported OS it should return 'null'", ["aix", undefined], (val) => val === null],
|
["w/ unsupported OS it should return 'null'", ["aix", undefined], null, null],
|
||||||
|
|
||||||
["w/ win32 and no APPDATA set it should return 'null'", ["win32", undefined], (val) => val === null],
|
["w/ win32 and no APPDATA set it should return 'null'", ["win32", undefined], null, null],
|
||||||
|
|
||||||
["w/ win32 and set APPDATA it should return set 'APPDATA'", ["win32", "AppData"], (val) => val === "AppData"],
|
["w/ win32 and set APPDATA it should return set 'APPDATA'", ["win32", "AppData"], "AppData", null],
|
||||||
|
|
||||||
["w/ linux it should return '/.local/share'", ["linux", undefined], (val) => val !== null && val.endsWith("/.local/share")],
|
["w/ linux it should return '~/.local/share'", ["linux", undefined], "/home/mock/.local/share", "/home/mock"],
|
||||||
|
|
||||||
["w/ linux and wrongly set APPDATA it should ignore APPDATA and return /.local/share", ["linux", "FakeAppData"], (val) => val !== null && val.endsWith("/.local/share")],
|
["w/ linux and wrongly set APPDATA it should ignore APPDATA and return '~/.local/share'", ["linux", "FakeAppData"], "/home/mock/.local/share", "/home/mock"],
|
||||||
|
|
||||||
["w/ darwin it should return /Library/Application Support", ["darwin", undefined], (val) => val !== null && val.endsWith("/Library/Application Support")]
|
["w/ darwin it should return '~/Library/Application Support'", ["darwin", undefined], "/Users/mock/Library/Application Support", "/Users/mock"]
|
||||||
];
|
];
|
||||||
|
|
||||||
testCases.forEach((testCase) => {
|
testCases.forEach((testCase) => {
|
||||||
const [testDescription, value, isExpected] = testCase;
|
const [testDescription, fnValues, expected, osHomedirMockValue] = testCase;
|
||||||
return it(testDescription, () => {
|
return it(testDescription, () => {
|
||||||
const actual = getPlatformAppDataDir(...value);
|
mockFn.osHomedirMock.mockReturnValue(osHomedirMockValue);
|
||||||
const result = isExpected(actual);
|
const actual = getPlatformAppDataDir(...fnValues);
|
||||||
expect(result).toBeTruthy();
|
expect(actual).toEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user