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 { import {
ChangeDetectionStrategy, ChangeDetectionStrategy,
ChangeDetectorRef, ChangeDetectorRef,
Component,
ElementRef, ElementRef,
NO_ERRORS_SCHEMA, NO_ERRORS_SCHEMA,
} from '@angular/core'; } from '@angular/core';
@@ -129,14 +128,13 @@ describe('CollectionSelectorComponent', () => {
}, },
}), }),
CollectionSelectorComponent, CollectionSelectorComponent,
// CollectionDropdownComponent, CollectionDropdownComponent,
], ],
providers: [ providers: [
{ provide: CollectionDataService, useValue: collectionDataServiceMock }, { provide: CollectionDataService, useValue: collectionDataServiceMock },
{ provide: ElementRef, useClass: MockElementRef }, { provide: ElementRef, useClass: MockElementRef },
{ provide: NgbActiveModal, useValue: modal }, { provide: NgbActiveModal, useValue: modal },
{ provide: ActivatedRoute, useValue: {} }, { provide: ActivatedRoute, useValue: {} },
{ provide: CollectionDropdownComponent, useClass: CollectionDropdownStubComponent },
ChangeDetectorRef, ChangeDetectorRef,
], ],
schemas: [NO_ERRORS_SCHEMA], schemas: [NO_ERRORS_SCHEMA],
@@ -153,7 +151,7 @@ describe('CollectionSelectorComponent', () => {
scheduler = getTestScheduler(); scheduler = getTestScheduler();
fixture = TestBed.overrideComponent(CollectionSelectorComponent, { fixture = TestBed.overrideComponent(CollectionSelectorComponent, {
set: { 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); }).createComponent(CollectionSelectorComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
@@ -180,19 +178,3 @@ describe('CollectionSelectorComponent', () => {
expect((component as any).activeModal.close).toHaveBeenCalled(); 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, waitForAsync,
} from '@angular/core/testing'; } from '@angular/core/testing';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { of } from 'rxjs';
import { RouteService } from '../core/services/route.service'; import { RouteService } from '../core/services/route.service';
import { SearchConfigurationService } from '../core/shared/search/search-configuration.service'; import { SearchConfigurationService } from '../core/shared/search/search-configuration.service';
import { configureSearchComponentTestingModule } from '../shared/search/search.component.spec'; import { configureSearchComponentTestingModule } from '../shared/search/search.component.spec';
import { ConfigurationSearchPageComponent } from './configuration-search-page.component'; import { ConfigurationSearchPageComponent } from './configuration-search-page.component';
import createSpy = jasmine.createSpy; import createSpy = jasmine.createSpy;
import { of } from 'rxjs';
const CONFIGURATION = 'test-configuration'; const CONFIGURATION = 'test-configuration';
const QUERY = 'test query'; const QUERY = 'test query';
@Component({ @Component({
template: ` template: `
<ds-configuration-search-page [configuration]="'${CONFIGURATION}'" <ds-base-configuration-search-page [configuration]="'${CONFIGURATION}'"
[fixedFilterQuery]="'${QUERY}'" [fixedFilterQuery]="'${QUERY}'"
#configurationSearchPage> #configurationSearchPage>
</ds-configuration-search-page> </ds-base-configuration-search-page>
`, `,
imports: [ imports: [
ConfigurationSearchPageComponent, ConfigurationSearchPageComponent,