From bb03a8714a55a08d83fa37b77ff5c27e5d73c1d9 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 23 May 2020 18:42:32 +0200 Subject: [PATCH] more tests --- spec/search.spec.js | 49 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/spec/search.spec.js b/spec/search.spec.js index f0b1fcbc4..32108f8e3 100644 --- a/spec/search.spec.js +++ b/spec/search.spec.js @@ -188,7 +188,9 @@ describe("Search", () => { rootNote .child(note("Europe") .child(note("Austria")) - .child(note("Czech Republic"))) + .child(note("Czech Republic") + .child(note("Prague"))) + ) .child(note("Asia") .child(note('Taiwan'))); @@ -202,13 +204,19 @@ describe("Search", () => { searchResults = await searchService.findNotesWithQuery('# note.parents.title = Asia', parsingContext); expect(searchResults.length).toEqual(1); expect(findNoteByTitle(searchResults, "Taiwan")).toBeTruthy(); + + searchResults = await searchService.findNotesWithQuery('# note.parents.parents.title = Europe', parsingContext); + expect(searchResults.length).toEqual(1); + expect(findNoteByTitle(searchResults, "Prague")).toBeTruthy(); }); it("filter by note's child", async () => { rootNote .child(note("Europe") - .child(note("Austria")) - .child(note("Czech Republic"))) + .child(note("Austria") + .child(note("Vienna"))) + .child(note("Czech Republic") + .child(note("Prague")))) .child(note("Oceania") .child(note('Australia'))); @@ -222,6 +230,10 @@ describe("Search", () => { searchResults = await searchService.findNotesWithQuery('# note.children.title =* Aust AND note.children.title *= republic', parsingContext); expect(searchResults.length).toEqual(1); expect(findNoteByTitle(searchResults, "Europe")).toBeTruthy(); + + searchResults = await searchService.findNotesWithQuery('# note.children.children.title = Prague', parsingContext); + expect(searchResults.length).toEqual(1); + expect(findNoteByTitle(searchResults, "Europe")).toBeTruthy(); }); it("filter by relation's note properties using short syntax", async () => { @@ -269,6 +281,37 @@ describe("Search", () => { expect(searchResults.length).toEqual(1); expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy(); }); + + it("filter by multiple level relation", async () => { + const austria = note("Austria"); + const slovakia = note("Slovakia"); + const italy = note("Italy"); + const ukraine = note("Ukraine"); + + rootNote + .child(note("Europe") + .child(austria + .relation('neighbor', italy.note) + .relation('neighbor', slovakia.note)) + .child(note("Czech Republic") + .relation('neighbor', austria.note) + .relation('neighbor', slovakia.note)) + .child(slovakia + .relation('neighbor', ukraine.note)) + .child(ukraine) + ); + + const parsingContext = new ParsingContext(); + + let searchResults = await searchService.findNotesWithQuery('# note.relations.neighbor.relations.neighbor.title = Italy', parsingContext); + expect(searchResults.length).toEqual(1); + expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy(); + + searchResults = await searchService.findNotesWithQuery('# note.relations.neighbor.relations.neighbor.title = Ukraine', parsingContext); + expect(searchResults.length).toEqual(2); + expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy(); + expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy(); + }); }); /** @return {Note} */