Files
dspace-angular/src/app/shared/starts-with/starts-with-loader.component.spec.ts
Alexandre Vryghem 6e29f306a7 108588: Fixed browse by date tab's year dropdown always being empty
- The data passed to the injector in BrowseByComponent was not updated by ngOnChanges
- Also refactored the injector logic to StartsWithLoaderComponent
2024-02-07 00:44:18 +01:00

72 lines
2.7 KiB
TypeScript

import { StartsWithLoaderComponent } from './starts-with-loader.component';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
import { DynamicComponentLoaderDirective } from '../abstract-component-loader/dynamic-component-loader.directive';
import { TranslateModule } from '@ngx-translate/core';
import { StartsWithTextComponent } from './text/starts-with-text.component';
import { Router, ActivatedRoute } from '@angular/router';
import { RouterStub } from '../testing/router.stub';
import { ThemeService } from '../theme-support/theme.service';
import { getMockThemeService } from '../mocks/theme-service.mock';
import { StartsWithType } from './starts-with-decorator';
import { ActivatedRouteStub } from '../testing/active-router.stub';
import { PaginationService } from '../../core/pagination/pagination.service';
import { PaginationServiceStub } from '../testing/pagination-service.stub';
describe('StartsWithLoaderComponent', () => {
let comp: StartsWithLoaderComponent;
let fixture: ComponentFixture<StartsWithLoaderComponent>;
let paginationService: PaginationServiceStub;
let route: ActivatedRouteStub;
let themeService: ThemeService;
const type: StartsWithType = StartsWithType.text;
beforeEach(waitForAsync(() => {
paginationService = new PaginationServiceStub();
route = new ActivatedRouteStub();
themeService = getMockThemeService('dspace');
void TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
],
declarations: [
StartsWithLoaderComponent,
StartsWithTextComponent,
DynamicComponentLoaderDirective,
],
providers: [
{ provide: PaginationService, useValue: paginationService },
{ provide: ActivatedRoute, useValue: route },
{ provide: Router, useValue: new RouterStub() },
{ provide: ThemeService, useValue: themeService },
],
schemas: [NO_ERRORS_SCHEMA],
}).overrideComponent(StartsWithLoaderComponent, {
set: {
changeDetection: ChangeDetectionStrategy.Default,
entryComponents: [StartsWithTextComponent],
}
}).compileComponents();
}));
beforeEach(waitForAsync(() => {
fixture = TestBed.createComponent(StartsWithLoaderComponent);
comp = fixture.componentInstance;
comp.type = type;
comp.paginationId = 'bbm';
comp.startsWithOptions = [];
spyOn(comp, 'getComponent').and.returnValue(StartsWithTextComponent);
fixture.detectChanges();
}));
describe('When the component is rendered', () => {
it('should call the getComponent function', () => {
expect(comp.getComponent).toHaveBeenCalled();
});
});
});