|
| 1 | +import { HttpClient } from '@angular/common/http'; |
| 2 | +import { |
| 3 | + ChangeDetectionStrategy, |
| 4 | + NO_ERRORS_SCHEMA, |
| 5 | +} from '@angular/core'; |
| 6 | +import { |
| 7 | + ComponentFixture, |
| 8 | + fakeAsync, |
| 9 | + TestBed, |
| 10 | + tick, |
| 11 | + waitForAsync, |
| 12 | +} from '@angular/core/testing'; |
| 13 | +import { By } from '@angular/platform-browser'; |
| 14 | +import { RouterTestingModule } from '@angular/router/testing'; |
| 15 | +import { APP_CONFIG } from '@dspace/config/app-config.interface'; |
| 16 | +import { BrowseDefinitionDataService } from '@dspace/core/browse/browse-definition-data.service'; |
| 17 | +import { RemoteDataBuildService } from '@dspace/core/cache/builders/remote-data-build.service'; |
| 18 | +import { ObjectCacheService } from '@dspace/core/cache/object-cache.service'; |
| 19 | +import { BitstreamDataService } from '@dspace/core/data/bitstream-data.service'; |
| 20 | +import { CommunityDataService } from '@dspace/core/data/community-data.service'; |
| 21 | +import { DefaultChangeAnalyzer } from '@dspace/core/data/default-change-analyzer.service'; |
| 22 | +import { DSOChangeAnalyzer } from '@dspace/core/data/dso-change-analyzer.service'; |
| 23 | +import { ItemDataService } from '@dspace/core/data/item-data.service'; |
| 24 | +import { RelationshipDataService } from '@dspace/core/data/relationship-data.service'; |
| 25 | +import { RemoteData } from '@dspace/core/data/remote-data'; |
| 26 | +import { VersionDataService } from '@dspace/core/data/version-data.service'; |
| 27 | +import { VersionHistoryDataService } from '@dspace/core/data/version-history-data.service'; |
| 28 | +import { APP_DATA_SERVICES_MAP } from '@dspace/core/data-services-map-type'; |
| 29 | +import { NotificationsService } from '@dspace/core/notification-system/notifications.service'; |
| 30 | +import { RouteService } from '@dspace/core/services/route.service'; |
| 31 | +import { Bitstream } from '@dspace/core/shared/bitstream.model'; |
| 32 | +import { HALEndpointService } from '@dspace/core/shared/hal-endpoint.service'; |
| 33 | +import { Item } from '@dspace/core/shared/item.model'; |
| 34 | +import { MetadataMap } from '@dspace/core/shared/metadata.models'; |
| 35 | +import { UUIDService } from '@dspace/core/shared/uuid.service'; |
| 36 | +import { WorkspaceitemDataService } from '@dspace/core/submission/workspaceitem-data.service'; |
| 37 | +import { BrowseDefinitionDataServiceStub } from '@dspace/core/testing/browse-definition-data-service.stub'; |
| 38 | +import { mockTruncatableService } from '@dspace/core/testing/mock-trucatable.service'; |
| 39 | +import { TranslateLoaderMock } from '@dspace/core/testing/translate-loader.mock'; |
| 40 | +import { createPaginatedList } from '@dspace/core/testing/utils.test'; |
| 41 | +import { createSuccessfulRemoteDataObject$ } from '@dspace/core/utilities/remote-data.utils'; |
| 42 | +import { Store } from '@ngrx/store'; |
| 43 | +import { |
| 44 | + TranslateLoader, |
| 45 | + TranslateModule, |
| 46 | +} from '@ngx-translate/core'; |
| 47 | +import { |
| 48 | + Observable, |
| 49 | + of, |
| 50 | +} from 'rxjs'; |
| 51 | + |
| 52 | +import { environment } from '../../../../../environments/environment.test'; |
| 53 | +import { DsoEditMenuComponent } from '../../../../shared/dso-page/dso-edit-menu/dso-edit-menu.component'; |
| 54 | +import { MetadataFieldWrapperComponent } from '../../../../shared/metadata-field-wrapper/metadata-field-wrapper.component'; |
| 55 | +import { ThemedResultsBackButtonComponent } from '../../../../shared/results-back-button/themed-results-back-button.component'; |
| 56 | +import { SearchService } from '../../../../shared/search/search.service'; |
| 57 | +import { TruncatableService } from '../../../../shared/truncatable/truncatable.service'; |
| 58 | +import { TruncatePipe } from '../../../../shared/utils/truncate.pipe'; |
| 59 | +import { ThemedThumbnailComponent } from '../../../../thumbnail/themed-thumbnail.component'; |
| 60 | +import { CollectionsComponent } from '../../../field-components/collections/collections.component'; |
| 61 | +import { ThemedMediaViewerComponent } from '../../../media-viewer/themed-media-viewer.component'; |
| 62 | +import { MiradorViewerComponent } from '../../../mirador-viewer/mirador-viewer.component'; |
| 63 | +import { ThemedFileSectionComponent } from '../../field-components/file-section/themed-file-section.component'; |
| 64 | +import { ItemPageAbstractFieldComponent } from '../../field-components/specific-field/abstract/item-page-abstract-field.component'; |
| 65 | +import { ItemPageDateFieldComponent } from '../../field-components/specific-field/date/item-page-date-field.component'; |
| 66 | +import { GenericItemPageFieldComponent } from '../../field-components/specific-field/generic/generic-item-page-field.component'; |
| 67 | +import { ThemedItemPageTitleFieldComponent } from '../../field-components/specific-field/title/themed-item-page-field.component'; |
| 68 | +import { ItemPageUriFieldComponent } from '../../field-components/specific-field/uri/item-page-uri-field.component'; |
| 69 | +import { ThemedMetadataRepresentationListComponent } from '../../metadata-representation-list/themed-metadata-representation-list.component'; |
| 70 | +import { RelatedItemsComponent } from '../../related-items/related-items-component'; |
| 71 | +import { |
| 72 | + createRelationshipsObservable, |
| 73 | + getIIIFEnabled, |
| 74 | + getIIIFSearchEnabled, |
| 75 | + mockRouteService, |
| 76 | +} from '../shared/item.component.spec'; |
| 77 | +import { DatasetComponent } from './dataset.component'; |
| 78 | + |
| 79 | +const noMetadata = new MetadataMap(); |
| 80 | + |
| 81 | +function getItem(metadata: MetadataMap) { |
| 82 | + return Object.assign(new Item(), { |
| 83 | + bundles: createSuccessfulRemoteDataObject$(createPaginatedList([])), |
| 84 | + metadata: metadata, |
| 85 | + relationships: createRelationshipsObservable(), |
| 86 | + }); |
| 87 | +} |
| 88 | + |
| 89 | +describe('DatasetComponent', () => { |
| 90 | + let comp: DatasetComponent; |
| 91 | + let fixture: ComponentFixture<DatasetComponent>; |
| 92 | + |
| 93 | + beforeEach(waitForAsync(() => { |
| 94 | + const mockBitstreamDataService = { |
| 95 | + getThumbnailFor(item: Item): Observable<RemoteData<Bitstream>> { |
| 96 | + return createSuccessfulRemoteDataObject$(new Bitstream()); |
| 97 | + }, |
| 98 | + }; |
| 99 | + TestBed.configureTestingModule({ |
| 100 | + imports: [ |
| 101 | + TranslateModule.forRoot({ |
| 102 | + loader: { |
| 103 | + provide: TranslateLoader, |
| 104 | + useClass: TranslateLoaderMock, |
| 105 | + }, |
| 106 | + }), |
| 107 | + RouterTestingModule, |
| 108 | + GenericItemPageFieldComponent, TruncatePipe, |
| 109 | + DatasetComponent, |
| 110 | + ], |
| 111 | + providers: [ |
| 112 | + { provide: ItemDataService, useValue: {} }, |
| 113 | + { provide: TruncatableService, useValue: mockTruncatableService }, |
| 114 | + { provide: RelationshipDataService, useValue: {} }, |
| 115 | + { provide: ObjectCacheService, useValue: {} }, |
| 116 | + { provide: UUIDService, useValue: {} }, |
| 117 | + { provide: Store, useValue: {} }, |
| 118 | + { provide: RemoteDataBuildService, useValue: {} }, |
| 119 | + { provide: CommunityDataService, useValue: {} }, |
| 120 | + { provide: HALEndpointService, useValue: {} }, |
| 121 | + { provide: NotificationsService, useValue: {} }, |
| 122 | + { provide: HttpClient, useValue: {} }, |
| 123 | + { provide: DSOChangeAnalyzer, useValue: {} }, |
| 124 | + { provide: DefaultChangeAnalyzer, useValue: {} }, |
| 125 | + { provide: VersionHistoryDataService, useValue: {} }, |
| 126 | + { provide: VersionDataService, useValue: {} }, |
| 127 | + { provide: BitstreamDataService, useValue: mockBitstreamDataService }, |
| 128 | + { provide: WorkspaceitemDataService, useValue: {} }, |
| 129 | + { provide: SearchService, useValue: {} }, |
| 130 | + { provide: RouteService, useValue: mockRouteService }, |
| 131 | + { provide: BrowseDefinitionDataService, useValue: BrowseDefinitionDataServiceStub }, |
| 132 | + { provide: APP_CONFIG, useValue: environment }, |
| 133 | + { provide: APP_DATA_SERVICES_MAP, useValue: {} }, |
| 134 | + ], |
| 135 | + schemas: [NO_ERRORS_SCHEMA], |
| 136 | + }).overrideComponent(DatasetComponent, { |
| 137 | + add: { changeDetection: ChangeDetectionStrategy.Default }, |
| 138 | + remove: { |
| 139 | + imports: [ThemedResultsBackButtonComponent, MiradorViewerComponent, ThemedItemPageTitleFieldComponent, DsoEditMenuComponent, MetadataFieldWrapperComponent, ThemedThumbnailComponent, ThemedMediaViewerComponent, ThemedFileSectionComponent, ItemPageDateFieldComponent, ThemedMetadataRepresentationListComponent, GenericItemPageFieldComponent, RelatedItemsComponent, ItemPageAbstractFieldComponent, ItemPageUriFieldComponent, CollectionsComponent, |
| 140 | + ], |
| 141 | + }, |
| 142 | + }); |
| 143 | + })); |
| 144 | + |
| 145 | + describe('default view', () => { |
| 146 | + beforeEach(waitForAsync(() => { |
| 147 | + TestBed.compileComponents(); |
| 148 | + fixture = TestBed.createComponent(DatasetComponent); |
| 149 | + comp = fixture.componentInstance; |
| 150 | + comp.object = getItem(noMetadata); |
| 151 | + fixture.detectChanges(); |
| 152 | + })); |
| 153 | + |
| 154 | + it('should contain a component to display the date', () => { |
| 155 | + const fields = fixture.debugElement.queryAll(By.css('ds-item-page-date-field')); |
| 156 | + expect(fields.length).toBeGreaterThanOrEqual(1); |
| 157 | + }); |
| 158 | + |
| 159 | + it('should not contain a metadata only author field', () => { |
| 160 | + const fields = fixture.debugElement.queryAll(By.css('ds-item-page-author-field')); |
| 161 | + expect(fields.length).toBe(0); |
| 162 | + }); |
| 163 | + |
| 164 | + it('should contain a mixed metadata and relationship field for authors', () => { |
| 165 | + const fields = fixture.debugElement.queryAll(By.css('.ds-item-page-mixed-author-field')); |
| 166 | + expect(fields.length).toBe(1); |
| 167 | + }); |
| 168 | + |
| 169 | + it('should contain a component to display the abstract', () => { |
| 170 | + const fields = fixture.debugElement.queryAll(By.css('ds-item-page-abstract-field')); |
| 171 | + expect(fields.length).toBeGreaterThanOrEqual(1); |
| 172 | + }); |
| 173 | + |
| 174 | + it('should contain a component to display the uri', () => { |
| 175 | + const fields = fixture.debugElement.queryAll(By.css('ds-item-page-uri-field')); |
| 176 | + expect(fields.length).toBeGreaterThanOrEqual(1); |
| 177 | + }); |
| 178 | + |
| 179 | + it('should contain a component to display the collections', () => { |
| 180 | + const fields = fixture.debugElement.queryAll(By.css('ds-item-page-collections')); |
| 181 | + expect(fields.length).toBeGreaterThanOrEqual(1); |
| 182 | + }); |
| 183 | + }); |
| 184 | + |
| 185 | + describe('with IIIF viewer', () => { |
| 186 | + |
| 187 | + beforeEach(waitForAsync(() => { |
| 188 | + const iiifEnabledMap: MetadataMap = { |
| 189 | + 'dspace.iiif.enabled': [getIIIFEnabled(true)], |
| 190 | + 'iiif.search.enabled': [getIIIFSearchEnabled(false)], |
| 191 | + }; |
| 192 | + TestBed.compileComponents(); |
| 193 | + fixture = TestBed.createComponent(DatasetComponent); |
| 194 | + comp = fixture.componentInstance; |
| 195 | + comp.object = getItem(iiifEnabledMap); |
| 196 | + fixture.detectChanges(); |
| 197 | + })); |
| 198 | + |
| 199 | + it('should contain an iiif viewer component', () => { |
| 200 | + const fields = fixture.debugElement.queryAll(By.css('ds-mirador-viewer')); |
| 201 | + expect(fields.length).toBeGreaterThanOrEqual(1); |
| 202 | + }); |
| 203 | + it('should not retrieve the query term for previous route', fakeAsync((): void => { |
| 204 | + //tick(10) |
| 205 | + expect(comp.iiifQuery$).toBeFalsy(); |
| 206 | + })); |
| 207 | + |
| 208 | + }); |
| 209 | + |
| 210 | + describe('with IIIF viewer and search', () => { |
| 211 | + |
| 212 | + const localMockRouteService = { |
| 213 | + getPreviousUrl(): Observable<string> { |
| 214 | + return of('/search?query=test%20query&fakeParam=true'); |
| 215 | + }, |
| 216 | + }; |
| 217 | + beforeEach(waitForAsync(() => { |
| 218 | + const iiifEnabledMap: MetadataMap = { |
| 219 | + 'dspace.iiif.enabled': [getIIIFEnabled(true)], |
| 220 | + 'iiif.search.enabled': [getIIIFSearchEnabled(true)], |
| 221 | + }; |
| 222 | + TestBed.overrideProvider(RouteService, { useValue: localMockRouteService }); |
| 223 | + TestBed.compileComponents(); |
| 224 | + fixture = TestBed.createComponent(DatasetComponent); |
| 225 | + comp = fixture.componentInstance; |
| 226 | + comp.object = getItem(iiifEnabledMap); |
| 227 | + fixture.detectChanges(); |
| 228 | + })); |
| 229 | + |
| 230 | + it('should contain an iiif viewer component', () => { |
| 231 | + const fields = fixture.debugElement.queryAll(By.css('ds-mirador-viewer')); |
| 232 | + expect(fields.length).toBeGreaterThanOrEqual(1); |
| 233 | + }); |
| 234 | + |
| 235 | + it('should retrieve the query term for previous route', fakeAsync((): void => { |
| 236 | + expect(comp.iiifQuery$.subscribe(result => expect(result).toEqual('test query'))); |
| 237 | + })); |
| 238 | + |
| 239 | + }); |
| 240 | + |
| 241 | + describe('with IIIF viewer and search but no previous search query', () => { |
| 242 | + const localMockRouteService = { |
| 243 | + getPreviousUrl(): Observable<string> { |
| 244 | + return of('/item'); |
| 245 | + }, |
| 246 | + }; |
| 247 | + beforeEach(waitForAsync(() => { |
| 248 | + const iiifEnabledMap: MetadataMap = { |
| 249 | + 'dspace.iiif.enabled': [getIIIFEnabled(true)], |
| 250 | + 'iiif.search.enabled': [getIIIFSearchEnabled(true)], |
| 251 | + }; |
| 252 | + TestBed.overrideProvider(RouteService, { useValue: localMockRouteService }); |
| 253 | + TestBed.compileComponents(); |
| 254 | + fixture = TestBed.createComponent(DatasetComponent); |
| 255 | + comp = fixture.componentInstance; |
| 256 | + comp.object = getItem(iiifEnabledMap); |
| 257 | + fixture.detectChanges(); |
| 258 | + })); |
| 259 | + |
| 260 | + it('should contain an iiif viewer component', () => { |
| 261 | + const fields = fixture.debugElement.queryAll(By.css('ds-mirador-viewer')); |
| 262 | + expect(fields.length).toBeGreaterThanOrEqual(1); |
| 263 | + }); |
| 264 | + |
| 265 | + it('should not retrieve the query term for previous route', fakeAsync( () => { |
| 266 | + let emitted; |
| 267 | + comp.iiifQuery$.subscribe(result => emitted = result); |
| 268 | + tick(10); |
| 269 | + expect(emitted).toBeUndefined(); |
| 270 | + })); |
| 271 | + |
| 272 | + }); |
| 273 | +}); |
0 commit comments