1
0

Manual fix: use base components in unit test templates

`Themed*` components should be used in the actual codebase to ensure we retain theme support.
However, in unit tests these components won't work without a fully-functional `ThemeService` & `Store`.

For this reason, the lint plugin allows `ds-base-*` selectors in unit test templates.
This commit is contained in:
Yury Bondarenko
2024-03-28 18:38:55 +01:00
parent 762e4616cc
commit a6e093038c
2 changed files with 5 additions and 23 deletions

View File

@@ -2,7 +2,6 @@
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
NO_ERRORS_SCHEMA,
} from '@angular/core';
@@ -129,14 +128,13 @@ describe('CollectionSelectorComponent', () => {
},
}),
CollectionSelectorComponent,
// CollectionDropdownComponent,
CollectionDropdownComponent,
],
providers: [
{ provide: CollectionDataService, useValue: collectionDataServiceMock },
{ provide: ElementRef, useClass: MockElementRef },
{ provide: NgbActiveModal, useValue: modal },
{ provide: ActivatedRoute, useValue: {} },
{ provide: CollectionDropdownComponent, useClass: CollectionDropdownStubComponent },
ChangeDetectorRef,
],
schemas: [NO_ERRORS_SCHEMA],
@@ -153,7 +151,7 @@ describe('CollectionSelectorComponent', () => {
scheduler = getTestScheduler();
fixture = TestBed.overrideComponent(CollectionSelectorComponent, {
set: {
template: '<ds-collection-dropdown (selectionChange)="selectObject($event)"></ds-collection-dropdown>',
template: '<ds-base-collection-dropdown (selectionChange)="selectObject($event)"></ds-base-collection-dropdown>',
},
}).createComponent(CollectionSelectorComponent);
component = fixture.componentInstance;
@@ -180,19 +178,3 @@ describe('CollectionSelectorComponent', () => {
expect((component as any).activeModal.close).toHaveBeenCalled();
});
});
@Component({
selector: 'ds-collection-dropdown',
template: `
<li
(click)="test()"
class="dropdown-item collection-item"
title="test" >
</li>`,
standalone: true,
})
export class CollectionDropdownStubComponent {
test() {
return 'test';
}
}

View File

@@ -8,23 +8,23 @@ import {
waitForAsync,
} from '@angular/core/testing';
import { Router } from '@angular/router';
import { of } from 'rxjs';
import { RouteService } from '../core/services/route.service';
import { SearchConfigurationService } from '../core/shared/search/search-configuration.service';
import { configureSearchComponentTestingModule } from '../shared/search/search.component.spec';
import { ConfigurationSearchPageComponent } from './configuration-search-page.component';
import createSpy = jasmine.createSpy;
import { of } from 'rxjs';
const CONFIGURATION = 'test-configuration';
const QUERY = 'test query';
@Component({
template: `
<ds-configuration-search-page [configuration]="'${CONFIGURATION}'"
<ds-base-configuration-search-page [configuration]="'${CONFIGURATION}'"
[fixedFilterQuery]="'${QUERY}'"
#configurationSearchPage>
</ds-configuration-search-page>
</ds-base-configuration-search-page>
`,
imports: [
ConfigurationSearchPageComponent,