-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2719 from 4Science/main_CST-12825
ROR Integration - Identifier Visualization
- Loading branch information
Showing
12 changed files
with
272 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...tem-page/simple/field-components/specific-field/img/item-page-img-field.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ItemPageImgFieldComponent } from './item-page-img-field.component'; | ||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; | ||
import { TranslateLoaderMock } from '../../../../../shared/testing/translate-loader.mock'; | ||
import { APP_CONFIG } from '../../../../../../config/app-config.interface'; | ||
import { environment } from '../../../../../../environments/environment'; | ||
import { BrowseDefinitionDataService } from '../../../../../core/browse/browse-definition-data.service'; | ||
import { BrowseDefinitionDataServiceStub } from '../../../../../shared/testing/browse-definition-data-service.stub'; | ||
import { GenericItemPageFieldComponent } from '../generic/generic-item-page-field.component'; | ||
import { MetadataValuesComponent } from '../../../../field-components/metadata-values/metadata-values.component'; | ||
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; | ||
import { mockItemWithMetadataFieldsAndValue } from '../item-page-field.component.spec'; | ||
import { By } from '@angular/platform-browser'; | ||
import { ImageField } from '../item-page-field.component'; | ||
|
||
let component: ItemPageImgFieldComponent; | ||
let fixture: ComponentFixture<ItemPageImgFieldComponent>; | ||
|
||
const mockField = 'organization.identifier.ror'; | ||
const mockValue = 'http://ror.org/awesome-identifier'; | ||
const mockLabel = 'ROR label'; | ||
const mockUrlRegex = '(.*)ror.org'; | ||
const mockImg = { | ||
URI: './assets/images/ror-icon.svg', | ||
alt: 'item.page.image.alt.ROR', | ||
heightVar: '--ds-item-page-img-field-ror-inline-height' | ||
} as ImageField; | ||
|
||
describe('ItemPageImgFieldComponent', () => { | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [TranslateModule.forRoot({ | ||
loader: { | ||
provide: TranslateLoader, | ||
useClass: TranslateLoaderMock | ||
} | ||
})], | ||
providers: [ | ||
{ provide: APP_CONFIG, useValue: environment }, | ||
{ provide: BrowseDefinitionDataService, useValue: BrowseDefinitionDataServiceStub } | ||
], | ||
declarations: [ItemPageImgFieldComponent, GenericItemPageFieldComponent, MetadataValuesComponent], | ||
schemas: [NO_ERRORS_SCHEMA] | ||
}) | ||
.overrideComponent(GenericItemPageFieldComponent, { | ||
set: { changeDetection: ChangeDetectionStrategy.Default } | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ItemPageImgFieldComponent); | ||
component = fixture.componentInstance; | ||
component.item = mockItemWithMetadataFieldsAndValue([mockField], mockValue); | ||
component.fields = [mockField]; | ||
component.label = mockLabel; | ||
component.urlRegex = mockUrlRegex; | ||
component.img = mockImg; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should display display img tag', () => { | ||
const image = fixture.debugElement.query(By.css('img.link-logo')); | ||
expect(image).not.toBeNull(); | ||
}); | ||
|
||
it('should have right attributes', () => { | ||
const image = fixture.debugElement.query(By.css('img.link-logo')); | ||
expect(image.attributes.src).toEqual(mockImg.URI); | ||
expect(image.attributes.alt).toEqual(mockImg.alt); | ||
|
||
const imageEl = image.nativeElement; | ||
expect(imageEl.style.height).toContain(mockImg.heightVar); | ||
}); | ||
|
||
it('should have the right value', () => { | ||
const imageAnchor = fixture.debugElement.query(By.css('a.link-anchor')); | ||
const anchorEl = imageAnchor.nativeElement; | ||
expect(anchorEl.innerHTML).toContain(mockValue); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
...app/item-page/simple/field-components/specific-field/img/item-page-img-field.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { ImageField, ItemPageFieldComponent } from '../item-page-field.component'; | ||
import { Item } from '../../../../../core/shared/item.model'; | ||
|
||
@Component({ | ||
selector: 'ds-item-page-img-field', | ||
templateUrl: '../item-page-field.component.html' | ||
}) | ||
/** | ||
* Component that renders an inline image for a given field. | ||
* This component uses a given {@code ImageField} configuration to correctly render the img. | ||
*/ | ||
export class ItemPageImgFieldComponent extends ItemPageFieldComponent { | ||
|
||
/** | ||
* The item to display metadata for | ||
*/ | ||
@Input() item: Item; | ||
|
||
/** | ||
* Separator string between multiple values of the metadata fields defined | ||
* @type {string} | ||
*/ | ||
@Input() separator: string; | ||
|
||
/** | ||
* Fields (schema.element.qualifier) used to render their values. | ||
*/ | ||
@Input() fields: string[]; | ||
|
||
/** | ||
* Label i18n key for the rendered metadata | ||
*/ | ||
@Input() label: string; | ||
|
||
/** | ||
* Image Configuration | ||
*/ | ||
@Input() img: ImageField; | ||
|
||
/** | ||
* Whether any valid HTTP(S) URL should be rendered as a link | ||
*/ | ||
@Input() urlRegex?: string; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.