diff --git a/src/app/+item-page/field-components/metadata-field-wrapper/metadata-field-wrapper.component.spec.ts b/src/app/+item-page/field-components/metadata-field-wrapper/metadata-field-wrapper.component.spec.ts
index cce54edf64..d7e1b80c76 100644
--- a/src/app/+item-page/field-components/metadata-field-wrapper/metadata-field-wrapper.component.spec.ts
+++ b/src/app/+item-page/field-components/metadata-field-wrapper/metadata-field-wrapper.component.spec.ts
@@ -1,18 +1,41 @@
-import { ComponentFixture, TestBed, async } from '@angular/core/testing';
-import { By } from '@angular/platform-browser';
-import { Component, DebugElement } from '@angular/core';
+import { Component } from '@angular/core';
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MetadataFieldWrapperComponent } from './metadata-field-wrapper.component';
+/* tslint:disable:max-classes-per-file */
@Component({
- selector: 'ds-component-with-content',
+ selector: 'ds-component-without-content',
template: '
\n' +
- ' \n' +
- ' \n' +
- '
\n' +
''
})
-class ContentComponent {}
+class NoContentComponent {}
+
+@Component({
+ selector: 'ds-component-with-empty-spans',
+ template: '
\n' +
+ ' \n' +
+ ' \n' +
+ ''
+})
+class SpanContentComponent {}
+
+@Component({
+ selector: 'ds-component-with-text',
+ template: '
\n' +
+ ' The quick brown fox jumps over the lazy dog\n' +
+ ''
+})
+class TextContentComponent {}
+
+@Component({
+ selector: 'ds-component-with-image',
+ template: '
\n' +
+ '
\n' +
+ ''
+})
+class ImgContentComponent {}
+/* tslint:enable:max-classes-per-file */
describe('MetadataFieldWrapperComponent', () => {
let component: MetadataFieldWrapperComponent;
@@ -20,7 +43,7 @@ describe('MetadataFieldWrapperComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
- declarations: [MetadataFieldWrapperComponent, ContentComponent]
+ declarations: [MetadataFieldWrapperComponent, NoContentComponent, SpanContentComponent, TextContentComponent, ImgContentComponent]
}).compileComponents();
}));
@@ -30,23 +53,21 @@ describe('MetadataFieldWrapperComponent', () => {
});
const wrapperSelector = '.simple-view-element';
- const labelSelector = '.simple-view-element-header';
- const contentSelector = '.my-content';
it('should create', () => {
expect(component).toBeDefined();
});
it('should not show the component when there is no content', () => {
- component.label = 'test label';
- fixture.detectChanges();
- const parentNative = fixture.nativeElement;
+ const parentFixture = TestBed.createComponent(NoContentComponent);
+ parentFixture.detectChanges();
+ const parentNative = parentFixture.nativeElement;
const nativeWrapper = parentNative.querySelector(wrapperSelector);
expect(nativeWrapper.classList.contains('d-none')).toBe(true);
});
- it('should not show the component when there is DOM content but no text', () => {
- const parentFixture = TestBed.createComponent(ContentComponent);
+ it('should not show the component when there is DOM content but not text or an image', () => {
+ const parentFixture = TestBed.createComponent(SpanContentComponent);
parentFixture.detectChanges();
const parentNative = parentFixture.nativeElement;
const nativeWrapper = parentNative.querySelector(wrapperSelector);
@@ -54,11 +75,18 @@ describe('MetadataFieldWrapperComponent', () => {
});
it('should show the component when there is text content', () => {
- const parentFixture = TestBed.createComponent(ContentComponent);
+ const parentFixture = TestBed.createComponent(TextContentComponent);
+ parentFixture.detectChanges();
+ const parentNative = parentFixture.nativeElement;
+ const nativeWrapper = parentNative.querySelector(wrapperSelector);
+ parentFixture.detectChanges();
+ expect(nativeWrapper.classList.contains('d-none')).toBe(false);
+ });
+
+ it('should show the component when there is img content', () => {
+ const parentFixture = TestBed.createComponent(ImgContentComponent);
parentFixture.detectChanges();
const parentNative = parentFixture.nativeElement;
- const nativeContent = parentNative.querySelector(contentSelector);
- nativeContent.textContent = 'lorem ipsum';
const nativeWrapper = parentNative.querySelector(wrapperSelector);
parentFixture.detectChanges();
expect(nativeWrapper.classList.contains('d-none')).toBe(false);
diff --git a/src/app/+item-page/field-components/metadata-field-wrapper/metadata-field-wrapper.component.ts b/src/app/+item-page/field-components/metadata-field-wrapper/metadata-field-wrapper.component.ts
index f528f06ba5..8af108cceb 100644
--- a/src/app/+item-page/field-components/metadata-field-wrapper/metadata-field-wrapper.component.ts
+++ b/src/app/+item-page/field-components/metadata-field-wrapper/metadata-field-wrapper.component.ts
@@ -1,4 +1,5 @@
import { Component, Input } from '@angular/core';
+import { hasNoValue } from '../../../shared/empty.util';
/**
* This component renders any content inside this wrapper.
@@ -16,4 +17,10 @@ export class MetadataFieldWrapperComponent {
*/
@Input() label: string;
+ /**
+ * Make hasNoValue() available in the template
+ */
+ hasNoValue(o: any): boolean {
+ return hasNoValue(o);
+ }
}