mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
79597: Update ds-metadata-field-wrapper unit tests
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
import { MetadataFieldWrapperComponent } from './metadata-field-wrapper.component';
|
import { MetadataFieldWrapperComponent } from './metadata-field-wrapper.component';
|
||||||
@@ -6,35 +6,34 @@ import { MetadataFieldWrapperComponent } from './metadata-field-wrapper.componen
|
|||||||
/* tslint:disable:max-classes-per-file */
|
/* tslint:disable:max-classes-per-file */
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-component-without-content',
|
selector: 'ds-component-without-content',
|
||||||
template: '<ds-metadata-field-wrapper [label]="\'test label\'">\n' +
|
template: '<ds-metadata-field-wrapper [hideIfNoTextContent]="hideIfNoTextContent" [label]="\'test label\'">\n' +
|
||||||
'</ds-metadata-field-wrapper>'
|
'</ds-metadata-field-wrapper>'
|
||||||
})
|
})
|
||||||
class NoContentComponent {}
|
class NoContentComponent {
|
||||||
|
public hideIfNoTextContent = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-component-with-empty-spans',
|
selector: 'ds-component-with-empty-spans',
|
||||||
template: '<ds-metadata-field-wrapper [label]="\'test label\'">\n' +
|
template: '<ds-metadata-field-wrapper [hideIfNoTextContent]="hideIfNoTextContent" [label]="\'test label\'">\n' +
|
||||||
' <span></span>\n' +
|
' <span></span>\n' +
|
||||||
' <span></span>\n' +
|
' <span></span>\n' +
|
||||||
'</ds-metadata-field-wrapper>'
|
'</ds-metadata-field-wrapper>'
|
||||||
})
|
})
|
||||||
class SpanContentComponent {}
|
class SpanContentComponent {
|
||||||
|
@Input() hideIfNoTextContent = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-component-with-text',
|
selector: 'ds-component-with-text',
|
||||||
template: '<ds-metadata-field-wrapper [label]="\'test label\'">\n' +
|
template: '<ds-metadata-field-wrapper [hideIfNoTextContent]="hideIfNoTextContent" [label]="\'test label\'">\n' +
|
||||||
' <span>The quick brown fox jumps over the lazy dog</span>\n' +
|
' <span>The quick brown fox jumps over the lazy dog</span>\n' +
|
||||||
'</ds-metadata-field-wrapper>'
|
'</ds-metadata-field-wrapper>'
|
||||||
})
|
})
|
||||||
class TextContentComponent {}
|
class TextContentComponent {
|
||||||
|
@Input() hideIfNoTextContent = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'ds-component-with-image',
|
|
||||||
template: '<ds-metadata-field-wrapper [label]="\'test label\'">\n' +
|
|
||||||
' <img src="https://some/image.png" alt="an alt text">\n' +
|
|
||||||
'</ds-metadata-field-wrapper>'
|
|
||||||
})
|
|
||||||
class ImgContentComponent {}
|
|
||||||
/* tslint:enable:max-classes-per-file */
|
/* tslint:enable:max-classes-per-file */
|
||||||
|
|
||||||
describe('MetadataFieldWrapperComponent', () => {
|
describe('MetadataFieldWrapperComponent', () => {
|
||||||
@@ -43,7 +42,7 @@ describe('MetadataFieldWrapperComponent', () => {
|
|||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [MetadataFieldWrapperComponent, NoContentComponent, SpanContentComponent, TextContentComponent, ImgContentComponent]
|
declarations: [MetadataFieldWrapperComponent, NoContentComponent, SpanContentComponent, TextContentComponent]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -58,38 +57,60 @@ describe('MetadataFieldWrapperComponent', () => {
|
|||||||
expect(component).toBeDefined();
|
expect(component).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not show the component when there is no content', () => {
|
describe('with hideIfNoTextContent=true', () => {
|
||||||
const parentFixture = TestBed.createComponent(NoContentComponent);
|
it('should not show the component when there is no content', () => {
|
||||||
parentFixture.detectChanges();
|
const parentFixture = TestBed.createComponent(NoContentComponent);
|
||||||
const parentNative = parentFixture.nativeElement;
|
parentFixture.detectChanges();
|
||||||
const nativeWrapper = parentNative.querySelector(wrapperSelector);
|
const parentNative = parentFixture.nativeElement;
|
||||||
expect(nativeWrapper.classList.contains('d-none')).toBe(true);
|
const nativeWrapper = parentNative.querySelector(wrapperSelector);
|
||||||
|
expect(nativeWrapper.classList.contains('d-none')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not show the component when there is no text content', () => {
|
||||||
|
const parentFixture = TestBed.createComponent(SpanContentComponent);
|
||||||
|
parentFixture.detectChanges();
|
||||||
|
const parentNative = parentFixture.nativeElement;
|
||||||
|
const nativeWrapper = parentNative.querySelector(wrapperSelector);
|
||||||
|
expect(nativeWrapper.classList.contains('d-none')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show the component when there is text content', () => {
|
||||||
|
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 not show the component when there is DOM content but not text or an image', () => {
|
describe('with hideIfNoTextContent=false', () => {
|
||||||
const parentFixture = TestBed.createComponent(SpanContentComponent);
|
it('should show the component when there is no content', () => {
|
||||||
parentFixture.detectChanges();
|
const parentFixture = TestBed.createComponent(NoContentComponent);
|
||||||
const parentNative = parentFixture.nativeElement;
|
parentFixture.componentInstance.hideIfNoTextContent = false;
|
||||||
const nativeWrapper = parentNative.querySelector(wrapperSelector);
|
parentFixture.detectChanges();
|
||||||
expect(nativeWrapper.classList.contains('d-none')).toBe(true);
|
const parentNative = parentFixture.nativeElement;
|
||||||
});
|
const nativeWrapper = parentNative.querySelector(wrapperSelector);
|
||||||
|
expect(nativeWrapper.classList.contains('d-none')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it('should show the component when there is text content', () => {
|
it('should show the component when there is no text content', () => {
|
||||||
const parentFixture = TestBed.createComponent(TextContentComponent);
|
const parentFixture = TestBed.createComponent(SpanContentComponent);
|
||||||
parentFixture.detectChanges();
|
parentFixture.componentInstance.hideIfNoTextContent = false;
|
||||||
const parentNative = parentFixture.nativeElement;
|
parentFixture.detectChanges();
|
||||||
const nativeWrapper = parentNative.querySelector(wrapperSelector);
|
const parentNative = parentFixture.nativeElement;
|
||||||
parentFixture.detectChanges();
|
const nativeWrapper = parentNative.querySelector(wrapperSelector);
|
||||||
expect(nativeWrapper.classList.contains('d-none')).toBe(false);
|
expect(nativeWrapper.classList.contains('d-none')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show the component when there is img content', () => {
|
it('should show the component when there is text content', () => {
|
||||||
const parentFixture = TestBed.createComponent(ImgContentComponent);
|
const parentFixture = TestBed.createComponent(TextContentComponent);
|
||||||
parentFixture.detectChanges();
|
parentFixture.componentInstance.hideIfNoTextContent = false;
|
||||||
const parentNative = parentFixture.nativeElement;
|
parentFixture.detectChanges();
|
||||||
const nativeWrapper = parentNative.querySelector(wrapperSelector);
|
const parentNative = parentFixture.nativeElement;
|
||||||
parentFixture.detectChanges();
|
const nativeWrapper = parentNative.querySelector(wrapperSelector);
|
||||||
expect(nativeWrapper.classList.contains('d-none')).toBe(false);
|
parentFixture.detectChanges();
|
||||||
|
expect(nativeWrapper.classList.contains('d-none')).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user