Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 0292489

Browse files
authored
Merge pull request #1004 from TriliumNext/test_simplify-data-dir
test(services/data_dir): simplify getPlatformAppDataDir
2 parents f36ec9b + 55ce7aa commit 0292489

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/services/data_dir.spec.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,28 @@ describe("data_dir.ts unit tests", async () => {
6161
};
6262

6363
describe("#getPlatformAppDataDir()", () => {
64-
type TestCaseGetPlatformAppDataDir = [description: string, fnValue: Parameters<typeof getPlatformAppDataDir>, expectedValueFn: (val: ReturnType<typeof getPlatformAppDataDir>) => boolean];
64+
type TestCaseGetPlatformAppDataDir = [description: string, fnValue: Parameters<typeof getPlatformAppDataDir>, expectedValue: string | null, osHomedirMockValue: string | null];
65+
6566
const testCases: TestCaseGetPlatformAppDataDir[] = [
66-
["w/ unsupported OS it should return 'null'", ["aix", undefined], (val) => val === null],
67+
["w/ unsupported OS it should return 'null'", ["aix", undefined], null, null],
6768

68-
["w/ win32 and no APPDATA set it should return 'null'", ["win32", undefined], (val) => val === null],
69+
["w/ win32 and no APPDATA set it should return 'null'", ["win32", undefined], null, null],
6970

70-
["w/ win32 and set APPDATA it should return set 'APPDATA'", ["win32", "AppData"], (val) => val === "AppData"],
71+
["w/ win32 and set APPDATA it should return set 'APPDATA'", ["win32", "AppData"], "AppData", null],
7172

72-
["w/ linux it should return '/.local/share'", ["linux", undefined], (val) => val !== null && val.endsWith("/.local/share")],
73+
["w/ linux it should return '~/.local/share'", ["linux", undefined], "/home/mock/.local/share", "/home/mock"],
7374

74-
["w/ linux and wrongly set APPDATA it should ignore APPDATA and return /.local/share", ["linux", "FakeAppData"], (val) => val !== null && val.endsWith("/.local/share")],
75+
["w/ linux and wrongly set APPDATA it should ignore APPDATA and return '~/.local/share'", ["linux", "FakeAppData"], "/home/mock/.local/share", "/home/mock"],
7576

76-
["w/ darwin it should return /Library/Application Support", ["darwin", undefined], (val) => val !== null && val.endsWith("/Library/Application Support")]
77+
["w/ darwin it should return '~/Library/Application Support'", ["darwin", undefined], "/Users/mock/Library/Application Support", "/Users/mock"]
7778
];
7879

7980
testCases.forEach((testCase) => {
80-
const [testDescription, value, isExpected] = testCase;
81+
const [testDescription, fnValues, expected, osHomedirMockValue] = testCase;
8182
return it(testDescription, () => {
82-
const actual = getPlatformAppDataDir(...value);
83-
const result = isExpected(actual);
84-
expect(result).toBeTruthy();
83+
mockFn.osHomedirMock.mockReturnValue(osHomedirMockValue);
84+
const actual = getPlatformAppDataDir(...fnValues);
85+
expect(actual).toEqual(expected);
8586
});
8687
});
8788
});

0 commit comments

Comments
 (0)