diff --git a/scilog/src/app/logbook/core/search-window/search-window.component.spec.ts b/scilog/src/app/logbook/core/search-window/search-window.component.spec.ts index a1878b3d..a898b1ea 100644 --- a/scilog/src/app/logbook/core/search-window/search-window.component.spec.ts +++ b/scilog/src/app/logbook/core/search-window/search-window.component.spec.ts @@ -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 = () => ({}); @@ -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 ?? []) }); }); @@ -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; diff --git a/scilog/src/app/logbook/core/search-window/search-window.component.ts b/scilog/src/app/logbook/core/search-window/search-window.component.ts index 6a9c833d..fbf87bc7 100644 --- a/scilog/src/app/logbook/core/search-window/search-window.component.ts +++ b/scilog/src/app/logbook/core/search-window/search-window.component.ts @@ -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"]; } } @@ -149,9 +149,9 @@ export class SearchWindowComponent implements OnInit { } private _prepareTags(config: Partial) { - 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)); }