Skip to content

Build your personal knowledge base with Trilium Notes

test fixes

zadam2b1383205b22
diff --git a/spec/search/parser.spec.js b/spec/search/parser.spec.js
index fa0ee5c2af..5814fbae39 100644
--- a/spec/search/parser.spec.js
+++ b/spec/search/parser.spec.js
@@ -24,12 +24,13 @@ describe("Parser", () => {
const rootExp = parse({
fulltextTokens: tokens(["hello", "hi"]),
expressionTokens: [],
- searchContext: new SearchContext({includeNoteContent: false})
+ searchContext: new SearchContext({includeNoteContent: false, excludeArchived: true})
});
expect(rootExp.constructor.name).toEqual("AndExp");
- expect(rootExp.subExpressions[0].constructor.name).toEqual("NoteCacheFlatTextExp");
- expect(rootExp.subExpressions[0].tokens).toEqual(["hello", "hi"]);
+ expect(rootExp.subExpressions[0].constructor.name).toEqual("PropertyComparisonExp");
+ expect(rootExp.subExpressions[1].constructor.name).toEqual("NoteCacheFlatTextExp");
+ expect(rootExp.subExpressions[1].tokens).toEqual(["hello", "hi"]);
});
it("fulltext parser with content", () => {
@@ -39,11 +40,9 @@ describe("Parser", () => {
searchContext: new SearchContext({includeNoteContent: true})
});
- expect(rootExp.constructor.name).toEqual("AndExp");
- expect(rootExp.subExpressions[0].constructor.name).toEqual("OrExp");
- expect(rootExp.subExpressions[1].constructor.name).toEqual("PropertyComparisonExp");
+ expect(rootExp.constructor.name).toEqual("OrExp");
- const subs = rootExp.subExpressions[0].subExpressions;
+ const subs = rootExp.subExpressions;
expect(subs[0].constructor.name).toEqual("NoteCacheFlatTextExp");
expect(subs[0].tokens).toEqual(["hello", "hi"]);
@@ -147,18 +146,20 @@ describe("Parser", () => {
const rootExp = parse({
fulltextTokens: tokens(["hello"]),
expressionTokens: tokens(["#mylabel", "=", "text"]),
- searchContext: new SearchContext()
+ searchContext: new SearchContext({excludeArchived: true})
});
expect(rootExp.constructor.name).toEqual("AndExp");
- const [firstSub, secondSub] = rootExp.subExpressions;
+ const [firstSub, secondSub, thirdSub] = rootExp.subExpressions;
- expect(firstSub.constructor.name).toEqual("AndExp");
- expect(firstSub.subExpressions[0].constructor.name).toEqual("NoteCacheFlatTextExp");
- expect(firstSub.subExpressions[0].tokens).toEqual(["hello"]);
+ expect(firstSub.constructor.name).toEqual("PropertyComparisonExp");
+ expect(firstSub.propertyName).toEqual('isArchived');
- expect(secondSub.constructor.name).toEqual("LabelComparisonExp");
- expect(secondSub.attributeName).toEqual("mylabel");
+ expect(secondSub.constructor.name).toEqual("NoteCacheFlatTextExp");
+ expect(secondSub.tokens).toEqual(["hello"]);
+
+ expect(thirdSub.constructor.name).toEqual("LabelComparisonExp");
+ expect(thirdSub.attributeName).toEqual("mylabel");
});
it("label sub-expression", () => {
@@ -236,4 +237,16 @@ describe("Invalid expressions", () => {
expect(rootExp.attributeName).toEqual("first");
expect(rootExp.comparator).toBeTruthy();
});
+
+ it("searching by relation without note property", () => {
+ const searchContext = new SearchContext();
+
+ parse({
+ fulltextTokens: [],
+ expressionTokens: tokens(["~first", "=", "text", "-", "abc"]),
+ searchContext
+ });
+
+ expect(searchContext.error).toEqual('Misplaced or incomplete expression "="')
+ });
});
diff --git a/spec/search/search.spec.js b/spec/search/search.spec.js
index e04c29bdc3..30d78bb3db 100644
--- a/spec/search/search.spec.js
+++ b/spec/search/search.spec.js
@@ -601,7 +601,7 @@ describe("Search", () => {
.child(note('Post Y')))
.child(note ('Reddit is bad'));
- const searchContext = new SearchContext();
+ const searchContext = new SearchContext({excludeArchived: true});
let searchResults = searchService.findNotesWithQuery('reddit', searchContext);
expect(searchResults.length).toEqual(1);
diff --git a/src/services/search/services/search.js b/src/services/search/services/search.js
index 7254db96c1..dae4c3a607 100644
--- a/src/services/search/services/search.js
+++ b/src/services/search/services/search.js
@@ -9,7 +9,6 @@ const SearchContext = require("../search_context.js");
const noteCache = require('../../note_cache/note_cache.js');
const noteCacheService = require('../../note_cache/note_cache_service.js');
const hoistedNoteService = require('../../hoisted_note.js');
-const repository = require('../../repository.js');
const utils = require('../../utils.js');
/**