From 26b075882d79af08c07da186f4ebb05b8a16b39f Mon Sep 17 00:00:00 2001 From: Kristof De Langhe Date: Fri, 19 Oct 2018 16:16:12 +0200 Subject: [PATCH] 56434: Fixed existing tests and added entity-list-element component tests --- .../search-page.component.spec.ts | 13 +- .../search-configuration.service.spec.ts | 3 +- .../search-configuration.service.ts | 7 +- .../entity-list-element.component.spec.ts | 108 ----------- .../journal-issue-list-element.component.html | 3 +- ...urnal-issue-list-element.component.spec.ts | 111 ++++++++++++ ...journal-volume-list-element.component.html | 3 +- ...rnal-volume-list-element.component.spec.ts | 111 ++++++++++++ .../journal-list-element.component.spec.ts | 82 +++++++++ .../orgunit-list-element.component.html | 2 +- .../orgunit-list-element.component.spec.ts | 82 +++++++++ .../person/person-list-element.component.html | 2 +- .../person-list-element.component.spec.ts | 82 +++++++++ .../project-list-element.component.html | 2 +- .../project-list-element.component.spec.ts | 82 +++++++++ ...publication-list-element.component.spec.ts | 169 ++++++++++++++++++ ...arch-result-list-element.component.spec.ts | 120 ------------- 17 files changed, 744 insertions(+), 238 deletions(-) delete mode 100644 src/app/shared/object-list/item-list-element/entity-list-element.component.spec.ts create mode 100644 src/app/shared/object-list/item-list-element/entity-types/journal-issue/journal-issue-list-element.component.spec.ts create mode 100644 src/app/shared/object-list/item-list-element/entity-types/journal-volume/journal-volume-list-element.component.spec.ts create mode 100644 src/app/shared/object-list/item-list-element/entity-types/journal/journal-list-element.component.spec.ts create mode 100644 src/app/shared/object-list/item-list-element/entity-types/orgunit/orgunit-list-element.component.spec.ts create mode 100644 src/app/shared/object-list/item-list-element/entity-types/person/person-list-element.component.spec.ts create mode 100644 src/app/shared/object-list/item-list-element/entity-types/project/project-list-element.component.spec.ts create mode 100644 src/app/shared/object-list/item-list-element/entity-types/publication/publication-list-element.component.spec.ts delete mode 100644 src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.spec.ts diff --git a/src/app/+search-page/search-page.component.spec.ts b/src/app/+search-page/search-page.component.spec.ts index 3ca18ce4c5..85283e7255 100644 --- a/src/app/+search-page/search-page.component.spec.ts +++ b/src/app/+search-page/search-page.component.spec.ts @@ -21,6 +21,7 @@ import { SearchSidebarService } from './search-sidebar/search-sidebar.service'; import { SearchFilterService } from './search-filters/search-filter/search-filter.service'; import { SearchConfigurationService } from './search-service/search-configuration.service'; import { RemoteData } from '../core/data/remote-data'; +import { RouteService } from '../shared/services/route.service'; describe('SearchPageComponent', () => { let comp: SearchPageComponent; @@ -62,6 +63,11 @@ describe('SearchPageComponent', () => { collapse: () => this.isCollapsed = Observable.of(true), expand: () => this.isCollapsed = Observable.of(false) }; + const routeServiceStub = { + getRouteParameterValue: () => { + return Observable.of(''); + } + }; beforeEach(async(() => { TestBed.configureTestingModule({ @@ -92,7 +98,8 @@ describe('SearchPageComponent', () => { { provide: SearchFilterService, useValue: {} - }, { + }, + { provide: SearchConfigurationService, useValue: { paginatedSearchOptions: hot('a', { @@ -101,6 +108,10 @@ describe('SearchPageComponent', () => { getCurrentScope: (a) => Observable.of('test-id') } }, + { + provide: RouteService, + useValue: routeServiceStub + } ], schemas: [NO_ERRORS_SCHEMA] }).overrideComponent(SearchPageComponent, { diff --git a/src/app/+search-page/search-service/search-configuration.service.spec.ts b/src/app/+search-page/search-service/search-configuration.service.spec.ts index 33d3dbef3b..6588da858f 100644 --- a/src/app/+search-page/search-service/search-configuration.service.spec.ts +++ b/src/app/+search-page/search-service/search-configuration.service.spec.ts @@ -25,7 +25,8 @@ describe('SearchConfigurationService', () => { const routeService = jasmine.createSpyObj('RouteService', { getQueryParameterValue: Observable.of(value1), - getQueryParamsWithPrefix: Observable.of(prefixFilter) + getQueryParamsWithPrefix: Observable.of(prefixFilter), + getRouteParameterValue: Observable.of('') }); const fixedFilterService = jasmine.createSpyObj('SearchFixedFilterService', { diff --git a/src/app/+search-page/search-service/search-configuration.service.ts b/src/app/+search-page/search-service/search-configuration.service.ts index a3ebf6b860..b2fb91417e 100644 --- a/src/app/+search-page/search-service/search-configuration.service.ts +++ b/src/app/+search-page/search-service/search-configuration.service.ts @@ -14,7 +14,7 @@ import { getSucceededRemoteData } from '../../core/shared/operators'; import { SearchFilter } from '../search-filter.model'; import { DSpaceObjectType } from '../../core/shared/dspace-object-type.model'; import { SearchFixedFilterService } from '../search-filters/search-filter/search-fixed-filter.service'; -import { map } from 'rxjs/operators'; +import { flatMap, map } from 'rxjs/operators'; /** * Service that performs all actions that have to do with the current search configuration @@ -173,8 +173,9 @@ export class SearchConfigurationService implements OnDestroy { * @returns {Observable} Emits the current fixed filter as a string */ getCurrentFixedFilter(): Observable { - const fixedFilter: Observable = this.routeService.getRouteParameterValue('filter'); - return fixedFilter.flatMap((f) => this.fixedFilterService.getQueryByFilterName(f)); + return this.routeService.getRouteParameterValue('filter').pipe( + flatMap((f) => this.fixedFilterService.getQueryByFilterName(f)) + ); } /** diff --git a/src/app/shared/object-list/item-list-element/entity-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/entity-list-element.component.spec.ts deleted file mode 100644 index 8ff375c1ea..0000000000 --- a/src/app/shared/object-list/item-list-element/entity-list-element.component.spec.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { EntityListElementComponent } from './entity-list-element.component'; -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; -import { By } from '@angular/platform-browser'; -import { TruncatePipe } from '../../utils/truncate.pipe'; -import { Item } from '../../../core/shared/item.model'; -import { Observable } from 'rxjs/Observable'; - -let itemListElementComponent: EntityListElementComponent; -let fixture: ComponentFixture; - -const mockItemWithAuthorAndDate: Item = Object.assign(new Item(), { - bitstreams: Observable.of({}), - metadata: [ - { - key: 'dc.contributor.author', - language: 'en_US', - value: 'Smith, Donald' - }, - { - key: 'dc.date.issued', - language: null, - value: '2015-06-26' - }] -}); -const mockItemWithoutAuthorAndDate: Item = Object.assign(new Item(), { - bitstreams: Observable.of({}), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'This is just another title' - }, - { - key: 'dc.type', - language: null, - value: 'Article' - }] -}); - -describe('EntityListElementComponent', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ EntityListElementComponent , TruncatePipe], - providers: [ - { provide: 'objectElementProvider', useValue: {mockItemWithAuthorAndDate}} - ], - - schemas: [ NO_ERRORS_SCHEMA ] - }).overrideComponent(EntityListElementComponent, { - set: { changeDetection: ChangeDetectionStrategy.Default } - }).compileComponents(); - })); - - beforeEach(async(() => { - fixture = TestBed.createComponent(EntityListElementComponent); - itemListElementComponent = fixture.componentInstance; - - })); - - describe('When the item has an author', () => { - beforeEach(() => { - itemListElementComponent.object = mockItemWithAuthorAndDate; - fixture.detectChanges(); - }); - - it('should show the author paragraph', () => { - const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-authors')); - expect(itemAuthorField).not.toBeNull(); - }); - }); - - describe('When the item has no author', () => { - beforeEach(() => { - itemListElementComponent.object = mockItemWithoutAuthorAndDate; - fixture.detectChanges(); - }); - - it('should not show the author paragraph', () => { - const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-authors')); - expect(itemAuthorField).toBeNull(); - }); - }); - - describe('When the item has an issuedate', () => { - beforeEach(() => { - itemListElementComponent.object = mockItemWithAuthorAndDate; - fixture.detectChanges(); - }); - - it('should show the issuedate span', () => { - const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-date')); - expect(itemAuthorField).not.toBeNull(); - }); - }); - - describe('When the item has no issuedate', () => { - beforeEach(() => { - itemListElementComponent.object = mockItemWithoutAuthorAndDate; - fixture.detectChanges(); - }); - - it('should not show the issuedate span', () => { - const dateField = fixture.debugElement.query(By.css('span.item-list-date')); - expect(dateField).toBeNull(); - }); - }); -}); diff --git a/src/app/shared/object-list/item-list-element/entity-types/journal-issue/journal-issue-list-element.component.html b/src/app/shared/object-list/item-list-element/entity-types/journal-issue/journal-issue-list-element.component.html index 08011cf04e..3f73460f04 100644 --- a/src/app/shared/object-list/item-list-element/entity-types/journal-issue/journal-issue-list-element.component.html +++ b/src/app/shared/object-list/item-list-element/entity-types/journal-issue/journal-issue-list-element.component.html @@ -9,7 +9,8 @@ - + - diff --git a/src/app/shared/object-list/item-list-element/entity-types/journal-issue/journal-issue-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/entity-types/journal-issue/journal-issue-list-element.component.spec.ts new file mode 100644 index 0000000000..58a27ffa8b --- /dev/null +++ b/src/app/shared/object-list/item-list-element/entity-types/journal-issue/journal-issue-list-element.component.spec.ts @@ -0,0 +1,111 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { Observable } from 'rxjs/Observable'; +import { Item } from '../../../../../core/shared/item.model'; +import { TruncatePipe } from '../../../../utils/truncate.pipe'; +import { TruncatableService } from '../../../../truncatable/truncatable.service'; +import { ITEM } from '../../../../entities/switcher/entity-type-switcher.component'; +import { JournalIssueListElementComponent } from './journal-issue-list-element.component'; + +let journalIssueListElementComponent: JournalIssueListElementComponent; +let fixture: ComponentFixture; + +const mockItemWithMetadata: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }, + { + key: 'journalvolume.identifier.volume', + language: 'en_US', + value: '1234' + }, + { + key: 'journalissue.identifier.number', + language: 'en_US', + value: '5678' + }] +}); +const mockItemWithoutMetadata: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }] +}); + +describe('JournalIssueListElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ JournalIssueListElementComponent , TruncatePipe], + providers: [ + { provide: ITEM, useValue: mockItemWithMetadata}, + { provide: TruncatableService, useValue: {} } + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).overrideComponent(JournalIssueListElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(JournalIssueListElementComponent); + journalIssueListElementComponent = fixture.componentInstance; + + })); + + describe('When the item has a journal identifier', () => { + beforeEach(() => { + journalIssueListElementComponent.item = mockItemWithMetadata; + fixture.detectChanges(); + }); + + it('should show the journal issues span', () => { + const journalIdentifierField = fixture.debugElement.query(By.css('span.item-list-journal-issues')); + expect(journalIdentifierField).not.toBeNull(); + }); + }); + + describe('When the item has no journal identifier', () => { + beforeEach(() => { + journalIssueListElementComponent.item = mockItemWithoutMetadata; + fixture.detectChanges(); + }); + + it('should not show the journal issues span', () => { + const journalIdentifierField = fixture.debugElement.query(By.css('span.item-list-journal-issues')); + expect(journalIdentifierField).toBeNull(); + }); + }); + + describe('When the item has a journal number', () => { + beforeEach(() => { + journalIssueListElementComponent.item = mockItemWithMetadata; + fixture.detectChanges(); + }); + + it('should show the journal issue numbers span', () => { + const journalNumberField = fixture.debugElement.query(By.css('span.item-list-journal-issue-numbers')); + expect(journalNumberField).not.toBeNull(); + }); + }); + + describe('When the item has no journal number', () => { + beforeEach(() => { + journalIssueListElementComponent.item = mockItemWithoutMetadata; + fixture.detectChanges(); + }); + + it('should not show the journal issue numbers span', () => { + const journalNumberField = fixture.debugElement.query(By.css('span.item-list-journal-issue-numbers')); + expect(journalNumberField).toBeNull(); + }); + }); +}); diff --git a/src/app/shared/object-list/item-list-element/entity-types/journal-volume/journal-volume-list-element.component.html b/src/app/shared/object-list/item-list-element/entity-types/journal-volume/journal-volume-list-element.component.html index b071179950..ec7acf1087 100644 --- a/src/app/shared/object-list/item-list-element/entity-types/journal-volume/journal-volume-list-element.component.html +++ b/src/app/shared/object-list/item-list-element/entity-types/journal-volume/journal-volume-list-element.component.html @@ -10,7 +10,8 @@ - + () diff --git a/src/app/shared/object-list/item-list-element/entity-types/journal-volume/journal-volume-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/entity-types/journal-volume/journal-volume-list-element.component.spec.ts new file mode 100644 index 0000000000..9c7eb7a029 --- /dev/null +++ b/src/app/shared/object-list/item-list-element/entity-types/journal-volume/journal-volume-list-element.component.spec.ts @@ -0,0 +1,111 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { Observable } from 'rxjs/Observable'; +import { Item } from '../../../../../core/shared/item.model'; +import { TruncatePipe } from '../../../../utils/truncate.pipe'; +import { TruncatableService } from '../../../../truncatable/truncatable.service'; +import { ITEM } from '../../../../entities/switcher/entity-type-switcher.component'; +import { JournalVolumeListElementComponent } from './journal-volume-list-element.component'; + +let journalVolumeListElementComponent: JournalVolumeListElementComponent; +let fixture: ComponentFixture; + +const mockItemWithMetadata: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }, + { + key: 'journal.title', + language: 'en_US', + value: 'This is just another journal title' + }, + { + key: 'journalvolume.identifier.volume', + language: 'en_US', + value: '1234' + }] +}); +const mockItemWithoutMetadata: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }] +}); + +describe('JournalVolumeListElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ JournalVolumeListElementComponent , TruncatePipe], + providers: [ + { provide: ITEM, useValue: mockItemWithMetadata}, + { provide: TruncatableService, useValue: {} } + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).overrideComponent(JournalVolumeListElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(JournalVolumeListElementComponent); + journalVolumeListElementComponent = fixture.componentInstance; + + })); + + describe('When the item has a journal title', () => { + beforeEach(() => { + journalVolumeListElementComponent.item = mockItemWithMetadata; + fixture.detectChanges(); + }); + + it('should show the journal title span', () => { + const journalTitleField = fixture.debugElement.query(By.css('span.item-list-journal-volumes')); + expect(journalTitleField).not.toBeNull(); + }); + }); + + describe('When the item has no journal title', () => { + beforeEach(() => { + journalVolumeListElementComponent.item = mockItemWithoutMetadata; + fixture.detectChanges(); + }); + + it('should not show the journal title span', () => { + const journalTitleField = fixture.debugElement.query(By.css('span.item-list-journal-volumes')); + expect(journalTitleField).toBeNull(); + }); + }); + + describe('When the item has a journal identifier', () => { + beforeEach(() => { + journalVolumeListElementComponent.item = mockItemWithMetadata; + fixture.detectChanges(); + }); + + it('should show the journal identifiers span', () => { + const journalIdentifierField = fixture.debugElement.query(By.css('span.item-list-journal-volume-identifiers')); + expect(journalIdentifierField).not.toBeNull(); + }); + }); + + describe('When the item has no journal identifier', () => { + beforeEach(() => { + journalVolumeListElementComponent.item = mockItemWithoutMetadata; + fixture.detectChanges(); + }); + + it('should not show the journal identifiers span', () => { + const journalIdentifierField = fixture.debugElement.query(By.css('span.item-list-journal-volume-identifiers')); + expect(journalIdentifierField).toBeNull(); + }); + }); +}); diff --git a/src/app/shared/object-list/item-list-element/entity-types/journal/journal-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/entity-types/journal/journal-list-element.component.spec.ts new file mode 100644 index 0000000000..bcf6cb7058 --- /dev/null +++ b/src/app/shared/object-list/item-list-element/entity-types/journal/journal-list-element.component.spec.ts @@ -0,0 +1,82 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { Observable } from 'rxjs/Observable'; +import { Item } from '../../../../../core/shared/item.model'; +import { TruncatePipe } from '../../../../utils/truncate.pipe'; +import { TruncatableService } from '../../../../truncatable/truncatable.service'; +import { ITEM } from '../../../../entities/switcher/entity-type-switcher.component'; +import { JournalListElementComponent } from './journal-list-element.component'; + +let journalListElementComponent: JournalListElementComponent; +let fixture: ComponentFixture; + +const mockItemWithMetadata: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }, + { + key: 'journal.identifier.issn', + language: 'en_US', + value: '1234' + }] +}); +const mockItemWithoutMetadata: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }] +}); + +describe('JournalListElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ JournalListElementComponent , TruncatePipe], + providers: [ + { provide: ITEM, useValue: mockItemWithMetadata}, + { provide: TruncatableService, useValue: {} } + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).overrideComponent(JournalListElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(JournalListElementComponent); + journalListElementComponent = fixture.componentInstance; + + })); + + describe('When the item has an issn', () => { + beforeEach(() => { + journalListElementComponent.item = mockItemWithMetadata; + fixture.detectChanges(); + }); + + it('should show the journals span', () => { + const issnField = fixture.debugElement.query(By.css('span.item-list-journals')); + expect(issnField).not.toBeNull(); + }); + }); + + describe('When the item has no issn', () => { + beforeEach(() => { + journalListElementComponent.item = mockItemWithoutMetadata; + fixture.detectChanges(); + }); + + it('should not show the journals span', () => { + const issnField = fixture.debugElement.query(By.css('span.item-list-journals')); + expect(issnField).toBeNull(); + }); + }); +}); diff --git a/src/app/shared/object-list/item-list-element/entity-types/orgunit/orgunit-list-element.component.html b/src/app/shared/object-list/item-list-element/entity-types/orgunit/orgunit-list-element.component.html index 824a90a3de..0a07901abb 100644 --- a/src/app/shared/object-list/item-list-element/entity-types/orgunit/orgunit-list-element.component.html +++ b/src/app/shared/object-list/item-list-element/entity-types/orgunit/orgunit-list-element.component.html @@ -5,7 +5,7 @@ + class="item-list-orgunit-description"> diff --git a/src/app/shared/object-list/item-list-element/entity-types/orgunit/orgunit-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/entity-types/orgunit/orgunit-list-element.component.spec.ts new file mode 100644 index 0000000000..2bc69e94fd --- /dev/null +++ b/src/app/shared/object-list/item-list-element/entity-types/orgunit/orgunit-list-element.component.spec.ts @@ -0,0 +1,82 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { Observable } from 'rxjs/Observable'; +import { Item } from '../../../../../core/shared/item.model'; +import { TruncatePipe } from '../../../../utils/truncate.pipe'; +import { TruncatableService } from '../../../../truncatable/truncatable.service'; +import { ITEM } from '../../../../entities/switcher/entity-type-switcher.component'; +import { OrgUnitListElementComponent } from './orgunit-list-element.component'; + +let orgUnitListElementComponent: OrgUnitListElementComponent; +let fixture: ComponentFixture; + +const mockItemWithMetadata: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }, + { + key: 'orgunit.identifier.description', + language: 'en_US', + value: 'A description about the OrgUnit' + }] +}); +const mockItemWithoutMetadata: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }] +}); + +describe('OrgUnitListElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ OrgUnitListElementComponent , TruncatePipe], + providers: [ + { provide: ITEM, useValue: mockItemWithMetadata}, + { provide: TruncatableService, useValue: {} } + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).overrideComponent(OrgUnitListElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(OrgUnitListElementComponent); + orgUnitListElementComponent = fixture.componentInstance; + + })); + + describe('When the item has an orgunit description', () => { + beforeEach(() => { + orgUnitListElementComponent.item = mockItemWithMetadata; + fixture.detectChanges(); + }); + + it('should show the description span', () => { + const orgunitDescriptionField = fixture.debugElement.query(By.css('span.item-list-orgunit-description')); + expect(orgunitDescriptionField).not.toBeNull(); + }); + }); + + describe('When the item has no orgunit description', () => { + beforeEach(() => { + orgUnitListElementComponent.item = mockItemWithoutMetadata; + fixture.detectChanges(); + }); + + it('should not show the description span', () => { + const orgunitDescriptionField = fixture.debugElement.query(By.css('span.item-list-orgunit-description')); + expect(orgunitDescriptionField).toBeNull(); + }); + }); +}); diff --git a/src/app/shared/object-list/item-list-element/entity-types/person/person-list-element.component.html b/src/app/shared/object-list/item-list-element/entity-types/person/person-list-element.component.html index 81e9300bb3..803674b56e 100644 --- a/src/app/shared/object-list/item-list-element/entity-types/person/person-list-element.component.html +++ b/src/app/shared/object-list/item-list-element/entity-types/person/person-list-element.component.html @@ -5,7 +5,7 @@ + class="item-list-job-title"> diff --git a/src/app/shared/object-list/item-list-element/entity-types/person/person-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/entity-types/person/person-list-element.component.spec.ts new file mode 100644 index 0000000000..60910474fd --- /dev/null +++ b/src/app/shared/object-list/item-list-element/entity-types/person/person-list-element.component.spec.ts @@ -0,0 +1,82 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { Observable } from 'rxjs/Observable'; +import { Item } from '../../../../../core/shared/item.model'; +import { TruncatePipe } from '../../../../utils/truncate.pipe'; +import { TruncatableService } from '../../../../truncatable/truncatable.service'; +import { ITEM } from '../../../../entities/switcher/entity-type-switcher.component'; +import { PersonListElementComponent } from './person-list-element.component'; + +let personListElementComponent: PersonListElementComponent; +let fixture: ComponentFixture; + +const mockItemWithMetadata: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }, + { + key: 'person.identifier.jobtitle', + language: 'en_US', + value: 'Developer' + }] +}); +const mockItemWithoutMetadata: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }] +}); + +describe('PersonListElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ PersonListElementComponent , TruncatePipe], + providers: [ + { provide: ITEM, useValue: mockItemWithMetadata}, + { provide: TruncatableService, useValue: {} } + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).overrideComponent(PersonListElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(PersonListElementComponent); + personListElementComponent = fixture.componentInstance; + + })); + + describe('When the item has a job title', () => { + beforeEach(() => { + personListElementComponent.item = mockItemWithMetadata; + fixture.detectChanges(); + }); + + it('should show the job title span', () => { + const jobTitleField = fixture.debugElement.query(By.css('span.item-list-job-title')); + expect(jobTitleField).not.toBeNull(); + }); + }); + + describe('When the item has no job title', () => { + beforeEach(() => { + personListElementComponent.item = mockItemWithoutMetadata; + fixture.detectChanges(); + }); + + it('should not show the job title span', () => { + const jobTitleField = fixture.debugElement.query(By.css('span.item-list-job-title')); + expect(jobTitleField).toBeNull(); + }); + }); +}); diff --git a/src/app/shared/object-list/item-list-element/entity-types/project/project-list-element.component.html b/src/app/shared/object-list/item-list-element/entity-types/project/project-list-element.component.html index 7eafd91317..e1d7814f40 100644 --- a/src/app/shared/object-list/item-list-element/entity-types/project/project-list-element.component.html +++ b/src/app/shared/object-list/item-list-element/entity-types/project/project-list-element.component.html @@ -5,7 +5,7 @@ + class="item-list-status"> diff --git a/src/app/shared/object-list/item-list-element/entity-types/project/project-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/entity-types/project/project-list-element.component.spec.ts new file mode 100644 index 0000000000..e0cba5f11e --- /dev/null +++ b/src/app/shared/object-list/item-list-element/entity-types/project/project-list-element.component.spec.ts @@ -0,0 +1,82 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { Observable } from 'rxjs/Observable'; +import { Item } from '../../../../../core/shared/item.model'; +import { TruncatePipe } from '../../../../utils/truncate.pipe'; +import { TruncatableService } from '../../../../truncatable/truncatable.service'; +import { ITEM } from '../../../../entities/switcher/entity-type-switcher.component'; +import { ProjectListElementComponent } from './project-list-element.component'; + +let projectListElementComponent: ProjectListElementComponent; +let fixture: ComponentFixture; + +const mockItemWithMetadata: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }, + { + key: 'project.identifier.status', + language: 'en_US', + value: 'A status about the project' + }] +}); +const mockItemWithoutMetadata: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }] +}); + +describe('ProjectListElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ProjectListElementComponent , TruncatePipe], + providers: [ + { provide: ITEM, useValue: mockItemWithMetadata}, + { provide: TruncatableService, useValue: {} } + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).overrideComponent(ProjectListElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(ProjectListElementComponent); + projectListElementComponent = fixture.componentInstance; + + })); + + describe('When the item has a status', () => { + beforeEach(() => { + projectListElementComponent.item = mockItemWithMetadata; + fixture.detectChanges(); + }); + + it('should show the status span', () => { + const statusField = fixture.debugElement.query(By.css('span.item-list-status')); + expect(statusField).not.toBeNull(); + }); + }); + + describe('When the item has no status', () => { + beforeEach(() => { + projectListElementComponent.item = mockItemWithoutMetadata; + fixture.detectChanges(); + }); + + it('should not show the status span', () => { + const statusField = fixture.debugElement.query(By.css('span.item-list-status')); + expect(statusField).toBeNull(); + }); + }); +}); diff --git a/src/app/shared/object-list/item-list-element/entity-types/publication/publication-list-element.component.spec.ts b/src/app/shared/object-list/item-list-element/entity-types/publication/publication-list-element.component.spec.ts new file mode 100644 index 0000000000..0e96999c3f --- /dev/null +++ b/src/app/shared/object-list/item-list-element/entity-types/publication/publication-list-element.component.spec.ts @@ -0,0 +1,169 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { Observable } from 'rxjs/Observable'; +import { PublicationListElementComponent } from './publication-list-element.component'; +import { Item } from '../../../../../core/shared/item.model'; +import { TruncatePipe } from '../../../../utils/truncate.pipe'; +import { TruncatableService } from '../../../../truncatable/truncatable.service'; +import { ITEM } from '../../../../entities/switcher/entity-type-switcher.component'; + +let publicationListElementComponent: PublicationListElementComponent; +let fixture: ComponentFixture; + +const mockItemWithMetadata: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }, + { + key: 'dc.contributor.author', + language: 'en_US', + value: 'Smith, Donald' + }, + { + key: 'dc.publisher', + language: 'en_US', + value: 'Atmire' + }, + { + key: 'dc.date.issued', + language: null, + value: '2015-06-26' + }, + { + key: 'dc.description.abstract', + language: 'en_US', + value: 'This is the abstract' + }] +}); +const mockItemWithoutMetadata: Item = Object.assign(new Item(), { + bitstreams: Observable.of({}), + metadata: [ + { + key: 'dc.title', + language: 'en_US', + value: 'This is just another title' + }] +}); + +describe('PublicationListElementComponent', () => { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ PublicationListElementComponent , TruncatePipe], + providers: [ + { provide: ITEM, useValue: mockItemWithMetadata}, + { provide: TruncatableService, useValue: {} } + ], + + schemas: [ NO_ERRORS_SCHEMA ] + }).overrideComponent(PublicationListElementComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default } + }).compileComponents(); + })); + + beforeEach(async(() => { + fixture = TestBed.createComponent(PublicationListElementComponent); + publicationListElementComponent = fixture.componentInstance; + + })); + + describe('When the item has an author', () => { + beforeEach(() => { + publicationListElementComponent.item = mockItemWithMetadata; + fixture.detectChanges(); + }); + + it('should show the author paragraph', () => { + const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-authors')); + expect(itemAuthorField).not.toBeNull(); + }); + }); + + describe('When the item has no author', () => { + beforeEach(() => { + publicationListElementComponent.item = mockItemWithoutMetadata; + fixture.detectChanges(); + }); + + it('should not show the author paragraph', () => { + const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-authors')); + expect(itemAuthorField).toBeNull(); + }); + }); + + describe('When the item has a publisher', () => { + beforeEach(() => { + publicationListElementComponent.item = mockItemWithMetadata; + fixture.detectChanges(); + }); + + it('should show the publisher span', () => { + const publisherField = fixture.debugElement.query(By.css('span.item-list-publisher')); + expect(publisherField).not.toBeNull(); + }); + }); + + describe('When the item has no publisher', () => { + beforeEach(() => { + publicationListElementComponent.item = mockItemWithoutMetadata; + fixture.detectChanges(); + }); + + it('should not show the publisher span', () => { + const publisherField = fixture.debugElement.query(By.css('span.item-list-publisher')); + expect(publisherField).toBeNull(); + }); + }); + + describe('When the item has an issuedate', () => { + beforeEach(() => { + publicationListElementComponent.item = mockItemWithMetadata; + fixture.detectChanges(); + }); + + it('should show the issuedate span', () => { + const dateField = fixture.debugElement.query(By.css('span.item-list-date')); + expect(dateField).not.toBeNull(); + }); + }); + + describe('When the item has no issuedate', () => { + beforeEach(() => { + publicationListElementComponent.item = mockItemWithoutMetadata; + fixture.detectChanges(); + }); + + it('should not show the issuedate span', () => { + const dateField = fixture.debugElement.query(By.css('span.item-list-date')); + expect(dateField).toBeNull(); + }); + }); + + describe('When the item has an abstract', () => { + beforeEach(() => { + publicationListElementComponent.item = mockItemWithMetadata; + fixture.detectChanges(); + }); + + it('should show the abstract span', () => { + const abstractField = fixture.debugElement.query(By.css('div.item-list-abstract')); + expect(abstractField).not.toBeNull(); + }); + }); + + describe('When the item has no abstract', () => { + beforeEach(() => { + publicationListElementComponent.item = mockItemWithoutMetadata; + fixture.detectChanges(); + }); + + it('should not show the abstract span', () => { + const abstractField = fixture.debugElement.query(By.css('div.item-list-abstract')); + expect(abstractField).toBeNull(); + }); + }); +}); diff --git a/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.spec.ts b/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.spec.ts deleted file mode 100644 index f492c58483..0000000000 --- a/src/app/shared/object-list/search-result-list-element/item-search-result/item-search-result-list-element.component.spec.ts +++ /dev/null @@ -1,120 +0,0 @@ -import { ItemSearchResultListElementComponent } from './item-search-result-list-element.component'; -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { Observable } from 'rxjs/Observable'; -import { NO_ERRORS_SCHEMA, ChangeDetectionStrategy } from '@angular/core'; -import { By } from '@angular/platform-browser'; -import { TruncatePipe } from '../../../utils/truncate.pipe'; -import { Item } from '../../../../core/shared/item.model'; -import { TruncatableService } from '../../../truncatable/truncatable.service'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { ItemSearchResult } from '../../../object-collection/shared/item-search-result.model'; - -let itemSearchResultListElementComponent: ItemSearchResultListElementComponent; -let fixture: ComponentFixture; - -const truncatableServiceStub: any = { - isCollapsed: (id: number) => Observable.of(true), -}; - -const mockItemWithAuthorAndDate: ItemSearchResult = new ItemSearchResult(); -mockItemWithAuthorAndDate.hitHighlights = []; -mockItemWithAuthorAndDate.dspaceObject = Object.assign(new Item(), { - bitstreams: Observable.of({}), - metadata: [ - { - key: 'dc.contributor.author', - language: 'en_US', - value: 'Smith, Donald' - }, - { - key: 'dc.date.issued', - language: null, - value: '2015-06-26' - }] -}); - -const mockItemWithoutAuthorAndDate: ItemSearchResult = new ItemSearchResult(); -mockItemWithoutAuthorAndDate.hitHighlights = []; -mockItemWithoutAuthorAndDate.dspaceObject = Object.assign(new Item(), { - bitstreams: Observable.of({}), - metadata: [ - { - key: 'dc.title', - language: 'en_US', - value: 'This is just another title' - }, - { - key: 'dc.type', - language: null, - value: 'Article' - }] -}); - -describe('ItemSearchResultListElementComponent', () => { - beforeEach(async(() => { - TestBed.configureTestingModule({ - imports: [NoopAnimationsModule], - declarations: [ItemSearchResultListElementComponent, TruncatePipe], - providers: [ - { provide: TruncatableService, useValue: truncatableServiceStub }, - { provide: 'objectElementProvider', useValue: (mockItemWithoutAuthorAndDate) } - ], - schemas: [NO_ERRORS_SCHEMA] - }).overrideComponent(ItemSearchResultListElementComponent, { - set: { changeDetection: ChangeDetectionStrategy.Default } - }).compileComponents(); - })); - - beforeEach(async(() => { - fixture = TestBed.createComponent(ItemSearchResultListElementComponent); - itemSearchResultListElementComponent = fixture.componentInstance; - })); - - describe('When the item has an author', () => { - beforeEach(() => { - itemSearchResultListElementComponent.dso = mockItemWithAuthorAndDate.dspaceObject; - fixture.detectChanges(); - }); - - it('should show the author paragraph', () => { - const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-authors')); - expect(itemAuthorField).not.toBeNull(); - }); - }); - - describe('When the item has no author', () => { - beforeEach(() => { - itemSearchResultListElementComponent.dso = mockItemWithoutAuthorAndDate.dspaceObject; - fixture.detectChanges(); - }); - - it('should not show the author paragraph', () => { - const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-authors')); - expect(itemAuthorField).toBeNull(); - }); - }); - - describe('When the item has an issuedate', () => { - beforeEach(() => { - itemSearchResultListElementComponent.dso = mockItemWithAuthorAndDate.dspaceObject; - fixture.detectChanges(); - }); - - it('should show the issuedate span', () => { - const itemAuthorField = fixture.debugElement.query(By.css('span.item-list-date')); - expect(itemAuthorField).not.toBeNull(); - }); - }); - - describe('When the item has no issuedate', () => { - beforeEach(() => { - itemSearchResultListElementComponent.dso = mockItemWithoutAuthorAndDate.dspaceObject; - fixture.detectChanges(); - }); - - it('should not show the issuedate span', () => { - const dateField = fixture.debugElement.query(By.css('span.item-list-date')); - expect(dateField).toBeNull(); - }); - }); -});