Skip to content

Commit

Permalink
Add word type priority order tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tadashi-aikawa committed Feb 13, 2022
1 parent 858f157 commit eed5154
Showing 1 changed file with 148 additions and 0 deletions.
148 changes: 148 additions & 0 deletions src/provider/suggester.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,78 @@ describe("suggestWords", () => {
// { value: "aiUEO", type: "currentFile" },
]);
});

const indexedWords2: IndexedWords = {
tag: {
a: [
{ value: "a", type: "tag", createdPath: "" },
{ value: "a", type: "tag", createdPath: "" },
],
},
internalLink: {
a: [
{ value: "a", type: "internalLink", createdPath: "" },
{ value: "a", type: "internalLink", createdPath: "" },
],
},
customDictionary: {
a: [
{ value: "a", type: "customDictionary", createdPath: "" },
{ value: "a", type: "customDictionary", createdPath: "" },
],
},
currentFile: {
a: [
{ value: "a", type: "currentFile", createdPath: "" },
{ value: "a", type: "currentFile", createdPath: "" },
],
},
currentVault: {
a: [
{ value: "a", type: "currentVault", createdPath: "" },
{ value: "a", type: "currentVault", createdPath: "" },
],
},
};

test("word type priority order in front matter", () => {
expect(suggestWords(indexedWords2, "a", 10, true)).toStrictEqual([
{ value: "a", type: "tag", createdPath: "" },
{ value: "a", type: "internalLink", createdPath: "" },
{ value: "a", type: "customDictionary", createdPath: "" },
]);
});

test("word type priority order not in front matter", () => {
expect(suggestWords(indexedWords2, "a", 10, false)).toStrictEqual([
{ value: "a", type: "internalLink", createdPath: "" },
{ value: "a", type: "customDictionary", createdPath: "" },
]);
});

const indexedWords3: IndexedWords = {
tag: {},
internalLink: {},
customDictionary: {},
currentFile: {
a: [
{ value: "a", type: "currentFile", createdPath: "" },
{ value: "a", type: "currentFile", createdPath: "" },
],
},
currentVault: {
a: [
{ value: "a", type: "currentVault", createdPath: "" },
{ value: "a", type: "currentVault", createdPath: "" },
],
},
};

test("word type priority order (currentFile & currentVault)", () => {
expect(suggestWords(indexedWords3, "a", 10, false)).toStrictEqual([
{ value: "a", type: "currentFile", createdPath: "" },
]);
});
});

describe("suggestWordsByPartialMatch", () => {
Expand Down Expand Up @@ -597,4 +669,80 @@ describe("suggestWordsByPartialMatch", () => {
{ value: "AWS", type: "internalLink", createdPath: "" },
]);
});

const indexedWords2: IndexedWords = {
tag: {
a: [
{ value: "a", type: "tag", createdPath: "" },
{ value: "a", type: "tag", createdPath: "" },
],
},
internalLink: {
a: [
{ value: "a", type: "internalLink", createdPath: "" },
{ value: "a", type: "internalLink", createdPath: "" },
],
},
customDictionary: {
a: [
{ value: "a", type: "customDictionary", createdPath: "" },
{ value: "a", type: "customDictionary", createdPath: "" },
],
},
currentFile: {
a: [
{ value: "a", type: "currentFile", createdPath: "" },
{ value: "a", type: "currentFile", createdPath: "" },
],
},
currentVault: {
a: [
{ value: "a", type: "currentVault", createdPath: "" },
{ value: "a", type: "currentVault", createdPath: "" },
],
},
};

test("word type priority order in front matter", () => {
expect(
suggestWordsByPartialMatch(indexedWords2, "a", 10, true)
).toStrictEqual([
{ value: "a", type: "tag", createdPath: "" },
{ value: "a", type: "internalLink", createdPath: "" },
{ value: "a", type: "customDictionary", createdPath: "" },
]);
});

test("word type priority order not in front matter", () => {
expect(
suggestWordsByPartialMatch(indexedWords2, "a", 10, false)
).toStrictEqual([
{ value: "a", type: "internalLink", createdPath: "" },
{ value: "a", type: "customDictionary", createdPath: "" },
]);
});

const indexedWords3: IndexedWords = {
tag: {},
internalLink: {},
customDictionary: {},
currentFile: {
a: [
{ value: "a", type: "currentFile", createdPath: "" },
{ value: "a", type: "currentFile", createdPath: "" },
],
},
currentVault: {
a: [
{ value: "a", type: "currentVault", createdPath: "" },
{ value: "a", type: "currentVault", createdPath: "" },
],
},
};

test("word type priority order (currentFile & currentVault)", () => {
expect(
suggestWordsByPartialMatch(indexedWords3, "a", 10, false)
).toStrictEqual([{ value: "a", type: "currentFile", createdPath: "" }]);
});
});

0 comments on commit eed5154

Please sign in to comment.