From 4ac23bd6769d216471fc6fc6c7d12636bd5b8a60 Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Tue, 3 Oct 2017 11:13:58 +0200 Subject: [PATCH 1/8] 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 2/8] 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 ad59cb3276283da702dc62768eec4146149209d9 Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Tue, 3 Oct 2017 15:49:26 +0200 Subject: [PATCH 3/8] 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 4/8] 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 16cff501733c4386e294efef4b2d4e7ab11c144c Mon Sep 17 00:00:00 2001 From: Lotte Hofstede Date: Wed, 4 Oct 2017 10:44:06 +0200 Subject: [PATCH 5/8] 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 6/8] 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 7/8] 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 8/8] 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();