From def3032dc0a4a8fdf57ef2c7c6e0207d2650fd70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20G=C3=B3mez?= Date: Thu, 10 Oct 2024 03:25:34 +0200 Subject: [PATCH] Fex minor changes * Restore the Input properties that allow configuring the license URI and name fields from a template * Update test cases using a stub configuration data service * Fix lint issues --- ...em-page-cc-license-field.component.spec.ts | 8 +++- .../item-page-cc-license-field.component.ts | 39 ++++++++++++------- .../untyped-item.component.spec.ts | 4 ++ 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/app/item-page/simple/field-components/specific-field/cc-license/item-page-cc-license-field.component.spec.ts b/src/app/item-page/simple/field-components/specific-field/cc-license/item-page-cc-license-field.component.spec.ts index 7a29fed2757..a3eae64e938 100644 --- a/src/app/item-page/simple/field-components/specific-field/cc-license/item-page-cc-license-field.component.spec.ts +++ b/src/app/item-page/simple/field-components/specific-field/cc-license/item-page-cc-license-field.component.spec.ts @@ -12,12 +12,14 @@ import { TranslateLoader, TranslateModule, } from '@ngx-translate/core'; +import { ConfigurationDataService } from 'src/app/core/data/configuration-data.service'; import { Item } from 'src/app/core/shared/item.model'; import { MetadataMap, MetadataValue, } from 'src/app/core/shared/metadata.models'; import { createSuccessfulRemoteDataObject$ } from 'src/app/shared/remote-data.utils'; +import { ConfigurationDataServiceStub } from 'src/app/shared/testing/configuration-data.service.stub'; import { createPaginatedList } from 'src/app/shared/testing/utils.test'; import { APP_CONFIG } from '../../../../../../config/app-config.interface'; @@ -202,6 +204,7 @@ function configureFixture( describe('ItemPageCcLicenseFieldComponent', () => { let fixture: ComponentFixture; + let configurationDataService = new ConfigurationDataServiceStub(); beforeEach(waitForAsync(() => { void TestBed.configureTestingModule({ @@ -214,7 +217,10 @@ describe('ItemPageCcLicenseFieldComponent', () => { }), ItemPageCcLicenseFieldComponent, ], - providers: [{ provide: APP_CONFIG, useValue: environment }], + providers: [ + { provide: APP_CONFIG, useValue: environment }, + { provide: ConfigurationDataService, useValue: configurationDataService }, + ], schemas: [NO_ERRORS_SCHEMA], }) .overrideComponent(ItemPageCcLicenseFieldComponent, { diff --git a/src/app/item-page/simple/field-components/specific-field/cc-license/item-page-cc-license-field.component.ts b/src/app/item-page/simple/field-components/specific-field/cc-license/item-page-cc-license-field.component.ts index 3b900284bc5..b6403bbea6e 100644 --- a/src/app/item-page/simple/field-components/specific-field/cc-license/item-page-cc-license-field.component.ts +++ b/src/app/item-page/simple/field-components/specific-field/cc-license/item-page-cc-license-field.component.ts @@ -38,6 +38,16 @@ export class ItemPageCcLicenseFieldComponent implements OnInit { */ @Input() item: Item; + /** + * Field name containing the CC license URI + */ + @Input() ccLicenseUriField?; + + /** + * Field name containing the CC license URI + */ + @Input() ccLicenseNameField?; + /** * 'full' variant shows image, a disclaimer (optional) and name (always), better for the item page content. * 'small' variant shows image and name (optional), better for the item page sidebar @@ -54,34 +64,37 @@ export class ItemPageCcLicenseFieldComponent implements OnInit { */ @Input() showDisclaimer? = this.appConfig.ccLicense.showDisclaimer; - ccLicenseUriField: string; - ccLicenseNameField: string; uri: string; name: string; showImage = true; imgSrc: string; constructor( - @Inject(APP_CONFIG) private appConfig: AppConfig, - private configService: ConfigurationDataService, + @Inject(APP_CONFIG) protected appConfig: AppConfig, + protected configService: ConfigurationDataService, ) { + } + + ngOnInit() { this.configService.findByPropertyName('cc.license.uri').pipe( getFirstCompletedRemoteData(), getRemoteDataPayload(), ).subscribe((remoteData: ConfigurationProperty) => { - this.ccLicenseNameField = remoteData.values && remoteData.values.length > 0 ? remoteData.values[0] : 'dc.rights.uri'; - }, - ); - this.configService.findByPropertyName('dc.rights').pipe( + if (this.ccLicenseUriField === undefined) { + // Set the value only if it has not manually set when declaring this component + this.ccLicenseUriField = remoteData.values && remoteData.values.length > 0 ? remoteData.values[0] : 'dc.rights.uri'; + } + }); + this.configService.findByPropertyName('cc.license.name').pipe( getFirstCompletedRemoteData(), getRemoteDataPayload(), ).subscribe((remoteData: ConfigurationProperty) => { - this.ccLicenseNameField = remoteData.values && remoteData.values.length > 0 ? remoteData.values[0] : 'dc.rights'; - }, - ); - } + if (this.ccLicenseNameField === undefined) { + // Set the value only if it has not manually set when declaring this component + this.ccLicenseNameField = remoteData.values && remoteData.values.length > 0 ? remoteData.values[0] : 'dc.rights'; + } + }); - ngOnInit() { this.uri = this.item.firstMetadataValue(this.ccLicenseUriField); this.name = this.item.firstMetadataValue(this.ccLicenseNameField); diff --git a/src/app/item-page/simple/item-types/untyped-item/untyped-item.component.spec.ts b/src/app/item-page/simple/item-types/untyped-item/untyped-item.component.spec.ts index a03b76e24eb..a7a491f61b1 100644 --- a/src/app/item-page/simple/item-types/untyped-item/untyped-item.component.spec.ts +++ b/src/app/item-page/simple/item-types/untyped-item/untyped-item.component.spec.ts @@ -21,6 +21,8 @@ import { Observable, of, } from 'rxjs'; +import { ConfigurationDataService } from 'src/app/core/data/configuration-data.service'; +import { ConfigurationDataServiceStub } from 'src/app/shared/testing/configuration-data.service.stub'; import { APP_CONFIG } from '../../../../../config/app-config.interface'; import { environment } from '../../../../../environments/environment.test'; @@ -88,6 +90,7 @@ function getItem(metadata: MetadataMap) { describe('UntypedItemComponent', () => { let comp: UntypedItemComponent; let fixture: ComponentFixture; + let configurationDataService = new ConfigurationDataServiceStub(); beforeEach(waitForAsync(() => { const mockBitstreamDataService = { @@ -130,6 +133,7 @@ describe('UntypedItemComponent', () => { { provide: ItemVersionsSharedService, useValue: {} }, { provide: RouteService, useValue: mockRouteService }, { provide: BrowseDefinitionDataService, useValue: BrowseDefinitionDataServiceStub }, + { provide: ConfigurationDataService, useValue: configurationDataService }, { provide: APP_CONFIG, useValue: environment }, ], schemas: [NO_ERRORS_SCHEMA],