Skip to content

Commit 81841fe

Browse files
committed
fix unit test
1 parent 533ad9b commit 81841fe

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/app/shared/modules/filters/multiselect-filter.component.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ describe("MultiSelectFilterComponent", () => {
115115
describe("#itemSelected()", () => {
116116
it("should dispatch an AddMultiSelectFilterAction", () => {
117117
dispatchSpy = spyOn(component.selectionChange, "emit");
118-
119-
const value = "test";
120-
component.itemSelected({ _id: value });
118+
const value = { _id: "test" };
119+
component.itemSelected(value);
121120

122121
expect(dispatchSpy).toHaveBeenCalledTimes(1);
123122
expect(dispatchSpy).toHaveBeenCalledWith({
@@ -132,8 +131,8 @@ describe("MultiSelectFilterComponent", () => {
132131
it("should dispatch a RemoveMultiSelectFilterAction", () => {
133132
dispatchSpy = spyOn(component.selectionChange, "emit");
134133

135-
const value = "test";
136-
component.itemRemoved(value);
134+
const value = { _id: "test" };
135+
component.itemRemoved("test");
137136

138137
expect(dispatchSpy).toHaveBeenCalledTimes(1);
139138
expect(dispatchSpy).toHaveBeenCalledWith({

src/app/shared/modules/filters/multiselect-filter.component.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, EventEmitter, Input, Output } from "@angular/core";
22
import { createSuggestionObserver, getFacetCount } from "./utils";
3-
import { BehaviorSubject, Observable } from "rxjs";
3+
import { BehaviorSubject, Observable, of } from "rxjs";
44
import { ClearableInputComponent } from "./clearable-input.component";
55
import { AppConfigService } from "app-config.service";
66
import { FacetCount } from "state-management/state/datasets.store";
@@ -22,8 +22,8 @@ export class MultiSelectFilterComponent extends ClearableInputComponent {
2222
@Input() key = "";
2323
@Input() label = "";
2424
@Input() tooltip = "";
25-
@Input() facetCounts$: Observable<FacetCount[]>;
26-
@Input() currentFilter$: Observable<string[]>;
25+
@Input() facetCounts$: Observable<FacetCount[]> = of([]);
26+
@Input() currentFilter$: Observable<string[]> = of([]);
2727
@Output() selectionChange = new EventEmitter<MultiSelectFilterValue>();
2828

2929
appConfig = this.appConfigService.getConfig();
@@ -53,14 +53,17 @@ export class MultiSelectFilterComponent extends ClearableInputComponent {
5353
}
5454

5555
itemSelected(value: { _id: string; label?: string } | null) {
56-
this.selectionChange.emit({ key: this.key, value: value, event: "add" });
56+
this.selectionChange.emit({ key: this.key, value, event: "add" });
5757
this.input$.next("");
5858
}
5959

6060
itemRemoved(value: string | null) {
61+
// This is workaround since the currentFilter$ only contains the id string
62+
const valueObj = { _id: value };
63+
6164
this.selectionChange.emit({
6265
key: this.key,
63-
value: { _id: value },
66+
value: valueObj,
6467
event: "remove",
6568
});
6669
}

0 commit comments

Comments
 (0)