Skip to content

Commit

Permalink
Fex minor changes
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
abelgomez committed Oct 10, 2024
1 parent dec0276 commit def3032
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -202,6 +204,7 @@ function configureFixture(

describe('ItemPageCcLicenseFieldComponent', () => {
let fixture: ComponentFixture<ItemPageCcLicenseFieldComponent>;
let configurationDataService = new ConfigurationDataServiceStub();

beforeEach(waitForAsync(() => {
void TestBed.configureTestingModule({
Expand All @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -88,6 +90,7 @@ function getItem(metadata: MetadataMap) {
describe('UntypedItemComponent', () => {
let comp: UntypedItemComponent;
let fixture: ComponentFixture<UntypedItemComponent>;
let configurationDataService = new ConfigurationDataServiceStub();

beforeEach(waitForAsync(() => {
const mockBitstreamDataService = {
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit def3032

Please sign in to comment.