mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 20:43:08 +00:00
81 lines
2.6 KiB
TypeScript
81 lines
2.6 KiB
TypeScript
import { CollectionGridElementComponent } from './collection-grid-element.component';
|
|
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
|
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
|
import { By } from '@angular/platform-browser';
|
|
import { Collection } from '../../../core/shared/collection.model';
|
|
import { LinkService } from '../../../core/cache/builders/link.service';
|
|
|
|
let collectionGridElementComponent: CollectionGridElementComponent;
|
|
let fixture: ComponentFixture<CollectionGridElementComponent>;
|
|
|
|
const mockCollectionWithAbstract: Collection = Object.assign(new Collection(), {
|
|
metadata: {
|
|
'dc.description.abstract': [
|
|
{
|
|
language: 'en_US',
|
|
value: 'Short description'
|
|
}
|
|
]
|
|
}
|
|
});
|
|
|
|
const mockCollectionWithoutAbstract: Collection = Object.assign(new Collection(), {
|
|
metadata: {
|
|
'dc.title': [
|
|
{
|
|
language: 'en_US',
|
|
value: 'Test title'
|
|
}
|
|
]
|
|
}
|
|
});
|
|
|
|
const linkService = jasmine.createSpyObj('linkService', {
|
|
resolveLink: mockCollectionWithAbstract
|
|
});
|
|
|
|
describe('CollectionGridElementComponent', () => {
|
|
beforeEach(waitForAsync(() => {
|
|
TestBed.configureTestingModule({
|
|
declarations: [CollectionGridElementComponent],
|
|
providers: [
|
|
{ provide: 'objectElementProvider', useValue: (mockCollectionWithAbstract) },
|
|
{ provide: LinkService, useValue: linkService }
|
|
],
|
|
|
|
schemas: [NO_ERRORS_SCHEMA]
|
|
}).overrideComponent(CollectionGridElementComponent, {
|
|
set: { changeDetection: ChangeDetectionStrategy.Default }
|
|
}).compileComponents();
|
|
}));
|
|
|
|
beforeEach(waitForAsync(() => {
|
|
fixture = TestBed.createComponent(CollectionGridElementComponent);
|
|
collectionGridElementComponent = fixture.componentInstance;
|
|
}));
|
|
|
|
describe('When the collection has an abstract', () => {
|
|
beforeEach(() => {
|
|
collectionGridElementComponent.object = mockCollectionWithAbstract;
|
|
fixture.detectChanges();
|
|
});
|
|
|
|
it('should show the description paragraph', () => {
|
|
const collectionAbstractField = fixture.debugElement.query(By.css('p.card-text'));
|
|
expect(collectionAbstractField).not.toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('When the collection has no abstract', () => {
|
|
beforeEach(() => {
|
|
collectionGridElementComponent.object = mockCollectionWithoutAbstract;
|
|
fixture.detectChanges();
|
|
});
|
|
|
|
it('should not show the description paragraph', () => {
|
|
const collectionAbstractField = fixture.debugElement.query(By.css('p.card-text'));
|
|
expect(collectionAbstractField).toBeNull();
|
|
});
|
|
});
|
|
});
|