79730: Add unit tests for sequence service & ds-search-filter IDs

This commit is contained in:
Yura Bondarenko
2021-06-25 10:00:06 +02:00
parent 24ffa6c63a
commit 98b2c75a3c
2 changed files with 32 additions and 1 deletions

View File

@@ -0,0 +1,22 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
import { SequenceService } from './sequence.service';
let service: SequenceService;
describe('SequenceService', () => {
beforeEach(() => {
service = new SequenceService();
});
it('should return sequential numbers on next(), starting with 1', () => {
const NUMBERS = [1,2,3,4,5];
const sequence = NUMBERS.map(() => service.next());
expect(sequence).toEqual(NUMBERS);
});
});

View File

@@ -51,12 +51,15 @@ describe('SearchFilterComponent', () => {
};
let filterService;
let sequenceService;
const mockResults = observableOf(['test', 'data']);
const searchServiceStub = {
getFacetValuesFor: (filter) => mockResults
};
beforeEach(waitForAsync(() => {
sequenceService = jasmine.createSpyObj('sequenceService', { next: 17 });
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NoopAnimationsModule],
declarations: [SearchFilterComponent],
@@ -67,7 +70,7 @@ describe('SearchFilterComponent', () => {
useValue: mockFilterService
},
{ provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() },
{ provide: SequenceService, useValue: new SequenceService() },
{ provide: SequenceService, useValue: sequenceService },
],
schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(SearchFilterComponent, {
@@ -83,6 +86,12 @@ describe('SearchFilterComponent', () => {
filterService = (comp as any).filterService;
});
it('should generate unique IDs', () => {
expect(sequenceService.next).toHaveBeenCalled();
expect(comp.toggleId).toContain('17');
expect(comp.regionId).toContain('17');
});
describe('when the toggle method is triggered', () => {
beforeEach(() => {
spyOn(filterService, 'toggle');