Commits

Yury Bondarenko authored a6e093038c9
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.
No tags

src/app/my-dspace-page/collection-selector/collection-selector.component.spec.ts

Modified
1 1 /* eslint-disable max-classes-per-file */
2 2 import {
3 3 ChangeDetectionStrategy,
4 4 ChangeDetectorRef,
5 - Component,
6 5 ElementRef,
7 6 NO_ERRORS_SCHEMA,
8 7 } from '@angular/core';
9 8 import {
10 9 ComponentFixture,
11 10 TestBed,
12 11 waitForAsync,
13 12 } from '@angular/core/testing';
14 13 import { ActivatedRoute } from '@angular/router';
15 14 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
122 121 beforeEach(waitForAsync(() => {
123 122 TestBed.configureTestingModule({
124 123 imports: [
125 124 TranslateModule.forRoot({
126 125 loader: {
127 126 provide: TranslateLoader,
128 127 useClass: TranslateLoaderMock,
129 128 },
130 129 }),
131 130 CollectionSelectorComponent,
132 - // CollectionDropdownComponent,
131 + CollectionDropdownComponent,
133 132 ],
134 133 providers: [
135 134 { provide: CollectionDataService, useValue: collectionDataServiceMock },
136 135 { provide: ElementRef, useClass: MockElementRef },
137 136 { provide: NgbActiveModal, useValue: modal },
138 137 { provide: ActivatedRoute, useValue: {} },
139 - { provide: CollectionDropdownComponent, useClass: CollectionDropdownStubComponent },
140 138 ChangeDetectorRef,
141 139 ],
142 140 schemas: [NO_ERRORS_SCHEMA],
143 141 })
144 142 .overrideComponent(CollectionSelectorComponent, {
145 143 set: {
146 144 changeDetection: ChangeDetectionStrategy.Default,
147 145 },
148 146 })
149 147 .compileComponents();
150 148 }));
151 149
152 150 beforeEach(() => {
153 151 scheduler = getTestScheduler();
154 152 fixture = TestBed.overrideComponent(CollectionSelectorComponent, {
155 153 set: {
156 - template: '<ds-collection-dropdown (selectionChange)="selectObject($event)"></ds-collection-dropdown>',
154 + template: '<ds-base-collection-dropdown (selectionChange)="selectObject($event)"></ds-base-collection-dropdown>',
157 155 },
158 156 }).createComponent(CollectionSelectorComponent);
159 157 component = fixture.componentInstance;
160 158 fixture.detectChanges();
161 159 });
162 160
163 161 it('should create', () => {
164 162 expect(component).toBeTruthy();
165 163 });
166 164
173 171 component.selectObject({ collection: { name: 'test', id: 'test', uuid: 'test' }, communities: [] });
174 172
175 173 expect(component.selectObject).toHaveBeenCalled();
176 174 });
177 175
178 176 it('should close the dialog', () => {
179 177 component.close();
180 178 expect((component as any).activeModal.close).toHaveBeenCalled();
181 179 });
182 180 });
183 -
184 -@Component({
185 - selector: 'ds-collection-dropdown',
186 - template: `
187 - <li
188 - (click)="test()"
189 - class="dropdown-item collection-item"
190 - title="test" >
191 - </li>`,
192 - standalone: true,
193 -})
194 -export class CollectionDropdownStubComponent {
195 - test() {
196 - return 'test';
197 - }
198 -}

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut