mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
79730: Add unit tests for sequence service & ds-search-filter IDs
This commit is contained in:
22
src/app/core/shared/sequence.service.spec.ts
Normal file
22
src/app/core/shared/sequence.service.spec.ts
Normal 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);
|
||||
});
|
||||
});
|
@@ -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');
|
||||
|
Reference in New Issue
Block a user