Added specs.

This commit is contained in:
Michael Spalti
2022-09-09 13:44:25 -07:00
parent ccb4c0794c
commit 9218c0545f
10 changed files with 387 additions and 4 deletions

View File

@@ -25,6 +25,7 @@ import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.util
import { PaginationService } from '../../core/pagination/pagination.service';
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub';
import { environment } from '../../../environments/environment';
describe('BrowseByMetadataPageComponent', () => {
let comp: BrowseByMetadataPageComponent;
@@ -104,6 +105,7 @@ describe('BrowseByMetadataPageComponent', () => {
}));
beforeEach(() => {
environment.browseBy.showItemThumbnails = true;
fixture = TestBed.createComponent(BrowseByMetadataPageComponent);
comp = fixture.componentInstance;
fixture.detectChanges();
@@ -118,6 +120,10 @@ describe('BrowseByMetadataPageComponent', () => {
expect(comp.items$).toBeUndefined();
});
it('should set embed thumbnail property to true', () => {
expect(comp.embedThumbnail).toBeTrue();
});
describe('when a value is provided', () => {
beforeEach(() => {
const paramsWithValue = {
@@ -152,7 +158,7 @@ describe('BrowseByMetadataPageComponent', () => {
field: 'fake-field',
};
result = browseParamsToOptions(paramsScope, paginationOptions, sortOptions, 'author');
result = browseParamsToOptions(paramsScope, paginationOptions, sortOptions, 'author', comp.embedThumbnail);
});
it('should return BrowseEntrySearchOptions with the correct properties', () => {
@@ -163,6 +169,7 @@ describe('BrowseByMetadataPageComponent', () => {
expect(result.sort.direction).toEqual(SortDirection.ASC);
expect(result.sort.field).toEqual('fake-field');
expect(result.scope).toEqual('fake-scope');
expect(result.embedThumbnail).toBeTrue();
});
});
});

View File

@@ -9,6 +9,7 @@ import { TruncatePipe } from '../../../../../shared/utils/truncate.pipe';
import { TruncatableService } from '../../../../../shared/truncatable/truncatable.service';
import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service';
import { DSONameServiceMock } from '../../../../../shared/mocks/dso-name.service.mock';
import { environment } from '../../../../../../environments/environment';
let journalIssueListElementComponent: JournalIssueSearchResultListElementComponent;
let fixture: ComponentFixture<JournalIssueSearchResultListElementComponent>;
@@ -73,11 +74,28 @@ describe('JournalIssueSearchResultListElementComponent', () => {
}));
beforeEach(waitForAsync(() => {
environment.browseBy.showItemThumbnails = true;
fixture = TestBed.createComponent(JournalIssueSearchResultListElementComponent);
journalIssueListElementComponent = fixture.componentInstance;
}));
describe('with environment.browseBy.showItemThumbnails set to true', () => {
beforeEach(() => {
journalIssueListElementComponent.object = mockItemWithMetadata;
fixture.detectChanges();
});
it('should set showThumbnails to true', () => {
expect(journalIssueListElementComponent.showThumbnails).toBeTrue();
});
it('should add thumbnail element', () => {
const thumbnailElement = fixture.debugElement.query(By.css('ds-thumbnail'));
expect(thumbnailElement).toBeTruthy();
});
});
describe('When the item has a journal identifier', () => {
beforeEach(() => {
journalIssueListElementComponent.object = mockItemWithMetadata;
@@ -126,3 +144,39 @@ describe('JournalIssueSearchResultListElementComponent', () => {
});
});
});
describe('JournalIssueSearchResultListElementComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [JournalIssueSearchResultListElementComponent, TruncatePipe],
providers: [
{provide: TruncatableService, useValue: {}},
{provide: DSONameService, useClass: DSONameServiceMock}
],
schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(JournalIssueSearchResultListElementComponent, {
set: {changeDetection: ChangeDetectionStrategy.Default}
}).compileComponents();
}));
beforeEach(waitForAsync(() => {
environment.browseBy.showItemThumbnails = false;
fixture = TestBed.createComponent(JournalIssueSearchResultListElementComponent);
journalIssueListElementComponent = fixture.componentInstance;
}));
describe('with environment.browseBy.showItemThumbnails set to false', () => {
beforeEach(() => {
journalIssueListElementComponent.object = mockItemWithMetadata;
fixture.detectChanges();
});
it('should not add thumbnail element', () => {
const thumbnailElement = fixture.debugElement.query(By.css('ds-thumbnail'));
expect(thumbnailElement).toBeFalsy();
});
});
});

