Skip to content

Commit

Permalink
Fix search for tags suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
minottic committed Aug 27, 2024
1 parent 1dc28db commit 4be01b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AppConfigService } from 'src/app/app-config.service';

import { SearchWindowComponent } from './search-window.component';
import { WidgetItemConfig } from 'src/app/core/model/config';
import { TagService } from '../tag.service';

const getConfig = () => ({});

Expand Down Expand Up @@ -140,12 +141,11 @@ describe('SearchWindowComponent', () => {
};
if (t)
component.configsArray = [{ cols: 0, rows: 1, y: 2, x: 3, config: t.config }];
if (t?.tagsIn)
component.tags = t.tagsIn;
component.tags = t?.tagsIn ?? [];
expect(component["_prepareConfig"]()).toEqual(t? t.configOut: defaultConfig);
if (t)
expect(component.searchStringFromConfig).toEqual(t.searchStringFromConfig);
expect(component.tags).toEqual(t?.tagsOut ?? ['alignment'])
expect(component.tags).toEqual(t?.tagsOut ?? [])
});
});

Expand Down Expand Up @@ -186,6 +186,7 @@ describe('SearchWindowComponent', () => {
{config: {filter: {excludeTags: ['c'] }}, tags: ['a', 'b', 'c', 'd'], expected: ['a', 'b', 'd']},
{config: {filter: {}}, tags: ['a', 'b', 'c', 'd'], expected: ['a', 'b', 'c', 'd']},
{config: {}, tags: ['a', 'b', 'c', 'd'], expected: ['a', 'b', 'c', 'd']},
{config: {filter: {tags: [], excludeTags: [] }}, tags: ['a', 'b', 'c', 'd'], expected: ['a', 'b', 'c', 'd']}
].forEach((t, i) => {
it(`should _prepareTags ${i}`, () => {
component.tags = t.tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class SearchWindowComponent implements OnInit {
}
if (!this.logbookId) return
this.tags = await this.tagService?.getTags();
if (this.tags?.length == 0) {
if (this.tags?.length === 0) {
this.tags = ["alignment"];
}
}
Expand Down Expand Up @@ -149,9 +149,9 @@ export class SearchWindowComponent implements OnInit {
}

private _prepareTags(config: Partial<WidgetItemConfig>) {
if (config.filter?.tags)
if (config.filter?.tags?.length > 0)
this.tags = this.tags.filter(tag => config.filter.tags.includes(tag));
if (config.filter?.excludeTags)
if (config.filter?.excludeTags?.length > 0)
this.tags = this.tags.filter(tag => !config.filter.excludeTags.includes(tag));
}

Expand Down

0 comments on commit 4be01b7

Please sign in to comment.