more tests & fixes

This commit is contained in:
zadam 2020-05-25 23:39:34 +02:00
parent a1a744bb00
commit c753f228ac
3 changed files with 21 additions and 3 deletions

View File

@ -492,6 +492,24 @@ describe("Search", () => {
expect(noteCache.notes[searchResults[1].noteId].title).toEqual("Ukraine");
expect(noteCache.notes[searchResults[2].noteId].title).toEqual("Italy");
expect(noteCache.notes[searchResults[3].noteId].title).toEqual("Austria");
searchResults = await searchService.findNotesWithQuery('# note.parents.title = Europe orderBy note.labels.capital DESC', parsingContext);
expect(searchResults.length).toEqual(4);
expect(noteCache.notes[searchResults[0].noteId].title).toEqual("Austria");
expect(noteCache.notes[searchResults[1].noteId].title).toEqual("Italy");
expect(noteCache.notes[searchResults[2].noteId].title).toEqual("Ukraine");
expect(noteCache.notes[searchResults[3].noteId].title).toEqual("Slovakia");
searchResults = await searchService.findNotesWithQuery('# note.parents.title = Europe orderBy note.labels.capital DESC limit 2', parsingContext);
expect(searchResults.length).toEqual(2);
expect(noteCache.notes[searchResults[0].noteId].title).toEqual("Austria");
expect(noteCache.notes[searchResults[1].noteId].title).toEqual("Italy");
searchResults = await searchService.findNotesWithQuery('# note.parents.title = Europe orderBy #capital DESC limit 0', parsingContext);
expect(searchResults.length).toEqual(0);
searchResults = await searchService.findNotesWithQuery('# note.parents.title = Europe orderBy #capital DESC limit 1000', parsingContext);
expect(searchResults.length).toEqual(4);
});
// FIXME: test what happens when we order without any filter criteria

View File

@ -44,7 +44,7 @@ class OrderByAndLimitExp extends Expression {
return 0;
});
if (this.limit) {
if (this.limit >= 0) {
notes = notes.slice(0, this.limit);
}

View File

@ -170,8 +170,8 @@ function getExpression(tokens, parsingContext, level = 0) {
i++;
} while (tokens[i] === '.');
if (["asc", "desc"].includes(tokens[i + 1])) {
direction = tokens[i + 1];
if (["asc", "desc"].includes(tokens[i])) {
direction = tokens[i];
i++;
}