View File

@@ -9,6 +9,7 @@ import { TruncatePipe } from '../../../../../shared/utils/truncate.pipe';
import { TruncatableService } from '../../../../../shared/truncatable/truncatable.service';
import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service';
import { DSONameServiceMock } from '../../../../../shared/mocks/dso-name.service.mock';
import { environment } from '../../../../../../environments/environment';
let journalVolumeListElementComponent: JournalVolumeSearchResultListElementComponent;
let fixture: ComponentFixture<JournalVolumeSearchResultListElementComponent>;
@@ -72,11 +73,27 @@ describe('JournalVolumeSearchResultListElementComponent', () => {
}));
beforeEach(waitForAsync(() => {
environment.browseBy.showItemThumbnails = true;
fixture = TestBed.createComponent(JournalVolumeSearchResultListElementComponent);
journalVolumeListElementComponent = fixture.componentInstance;
}));
describe('with environment.browseBy.showItemThumbnails set to true', () => {
beforeEach(() => {
journalVolumeListElementComponent.object = mockItemWithMetadata;
fixture.detectChanges();
});
it('should set showThumbnails to true', () => {
expect(journalVolumeListElementComponent.showThumbnails).toBeTrue();
});
it('should add thumbnail element', () => {
const thumbnailElement = fixture.debugElement.query(By.css('ds-thumbnail'));
expect(thumbnailElement).toBeTruthy();
});
});
describe('When the item has a journal title', () => {
beforeEach(() => {
journalVolumeListElementComponent.object = mockItemWithMetadata;
@@ -125,3 +142,38 @@ describe('JournalVolumeSearchResultListElementComponent', () => {
});
});
});
describe('JournalVolumeSearchResultListElementComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [JournalVolumeSearchResultListElementComponent, TruncatePipe],
providers: [
{provide: TruncatableService, useValue: {}},
{provide: DSONameService, useClass: DSONameServiceMock}
],
schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(JournalVolumeSearchResultListElementComponent, {
set: {changeDetection: ChangeDetectionStrategy.Default}
}).compileComponents();
}));
beforeEach(waitForAsync(() => {
environment.browseBy.showItemThumbnails = false;
fixture = TestBed.createComponent(JournalVolumeSearchResultListElementComponent);
journalVolumeListElementComponent = fixture.componentInstance;
}));
describe('with environment.browseBy.showItemThumbnails set to false', () => {
beforeEach(() => {
journalVolumeListElementComponent.object = mockItemWithMetadata;
fixture.detectChanges();
});
it('should not add thumbnail element', () => {
const thumbnailElement = fixture.debugElement.query(By.css('ds-thumbnail'));
expect(thumbnailElement).toBeFalsy();
});
});
});

View File

@@ -9,6 +9,7 @@ import { TruncatableService } from '../../../../../shared/truncatable/truncatabl
import { ItemSearchResult } from '../../../../../shared/object-collection/shared/item-search-result.model';
import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service';
import { DSONameServiceMock } from '../../../../../shared/mocks/dso-name.service.mock';
import { environment } from '../../../../../../environments/environment';
let journalListElementComponent: JournalSearchResultListElementComponent;
let fixture: ComponentFixture<JournalSearchResultListElementComponent>;
@@ -68,11 +69,27 @@ describe('JournalSearchResultListElementComponent', () => {
}));
beforeEach(waitForAsync(() => {
environment.browseBy.showItemThumbnails = true;
fixture = TestBed.createComponent(JournalSearchResultListElementComponent);
journalListElementComponent = fixture.componentInstance;
}));
describe('with environment.browseBy.showItemThumbnails set to true', () => {
beforeEach(() => {
journalListElementComponent.object = mockItemWithMetadata;
fixture.detectChanges();
});
it('should set showThumbnails to true', () => {
expect(journalListElementComponent.showThumbnails).toBeTrue();
});
it('should add thumbnail element', () => {
const thumbnailElement = fixture.debugElement.query(By.css('ds-thumbnail'));
expect(thumbnailElement).toBeTruthy();
});
});
describe('When the item has an issn', () => {
beforeEach(() => {
journalListElementComponent.object = mockItemWithMetadata;
@@ -97,3 +114,39 @@ describe('JournalSearchResultListElementComponent', () => {
});
});
});
describe('JournalSearchResultListElementComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [JournalSearchResultListElementComponent, TruncatePipe],
providers: [
{provide: TruncatableService, useValue: {}},
{provide: DSONameService, useClass: DSONameServiceMock}
],
schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(JournalSearchResultListElementComponent, {
set: {changeDetection: ChangeDetectionStrategy.Default}
}).compileComponents();
}));
beforeEach(waitForAsync(() => {
environment.browseBy.showItemThumbnails = false;
fixture = TestBed.createComponent(JournalSearchResultListElementComponent);
journalListElementComponent = fixture.componentInstance;
}));
describe('with environment.browseBy.showItemThumbnails set to false', () => {
beforeEach(() => {
journalListElementComponent.object = mockItemWithMetadata;
fixture.detectChanges();
});
it('should not add thumbnail element', () => {
const thumbnailElement = fixture.debugElement.query(By.css('ds-thumbnail'));
expect(thumbnailElement).toBeFalsy();
});
});
});

