From da881f7a30173c3b9b295144f68bb84b7b169a26 Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Tue, 3 Oct 2017 11:05:42 +0200 Subject: [PATCH 01/40] Fixed and updated merge related issues for simple search --- .../search-options.model.ts | 0 .../search-page-routing.module.ts | 2 +- .../search-page.component.html | 0 .../search-page.component.scss | 0 .../search-page.component.ts | 6 ++--- .../search-page.module.ts | 8 ++++--- .../search-result.model.ts | 0 .../search-results.component.html | 0 .../search-results.compontent.ts | 4 ++-- .../search.service.ts | 4 ++-- src/app/app-routing.module.ts | 1 + .../collection-search-result.model.ts | 2 +- .../community-search-result.model.ts | 2 +- .../item-search-result.model.ts | 2 +- .../search-result-list-element.component.ts | 2 +- src/app/search/search.module.ts | 17 ------------- .../search-form/search-form.component.ts | 24 ++----------------- 17 files changed, 20 insertions(+), 54 deletions(-) rename src/app/{search => +search-page}/search-options.model.ts (100%) rename src/app/{search-page => +search-page}/search-page-routing.module.ts (82%) rename src/app/{search-page => +search-page}/search-page.component.html (100%) rename src/app/{search-page => +search-page}/search-page.component.scss (100%) rename src/app/{search-page => +search-page}/search-page.component.ts (94%) rename src/app/{search-page => +search-page}/search-page.module.ts (93%) rename src/app/{search => +search-page}/search-result.model.ts (100%) rename src/app/{search-page => +search-page}/search-results/search-results.component.html (100%) rename src/app/{search-page => +search-page}/search-results/search-results.compontent.ts (82%) rename src/app/{search => +search-page}/search.service.ts (96%) delete mode 100644 src/app/search/search.module.ts diff --git a/src/app/search/search-options.model.ts b/src/app/+search-page/search-options.model.ts similarity index 100% rename from src/app/search/search-options.model.ts rename to src/app/+search-page/search-options.model.ts diff --git a/src/app/search-page/search-page-routing.module.ts b/src/app/+search-page/search-page-routing.module.ts similarity index 82% rename from src/app/search-page/search-page-routing.module.ts rename to src/app/+search-page/search-page-routing.module.ts index 76b7d9ad0c..de2d64c6c9 100644 --- a/src/app/search-page/search-page-routing.module.ts +++ b/src/app/+search-page/search-page-routing.module.ts @@ -6,7 +6,7 @@ import { SearchPageComponent } from './search-page.component'; @NgModule({ imports: [ RouterModule.forChild([ - { path: 'search', component: SearchPageComponent } + { path: '', component: SearchPageComponent } ]) ] }) diff --git a/src/app/search-page/search-page.component.html b/src/app/+search-page/search-page.component.html similarity index 100% rename from src/app/search-page/search-page.component.html rename to src/app/+search-page/search-page.component.html diff --git a/src/app/search-page/search-page.component.scss b/src/app/+search-page/search-page.component.scss similarity index 100% rename from src/app/search-page/search-page.component.scss rename to src/app/+search-page/search-page.component.scss diff --git a/src/app/search-page/search-page.component.ts b/src/app/+search-page/search-page.component.ts similarity index 94% rename from src/app/search-page/search-page.component.ts rename to src/app/+search-page/search-page.component.ts index a35f6f01a3..90da376597 100644 --- a/src/app/search-page/search-page.component.ts +++ b/src/app/+search-page/search-page.component.ts @@ -1,12 +1,12 @@ import { Component, OnInit, OnDestroy } from '@angular/core'; -import { SearchService } from '../search/search.service'; +import { SearchService } from './search.service'; import { ActivatedRoute, Router } from '@angular/router'; import { RemoteData } from '../core/data/remote-data'; -import { SearchResult } from '../search/search-result.model'; +import { SearchResult } from './search-result.model'; import { DSpaceObject } from '../core/shared/dspace-object.model'; import { SortOptions } from '../core/cache/models/sort-options.model'; import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; -import { SearchOptions } from '../search/search-options.model'; +import { SearchOptions } from './search-options.model'; import { CommunityDataService } from '../core/data/community-data.service'; import { isNotEmpty } from '../shared/empty.util'; import { Community } from '../core/shared/community.model'; diff --git a/src/app/search-page/search-page.module.ts b/src/app/+search-page/search-page.module.ts similarity index 93% rename from src/app/search-page/search-page.module.ts rename to src/app/+search-page/search-page.module.ts index 67a88f579c..a4fe47f8ba 100644 --- a/src/app/search-page/search-page.module.ts +++ b/src/app/+search-page/search-page.module.ts @@ -8,10 +8,10 @@ import { SharedModule } from '../shared/shared.module'; import { SearchPageRoutingModule } from './search-page-routing.module'; import { SearchPageComponent } from './search-page.component'; import { SearchResultsComponent } from './search-results/search-results.compontent'; -import { SearchModule } from '../search/search.module'; import { ItemSearchResultListElementComponent } from '../object-list/search-result-list-element/item-search-result/item-search-result-list-element.component'; import { CollectionSearchResultListElementComponent } from '../object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component'; import { CommunitySearchResultListElementComponent } from '../object-list/search-result-list-element/community-search-result/community-search-result-list-element.component'; +import { SearchService } from './search.service'; @NgModule({ imports: [ @@ -19,8 +19,7 @@ import { CommunitySearchResultListElementComponent } from '../object-list/search CommonModule, TranslateModule, RouterModule, - SharedModule, - SearchModule + SharedModule ], declarations: [ SearchPageComponent, @@ -29,6 +28,9 @@ import { CommunitySearchResultListElementComponent } from '../object-list/search CollectionSearchResultListElementComponent, CommunitySearchResultListElementComponent ], + providers: [ + SearchService + ], entryComponents: [ ItemSearchResultListElementComponent, CollectionSearchResultListElementComponent, diff --git a/src/app/search/search-result.model.ts b/src/app/+search-page/search-result.model.ts similarity index 100% rename from src/app/search/search-result.model.ts rename to src/app/+search-page/search-result.model.ts diff --git a/src/app/search-page/search-results/search-results.component.html b/src/app/+search-page/search-results/search-results.component.html similarity index 100% rename from src/app/search-page/search-results/search-results.component.html rename to src/app/+search-page/search-results/search-results.component.html diff --git a/src/app/search-page/search-results/search-results.compontent.ts b/src/app/+search-page/search-results/search-results.compontent.ts similarity index 82% rename from src/app/search-page/search-results/search-results.compontent.ts rename to src/app/+search-page/search-results/search-results.compontent.ts index 505a3eeae4..62357b8e8d 100644 --- a/src/app/search-page/search-results/search-results.compontent.ts +++ b/src/app/+search-page/search-results/search-results.compontent.ts @@ -1,8 +1,8 @@ import { Component, Input } from '@angular/core'; import { RemoteData } from '../../core/data/remote-data'; -import { SearchResult } from '../../search/search-result.model'; +import { SearchResult } from '../search-result.model'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; -import { SearchOptions } from '../../search/search-options.model'; +import { SearchOptions } from '../search-options.model'; /** * This component renders a simple item page. diff --git a/src/app/search/search.service.ts b/src/app/+search-page/search.service.ts similarity index 96% rename from src/app/search/search.service.ts rename to src/app/+search-page/search.service.ts index 4236cad9ac..81d6a61c82 100644 --- a/src/app/search/search.service.ts +++ b/src/app/+search-page/search.service.ts @@ -84,8 +84,8 @@ export class SearchService { }); const pageInfo = itemsRD.pageInfo.map((info: PageInfo) => { - info.totalElements = info.totalElements > 20 ? 20 : info.totalElements; - return info; + const totalElements = info.totalElements > 20 ? 20 : info.totalElements; + return Object.assign({}, info, {totalElements: totalElements}); }); const payload = itemsRD.payload.map((items: Item[]) => { diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 8fd2a03f3d..fb793df7dc 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -11,6 +11,7 @@ import { PageNotFoundComponent } from './pagenotfound/pagenotfound.component'; { path: 'communities', loadChildren: './+community-page/community-page.module#CommunityPageModule' }, { path: 'collections', loadChildren: './+collection-page/collection-page.module#CollectionPageModule' }, { path: 'items', loadChildren: './+item-page/item-page.module#ItemPageModule' }, + { path: 'search', loadChildren: './+search-page/search-page.module#SearchPageModule' }, { path: '**', pathMatch: 'full', component: PageNotFoundComponent }, ]) ], diff --git a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts b/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts index 081111e96c..fa7945dedd 100644 --- a/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts +++ b/src/app/object-list/search-result-list-element/collection-search-result/collection-search-result.model.ts @@ -1,4 +1,4 @@ -import { SearchResult } from '../../../search/search-result.model'; +import { SearchResult } from '../../../+search-page/search-result.model'; import { Collection } from '../../../core/shared/collection.model'; export class CollectionSearchResult extends SearchResult { diff --git a/src/app/object-list/search-result-list-element/community-search-result/community-search-result.model.ts b/src/app/object-list/search-result-list-element/community-search-result/community-search-result.model.ts index 522b41700e..79ea34b6cd 100644 --- a/src/app/object-list/search-result-list-element/community-search-result/community-search-result.model.ts +++ b/src/app/object-list/search-result-list-element/community-search-result/community-search-result.model.ts @@ -1,4 +1,4 @@ -import { SearchResult } from '../../../search/search-result.model'; +import { SearchResult } from '../../../+search-page/search-result.model'; import { Community } from '../../../core/shared/community.model'; export class CommunitySearchResult extends SearchResult { diff --git a/src/app/object-list/search-result-list-element/item-search-result/item-search-result.model.ts b/src/app/object-list/search-result-list-element/item-search-result/item-search-result.model.ts index dc5d282c25..d9af3539a0 100644 --- a/src/app/object-list/search-result-list-element/item-search-result/item-search-result.model.ts +++ b/src/app/object-list/search-result-list-element/item-search-result/item-search-result.model.ts @@ -1,4 +1,4 @@ -import { SearchResult } from '../../../search/search-result.model'; +import { SearchResult } from '../../../+search-page/search-result.model'; import { Item } from '../../../core/shared/item.model'; export class ItemSearchResult extends SearchResult { diff --git a/src/app/object-list/search-result-list-element/search-result-list-element.component.ts b/src/app/object-list/search-result-list-element/search-result-list-element.component.ts index 3a2bf51c97..4119bc3c2e 100644 --- a/src/app/object-list/search-result-list-element/search-result-list-element.component.ts +++ b/src/app/object-list/search-result-list-element/search-result-list-element.component.ts @@ -2,7 +2,7 @@ import { Component, Inject } from '@angular/core'; import { ObjectListElementComponent } from '../object-list-element/object-list-element.component'; import { ListableObject } from '../listable-object/listable-object.model'; -import { SearchResult } from '../../search/search-result.model'; +import { SearchResult } from '../../+search-page/search-result.model'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { Metadatum } from '../../core/shared/metadatum.model'; import { isEmpty, hasNoValue } from '../../shared/empty.util'; diff --git a/src/app/search/search.module.ts b/src/app/search/search.module.ts deleted file mode 100644 index 5a7f919a56..0000000000 --- a/src/app/search/search.module.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { NgModule } from '@angular/core'; -import { CoreModule } from '../core/core.module'; -import { SearchService } from './search.service'; - -@NgModule({ - imports: [ - - ], - declarations: [ - ], - exports: [ - ], - providers: [ - SearchService - ] -}) -export class SearchModule { } diff --git a/src/app/shared/search-form/search-form.component.ts b/src/app/shared/search-form/search-form.component.ts index fa019e61d1..84d0509530 100644 --- a/src/app/shared/search-form/search-form.component.ts +++ b/src/app/shared/search-form/search-form.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnDestroy, OnInit } from '@angular/core'; +import { Component, Input } from '@angular/core'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { Router } from '@angular/router'; import { isNotEmpty, hasValue, isEmpty } from '../empty.util'; @@ -15,14 +15,12 @@ import { Observable } from 'rxjs/Observable'; styleUrls: ['./search-form.component.scss'], templateUrl: './search-form.component.html', }) -export class SearchFormComponent implements OnInit, OnDestroy { +export class SearchFormComponent { @Input() query: string; selectedId = ''; // Optional existing search parameters @Input() currentParams: {}; @Input() scopes: Observable; - scopeOptions: string[] = []; - sub; @Input() set scope(dso: DSpaceObject) { @@ -31,19 +29,6 @@ export class SearchFormComponent implements OnInit, OnDestroy { } } - ngOnInit(): void { - if (this.scopes) { - this.sub = - this.scopes - .filter((scopes: DSpaceObject[]) => isEmpty(scopes)) - .subscribe((scopes: DSpaceObject[]) => { - this.scopeOptions = scopes - .map((scope: DSpaceObject) => scope.id); - } - ); - } - } - constructor(private router: Router) { } @@ -75,9 +60,4 @@ export class SearchFormComponent implements OnInit, OnDestroy { return id1 === id2; } - ngOnDestroy(): void { - if (this.sub) { - this.sub.unsubscribe(); - } - } } From 4ac23bd6769d216471fc6fc6c7d12636bd5b8a60 Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Tue, 3 Oct 2017 11:13:58 +0200 Subject: [PATCH 02/40] 44878: first test files --- .../search-page.component.spec.ts | 49 +++++ .../search-form/search-form.component.spec.ts | 204 ++++++++++++++++++ 2 files changed, 253 insertions(+) create mode 100644 src/app/+search-page/search-page.component.spec.ts create mode 100644 src/app/shared/search-form/search-form.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 new file mode 100644 index 0000000000..c6b4d25498 --- /dev/null +++ b/src/app/+search-page/search-page.component.spec.ts @@ -0,0 +1,49 @@ +import { ComponentFixture, TestBed, async, inject } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; +import { TranslateModule } from '@ngx-translate/core'; +import { SearchPageComponent } from './search-page.component'; +import { Router } from '@angular/router'; +import { SearchFormComponent } from '../shared/search-form/search-form.component'; +import { SearchResultsComponent } from './search-results/search-results.compontent'; +import { FormsModule } from '@angular/forms'; +import { ObjectListComponent } from '../shared/object-list/object-list.component'; +import { CommonModule } from '@angular/common'; +import { WrapperListElementComponent } from '../object-list/wrapper-list-element/wrapper-list-element.component'; +import { PaginationComponent } from '../shared/pagination/pagination.component'; +import { PaginatePipe } from 'ngx-pagination'; +import { NgbDropdown, NgbPagination } from '@ng-bootstrap/ng-bootstrap'; +import { EnumKeysPipe } from '../shared/utils/enum-keys-pipe'; +import { SearchService } from './search.service'; +import { ItemDataService } from '../core/data/item-data.service'; +import { ResponseCacheService } from '../core/cache/response-cache.service'; +import { StateObservable, Store } from '@ngrx/store'; + +fdescribe('SearchPageComponent', () => { + let comp: SearchPageComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [CommonModule, FormsModule, RouterTestingModule, TranslateModule.forRoot()], + declarations: [SearchPageComponent, SearchFormComponent, SearchResultsComponent, ObjectListComponent, WrapperListElementComponent, PaginationComponent, PaginatePipe, NgbPagination, NgbDropdown, EnumKeysPipe], + providers: [SearchService, ItemDataService, ResponseCacheService, Store, StateObservable], + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(SearchPageComponent); + comp = fixture.componentInstance; // SearchPageComponent test instance + fixture.detectChanges(); + }); + + it('should set the scope and query based on the route parameters', inject([Router], (router: Router) => { + // const query = 'test query'; + // const scope = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; + // router.navigate([], { + // queryParams: Object.assign({}, this.currentQueryParams, { query: query, scope: scope }) + // }); + // expect(this.comp.query).toBe(query); + // expect(this.comp.scope).toBe(scope); + + })); +}); diff --git a/src/app/shared/search-form/search-form.component.spec.ts b/src/app/shared/search-form/search-form.component.spec.ts new file mode 100644 index 0000000000..60942cd62d --- /dev/null +++ b/src/app/shared/search-form/search-form.component.spec.ts @@ -0,0 +1,204 @@ +import { ComponentFixture, TestBed, async, tick, fakeAsync } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { DebugElement } from '@angular/core'; +import { SearchFormComponent } from './search-form.component'; +import { Observable } from 'rxjs/Observable'; +import { FormsModule } from '@angular/forms'; +import { ResourceType } from '../../core/shared/resource-type'; +import { RouterTestingModule } from '@angular/router/testing'; +import { Community } from '../../core/shared/community.model'; +import { TranslateModule } from '@ngx-translate/core'; + +describe('SearchFormComponent', () => { + let comp: SearchFormComponent; + let fixture: ComponentFixture; + let de: DebugElement; + let el: HTMLElement; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [FormsModule, RouterTestingModule, TranslateModule.forRoot()], + declarations: [SearchFormComponent] + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(SearchFormComponent); + comp = fixture.componentInstance; // SearchFormComponent test instance + de = fixture.debugElement.query(By.css('form')); + el = de.nativeElement; + }); + + it('should display scopes when available with default and all scopes', () => { + comp.scopes = Observable.of(objects); + fixture.detectChanges(); + const select: HTMLElement = de.query(By.css('select')).nativeElement; + expect(select).toBeDefined(); + const options: HTMLCollection = select.children; + const defOption: Element = options.item(0); + expect(defOption.getAttribute('value')).toBe(''); + + let index = 1; + objects.forEach((object) => { + expect(options.item(index).textContent).toBe(object.name); + expect(options.item(index).getAttribute('value')).toBe(object.uuid); + index++; + }); + }); + + it('should not display scopes when empty', () => { + fixture.detectChanges(); + const select = de.query(By.css('select')); + expect(select).toBeNull(); + }); + + it('should display set query value in input field', fakeAsync(() => { + const testString = 'This is a test query'; + comp.query = testString; + + fixture.detectChanges(); + tick(); + const queryInput = de.query(By.css('input')).nativeElement; + + expect(queryInput.value).toBe(testString); + })); + + it('should select correct scope option in scope select', fakeAsync(() => { + comp.scopes = Observable.of(objects); + fixture.detectChanges(); + + const testCommunity = objects[1]; + comp.scope = testCommunity; + + fixture.detectChanges(); + tick(); + const scopeSelect = de.query(By.css('select')).nativeElement; + + expect(scopeSelect.value).toBe(testCommunity.id); + })); + // fit('should call updateSearch when clicking the submit button with correct parameters', fakeAsync(() => { + // comp.query = 'Test String' + // fixture.detectChanges(); + // spyOn(comp, 'updateSearch').and.callThrough(); + // fixture.detectChanges(); + // + // const submit = de.query(By.css('button.search-button')).nativeElement; + // const scope = '123456'; + // const query = 'test'; + // const select = de.query(By.css('select')).nativeElement; + // const input = de.query(By.css('input')).nativeElement; + // + // tick(); + // select.value = scope; + // input.value = query; + // + // fixture.detectChanges(); + // + // submit.click(); + // + // expect(comp.updateSearch).toHaveBeenCalledWith({ scope: scope, query: query }); + // })); +}); + +export const objects = [ + Object.assign(new Community(), { + handle: '10673/11', + logo: { + self: { + _isScalar: true, + value: 'https://dspace7.4science.it/dspace-spring-rest/api/core/bitstreams/10b636d0-7890-4968-bcd6-0d83bf4e2b42', + scheduler: null + } + }, + collections: { + self: { + _isScalar: true, + value: '1506937433727', + scheduler: null + } + }, + self: 'https://dspace7.4science.it/dspace-spring-rest/api/core/communities/7669c72a-3f2a-451f-a3b9-9210e7a4c02f', + id: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f', + uuid: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f', + type: ResourceType.Community, + name: 'OR2017 - Demonstration', + metadata: [ + { + key: 'dc.description', + language: null, + value: '' + }, + { + key: 'dc.description.abstract', + language: null, + value: 'This is a test community to hold content for the OR2017 demostration' + }, + { + key: 'dc.description.tableofcontents', + language: null, + value: '' + }, + { + key: 'dc.rights', + language: null, + value: '' + }, + { + key: 'dc.title', + language: null, + value: 'OR2017 - Demonstration' + } + ] + }), + Object.assign(new Community(), + { + handle: '10673/1', + logo: { + self: { + _isScalar: true, + value: 'https://dspace7.4science.it/dspace-spring-rest/api/core/bitstreams/f446c17d-6d51-45ea-a610-d58a73642d40', + scheduler: null + } + }, + collections: { + self: { + _isScalar: true, + value: '1506937433727', + scheduler: null + } + }, + self: 'https://dspace7.4science.it/dspace-spring-rest/api/core/communities/9076bd16-e69a-48d6-9e41-0238cb40d863', + id: '9076bd16-e69a-48d6-9e41-0238cb40d863', + uuid: '9076bd16-e69a-48d6-9e41-0238cb40d863', + type: ResourceType.Community, + name: 'Sample Community', + metadata: [ + { + key: 'dc.description', + language: null, + value: '

This is the introductory text for the Sample Community on the DSpace Demonstration Site. It is editable by System or Community Administrators (of this Community).

\r\n

DSpace Communities may contain one or more Sub-Communities or Collections (of Items).

\r\n

This particular Community has its own logo (the DuraSpace logo).

' + }, + { + key: 'dc.description.abstract', + language: null, + value: 'This is a sample top-level community' + }, + { + key: 'dc.description.tableofcontents', + language: null, + value: '

This is the news section for this Sample Community. System or Community Administrators (of this Community) can edit this News field.

' + }, + { + key: 'dc.rights', + language: null, + value: '

If this Community had special copyright text to display, it would be displayed here.

' + }, + { + key: 'dc.title', + language: null, + value: 'Sample Community' + } + ] + } + ) +]; From 663e6fd221251c8720718684ce4f8ea0c0bb07db Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Tue, 3 Oct 2017 13:54:31 +0200 Subject: [PATCH 03/40] 44878: dynamic test fix --- .../search-page.component.spec.ts | 69 +++++++++++-------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/src/app/+search-page/search-page.component.spec.ts b/src/app/+search-page/search-page.component.spec.ts index c6b4d25498..d577e0e7d8 100644 --- a/src/app/+search-page/search-page.component.spec.ts +++ b/src/app/+search-page/search-page.component.spec.ts @@ -1,32 +1,48 @@ -import { ComponentFixture, TestBed, async, inject } from '@angular/core/testing'; -import { RouterTestingModule } from '@angular/router/testing'; -import { TranslateModule } from '@ngx-translate/core'; +import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing'; +import { ActivatedRoute, Router } from '@angular/router'; +import { Observable } from 'rxjs/Observable'; +import { CommunityDataService } from '../core/data/community-data.service'; import { SearchPageComponent } from './search-page.component'; -import { Router } from '@angular/router'; -import { SearchFormComponent } from '../shared/search-form/search-form.component'; -import { SearchResultsComponent } from './search-results/search-results.compontent'; -import { FormsModule } from '@angular/forms'; -import { ObjectListComponent } from '../shared/object-list/object-list.component'; -import { CommonModule } from '@angular/common'; -import { WrapperListElementComponent } from '../object-list/wrapper-list-element/wrapper-list-element.component'; -import { PaginationComponent } from '../shared/pagination/pagination.component'; -import { PaginatePipe } from 'ngx-pagination'; -import { NgbDropdown, NgbPagination } from '@ng-bootstrap/ng-bootstrap'; -import { EnumKeysPipe } from '../shared/utils/enum-keys-pipe'; import { SearchService } from './search.service'; -import { ItemDataService } from '../core/data/item-data.service'; -import { ResponseCacheService } from '../core/cache/response-cache.service'; -import { StateObservable, Store } from '@ngrx/store'; +import { Community } from '../core/shared/community.model'; fdescribe('SearchPageComponent', () => { let comp: SearchPageComponent; let fixture: ComponentFixture; + const mockResults = []; // TODO + const searchServiceStub = { + search: () => mockResults + }; + const queryParam = 'test query'; + const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; + const activatedRouteStub = { + queryParams: Observable.of({ + query: queryParam, + scope: scopeParam + }) + }; + const mockCommunityList = []; + const communityDataServiceStub = { + findAll: () => mockCommunityList, + findById: () => new Community() + }; + + class RouterStub { + navigateByUrl(url: string) { return url; } + } beforeEach(async(() => { TestBed.configureTestingModule({ - imports: [CommonModule, FormsModule, RouterTestingModule, TranslateModule.forRoot()], - declarations: [SearchPageComponent, SearchFormComponent, SearchResultsComponent, ObjectListComponent, WrapperListElementComponent, PaginationComponent, PaginatePipe, NgbPagination, NgbDropdown, EnumKeysPipe], - providers: [SearchService, ItemDataService, ResponseCacheService, Store, StateObservable], + // imports: [ SearchPageModule ], + declarations: [ SearchPageComponent ], + providers: [ + { provide: SearchService, useValue: searchServiceStub }, + { provide: ActivatedRoute, useValue: activatedRouteStub }, + { provide: CommunityDataService, useValue: communityDataServiceStub }, + { provide: Router, useClass: RouterStub } + ], + schemas: [ NO_ERRORS_SCHEMA ] }).compileComponents(); })); @@ -36,14 +52,9 @@ fdescribe('SearchPageComponent', () => { fixture.detectChanges(); }); - it('should set the scope and query based on the route parameters', inject([Router], (router: Router) => { - // const query = 'test query'; - // const scope = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; - // router.navigate([], { - // queryParams: Object.assign({}, this.currentQueryParams, { query: query, scope: scope }) - // }); - // expect(this.comp.query).toBe(query); - // expect(this.comp.scope).toBe(scope); + it('should set the scope and query based on the route parameters', () => { + expect(comp.query).toBe(queryParam); + expect((comp as any).scope).toBe(scopeParam); + }); - })); }); From b99bc7030275a4e46aea1d56c0b070a6c3d08e8a Mon Sep 17 00:00:00 2001 From: William Welling Date: Tue, 3 Oct 2017 08:17:54 -0500 Subject: [PATCH 04/40] updated yarn lock --- yarn.lock | 140 ++++++------------------------------------------------ 1 file changed, 14 insertions(+), 126 deletions(-) diff --git a/yarn.lock b/yarn.lock index d70e3b3a2d..7ee4626496 100644 --- a/yarn.lock +++ b/yarn.lock @@ -195,19 +195,11 @@ version "2.0.0" resolved "https://registry.yarnpkg.com/@types/mime/-/mime-2.0.0.tgz#5a7306e367c539b9f6543499de8dd519fac37a8b" -"@types/minimatch@*": - version "3.0.1" - resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.1.tgz#b683eb60be358304ef146f5775db4c0e3696a550" - -"@types/minimatch@^2.0.29": +"@types/minimatch@*", "@types/minimatch@^2.0.29": version "2.0.29" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-2.0.29.tgz#5002e14f75e2d71e564281df0431c8c1b4a2a36a" -"@types/node@*": - version "8.0.31" - resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.31.tgz#d9af61093cf4bfc9f066ca34de0175012cfb0ce9" - -"@types/node@8.0.26": +"@types/node@*", "@types/node@8.0.26": version "8.0.26" resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.26.tgz#4d58be925306fd22b1141085535a0268b8beb189" @@ -245,11 +237,7 @@ version "1.6.29" resolved "https://registry.yarnpkg.com/@types/webfontloader/-/webfontloader-1.6.29.tgz#c6b5f6eb8ca31d0aae6b02b6c1300349dd93ea8e" -abbrev@1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" - -abbrev@1.0.x: +abbrev@1, abbrev@1.0.x: version "1.0.9" resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135" @@ -566,7 +554,7 @@ async@2.0.1: dependencies: lodash "^4.8.0" -async@2.4.1: +async@2.4.1, async@^2.0.0, async@^2.1.2, async@^2.1.5: version "2.4.1" resolved "https://registry.yarnpkg.com/async/-/async-2.4.1.tgz#62a56b279c98a11d0987096a01cc3eeb8eb7bbd7" dependencies: @@ -576,12 +564,6 @@ async@^0.9.0, async@~0.9.0: version "0.9.2" resolved "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d" -async@^2.0.0, async@^2.1.2, async@^2.1.5: - version "2.5.0" - resolved "https://registry.yarnpkg.com/async/-/async-2.5.0.tgz#843190fd6b7357a0b9e1c956edddd5ec8462b54d" - dependencies: - lodash "^4.14.0" - asynckit@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" @@ -1544,14 +1526,10 @@ crc32-stream@^2.0.0: crc "^3.4.4" readable-stream "^2.0.0" -crc@3.4.4: +crc@3.4.4, crc@^3.4.4: version "3.4.4" resolved "https://registry.yarnpkg.com/crc/-/crc-3.4.4.tgz#9da1e980e3bd44fc5c93bf5ab3da3378d85e466b" -crc@^3.4.4: - version "3.5.0" - resolved "https://registry.yarnpkg.com/crc/-/crc-3.5.0.tgz#98b8ba7d489665ba3979f59b21381374101a1964" - create-ecdh@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.0.tgz#888c723596cdf7612f6498233eebd7a35301737d" @@ -2422,7 +2400,7 @@ express-session@1.15.6: uid-safe "~2.1.5" utils-merge "1.0.1" -express@4.16.1: +express@4.16.1, express@^4.13.3, express@^4.15.2: version "4.16.1" resolved "https://registry.yarnpkg.com/express/-/express-4.16.1.tgz#6b33b560183c9b253b7b62144df33a4654ac9ed0" dependencies: @@ -2457,41 +2435,6 @@ express@4.16.1: utils-merge "1.0.1" vary "~1.1.2" -express@^4.13.3, express@^4.15.2: - version "4.16.0" - resolved "https://registry.yarnpkg.com/express/-/express-4.16.0.tgz#b519638e4eb58e7178c81b498ef22f798cb2e255" - dependencies: - accepts "~1.3.4" - array-flatten "1.1.1" - body-parser "1.18.2" - content-disposition "0.5.2" - content-type "~1.0.4" - cookie "0.3.1" - cookie-signature "1.0.6" - debug "2.6.9" - depd "~1.1.1" - encodeurl "~1.0.1" - escape-html "~1.0.3" - etag "~1.8.1" - finalhandler "1.1.0" - fresh "0.5.2" - merge-descriptors "1.0.1" - methods "~1.1.2" - on-finished "~2.3.0" - parseurl "~1.3.2" - path-to-regexp "0.1.7" - proxy-addr "~2.0.2" - qs "6.5.1" - range-parser "~1.2.0" - safe-buffer "5.1.1" - send "0.16.0" - serve-static "1.13.0" - setprototypeof "1.1.0" - statuses "~1.3.1" - type-is "~1.6.15" - utils-merge "1.0.1" - vary "~1.1.2" - extend-shallow@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-2.0.1.tgz#51af7d614ad9a9f610ea1bafbb989d6b1c56890f" @@ -5017,7 +4960,7 @@ os-locale@^2.0.0: lcid "^1.0.0" mem "^1.1.0" -os-tmpdir@^1.0.0, os-tmpdir@^1.0.1, os-tmpdir@~1.0.1, os-tmpdir@~1.0.2: +os-tmpdir@^1.0.0, os-tmpdir@^1.0.1, os-tmpdir@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" @@ -5950,14 +5893,10 @@ punycode@^1.2.4, punycode@^1.4.1: version "1.4.1" resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e" -q@1.4.1: +q@1.4.1, q@^1.1.2, q@^1.4.1: version "1.4.1" resolved "https://registry.yarnpkg.com/q/-/q-1.4.1.tgz#55705bcd93c5f3673530c2c2cbc0c2b3addc286e" -q@^1.1.2, q@^1.4.1: - version "1.5.0" - resolved "https://registry.yarnpkg.com/q/-/q-1.5.0.tgz#dd01bac9d06d30e6f219aecb8253ee9ebdc308f1" - qjobs@^1.1.4: version "1.1.5" resolved "https://registry.yarnpkg.com/qjobs/-/qjobs-1.1.5.tgz#659de9f2cf8dcc27a1481276f205377272382e73" @@ -6089,7 +6028,7 @@ readable-stream@1.0, readable-stream@~1.0.2: isarray "0.0.1" string_decoder "~0.10.x" -readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.2.6, readable-stream@^2.2.9: +readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.2.2, readable-stream@^2.2.6, readable-stream@^2.2.9: version "2.3.3" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.3.tgz#368f2512d79f9d46fdfc71349ae7878bbc1eb95c" dependencies: @@ -6639,24 +6578,6 @@ semver@~5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f" -send@0.16.0: - version "0.16.0" - resolved "https://registry.yarnpkg.com/send/-/send-0.16.0.tgz#16338dbb9a2ede4ad57b48420ec3b82d8e80a57b" - dependencies: - debug "2.6.9" - depd "~1.1.1" - destroy "~1.0.4" - encodeurl "~1.0.1" - escape-html "~1.0.3" - etag "~1.8.1" - fresh "0.5.2" - http-errors "~1.6.2" - mime "1.4.1" - ms "2.0.0" - on-finished "~2.3.0" - range-parser "~1.2.0" - statuses "~1.3.1" - send@0.16.1: version "0.16.1" resolved "https://registry.yarnpkg.com/send/-/send-0.16.1.tgz#a70e1ca21d1382c11d0d9f6231deb281080d7ab3" @@ -6687,15 +6608,6 @@ serve-index@^1.7.2: mime-types "~2.1.17" parseurl "~1.3.2" -serve-static@1.13.0: - version "1.13.0" - resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.13.0.tgz#810c91db800e94ba287eae6b4e06caab9fdc16f1" - dependencies: - encodeurl "~1.0.1" - escape-html "~1.0.3" - parseurl "~1.3.2" - send "0.16.0" - serve-static@1.13.1: version "1.13.1" resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.13.1.tgz#4c57d53404a761d8f2e7c1e8a18a47dbf278a719" @@ -6953,14 +6865,10 @@ source-map-url@~0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.3.0.tgz#7ecaf13b57bcd09da8a40c5d269db33799d4aaf9" -source-map@0.5.x, source-map@^0.5.1, source-map@^0.5.3, source-map@^0.5.6, source-map@^0.5.7, source-map@~0.5.1, source-map@~0.5.3: +source-map@0.5.x, source-map@>=0.5.6, source-map@^0.5.1, source-map@^0.5.3, source-map@^0.5.6, source-map@^0.5.7, source-map@~0.5.1, source-map@~0.5.3: version "0.5.7" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" -source-map@>=0.5.6: - version "0.6.1" - resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" - source-map@^0.1.38, source-map@^0.1.41, source-map@~0.1.33: version "0.1.43" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.1.43.tgz#c24bc146ca517c1471f5dacbe2571b2b7f9e3346" @@ -7266,20 +7174,13 @@ throttleit@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/throttleit/-/throttleit-1.0.0.tgz#9e785836daf46743145a5984b6268d828528ac6c" -through2@2.0.1: +through2@2.0.1, through2@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.1.tgz#384e75314d49f32de12eebb8136b8eb6b5d59da9" dependencies: readable-stream "~2.0.0" xtend "~4.0.0" -through2@^2.0.0: - version "2.0.3" - resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.3.tgz#0004569b37c7c74ba39c43f3ced78d1ad94140be" - dependencies: - readable-stream "^2.1.5" - xtend "~4.0.1" - through@2, through@X.X.X, through@~2.3, through@~2.3.1: version "2.3.8" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" @@ -7320,18 +7221,12 @@ tmp@0.0.30: dependencies: os-tmpdir "~1.0.1" -tmp@0.0.31: +tmp@0.0.31, tmp@0.0.x: version "0.0.31" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.31.tgz#8f38ab9438e17315e5dbd8b3657e8bfb277ae4a7" dependencies: os-tmpdir "~1.0.1" -tmp@0.0.x: - version "0.0.33" - resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" - dependencies: - os-tmpdir "~1.0.2" - to-array@0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/to-array/-/to-array-0.1.4.tgz#17e6c11f73dd4f3d74cda7a4ff3238e9ad9bf890" @@ -8045,20 +7940,13 @@ write-file-atomic@^2.0.0: imurmurhash "^0.1.4" signal-exit "^3.0.2" -ws@1.1.2: +ws@1.1.2, ws@^1.0.1: version "1.1.2" resolved "https://registry.yarnpkg.com/ws/-/ws-1.1.2.tgz#8a244fa052401e08c9886cf44a85189e1fd4067f" dependencies: options ">=0.0.5" ultron "1.0.x" -ws@^1.0.1: - version "1.1.4" - resolved "https://registry.yarnpkg.com/ws/-/ws-1.1.4.tgz#57f40d036832e5f5055662a397c4de76ed66bf61" - dependencies: - options ">=0.0.5" - ultron "1.0.x" - ws@^2.3.1: version "2.3.1" resolved "https://registry.yarnpkg.com/ws/-/ws-2.3.1.tgz#6b94b3e447cb6a363f785eaf94af6359e8e81c80" @@ -8104,7 +7992,7 @@ xmlhttprequest-ssl@1.5.3: version "1.5.3" resolved "https://registry.yarnpkg.com/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.3.tgz#185a888c04eca46c3e4070d99f7b49de3528992d" -xtend@^4.0.0, xtend@~4.0.0, xtend@~4.0.1: +xtend@^4.0.0, xtend@~4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af" From ad59cb3276283da702dc62768eec4146149209d9 Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Tue, 3 Oct 2017 15:49:26 +0200 Subject: [PATCH 05/40] 44878: more unit tests --- .../search-page.component.spec.ts | 62 +++++++- src/app/+search-page/search-page.module.ts | 2 +- .../search-results.component.spec.ts | 147 ++++++++++++++++++ ...pontent.ts => search-results.component.ts} | 0 4 files changed, 204 insertions(+), 7 deletions(-) create mode 100644 src/app/+search-page/search-results/search-results.component.spec.ts rename src/app/+search-page/search-results/{search-results.compontent.ts => search-results.component.ts} (100%) diff --git a/src/app/+search-page/search-page.component.spec.ts b/src/app/+search-page/search-page.component.spec.ts index d577e0e7d8..07f70cc648 100644 --- a/src/app/+search-page/search-page.component.spec.ts +++ b/src/app/+search-page/search-page.component.spec.ts @@ -1,16 +1,19 @@ import { NO_ERRORS_SCHEMA } from '@angular/core'; -import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { ActivatedRoute, Router } from '@angular/router'; import { Observable } from 'rxjs/Observable'; import { CommunityDataService } from '../core/data/community-data.service'; import { SearchPageComponent } from './search-page.component'; import { SearchService } from './search.service'; import { Community } from '../core/shared/community.model'; +import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; +import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model'; -fdescribe('SearchPageComponent', () => { +describe('SearchPageComponent', () => { let comp: SearchPageComponent; let fixture: ComponentFixture; - const mockResults = []; // TODO + let searchServiceObject: SearchService; + const mockResults = ['test', 'data']; const searchServiceStub = { search: () => mockResults }; @@ -29,20 +32,22 @@ fdescribe('SearchPageComponent', () => { }; class RouterStub { - navigateByUrl(url: string) { return url; } + navigateByUrl(url: string) { + return url; + } } beforeEach(async(() => { TestBed.configureTestingModule({ // imports: [ SearchPageModule ], - declarations: [ SearchPageComponent ], + declarations: [SearchPageComponent], providers: [ { provide: SearchService, useValue: searchServiceStub }, { provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: CommunityDataService, useValue: communityDataServiceStub }, { provide: Router, useClass: RouterStub } ], - schemas: [ NO_ERRORS_SCHEMA ] + schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); })); @@ -50,6 +55,7 @@ fdescribe('SearchPageComponent', () => { fixture = TestBed.createComponent(SearchPageComponent); comp = fixture.componentInstance; // SearchPageComponent test instance fixture.detectChanges(); + searchServiceObject = (comp as any).service; }); it('should set the scope and query based on the route parameters', () => { @@ -57,4 +63,48 @@ fdescribe('SearchPageComponent', () => { expect((comp as any).scope).toBe(scopeParam); }); + describe('when update search results is called', () => { + let pagination; + let sort; + beforeEach(() => { + pagination = Object.assign( + {}, + new PaginationComponentOptions(), + { + currentPage: 5, + pageSize: 15 + } + ); + sort = Object.assign({}, + new SortOptions(), + { + direction: SortDirection.Ascending, + field: 'test-field' + } + ); + }); + + it('should call the search function of the search service with the right parameters', () => { + spyOn(searchServiceObject, 'search').and.callThrough(); + + (comp as any).updateSearchResults({ + pagination: pagination, + sort: sort + }); + + expect(searchServiceObject.search).toHaveBeenCalledWith(queryParam, scopeParam, { + pagination: pagination, + sort: sort + }); + }); + + it('should update the results', () => { + spyOn(searchServiceObject, 'search').and.callThrough(); + + (comp as any).updateSearchResults({}); + + expect(comp.results as any).toBe(mockResults); + }); + + }); }); diff --git a/src/app/+search-page/search-page.module.ts b/src/app/+search-page/search-page.module.ts index a4fe47f8ba..7cb5f6cbe6 100644 --- a/src/app/+search-page/search-page.module.ts +++ b/src/app/+search-page/search-page.module.ts @@ -7,7 +7,7 @@ import { TranslateModule } from '@ngx-translate/core'; import { SharedModule } from '../shared/shared.module'; import { SearchPageRoutingModule } from './search-page-routing.module'; import { SearchPageComponent } from './search-page.component'; -import { SearchResultsComponent } from './search-results/search-results.compontent'; +import { SearchResultsComponent } from './search-results/search-results.component'; import { ItemSearchResultListElementComponent } from '../object-list/search-result-list-element/item-search-result/item-search-result-list-element.component'; import { CollectionSearchResultListElementComponent } from '../object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component'; import { CommunitySearchResultListElementComponent } from '../object-list/search-result-list-element/community-search-result/community-search-result-list-element.component'; diff --git a/src/app/+search-page/search-results/search-results.component.spec.ts b/src/app/+search-page/search-results/search-results.component.spec.ts new file mode 100644 index 0000000000..ffe7d4133e --- /dev/null +++ b/src/app/+search-page/search-results/search-results.component.spec.ts @@ -0,0 +1,147 @@ +import { ComponentFixture, TestBed, async, tick, fakeAsync } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core'; +import { ResourceType } from '../../core/shared/resource-type'; +import { Community } from '../../core/shared/community.model'; +import { TranslateModule } from '@ngx-translate/core'; +import { SearchResultsComponent } from './search-results.component'; +import { Observable } from 'rxjs/Observable'; +import { RemoteData } from '../../core/data/remote-data'; +import { PageInfo } from '../../core/shared/page-info.model'; + +fdescribe('SearchResultsComponent', () => { + let comp: SearchResultsComponent; + let fixture: ComponentFixture; + let heading: DebugElement; + + + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [TranslateModule.forRoot()], + declarations: [SearchResultsComponent], + schemas: [NO_ERRORS_SCHEMA] + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(SearchResultsComponent); + comp = fixture.componentInstance; // SearchFormComponent test instance + heading = fixture.debugElement.query(By.css('heading')); + }); + + it('should display heading when results are not empty', fakeAsync(() => { + (comp as any).searchResults = 'test'; + (comp as any).searchConfig = {pagination: ''}; + fixture.detectChanges(); + tick(); + expect(heading).toBeDefined(); + })); + + it('should not display heading when results is empty', () => { + expect(heading).toBeNull(); + }); +}); + +export const objects = [ + Object.assign(new Community(), { + handle: '10673/11', + logo: { + self: { + _isScalar: true, + value: 'https://dspace7.4science.it/dspace-spring-rest/api/core/bitstreams/10b636d0-7890-4968-bcd6-0d83bf4e2b42', + scheduler: null + } + }, + collections: { + self: { + _isScalar: true, + value: '1506937433727', + scheduler: null + } + }, + self: 'https://dspace7.4science.it/dspace-spring-rest/api/core/communities/7669c72a-3f2a-451f-a3b9-9210e7a4c02f', + id: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f', + uuid: '7669c72a-3f2a-451f-a3b9-9210e7a4c02f', + type: ResourceType.Community, + name: 'OR2017 - Demonstration', + metadata: [ + { + key: 'dc.description', + language: null, + value: '' + }, + { + key: 'dc.description.abstract', + language: null, + value: 'This is a test community to hold content for the OR2017 demostration' + }, + { + key: 'dc.description.tableofcontents', + language: null, + value: '' + }, + { + key: 'dc.rights', + language: null, + value: '' + }, + { + key: 'dc.title', + language: null, + value: 'OR2017 - Demonstration' + } + ] + }), + Object.assign(new Community(), + { + handle: '10673/1', + logo: { + self: { + _isScalar: true, + value: 'https://dspace7.4science.it/dspace-spring-rest/api/core/bitstreams/f446c17d-6d51-45ea-a610-d58a73642d40', + scheduler: null + } + }, + collections: { + self: { + _isScalar: true, + value: '1506937433727', + scheduler: null + } + }, + self: 'https://dspace7.4science.it/dspace-spring-rest/api/core/communities/9076bd16-e69a-48d6-9e41-0238cb40d863', + id: '9076bd16-e69a-48d6-9e41-0238cb40d863', + uuid: '9076bd16-e69a-48d6-9e41-0238cb40d863', + type: ResourceType.Community, + name: 'Sample Community', + metadata: [ + { + key: 'dc.description', + language: null, + value: '

This is the introductory text for the Sample Community on the DSpace Demonstration Site. It is editable by System or Community Administrators (of this Community).

\r\n

DSpace Communities may contain one or more Sub-Communities or Collections (of Items).

\r\n

This particular Community has its own logo (the DuraSpace logo).

' + }, + { + key: 'dc.description.abstract', + language: null, + value: 'This is a sample top-level community' + }, + { + key: 'dc.description.tableofcontents', + language: null, + value: '

This is the news section for this Sample Community. System or Community Administrators (of this Community) can edit this News field.

' + }, + { + key: 'dc.rights', + language: null, + value: '

If this Community had special copyright text to display, it would be displayed here.

' + }, + { + key: 'dc.title', + language: null, + value: 'Sample Community' + } + ] + } + ) +]; diff --git a/src/app/+search-page/search-results/search-results.compontent.ts b/src/app/+search-page/search-results/search-results.component.ts similarity index 100% rename from src/app/+search-page/search-results/search-results.compontent.ts rename to src/app/+search-page/search-results/search-results.component.ts From 50cb2078f0f7fc00e1813fdc2add575da06ac23d Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Tue, 3 Oct 2017 16:24:14 +0200 Subject: [PATCH 06/40] 44878: Protractor tests --- e2e/search-page/search-page.e2e-spec.ts | 25 +++++++++++++++ e2e/search-page/search-page.po.ts | 31 +++++++++++++++++++ .../search-results.component.spec.ts | 7 +---- 3 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 e2e/search-page/search-page.e2e-spec.ts create mode 100644 e2e/search-page/search-page.po.ts diff --git a/e2e/search-page/search-page.e2e-spec.ts b/e2e/search-page/search-page.e2e-spec.ts new file mode 100644 index 0000000000..8cfdd1bc72 --- /dev/null +++ b/e2e/search-page/search-page.e2e-spec.ts @@ -0,0 +1,25 @@ +import { ProtractorPage } from './search-page.po'; + +fdescribe('protractor SearchPage', () => { + let page: ProtractorPage; + + beforeEach(() => { + page = new ProtractorPage(); + }); + + it('should contain query value when navigating to page with query parameter', () => { + const queryString = 'Interesting query string'; + page.navigateToSearchWithQueryParameter(queryString); + page.getCurrentQuery().then((query: string) => { + expect(query).toEqual(queryString); + }); + }); + + it('should not contain element ds-pagenotfound when navigating to existing page', () => { + const scopeString = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; + page.navigateToSearchWithScopeParameter(scopeString); + page.getCurrentScope().then((scope: string) => { + expect(scope).toEqual(scopeString); + }); + }); +}); diff --git a/e2e/search-page/search-page.po.ts b/e2e/search-page/search-page.po.ts new file mode 100644 index 0000000000..faf0912635 --- /dev/null +++ b/e2e/search-page/search-page.po.ts @@ -0,0 +1,31 @@ +import { browser, element, by } from 'protractor'; +import { promise } from 'selenium-webdriver'; + +export class ProtractorPage { + SEARCH = '/search'; + + navigateToSearch() { + return browser.get(this.SEARCH); + } + + navigateToSearchWithQueryParameter(query: string) { + return browser.get(this.SEARCH + '?query=' + query); + } + + navigateToSearchWithScopeParameter(scope: string) { + return browser.get(this.SEARCH + '?scope=' + scope); + } + + getCurrentScope(): promise.Promise { + return element(by.tagName('select')).getAttribute('value'); + } + + getCurrentQuery(): promise.Promise { + return element(by.tagName('input')).getAttribute('value'); + } + + elementTagExists(tag: string) { + return element(by.tagName(tag)).isPresent(); + } + +} diff --git a/src/app/+search-page/search-results/search-results.component.spec.ts b/src/app/+search-page/search-results/search-results.component.spec.ts index ffe7d4133e..4f299c5c50 100644 --- a/src/app/+search-page/search-results/search-results.component.spec.ts +++ b/src/app/+search-page/search-results/search-results.component.spec.ts @@ -5,17 +5,12 @@ import { ResourceType } from '../../core/shared/resource-type'; import { Community } from '../../core/shared/community.model'; import { TranslateModule } from '@ngx-translate/core'; import { SearchResultsComponent } from './search-results.component'; -import { Observable } from 'rxjs/Observable'; -import { RemoteData } from '../../core/data/remote-data'; -import { PageInfo } from '../../core/shared/page-info.model'; -fdescribe('SearchResultsComponent', () => { +describe('SearchResultsComponent', () => { let comp: SearchResultsComponent; let fixture: ComponentFixture; let heading: DebugElement; - - beforeEach(async(() => { TestBed.configureTestingModule({ imports: [TranslateModule.forRoot()], From fa99152104c4e1d9bab086231d0a9653cdad1db6 Mon Sep 17 00:00:00 2001 From: William Welling Date: Tue, 3 Oct 2017 15:29:30 -0500 Subject: [PATCH 07/40] ngIf else ng-template for initial loading work --- .../collection-page.component.html | 18 +++++--- .../community-page.component.html | 21 +++++---- .../top-level-community-list.component.html | 12 +++-- .../full/full-item-page.component.html | 43 ++++++++--------- .../simple/item-page.component.html | 46 +++++++++---------- src/app/shared/loading/loading.component.html | 1 + src/app/shared/loading/loading.component.scss | 0 src/app/shared/loading/loading.component.ts | 12 +++++ src/app/shared/shared.module.ts | 4 +- 9 files changed, 89 insertions(+), 68 deletions(-) create mode 100644 src/app/shared/loading/loading.component.html create mode 100644 src/app/shared/loading/loading.component.scss create mode 100644 src/app/shared/loading/loading.component.ts diff --git a/src/app/+collection-page/collection-page.component.html b/src/app/+collection-page/collection-page.component.html index b1aae17f7c..e9d4f29257 100644 --- a/src/app/+collection-page/collection-page.component.html +++ b/src/app/+collection-page/collection-page.component.html @@ -1,13 +1,13 @@
-
+
+ [logo]="logoData.payload | async" + [alternateText]="'Collection Logo'">
+
-
+

{{'collection.page.browse.recent.head' | translate}}

- + +
+
diff --git a/src/app/+community-page/community-page.component.html b/src/app/+community-page/community-page.component.html index 4f02c885e6..e58b358c35 100644 --- a/src/app/+community-page/community-page.component.html +++ b/src/app/+community-page/community-page.component.html @@ -1,26 +1,27 @@ -
+
+ [logo]="logoData.payload | async" + [alternateText]="'Community Logo'"> + [content]="(communityData.payload | async)?.introductoryText" + [hasInnerHtml]="true"> + [content]="(communityData.payload | async)?.sidebarText" + [hasInnerHtml]="true" + [title]="'community.page.news'"> + [content]="(communityData.payload | async)?.copyrightText" + [hasInnerHtml]="true">
+ diff --git a/src/app/+home/top-level-community-list/top-level-community-list.component.html b/src/app/+home/top-level-community-list/top-level-community-list.component.html index 772eb66012..183be2605c 100644 --- a/src/app/+home/top-level-community-list/top-level-community-list.component.html +++ b/src/app/+home/top-level-community-list/top-level-community-list.component.html @@ -1,6 +1,12 @@ -
+

{{'home.top-level-communities.head' | translate}}

{{'home.top-level-communities.help' | translate}}

- + +
+ \ No newline at end of file diff --git a/src/app/+item-page/full/full-item-page.component.html b/src/app/+item-page/full/full-item-page.component.html index 59511d7d9d..ba8f7409d9 100644 --- a/src/app/+item-page/full/full-item-page.component.html +++ b/src/app/+item-page/full/full-item-page.component.html @@ -1,25 +1,20 @@ -
- - - - - - - - - - - - -
{{metadatum.key}}{{metadatum.value}}{{metadatum.language}}
- - - - - - +
+ + + + + + + + + + +
{{metadatum.key}}{{metadatum.value}}{{metadatum.language}}
+ +
+ diff --git a/src/app/+item-page/simple/item-page.component.html b/src/app/+item-page/simple/item-page.component.html index 94ab99482f..455b014add 100644 --- a/src/app/+item-page/simple/item-page.component.html +++ b/src/app/+item-page/simple/item-page.component.html @@ -1,26 +1,24 @@ -
- -
-
- - - - - - - -
- - +
+ +
+
+ + + + + +
+ +
+ diff --git a/src/app/shared/loading/loading.component.html b/src/app/shared/loading/loading.component.html new file mode 100644 index 0000000000..fb5224e1ac --- /dev/null +++ b/src/app/shared/loading/loading.component.html @@ -0,0 +1 @@ +
{{ message }}
\ No newline at end of file diff --git a/src/app/shared/loading/loading.component.scss b/src/app/shared/loading/loading.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/shared/loading/loading.component.ts b/src/app/shared/loading/loading.component.ts new file mode 100644 index 0000000000..8bb47c20d6 --- /dev/null +++ b/src/app/shared/loading/loading.component.ts @@ -0,0 +1,12 @@ +import { Component, Input } from '@angular/core'; + +@Component({ + selector: 'ds-loading', + styleUrls: ['./loading.component.scss'], + templateUrl: './loading.component.html' +}) +export class LoadingComponent { + + @Input() message: "Loading..."; + +} diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 7f0975ea6e..669f490c13 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -27,6 +27,7 @@ import { TruncatePipe } from './utils/truncate.pipe'; import { WrapperListElementComponent } from '../object-list/wrapper-list-element/wrapper-list-element.component'; import { SearchResultListElementComponent } from '../object-list/search-result-list-element/search-result-list-element.component'; import { SearchFormComponent } from './search-form/search-form.component'; +import { LoadingComponent } from './loading/loading.component'; const MODULES = [ // Do NOT include UniversalModule, HttpModule, or JsonpModule here @@ -57,7 +58,8 @@ const COMPONENTS = [ ObjectListComponent, ObjectListElementComponent, WrapperListElementComponent, - SearchFormComponent + SearchFormComponent, + LoadingComponent ]; const ENTRY_COMPONENTS = [ From 16cff501733c4386e294efef4b2d4e7ab11c144c Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Wed, 4 Oct 2017 10:44:06 +0200 Subject: [PATCH 08/40] 44373: e2e test --- e2e/search-page/search-page.e2e-spec.ts | 32 +++++++++++++++++++++---- e2e/search-page/search-page.po.ts | 22 ++++++++++++++--- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/e2e/search-page/search-page.e2e-spec.ts b/e2e/search-page/search-page.e2e-spec.ts index 8cfdd1bc72..fd7be52733 100644 --- a/e2e/search-page/search-page.e2e-spec.ts +++ b/e2e/search-page/search-page.e2e-spec.ts @@ -1,4 +1,6 @@ import { ProtractorPage } from './search-page.po'; +import { browser } from 'protractor'; +import { promise } from 'selenium-webdriver'; fdescribe('protractor SearchPage', () => { let page: ProtractorPage; @@ -16,10 +18,32 @@ fdescribe('protractor SearchPage', () => { }); it('should not contain element ds-pagenotfound when navigating to existing page', () => { - const scopeString = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; - page.navigateToSearchWithScopeParameter(scopeString); - page.getCurrentScope().then((scope: string) => { - expect(scope).toEqual(scopeString); + const scope: promise.Promise = page.getRandomScopeOption(); + scope.then((scopeString: string) => { + page.navigateToSearchWithScopeParameter(scopeString); + page.getCurrentScope().then((s: string) => { + expect(s).toEqual(scopeString); + }); + }); + }); + + it('should redirect to the correct url when scope was set and submit button was triggered', () => { + const scope: promise.Promise = page.getRandomScopeOption(); + scope.then((scopeString: string) => { + page.setCurrentScope(scopeString); + page.submitSearchForm(); + browser.getCurrentUrl().then((url: string) => { + expect(url.indexOf('scope=' + encodeURI(scopeString))).toBeGreaterThanOrEqual(0); + }); + }); + }); + + it('should redirect to the correct url when query was set and submit button was triggered', () => { + const queryString = 'Another interesting query string'; + page.setCurrentQuery(queryString); + page.submitSearchForm(); + browser.getCurrentUrl().then((url: string) => { + expect(url.indexOf('query=' + encodeURI(queryString))).toBeGreaterThanOrEqual(0); }); }); }); diff --git a/e2e/search-page/search-page.po.ts b/e2e/search-page/search-page.po.ts index faf0912635..b5e43dcf82 100644 --- a/e2e/search-page/search-page.po.ts +++ b/e2e/search-page/search-page.po.ts @@ -20,12 +20,28 @@ export class ProtractorPage { return element(by.tagName('select')).getAttribute('value'); } - getCurrentQuery(): promise.Promise { + getCurrentQuery(): promise.Promise { return element(by.tagName('input')).getAttribute('value'); } - elementTagExists(tag: string) { - return element(by.tagName(tag)).isPresent(); + setCurrentScope(scope: string) { + element(by.css('option[value="' + scope + '"]')).click(); + } + + setCurrentQuery(query: string) { + element(by.css('input[name="query"]')).sendKeys(query); + } + + submitSearchForm() { + element(by.css('button.search-button')).click(); + } + + getRandomScopeOption(): promise.Promise { + const options = element(by.css('select[name="scope"]')).all(by.tagName('option')); + return options.count().then((c: number) => { + const index: number = Math.floor(Math.random() * c); + return options.get(index).getAttribute('value'); + }); } } From f8496839bdce39d5c559384db9264826f98158a1 Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Wed, 4 Oct 2017 10:46:55 +0200 Subject: [PATCH 09/40] 44878: fixed description --- e2e/search-page/search-page.e2e-spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/search-page/search-page.e2e-spec.ts b/e2e/search-page/search-page.e2e-spec.ts index fd7be52733..43e49ded87 100644 --- a/e2e/search-page/search-page.e2e-spec.ts +++ b/e2e/search-page/search-page.e2e-spec.ts @@ -17,7 +17,7 @@ fdescribe('protractor SearchPage', () => { }); }); - it('should not contain element ds-pagenotfound when navigating to existing page', () => { + it('should have right scope selected when navigating to page with query parameter', () => { const scope: promise.Promise = page.getRandomScopeOption(); scope.then((scopeString: string) => { page.navigateToSearchWithScopeParameter(scopeString); From 767c393a1d1a3f9e43cc2a7ff0cb4386d89be232 Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Wed, 4 Oct 2017 10:47:36 +0200 Subject: [PATCH 10/40] 44878: fixed description --- e2e/search-page/search-page.e2e-spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/search-page/search-page.e2e-spec.ts b/e2e/search-page/search-page.e2e-spec.ts index 43e49ded87..5403d695d2 100644 --- a/e2e/search-page/search-page.e2e-spec.ts +++ b/e2e/search-page/search-page.e2e-spec.ts @@ -17,7 +17,7 @@ fdescribe('protractor SearchPage', () => { }); }); - it('should have right scope selected when navigating to page with query parameter', () => { + it('should have right scope selected when navigating to page with scope parameter', () => { const scope: promise.Promise = page.getRandomScopeOption(); scope.then((scopeString: string) => { page.navigateToSearchWithScopeParameter(scopeString); From 9243b29b3e66cfede7b801f4e8876dff50d66360 Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Wed, 4 Oct 2017 11:28:33 +0200 Subject: [PATCH 11/40] 44878: removed f from describe --- e2e/search-page/search-page.e2e-spec.ts | 2 +- src/app/shared/search-form/search-form.component.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/search-page/search-page.e2e-spec.ts b/e2e/search-page/search-page.e2e-spec.ts index 5403d695d2..421781f585 100644 --- a/e2e/search-page/search-page.e2e-spec.ts +++ b/e2e/search-page/search-page.e2e-spec.ts @@ -2,7 +2,7 @@ import { ProtractorPage } from './search-page.po'; import { browser } from 'protractor'; import { promise } from 'selenium-webdriver'; -fdescribe('protractor SearchPage', () => { +describe('protractor SearchPage', () => { let page: ProtractorPage; beforeEach(() => { diff --git a/src/app/shared/search-form/search-form.component.spec.ts b/src/app/shared/search-form/search-form.component.spec.ts index 60942cd62d..0da50658a5 100644 --- a/src/app/shared/search-form/search-form.component.spec.ts +++ b/src/app/shared/search-form/search-form.component.spec.ts @@ -76,7 +76,7 @@ describe('SearchFormComponent', () => { expect(scopeSelect.value).toBe(testCommunity.id); })); - // fit('should call updateSearch when clicking the submit button with correct parameters', fakeAsync(() => { + // it('should call updateSearch when clicking the submit button with correct parameters', fakeAsync(() => { // comp.query = 'Test String' // fixture.detectChanges(); // spyOn(comp, 'updateSearch').and.callThrough(); From 91d2f4d1ef6e97d4a38faf044a8a87aae6f74429 Mon Sep 17 00:00:00 2001 From: William Welling Date: Wed, 4 Oct 2017 06:54:27 -0500 Subject: [PATCH 12/40] fixed lint errror --- src/app/shared/loading/loading.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/shared/loading/loading.component.ts b/src/app/shared/loading/loading.component.ts index 8bb47c20d6..3aa63af3ab 100644 --- a/src/app/shared/loading/loading.component.ts +++ b/src/app/shared/loading/loading.component.ts @@ -7,6 +7,6 @@ import { Component, Input } from '@angular/core'; }) export class LoadingComponent { - @Input() message: "Loading..."; + @Input() message: 'Loading...'; } From db890a65ed130ca17f4ac338bff415d4939c60ea Mon Sep 17 00:00:00 2001 From: William Welling Date: Wed, 4 Oct 2017 07:46:15 -0500 Subject: [PATCH 13/40] test showing RemoteData isLoading --- .../top-level-community-list.component.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/+home/top-level-community-list/top-level-community-list.component.html b/src/app/+home/top-level-community-list/top-level-community-list.component.html index 183be2605c..36c27ecf26 100644 --- a/src/app/+home/top-level-community-list/top-level-community-list.component.html +++ b/src/app/+home/top-level-community-list/top-level-community-list.component.html @@ -1,4 +1,5 @@ -
+ +

{{'home.top-level-communities.head' | translate}}

{{'home.top-level-communities.help' | translate}}

- \ No newline at end of file + + \ No newline at end of file From 3ab257697ae794fbe244162e274115386482c405 Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Wed, 4 Oct 2017 15:37:52 +0200 Subject: [PATCH 14/40] fixed an issue where the remote data state observable would only fire for the first time after the response had already returned --- .../builders/remote-data-build.service.ts | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/app/core/cache/builders/remote-data-build.service.ts b/src/app/core/cache/builders/remote-data-build.service.ts index 744ef7fb25..046250efda 100644 --- a/src/app/core/cache/builders/remote-data-build.service.ts +++ b/src/app/core/cache/builders/remote-data-build.service.ts @@ -49,12 +49,20 @@ export class RemoteDataBuildService { requestHrefObs.flatMap((requestHref) => this.responseCache.get(requestHref)).filter((entry) => hasValue(entry)) ); - const requestPending = requestObs.map((entry: RequestEntry) => entry.requestPending).distinctUntilChanged(); + const requestPending = requestObs + .map((entry: RequestEntry) => entry.requestPending) + .startWith(true) + .distinctUntilChanged(); - const responsePending = requestObs.map((entry: RequestEntry) => entry.responsePending).distinctUntilChanged(); + const responsePending = requestObs + .map((entry: RequestEntry) => entry.responsePending) + .startWith(false) + .distinctUntilChanged(); const isSuccessFul = responseCacheObs - .map((entry: ResponseCacheEntry) => entry.response.isSuccessful).distinctUntilChanged(); + .map((entry: ResponseCacheEntry) => entry.response.isSuccessful) + .startWith(false) + .distinctUntilChanged(); const errorMessage = responseCacheObs .filter((entry: ResponseCacheEntry) => !entry.response.isSuccessful) @@ -133,12 +141,20 @@ export class RemoteDataBuildService { const responseCacheObs = hrefObs.flatMap((href: string) => this.responseCache.get(href)) .filter((entry) => hasValue(entry)); - const requestPending = requestObs.map((entry: RequestEntry) => entry.requestPending).distinctUntilChanged(); + const requestPending = requestObs + .map((entry: RequestEntry) => entry.requestPending) + .startWith(true) + .distinctUntilChanged(); - const responsePending = requestObs.map((entry: RequestEntry) => entry.responsePending).distinctUntilChanged(); + const responsePending = requestObs + .map((entry: RequestEntry) => entry.responsePending) + .startWith(false) + .distinctUntilChanged(); const isSuccessFul = responseCacheObs - .map((entry: ResponseCacheEntry) => entry.response.isSuccessful).distinctUntilChanged(); + .map((entry: ResponseCacheEntry) => entry.response.isSuccessful) + .startWith(false) + .distinctUntilChanged(); const errorMessage = responseCacheObs .filter((entry: ResponseCacheEntry) => !entry.response.isSuccessful) From f432fcb73bcd338f72aa44e07c79beac78cf63c4 Mon Sep 17 00:00:00 2001 From: William Welling Date: Wed, 4 Oct 2017 10:42:38 -0500 Subject: [PATCH 15/40] updated postcss dependency --- package.json | 2 +- yarn.lock | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index f758eae6e8..02bddc485e 100644 --- a/package.json +++ b/package.json @@ -163,7 +163,7 @@ "node-sass": "4.5.3", "nodemon": "1.12.1", "npm-run-all": "4.1.1", - "postcss": "6.0.12", + "postcss": "6.0.13", "postcss-apply": "0.8.0", "postcss-cli": "4.1.1", "postcss-cssnext": "3.0.2", diff --git a/yarn.lock b/yarn.lock index 7ee4626496..054ae414d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5759,12 +5759,12 @@ postcss-zindex@^2.0.1: postcss "^5.0.4" uniqs "^2.0.0" -postcss@6.0.12, postcss@^6.0.0, postcss@^6.0.1, postcss@^6.0.11, postcss@^6.0.2, postcss@^6.0.3, postcss@^6.0.5, postcss@^6.0.6, postcss@^6.0.8: - version "6.0.12" - resolved "https://registry.yarnpkg.com/postcss/-/postcss-6.0.12.tgz#6b0155089d2d212f7bd6a0cecd4c58c007403535" +postcss@6.0.13: + version "6.0.13" + resolved "https://registry.yarnpkg.com/postcss/-/postcss-6.0.13.tgz#b9ecab4ee00c89db3ec931145bd9590bbf3f125f" dependencies: chalk "^2.1.0" - source-map "^0.5.7" + source-map "^0.6.1" supports-color "^4.4.0" postcss@^5.0.10, postcss@^5.0.11, postcss@^5.0.12, postcss@^5.0.13, postcss@^5.0.14, postcss@^5.0.16, postcss@^5.0.2, postcss@^5.0.4, postcss@^5.0.5, postcss@^5.0.6, postcss@^5.0.8, postcss@^5.2.16, postcss@^5.2.6: @@ -5776,6 +5776,14 @@ postcss@^5.0.10, postcss@^5.0.11, postcss@^5.0.12, postcss@^5.0.13, postcss@^5.0 source-map "^0.5.6" supports-color "^3.2.3" +postcss@^6.0.0, postcss@^6.0.1, postcss@^6.0.11, postcss@^6.0.2, postcss@^6.0.3, postcss@^6.0.5, postcss@^6.0.6, postcss@^6.0.8: + version "6.0.12" + resolved "https://registry.yarnpkg.com/postcss/-/postcss-6.0.12.tgz#6b0155089d2d212f7bd6a0cecd4c58c007403535" + dependencies: + chalk "^2.1.0" + source-map "^0.5.7" + supports-color "^4.4.0" + prelude-ls@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" @@ -6881,6 +6889,10 @@ source-map@^0.4.2, source-map@^0.4.4: dependencies: amdefine ">=0.0.4" +source-map@^0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" + source-map@~0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.2.0.tgz#dab73fbcfc2ba819b4de03bd6f6eaa48164b3f9d" From f595fda708c7c9a10a8ea9d0fbe55e45614f8460 Mon Sep 17 00:00:00 2001 From: William Welling Date: Wed, 4 Oct 2017 10:46:16 -0500 Subject: [PATCH 16/40] using fixed RemoteData isLoading --- src/app/+collection-page/collection-page.component.html | 8 ++++---- src/app/+community-page/community-page.component.html | 4 ++-- .../top-level-community-list.component.html | 4 +--- src/app/+item-page/full/full-item-page.component.html | 4 ++-- src/app/+item-page/simple/item-page.component.html | 4 ++-- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/app/+collection-page/collection-page.component.html b/src/app/+collection-page/collection-page.component.html index e9d4f29257..ee7d97f4c8 100644 --- a/src/app/+collection-page/collection-page.component.html +++ b/src/app/+collection-page/collection-page.component.html @@ -1,5 +1,5 @@
-
+
@@ -31,9 +31,9 @@ [title]="'collection.page.license'">
- +
-
+

{{'collection.page.browse.recent.head' | translate}}

- +
diff --git a/src/app/+community-page/community-page.component.html b/src/app/+community-page/community-page.component.html index e58b358c35..a55a597c74 100644 --- a/src/app/+community-page/community-page.component.html +++ b/src/app/+community-page/community-page.component.html @@ -1,4 +1,4 @@ -
+
@@ -24,4 +24,4 @@
- + diff --git a/src/app/+home/top-level-community-list/top-level-community-list.component.html b/src/app/+home/top-level-community-list/top-level-community-list.component.html index 36c27ecf26..bd5666122f 100644 --- a/src/app/+home/top-level-community-list/top-level-community-list.component.html +++ b/src/app/+home/top-level-community-list/top-level-community-list.component.html @@ -1,4 +1,3 @@ -

{{'home.top-level-communities.head' | translate}}

{{'home.top-level-communities.help' | translate}}

@@ -10,5 +9,4 @@ (paginationChange)="updatePage($event)">
- - \ No newline at end of file + \ No newline at end of file diff --git a/src/app/+item-page/full/full-item-page.component.html b/src/app/+item-page/full/full-item-page.component.html index ba8f7409d9..d6ff321794 100644 --- a/src/app/+item-page/full/full-item-page.component.html +++ b/src/app/+item-page/full/full-item-page.component.html @@ -1,4 +1,4 @@ -
+
- + diff --git a/src/app/+item-page/simple/item-page.component.html b/src/app/+item-page/simple/item-page.component.html index 455b014add..6b650b9476 100644 --- a/src/app/+item-page/simple/item-page.component.html +++ b/src/app/+item-page/simple/item-page.component.html @@ -1,4 +1,4 @@ -
+
@@ -21,4 +21,4 @@
- + From a9faab683321bd7ceef76bf9cee740f8460bff36 Mon Sep 17 00:00:00 2001 From: William Welling Date: Wed, 4 Oct 2017 10:51:48 -0500 Subject: [PATCH 17/40] refactor home to home-page --- .../home-news/home-news.component.html | 0 .../home-news/home-news.component.scss | 0 .../home-news/home-news.component.ts | 0 src/app/+home-page/home-page-routing.module.ts | 13 +++++++++++++ .../home-page.component.html} | 0 .../home-page.component.scss} | 0 src/app/+home-page/home-page.component.ts | 10 ++++++++++ .../home-page.module.ts} | 10 +++++----- .../top-level-community-list.component.html | 0 .../top-level-community-list.component.scss | 0 .../top-level-community-list.component.ts | 0 src/app/+home/home-routing.module.ts | 13 ------------- src/app/+home/home.component.ts | 10 ---------- src/app/app-routing.module.ts | 2 +- 14 files changed, 29 insertions(+), 29 deletions(-) rename src/app/{+home => +home-page}/home-news/home-news.component.html (100%) rename src/app/{+home => +home-page}/home-news/home-news.component.scss (100%) rename src/app/{+home => +home-page}/home-news/home-news.component.ts (100%) create mode 100644 src/app/+home-page/home-page-routing.module.ts rename src/app/{+home/home.component.html => +home-page/home-page.component.html} (100%) rename src/app/{+home/home.component.scss => +home-page/home-page.component.scss} (100%) create mode 100644 src/app/+home-page/home-page.component.ts rename src/app/{+home/home.module.ts => +home-page/home-page.module.ts} (70%) rename src/app/{+home => +home-page}/top-level-community-list/top-level-community-list.component.html (100%) rename src/app/{+home => +home-page}/top-level-community-list/top-level-community-list.component.scss (100%) rename src/app/{+home => +home-page}/top-level-community-list/top-level-community-list.component.ts (100%) delete mode 100644 src/app/+home/home-routing.module.ts delete mode 100644 src/app/+home/home.component.ts diff --git a/src/app/+home/home-news/home-news.component.html b/src/app/+home-page/home-news/home-news.component.html similarity index 100% rename from src/app/+home/home-news/home-news.component.html rename to src/app/+home-page/home-news/home-news.component.html diff --git a/src/app/+home/home-news/home-news.component.scss b/src/app/+home-page/home-news/home-news.component.scss similarity index 100% rename from src/app/+home/home-news/home-news.component.scss rename to src/app/+home-page/home-news/home-news.component.scss diff --git a/src/app/+home/home-news/home-news.component.ts b/src/app/+home-page/home-news/home-news.component.ts similarity index 100% rename from src/app/+home/home-news/home-news.component.ts rename to src/app/+home-page/home-news/home-news.component.ts diff --git a/src/app/+home-page/home-page-routing.module.ts b/src/app/+home-page/home-page-routing.module.ts new file mode 100644 index 0000000000..e68b633a6d --- /dev/null +++ b/src/app/+home-page/home-page-routing.module.ts @@ -0,0 +1,13 @@ +import { NgModule } from '@angular/core'; +import { RouterModule } from '@angular/router'; + +import { HomePageComponent } from './home-page.component'; + +@NgModule({ + imports: [ + RouterModule.forChild([ + { path: '', component: HomePageComponent, pathMatch: 'full' } + ]) + ] +}) +export class HomePageRoutingModule { } diff --git a/src/app/+home/home.component.html b/src/app/+home-page/home-page.component.html similarity index 100% rename from src/app/+home/home.component.html rename to src/app/+home-page/home-page.component.html diff --git a/src/app/+home/home.component.scss b/src/app/+home-page/home-page.component.scss similarity index 100% rename from src/app/+home/home.component.scss rename to src/app/+home-page/home-page.component.scss diff --git a/src/app/+home-page/home-page.component.ts b/src/app/+home-page/home-page.component.ts new file mode 100644 index 0000000000..ad25ec0155 --- /dev/null +++ b/src/app/+home-page/home-page.component.ts @@ -0,0 +1,10 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'ds-home-page', + styleUrls: ['./home-page.component.scss'], + templateUrl: './home-page.component.html' +}) +export class HomePageComponent { + +} diff --git a/src/app/+home/home.module.ts b/src/app/+home-page/home-page.module.ts similarity index 70% rename from src/app/+home/home.module.ts rename to src/app/+home-page/home-page.module.ts index 7a68629deb..45c460c89c 100644 --- a/src/app/+home/home.module.ts +++ b/src/app/+home-page/home-page.module.ts @@ -2,8 +2,8 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { SharedModule } from '../shared/shared.module'; -import { HomeComponent } from './home.component'; -import { HomeRoutingModule } from './home-routing.module'; +import { HomePageComponent } from './home-page.component'; +import { HomePageRoutingModule } from './home-page-routing.module'; import { TopLevelCommunityListComponent } from './top-level-community-list/top-level-community-list.component'; import { HomeNewsComponent } from './home-news/home-news.component'; @@ -11,14 +11,14 @@ import { HomeNewsComponent } from './home-news/home-news.component'; imports: [ CommonModule, SharedModule, - HomeRoutingModule + HomePageRoutingModule ], declarations: [ - HomeComponent, + HomePageComponent, TopLevelCommunityListComponent, HomeNewsComponent ] }) -export class HomeModule { +export class HomePageModule { } diff --git a/src/app/+home/top-level-community-list/top-level-community-list.component.html b/src/app/+home-page/top-level-community-list/top-level-community-list.component.html similarity index 100% rename from src/app/+home/top-level-community-list/top-level-community-list.component.html rename to src/app/+home-page/top-level-community-list/top-level-community-list.component.html diff --git a/src/app/+home/top-level-community-list/top-level-community-list.component.scss b/src/app/+home-page/top-level-community-list/top-level-community-list.component.scss similarity index 100% rename from src/app/+home/top-level-community-list/top-level-community-list.component.scss rename to src/app/+home-page/top-level-community-list/top-level-community-list.component.scss diff --git a/src/app/+home/top-level-community-list/top-level-community-list.component.ts b/src/app/+home-page/top-level-community-list/top-level-community-list.component.ts similarity index 100% rename from src/app/+home/top-level-community-list/top-level-community-list.component.ts rename to src/app/+home-page/top-level-community-list/top-level-community-list.component.ts diff --git a/src/app/+home/home-routing.module.ts b/src/app/+home/home-routing.module.ts deleted file mode 100644 index 9bc4619f74..0000000000 --- a/src/app/+home/home-routing.module.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { NgModule } from '@angular/core'; -import { RouterModule } from '@angular/router'; - -import { HomeComponent } from './home.component'; - -@NgModule({ - imports: [ - RouterModule.forChild([ - { path: '', component: HomeComponent, pathMatch: 'full' } - ]) - ] -}) -export class HomeRoutingModule { } diff --git a/src/app/+home/home.component.ts b/src/app/+home/home.component.ts deleted file mode 100644 index d1222b8ae0..0000000000 --- a/src/app/+home/home.component.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Component } from '@angular/core'; - -@Component({ - selector: 'ds-home', - styleUrls: ['./home.component.scss'], - templateUrl: './home.component.html' -}) -export class HomeComponent { - -} diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index fb793df7dc..b3b8eacfce 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -7,7 +7,7 @@ import { PageNotFoundComponent } from './pagenotfound/pagenotfound.component'; imports: [ RouterModule.forRoot([ { path: '', redirectTo: '/home', pathMatch: 'full' }, - { path: 'home', loadChildren: './+home/home.module#HomeModule' }, + { path: 'home', loadChildren: './+home-page/home-page.module#HomePageModule' }, { path: 'communities', loadChildren: './+community-page/community-page.module#CommunityPageModule' }, { path: 'collections', loadChildren: './+collection-page/collection-page.module#CollectionPageModule' }, { path: 'items', loadChildren: './+item-page/item-page.module#ItemPageModule' }, From 7937a47aa5a20f43eeef9ca74eb9e129b1a5b504 Mon Sep 17 00:00:00 2001 From: William Welling Date: Wed, 4 Oct 2017 14:17:19 -0500 Subject: [PATCH 18/40] added error component and coverage for new components --- .../collection-page.component.html | 2 + .../community-page.component.html | 1 + .../top-level-community-list.component.html | 1 + .../full/full-item-page.component.html | 1 + .../simple/item-page.component.html | 1 + src/app/app.module.ts | 1 - src/app/shared/error/error.component.html | 1 + src/app/shared/error/error.component.scss | 0 src/app/shared/error/error.component.spec.ts | 45 +++++++++++++++++++ src/app/shared/error/error.component.ts | 12 +++++ .../shared/loading/loading.component.spec.ts | 45 +++++++++++++++++++ src/app/shared/loading/loading.component.ts | 2 +- src/app/shared/shared.module.ts | 32 ++++++------- webpack/webpack.test.js | 14 ++++-- 14 files changed, 138 insertions(+), 20 deletions(-) create mode 100644 src/app/shared/error/error.component.html create mode 100644 src/app/shared/error/error.component.scss create mode 100644 src/app/shared/error/error.component.spec.ts create mode 100644 src/app/shared/error/error.component.ts create mode 100644 src/app/shared/loading/loading.component.spec.ts diff --git a/src/app/+collection-page/collection-page.component.html b/src/app/+collection-page/collection-page.component.html index ee7d97f4c8..8a8f2f0aad 100644 --- a/src/app/+collection-page/collection-page.component.html +++ b/src/app/+collection-page/collection-page.component.html @@ -31,6 +31,7 @@ [title]="'collection.page.license'">
+
@@ -42,5 +43,6 @@ [hideGear]="false">
+
diff --git a/src/app/+community-page/community-page.component.html b/src/app/+community-page/community-page.component.html index a55a597c74..f29fa364fb 100644 --- a/src/app/+community-page/community-page.component.html +++ b/src/app/+community-page/community-page.component.html @@ -24,4 +24,5 @@
+ diff --git a/src/app/+home-page/top-level-community-list/top-level-community-list.component.html b/src/app/+home-page/top-level-community-list/top-level-community-list.component.html index bd5666122f..c8a889a4f7 100644 --- a/src/app/+home-page/top-level-community-list/top-level-community-list.component.html +++ b/src/app/+home-page/top-level-community-list/top-level-community-list.component.html @@ -9,4 +9,5 @@ (paginationChange)="updatePage($event)">
+ \ No newline at end of file diff --git a/src/app/+item-page/full/full-item-page.component.html b/src/app/+item-page/full/full-item-page.component.html index d6ff321794..ccd8ca3932 100644 --- a/src/app/+item-page/full/full-item-page.component.html +++ b/src/app/+item-page/full/full-item-page.component.html @@ -17,4 +17,5 @@
+ diff --git a/src/app/+item-page/simple/item-page.component.html b/src/app/+item-page/simple/item-page.component.html index 6b650b9476..fe7e1138e6 100644 --- a/src/app/+item-page/simple/item-page.component.html +++ b/src/app/+item-page/simple/item-page.component.html @@ -21,4 +21,5 @@
+ diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 3ec0cdebab..a80a173297 100755 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,7 +1,6 @@ import { NgModule } from '@angular/core'; import { CommonModule, APP_BASE_HREF } from '@angular/common'; import { HttpModule } from '@angular/http'; -import { FormsModule } from '@angular/forms'; import { RouterModule } from '@angular/router'; import { EffectsModule } from '@ngrx/effects'; diff --git a/src/app/shared/error/error.component.html b/src/app/shared/error/error.component.html new file mode 100644 index 0000000000..fb5224e1ac --- /dev/null +++ b/src/app/shared/error/error.component.html @@ -0,0 +1 @@ +
{{ message }}
\ No newline at end of file diff --git a/src/app/shared/error/error.component.scss b/src/app/shared/error/error.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/shared/error/error.component.spec.ts b/src/app/shared/error/error.component.spec.ts new file mode 100644 index 0000000000..078aa95592 --- /dev/null +++ b/src/app/shared/error/error.component.spec.ts @@ -0,0 +1,45 @@ +import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { DebugElement } from '@angular/core'; + +import { ErrorComponent } from './error.component'; + +describe('ErrorComponent (inline template)', () => { + + let comp: ErrorComponent; + let fixture: ComponentFixture; + let de: DebugElement; + let el: HTMLElement; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ErrorComponent ], // declare the test component + }).compileComponents(); // compile template and css + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ErrorComponent); + + comp = fixture.componentInstance; // ErrorComponent test instance + + // query for the title
by CSS element selector + de = fixture.debugElement.query(By.css('div')); + el = de.nativeElement; + }); + + it('should create', () => { + expect(comp).toBeTruthy(); + }); + + it('should display default message', () => { + fixture.detectChanges(); + expect(el.textContent).toContain(comp.message); + }); + + it('should display input message', () => { + comp.message = 'Test Message'; + fixture.detectChanges(); + expect(el.textContent).toContain('Test Message'); + }); + +}); diff --git a/src/app/shared/error/error.component.ts b/src/app/shared/error/error.component.ts new file mode 100644 index 0000000000..b65979f7b0 --- /dev/null +++ b/src/app/shared/error/error.component.ts @@ -0,0 +1,12 @@ +import { Component, Input } from '@angular/core'; + +@Component({ + selector: 'ds-error', + styleUrls: ['./error.component.scss'], + templateUrl: './error.component.html' +}) +export class ErrorComponent { + + @Input() message = 'Error...'; + +} diff --git a/src/app/shared/loading/loading.component.spec.ts b/src/app/shared/loading/loading.component.spec.ts new file mode 100644 index 0000000000..45583ed198 --- /dev/null +++ b/src/app/shared/loading/loading.component.spec.ts @@ -0,0 +1,45 @@ +import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { DebugElement } from '@angular/core'; + +import { LoadingComponent } from './loading.component'; + +describe('LoadingComponent (inline template)', () => { + + let comp: LoadingComponent; + let fixture: ComponentFixture; + let de: DebugElement; + let el: HTMLElement; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ LoadingComponent ], // declare the test component + }).compileComponents(); // compile template and css + })); + + beforeEach(() => { + fixture = TestBed.createComponent(LoadingComponent); + + comp = fixture.componentInstance; // LoadingComponent test instance + + // query for the title
by CSS element selector + de = fixture.debugElement.query(By.css('div')); + el = de.nativeElement; + }); + + it('should create', () => { + expect(comp).toBeTruthy(); + }); + + it('should display default message', () => { + fixture.detectChanges(); + expect(el.textContent).toContain(comp.message); + }); + + it('should display input message', () => { + comp.message = 'Test Message'; + fixture.detectChanges(); + expect(el.textContent).toContain('Test Message'); + }); + +}); diff --git a/src/app/shared/loading/loading.component.ts b/src/app/shared/loading/loading.component.ts index 3aa63af3ab..6bc7d99f4b 100644 --- a/src/app/shared/loading/loading.component.ts +++ b/src/app/shared/loading/loading.component.ts @@ -7,6 +7,6 @@ import { Component, Input } from '@angular/core'; }) export class LoadingComponent { - @Input() message: 'Loading...'; + @Input() message = 'Loading...'; } diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 669f490c13..21ca8c51c4 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -9,25 +9,26 @@ import { TranslateModule } from '@ngx-translate/core'; import { NgxPaginationModule } from 'ngx-pagination'; -import { PaginationComponent } from './pagination/pagination.component'; +import { EnumKeysPipe } from './utils/enum-keys-pipe'; import { FileSizePipe } from './utils/file-size-pipe'; -import { ThumbnailComponent } from '../thumbnail/thumbnail.component'; import { SafeUrlPipe } from './utils/safe-url-pipe'; +import { TruncatePipe } from './utils/truncate.pipe'; +import { CollectionListElementComponent } from '../object-list/collection-list-element/collection-list-element.component'; import { ComcolPageContentComponent } from './comcol-page-content/comcol-page-content.component'; import { ComcolPageHeaderComponent } from './comcol-page-header/comcol-page-header.component'; import { ComcolPageLogoComponent } from './comcol-page-logo/comcol-page-logo.component'; -import { EnumKeysPipe } from './utils/enum-keys-pipe'; +import { CommunityListElementComponent } from '../object-list/community-list-element/community-list-element.component'; +import { ErrorComponent } from './error/error.component'; +import { LoadingComponent } from './loading/loading.component'; +import { ItemListElementComponent } from '../object-list/item-list-element/item-list-element.component'; import { ObjectListComponent } from './object-list/object-list.component'; import { ObjectListElementComponent } from '../object-list/object-list-element/object-list-element.component'; -import { ItemListElementComponent } from '../object-list/item-list-element/item-list-element.component'; -import { CommunityListElementComponent } from '../object-list/community-list-element/community-list-element.component'; -import { CollectionListElementComponent } from '../object-list/collection-list-element/collection-list-element.component'; -import { TruncatePipe } from './utils/truncate.pipe'; -import { WrapperListElementComponent } from '../object-list/wrapper-list-element/wrapper-list-element.component'; +import { PaginationComponent } from './pagination/pagination.component'; +import { ThumbnailComponent } from '../thumbnail/thumbnail.component'; import { SearchResultListElementComponent } from '../object-list/search-result-list-element/search-result-list-element.component'; import { SearchFormComponent } from './search-form/search-form.component'; -import { LoadingComponent } from './loading/loading.component'; +import { WrapperListElementComponent } from '../object-list/wrapper-list-element/wrapper-list-element.component'; const MODULES = [ // Do NOT include UniversalModule, HttpModule, or JsonpModule here @@ -42,31 +43,32 @@ const MODULES = [ const PIPES = [ // put shared pipes here + EnumKeysPipe, FileSizePipe, SafeUrlPipe, - EnumKeysPipe, TruncatePipe ]; const COMPONENTS = [ // put shared components here - PaginationComponent, - ThumbnailComponent, ComcolPageContentComponent, ComcolPageHeaderComponent, ComcolPageLogoComponent, + ErrorComponent, + LoadingComponent, ObjectListComponent, ObjectListElementComponent, - WrapperListElementComponent, + PaginationComponent, SearchFormComponent, - LoadingComponent + ThumbnailComponent, + WrapperListElementComponent ]; const ENTRY_COMPONENTS = [ // put shared entry components (components that are created dynamically) here - ItemListElementComponent, CollectionListElementComponent, CommunityListElementComponent, + ItemListElementComponent, SearchResultListElementComponent ]; diff --git a/webpack/webpack.test.js b/webpack/webpack.test.js index a353dec9d6..818e348c7e 100644 --- a/webpack/webpack.test.js +++ b/webpack/webpack.test.js @@ -5,9 +5,10 @@ const { /** * Webpack Plugins */ -const ProvidePlugin = require('webpack/lib/ProvidePlugin'); +const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin'); const DefinePlugin = require('webpack/lib/DefinePlugin'); const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin'); +const ProvidePlugin = require('webpack/lib/ProvidePlugin'); /** * Webpack Constants @@ -75,8 +76,9 @@ module.exports = function (options) { loader: 'source-map-loader', exclude: [ // these packages have problems with their sourcemaps - root('node_modules/rxjs'), - root('node_modules/@angular') + root('node_modules/@angular'), + root('node_modules/@nguniversal'), + root('node_modules/rxjs') ] }, @@ -221,6 +223,12 @@ module.exports = function (options) { */ plugins: [ + new ContextReplacementPlugin( + /angular(\\|\/)core(\\|\/)@angular/, + root('./src'), + {} + ), + /** * Plugin: DefinePlugin * Description: Define free variables. From 45ca74410c21fad99fa56050e49915d34d8e134f Mon Sep 17 00:00:00 2001 From: William Welling Date: Wed, 4 Oct 2017 15:39:08 -0500 Subject: [PATCH 19/40] simple loading animation and fade in and out animations --- rollup.config.js | 42 +++++------ .../collection-page.component.html | 4 +- .../collection-page.component.ts | 11 ++- .../community-page.component.html | 2 +- .../community-page.component.ts | 3 + ...ty-page-sub-collection-list.component.html | 4 +- ...nity-page-sub-collection-list.component.ts | 3 + .../top-level-community-list.component.html | 2 +- .../top-level-community-list.component.ts | 4 +- .../full/full-item-page.component.html | 2 +- .../full/full-item-page.component.ts | 5 ++ .../simple/item-page.component.html | 2 +- .../+item-page/simple/item-page.component.ts | 5 ++ .../+search-page/search-page.component.html | 7 +- src/app/+search-page/search-page.component.ts | 12 ++-- .../search-results.component.html | 8 ++- src/app/app.component.html | 26 +++---- src/app/browser-app.module.ts | 2 + .../object-list/object-list.component.html | 5 +- src/app/server-app.module.ts | 2 + src/app/shared/animations/fade.ts | 24 +++++++ src/app/shared/error/error.component.html | 4 +- src/app/shared/error/error.component.spec.ts | 4 +- src/app/shared/loading/loading.component.html | 16 ++++- src/app/shared/loading/loading.component.scss | 72 +++++++++++++++++++ .../shared/loading/loading.component.spec.ts | 4 +- .../object-list/object-list.component.ts | 5 +- 27 files changed, 222 insertions(+), 58 deletions(-) create mode 100644 src/app/shared/animations/fade.ts diff --git a/rollup.config.js b/rollup.config.js index a47b46dd37..caa63ac03e 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,20 +1,22 @@ -import nodeResolve from 'rollup-plugin-node-resolve' -import commonjs from 'rollup-plugin-commonjs'; -import uglify from 'rollup-plugin-uglify' - -export default { - entry: 'dist/client.js', - dest: 'dist/client.js', - sourceMap: false, - format: 'iife', - plugins: [ - nodeResolve({ - jsnext: true, - module: true - }), - commonjs({ - include: 'node_modules/rxjs/**' - }), - uglify() - ] -} +import nodeResolve from 'rollup-plugin-node-resolve' +import commonjs from 'rollup-plugin-commonjs'; +import uglify from 'rollup-plugin-uglify' + +export default { + input: 'dist/client.js', + output: { + file: 'dist/client.js', + format: 'iife', + }, + sourceMap: false, + plugins: [ + nodeResolve({ + jsnext: true, + module: true + }), + commonjs({ + include: 'node_modules/rxjs/**' + }), + uglify() + ] +} diff --git a/src/app/+collection-page/collection-page.component.html b/src/app/+collection-page/collection-page.component.html index 8a8f2f0aad..a4e81cd272 100644 --- a/src/app/+collection-page/collection-page.component.html +++ b/src/app/+collection-page/collection-page.component.html @@ -1,5 +1,5 @@
-
+
@@ -34,7 +34,7 @@
-
+

{{'collection.page.browse.recent.head' | translate}}

; diff --git a/src/app/+community-page/community-page.component.html b/src/app/+community-page/community-page.component.html index f29fa364fb..1acaf2d89e 100644 --- a/src/app/+community-page/community-page.component.html +++ b/src/app/+community-page/community-page.component.html @@ -1,4 +1,4 @@ -
+
diff --git a/src/app/+community-page/community-page.component.ts b/src/app/+community-page/community-page.component.ts index 2bd19b0f06..d1d1081757 100644 --- a/src/app/+community-page/community-page.component.ts +++ b/src/app/+community-page/community-page.component.ts @@ -9,10 +9,13 @@ import { RemoteData } from '../core/data/remote-data'; import { CommunityDataService } from '../core/data/community-data.service'; import { hasValue } from '../shared/empty.util'; +import { fadeInOut } from '../shared/animations/fade'; + @Component({ selector: 'ds-community-page', styleUrls: ['./community-page.component.scss'], templateUrl: './community-page.component.html', + animations:[fadeInOut] }) export class CommunityPageComponent implements OnInit, OnDestroy { communityData: RemoteData; diff --git a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html index f1f05a0467..82ae6bd3e1 100644 --- a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html +++ b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.html @@ -1,4 +1,4 @@ -
+

{{'community.sub-collection-list.head' | translate}}

  • @@ -9,3 +9,5 @@
+ + diff --git a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.ts b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.ts index caa764c39f..618890a60c 100644 --- a/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.ts +++ b/src/app/+community-page/sub-collection-list/community-page-sub-collection-list.component.ts @@ -4,10 +4,13 @@ import { CollectionDataService } from '../../core/data/collection-data.service'; import { RemoteData } from '../../core/data/remote-data'; import { Collection } from '../../core/shared/collection.model'; +import { fadeIn } from '../../shared/animations/fade'; + @Component({ selector: 'ds-community-page-sub-collection-list', styleUrls: ['./community-page-sub-collection-list.component.scss'], templateUrl: './community-page-sub-collection-list.component.html', + animations:[fadeIn] }) export class CommunityPageSubCollectionListComponent implements OnInit { subCollections: RemoteData; diff --git a/src/app/+home-page/top-level-community-list/top-level-community-list.component.html b/src/app/+home-page/top-level-community-list/top-level-community-list.component.html index c8a889a4f7..69df3b99d0 100644 --- a/src/app/+home-page/top-level-community-list/top-level-community-list.component.html +++ b/src/app/+home-page/top-level-community-list/top-level-community-list.component.html @@ -1,4 +1,4 @@ -
+

{{'home.top-level-communities.head' | translate}}

{{'home.top-level-communities.help' | translate}}

; config: PaginationComponentOptions; diff --git a/src/app/+item-page/full/full-item-page.component.html b/src/app/+item-page/full/full-item-page.component.html index ccd8ca3932..bc8ee3f3a8 100644 --- a/src/app/+item-page/full/full-item-page.component.html +++ b/src/app/+item-page/full/full-item-page.component.html @@ -1,4 +1,4 @@ -
+
- - + + diff --git a/src/app/object-list/object-list.component.html b/src/app/object-list/object-list.component.html index 6ef14d103c..84c800fef4 100644 --- a/src/app/object-list/object-list.component.html +++ b/src/app/object-list/object-list.component.html @@ -15,6 +15,6 @@ - - + + diff --git a/src/app/shared/error/error.component.spec.ts b/src/app/shared/error/error.component.spec.ts index 73a4e5a26e..a0226f7f86 100644 --- a/src/app/shared/error/error.component.spec.ts +++ b/src/app/shared/error/error.component.spec.ts @@ -2,6 +2,10 @@ import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { DebugElement } from '@angular/core'; +import { TranslateModule, TranslateLoader, TranslateService } from '@ngx-translate/core'; + +import { MockTranslateLoader } from '../testing/mock-translate-loader'; + import { ErrorComponent } from './error.component'; describe('ErrorComponent (inline template)', () => { @@ -13,7 +17,16 @@ describe('ErrorComponent (inline template)', () => { beforeEach(async(() => { TestBed.configureTestingModule({ + imports: [ + TranslateModule.forRoot({ + loader: { + provide: TranslateLoader, + useClass: MockTranslateLoader + } + }), + ], declarations: [ ErrorComponent ], // declare the test component + providers: [ TranslateService ] }).compileComponents(); // compile template and css })); diff --git a/src/app/shared/error/error.component.ts b/src/app/shared/error/error.component.ts index b65979f7b0..08d06c31d6 100644 --- a/src/app/shared/error/error.component.ts +++ b/src/app/shared/error/error.component.ts @@ -1,5 +1,9 @@ import { Component, Input } from '@angular/core'; +import { TranslateService } from '@ngx-translate/core'; + +import { Subscription } from 'rxjs/Subscription'; + @Component({ selector: 'ds-error', styleUrls: ['./error.component.scss'], @@ -9,4 +13,24 @@ export class ErrorComponent { @Input() message = 'Error...'; + private subscription: Subscription; + + constructor(private translate: TranslateService) { + + } + + ngOnInit() { + if (this.message === undefined) { + this.subscription = this.translate.get('error.default').subscribe((message: string) => { + this.message = message; + }); + } + } + + ngOnDestroy() { + if (this.subscription !== undefined) { + this.subscription.unsubscribe(); + } + } + } diff --git a/src/app/shared/loading/loading.component.scss b/src/app/shared/loading/loading.component.scss index bb98849cae..c9ccb5b2fa 100644 --- a/src/app/shared/loading/loading.component.scss +++ b/src/app/shared/loading/loading.component.scss @@ -8,7 +8,8 @@ span { } span[class*="l-"] { - height: 4px; width: 4px; + height: 4px; + width: 4px; background: #000; display: inline-block; margin: 12px 2px; diff --git a/src/app/shared/loading/loading.component.spec.ts b/src/app/shared/loading/loading.component.spec.ts index ed39708fbe..0b758b8218 100644 --- a/src/app/shared/loading/loading.component.spec.ts +++ b/src/app/shared/loading/loading.component.spec.ts @@ -2,6 +2,10 @@ import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { DebugElement } from '@angular/core'; +import { TranslateModule, TranslateLoader, TranslateService } from '@ngx-translate/core'; + +import { MockTranslateLoader } from '../testing/mock-translate-loader'; + import { LoadingComponent } from './loading.component'; describe('LoadingComponent (inline template)', () => { @@ -13,7 +17,16 @@ describe('LoadingComponent (inline template)', () => { beforeEach(async(() => { TestBed.configureTestingModule({ + imports: [ + TranslateModule.forRoot({ + loader: { + provide: TranslateLoader, + useClass: MockTranslateLoader + } + }), + ], declarations: [ LoadingComponent ], // declare the test component + providers: [ TranslateService ] }).compileComponents(); // compile template and css })); diff --git a/src/app/shared/loading/loading.component.ts b/src/app/shared/loading/loading.component.ts index 6bc7d99f4b..8276ab574a 100644 --- a/src/app/shared/loading/loading.component.ts +++ b/src/app/shared/loading/loading.component.ts @@ -1,12 +1,36 @@ -import { Component, Input } from '@angular/core'; +import { Component, Input, OnDestroy, OnInit } from '@angular/core'; + +import { TranslateService } from '@ngx-translate/core'; + +import { Subscription } from 'rxjs/Subscription'; @Component({ selector: 'ds-loading', styleUrls: ['./loading.component.scss'], templateUrl: './loading.component.html' }) -export class LoadingComponent { +export class LoadingComponent implements OnDestroy, OnInit { - @Input() message = 'Loading...'; + @Input() message: string; + + private subscription: Subscription; + + constructor(private translate: TranslateService) { + + } + + ngOnInit() { + if (this.message === undefined) { + this.subscription = this.translate.get('loading.default').subscribe((message: string) => { + this.message = message; + }); + } + } + + ngOnDestroy() { + if (this.subscription !== undefined) { + this.subscription.unsubscribe(); + } + } } From fca61830c3dc7947cdfa4d47d138e28db2cd4803 Mon Sep 17 00:00:00 2001 From: William Welling Date: Thu, 5 Oct 2017 08:28:06 -0500 Subject: [PATCH 27/40] removed async pipe against local variable --- src/app/+item-page/full/full-item-page.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/+item-page/full/full-item-page.component.html b/src/app/+item-page/full/full-item-page.component.html index 6a209566b7..7b25f88753 100644 --- a/src/app/+item-page/full/full-item-page.component.html +++ b/src/app/+item-page/full/full-item-page.component.html @@ -1,6 +1,6 @@
- +