Skip to content

Commit 935b754

Browse files
committed
Added onebox component tests
1 parent 4a9cbfe commit 935b754

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/app/core/testing/search-service.stub.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Observable,
44
of,
55
} from 'rxjs';
6+
import { SuggestionEntry } from 'src/app/shared/search/suggestion-entry.model';
67

78
import { AppliedFilter } from '../shared/search/models/applied-filter.model';
89
import { PaginatedSearchOptions } from '../shared/search/models/paginated-search-options.model';
@@ -39,6 +40,10 @@ export class SearchServiceStub {
3940
return null;
4041
}
4142

43+
getSuggestionsFor(_query: string, _dictionary: string): Observable<SuggestionEntry[]> {
44+
return of([]);
45+
}
46+
4247
get testViewMode(): ViewMode {
4348
return this._viewMode;
4449
}

src/app/shared/form/builder/ds-dynamic-form-ui/models/onebox/dynamic-onebox.component.spec.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ describe('DsDynamicOneboxComponent test suite', () => {
142142
vocabularyServiceStub = new VocabularyServiceStub();
143143
searchServiceStub = new SearchServiceStub();
144144

145+
145146
modal = jasmine.createSpyObj('modal',
146147
{
147148
open: jasmine.createSpy('open'),
@@ -470,6 +471,33 @@ describe('DsDynamicOneboxComponent test suite', () => {
470471
});
471472

472473
});
474+
475+
describe('When vocabulary type is \'suggest\'', () => {
476+
beforeEach(() => {
477+
oneboxCompFixture = TestBed.createComponent(DsDynamicOneboxComponent);
478+
oneboxComponent = oneboxCompFixture.componentInstance; // FormComponent test instance
479+
oneboxComponent.group = ONEBOX_TEST_GROUP;
480+
oneboxComponent.model = new DynamicOneboxModel(ONEBOX_TEST_MODEL_CONFIG);
481+
oneboxComponent.model.vocabularyOptions.type = 'suggest';
482+
oneboxComponent.model.vocabularyOptions.name = 'authors';
483+
spyOn(oneboxComponent, 'setCurrentValue').and.callThrough();
484+
spyOn(searchServiceStub, 'getSuggestionsFor');
485+
});
486+
487+
it('should not call setCurrentValue with \'init\' during init', () => {
488+
oneboxComponent.model.value = 'hi!';
489+
oneboxComponent.ngOnInit();
490+
expect(oneboxComponent.setCurrentValue)
491+
.toHaveBeenCalledWith('hi!', false);
492+
});
493+
494+
it('should call getSuggestionsFor() when searching', fakeAsync(() => {
495+
oneboxComponent.search(of('hello')).subscribe();
496+
tick(400);
497+
expect(searchServiceStub.getSuggestionsFor).toHaveBeenCalledWith(
498+
'hello', 'authors');
499+
}));
500+
});
473501
});
474502

475503
// declare a test component
@@ -491,4 +519,3 @@ class TestComponent {
491519
model = new DynamicOneboxModel(ONEBOX_TEST_MODEL_CONFIG);
492520

493521
}
494-

0 commit comments

Comments
 (0)