View File

@@ -9,6 +9,7 @@ import { TruncatableService } from '../../../../../shared/truncatable/truncatabl
import { ItemSearchResult } from '../../../../../shared/object-collection/shared/item-search-result.model';
import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service';
import { DSONameServiceMock } from '../../../../../shared/mocks/dso-name.service.mock';
import { environment } from '../../../../../../environments/environment';
let orgUnitListElementComponent: OrgUnitSearchResultListElementComponent;
let fixture: ComponentFixture<OrgUnitSearchResultListElementComponent>;
@@ -66,11 +67,27 @@ describe('OrgUnitSearchResultListElementComponent', () => {
}));
beforeEach(waitForAsync(() => {
environment.browseBy.showItemThumbnails = true;
fixture = TestBed.createComponent(OrgUnitSearchResultListElementComponent);
orgUnitListElementComponent = fixture.componentInstance;
}));
describe('with environment.browseBy.showItemThumbnails set to true', () => {
beforeEach(() => {
orgUnitListElementComponent.object = mockItemWithMetadata;
fixture.detectChanges();
});
it('should set showThumbnails to true', () => {
expect(orgUnitListElementComponent.showThumbnails).toBeTrue();
});
it('should add thumbnail element', () => {
const thumbnailElement = fixture.debugElement.query(By.css('ds-thumbnail'));
expect(thumbnailElement).toBeTruthy();
});
});
describe('When the item has an org unit description', () => {
beforeEach(() => {
orgUnitListElementComponent.object = mockItemWithMetadata;
@@ -95,3 +112,39 @@ describe('OrgUnitSearchResultListElementComponent', () => {
});
});
});
describe('OrgUnitSearchResultListElementComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [OrgUnitSearchResultListElementComponent, TruncatePipe],
providers: [
{provide: TruncatableService, useValue: {}},
{provide: DSONameService, useClass: DSONameServiceMock}
],
schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(OrgUnitSearchResultListElementComponent, {
set: {changeDetection: ChangeDetectionStrategy.Default}
}).compileComponents();
}));
beforeEach(waitForAsync(() => {
environment.browseBy.showItemThumbnails = false;
fixture = TestBed.createComponent(OrgUnitSearchResultListElementComponent);
orgUnitListElementComponent = fixture.componentInstance;
}));
describe('with environment.browseBy.showItemThumbnails set to false', () => {
beforeEach(() => {
orgUnitListElementComponent.object = mockItemWithMetadata;
fixture.detectChanges();
});
it('should not add thumbnail element', () => {
const thumbnailElement = fixture.debugElement.query(By.css('ds-thumbnail'));
expect(thumbnailElement).toBeFalsy();
});
});
});

View File

