Skip to content

Commit

Permalink
PER-9353: Search with qutation marks
Browse files Browse the repository at this point in the history
Remove tests that do not correspond anymore
  • Loading branch information
crisnicandrei committed Sep 21, 2023
1 parent 1d9b067 commit 5590485
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 36 deletions.
30 changes: 0 additions & 30 deletions src/app/search/services/search.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ describe('SearchService', () => {
expectSearchToBe(service.parseSearchTerm('Potato'), 'Potato', []);
});

it('should remove tag tokens from search', () => {
expectSearchToBe(
service.parseSearchTerm('tag:"NonExistentTag"'),
undefined,
[]
);
});

it('should load tag tokens into the tags array', () => {
tags.setTags([{ name: 'Potato' }]);
expectSearchToBe(service.parseSearchTerm('tag:"Potato"'), undefined, [
Expand All @@ -110,28 +102,6 @@ describe('SearchService', () => {
);
});

it('removes quotation marks from tag names', () => {
/*
This test probably represents erroneous behavior that we want to change
at some point. For now, this represents the original functionality of
the SearchService as it was written.
*/
tags.setTags([
{ name: 'Potato', tagId: 0 },
{ name: '"Potato"', tagId: 1 },
]);
const searchTokens = service.parseSearchTerm('tag:""Potato""');
expect(searchTokens[1].length).toBe(1);
expect(searchTokens[1][0].tagId).toBe(0);
});

it('handles tag edge cases', () => {
tags.setTags([{ name: 'tag:Test' }]);
expectSearchToBe(service.parseSearchTerm('tag:"tag:"Test""'), undefined, [
{ name: 'tag:Test' },
]);
});

function expectSearchToBe(
search: [string, TagVOData[]],
expectedSearch: string,
Expand Down
12 changes: 6 additions & 6 deletions src/app/search/services/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ export class SearchService {
const tagNames = part.match(getTagName) || [];
for (const tagName of tagNames) {
if (tagName) {
const name = this.removeFirstAndLastQuotes(tagName)
const name = this.removeFirstAndLastQuotes(tagName);
const tag = this.tags.getTagByName(name);
if (tag) {
parsedTags.push(tag);
}
}
}
if(!parsedTags.length){
if (!parsedTags.length) {
queryString = termString;
}
} else {
Expand All @@ -85,16 +85,16 @@ export class SearchService {
}
return [queryString, parsedTags];
}

private removeFirstAndLastQuotes(str) {
if (str.startsWith('"')) {
str = str.substr(1);
str = str.substr(1);
}
if (str.endsWith('"')) {
str = str.substring(0, str.length - 1);
str = str.substring(0, str.length - 1);
}
return str;
}
}

public getResultsInCurrentArchive(
searchTerm: string,
Expand Down

0 comments on commit 5590485

Please sign in to comment.