Skip to content

Commit

Permalink
Manual fix: use base components in unit test templates
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
ybnd committed Mar 28, 2024
1 parent 762e461 commit a6e0930
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
NO_ERRORS_SCHEMA,
} from '@angular/core';
Expand Down Expand Up @@ -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],
Expand All @@ -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;
Expand All @@ -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';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a6e0930

Please sign in to comment.