@@ -9,6 +9,7 @@ import { TruncatePipe } from '../../../../../shared/utils/truncate.pipe';
import { TruncatableService } from '../../../../../shared/truncatable/truncatable.service';
import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service';
import { DSONameServiceMock } from '../../../../../shared/mocks/dso-name.service.mock';
import { environment } from '../../../../../../environments/environment';
let personListElementComponent: PersonSearchResultListElementComponent;
let fixture: ComponentFixture<PersonSearchResultListElementComponent>;
@@ -66,11 +67,27 @@ describe('PersonSearchResultListElementComponent', () => {
}));
beforeEach(waitForAsync(() => {
environment.browseBy.showItemThumbnails = true;
fixture = TestBed.createComponent(PersonSearchResultListElementComponent);
personListElementComponent = fixture.componentInstance;
}));
describe('with environment.browseBy.showItemThumbnails set to true', () => {
beforeEach(() => {
personListElementComponent.object = mockItemWithMetadata;
fixture.detectChanges();
});
it('should set showThumbnails to true', () => {
expect(personListElementComponent.showThumbnails).toBeTrue();
});
it('should add thumbnail element', () => {
const thumbnailElement = fixture.debugElement.query(By.css('ds-thumbnail'));
expect(thumbnailElement).toBeTruthy();
});
});
describe('When the item has a job title', () => {
beforeEach(() => {
personListElementComponent.object = mockItemWithMetadata;
@@ -95,3 +112,39 @@ describe('PersonSearchResultListElementComponent', () => {
});
});
});
describe('PersonSearchResultListElementComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [PersonSearchResultListElementComponent, TruncatePipe],
providers: [
{provide: TruncatableService, useValue: {}},
{provide: DSONameService, useClass: DSONameServiceMock}
],
schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(PersonSearchResultListElementComponent, {
set: {changeDetection: ChangeDetectionStrategy.Default}
}).compileComponents();
}));
beforeEach(waitForAsync(() => {
environment.browseBy.showItemThumbnails = false;
fixture = TestBed.createComponent(PersonSearchResultListElementComponent);
personListElementComponent = fixture.componentInstance;
}));
describe('with environment.browseBy.showItemThumbnails set to false', () => {
beforeEach(() => {
personListElementComponent.object = mockItemWithMetadata;
fixture.detectChanges();
});
it('should not add thumbnail element', () => {
const thumbnailElement = fixture.debugElement.query(By.css('ds-thumbnail'));
expect(thumbnailElement).toBeFalsy();
});
});
});

View File

@@ -8,6 +8,8 @@ import { TruncatePipe } from '../../../../../shared/utils/truncate.pipe';
import { TruncatableService } from '../../../../../shared/truncatable/truncatable.service';
import { DSONameService } from '../../../../../core/breadcrumbs/dso-name.service';
import { DSONameServiceMock } from '../../../../../shared/mocks/dso-name.service.mock';
import { environment } from '../../../../../../environments/environment';
import { By } from '@angular/platform-browser';
let projectListElementComponent: ProjectSearchResultListElementComponent;
let fixture: ComponentFixture<ProjectSearchResultListElementComponent>;
@@ -66,11 +68,27 @@ describe('ProjectSearchResultListElementComponent', () => {
}));
beforeEach(waitForAsync(() => {
environment.browseBy.showItemThumbnails = true;
fixture = TestBed.createComponent(ProjectSearchResultListElementComponent);
projectListElementComponent = fixture.componentInstance;
}));
describe('with environment.browseBy.showItemThumbnails set to true', () => {
beforeEach(() => {
projectListElementComponent.object = mockItemWithMetadata;
fixture.detectChanges();
});
it('should set showThumbnails to true', () => {
expect(projectListElementComponent.showThumbnails).toBeTrue();
});
it('should add thumbnail element', () => {
const thumbnailElement = fixture.debugElement.query(By.css('ds-thumbnail'));
expect(thumbnailElement).toBeTruthy();
});
});
// describe('When the item has a status', () => {
// beforeEach(() => {
// projectListElementComponent.item = mockItemWithMetadata;
@@ -95,3 +113,39 @@ describe('ProjectSearchResultListElementComponent', () => {
// });
// });
});
describe('ProjectSearchResultListElementComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [ProjectSearchResultListElementComponent, TruncatePipe],
providers: [
{provide: TruncatableService, useValue: {}},
{provide: DSONameService, useClass: DSONameServiceMock}
],
schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(ProjectSearchResultListElementComponent, {
set: {changeDetection: ChangeDetectionStrategy.Default}
}).compileComponents();
}));
beforeEach(waitForAsync(() => {
environment.browseBy.showItemThumbnails = false;
fixture = TestBed.createComponent(ProjectSearchResultListElementComponent);
projectListElementComponent = fixture.componentInstance;
}));
describe('with environment.browseBy.showItemThumbnails set to false', () => {
beforeEach(() => {
projectListElementComponent.object = mockItemWithMetadata;
fixture.detectChanges();
});
it('should not add thumbnail element', () => {
const thumbnailElement = fixture.debugElement.query(By.css('ds-thumbnail'));
expect(thumbnailElement).toBeFalsy();
});
});
});

View File

@@ -48,5 +48,9 @@ describe('ObjectCollectionComponent', () => {
expect(fixture.debugElement.query(By.css('ds-object-list'))).toBeDefined();
expect(fixture.debugElement.query(By.css('ds-object-grid'))).toBeNull();
});
it('should set fallback placeholder font size during test', () => {
objectCollectionComponent.currentMode$ = observableOf(ViewMode.ListElement);
expect(fixture.debugElement.query(By.css('thumb-font-3'))).toBeDefined();
});
});

View File

@@ -243,11 +243,11 @@ export class ObjectCollectionComponent implements OnInit {
setPlaceHolderFontSize() {
const width = this.elementRef.nativeElement.offsetWidth;
if (width < 750) {
this.placeholderFontClass = "thumb-font-1";
this.placeholderFontClass = 'thumb-font-1';
} else if (width < 1000) {
this.placeholderFontClass = "thumb-font-2";
this.placeholderFontClass = 'thumb-font-2';
} else {
this.placeholderFontClass = "thumb-font-3";
this.placeholderFontClass = 'thumb-font-3';
}
}

View File

@@ -9,6 +9,7 @@ import { TruncatableService } from '../../../../../truncatable/truncatable.servi
import { ItemSearchResult } from '../../../../../object-collection/shared/item-search-result.model';
import { DSONameService } from '../../../../../../core/breadcrumbs/dso-name.service';
import { DSONameServiceMock, UNDEFINED_NAME } from '../../../../../mocks/dso-name.service.mock';
import { environment } from '../../../../../../../environments/environment';
let publicationListElementComponent: ItemSearchResultListElementComponent;
let fixture: ComponentFixture<ItemSearchResultListElementComponent>;
@@ -76,11 +77,27 @@ describe('ItemListElementComponent', () => {
}));
beforeEach(waitForAsync(() => {
environment.browseBy.showItemThumbnails = true;
fixture = TestBed.createComponent(ItemSearchResultListElementComponent);
publicationListElementComponent = fixture.componentInstance;
}));
describe('with environment.browseBy.showItemThumbnails set to true', () => {
beforeEach(() => {
publicationListElementComponent.object = mockItemWithMetadata;
fixture.detectChanges();
});
it('should set showThumbnails to true', () => {
expect(publicationListElementComponent.showThumbnails).toBeTrue();
});
it('should add thumbnail element', () => {
const thumbnailElement = fixture.debugElement.query(By.css('ds-thumbnail'));
expect(thumbnailElement).toBeTruthy();
});
});
describe('When the item has an author', () => {
beforeEach(() => {
publicationListElementComponent.object = mockItemWithMetadata;
@@ -189,3 +206,39 @@ describe('ItemListElementComponent', () => {
});
});
});
describe('ItemListElementComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [ItemSearchResultListElementComponent, TruncatePipe],
providers: [
{provide: TruncatableService, useValue: {}},
{provide: DSONameService, useClass: DSONameServiceMock}
],
schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(ItemSearchResultListElementComponent, {
set: {changeDetection: ChangeDetectionStrategy.Default}
}).compileComponents();
}));
beforeEach(waitForAsync(() => {
environment.browseBy.showItemThumbnails = false;
fixture = TestBed.createComponent(ItemSearchResultListElementComponent);
publicationListElementComponent = fixture.componentInstance;
}));
describe('with environment.browseBy.showItemThumbnails set to false', () => {
beforeEach(() => {
publicationListElementComponent.object = mockItemWithMetadata;
fixture.detectChanges();
});
it('should not add thumbnail element', () => {
const thumbnailElement = fixture.debugElement.query(By.css('ds-thumbnail'));
expect(thumbnailElement).toBeFalsy();
});
});
});