From 5f8b41411a97dcadb1e1a044d26076f10a5088a8 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Wed, 11 Apr 2018 09:03:03 +0100 Subject: [PATCH] [NO-ISSUE] RE enable failing test (#3168) * restore viewer test * fix content node selector breadcrumb tests * fix skipped test * notification service uncomment test * remove duplicated test exclude dialog test --- ...content-node-selector-panel.component.html | 8 +- ...tent-node-selector-panel.component.spec.ts | 89 +++---------------- .../content-node-selector-panel.component.ts | 70 +++++++-------- .../document-list.component.spec.ts | 9 -- .../services/document-list.service.spec.ts | 2 +- .../services/document-list.service.ts | 8 +- .../infinite-pagination.component.html | 2 +- .../infinite-pagination.component.ts | 3 +- .../paginated-component.interface.ts | 4 +- .../services/notification.service.spec.ts | 4 +- .../components/viewer.component.spec.ts | 2 +- 11 files changed, 58 insertions(+), 143 deletions(-) diff --git a/lib/content-services/content-node-selector/content-node-selector-panel.component.html b/lib/content-services/content-node-selector/content-node-selector-panel.component.html index 125a2fa5f8..be04d5244c 100644 --- a/lib/content-services/content-node-selector/content-node-selector-panel.component.html +++ b/lib/content-services/content-node-selector/content-node-selector-panel.component.html @@ -33,10 +33,10 @@ - + {{ 'NODE_SELECTOR.SEARCH_RESULTS' | translate }} - {{ 'ADF-DOCUMENT-LIST.LAYOUT.LOAD_MORE' | translate }} diff --git a/lib/content-services/content-node-selector/content-node-selector-panel.component.spec.ts b/lib/content-services/content-node-selector/content-node-selector-panel.component.spec.ts index b9282bd8ba..4ce12c9cd5 100644 --- a/lib/content-services/content-node-selector/content-node-selector-panel.component.spec.ts +++ b/lib/content-services/content-node-selector/content-node-selector-panel.component.spec.ts @@ -132,23 +132,9 @@ describe('ContentNodeSelectorComponent', () => { component.chosenNode = expectedNode; }); - - it('should update skipCount on folder loaded', () => { - component.skipCount = 8; - - component.onFolderLoaded({ - list: { - pagination: { - skipCount: 10 - } - } - }); - - expect(component.skipCount).toBe(10, 'skipCount is updated'); - }); }); - xdescribe('Breadcrumbs', () => { + describe('Breadcrumbs', () => { let documentListService, sitesService, @@ -498,7 +484,7 @@ describe('ContentNodeSelectorComponent', () => { expect(component.folderIdToShow).toBe('cat-girl-nuku-nuku', 'back to the folder in which the search was performed'); })); - xit('should clear the search field, nodes and chosenNode on folder navigation in the results list', fakeAsync(() => { + it('should clear the search field, nodes and chosenNode on folder navigation in the results list', fakeAsync(() => { spyOn(component, 'clearSearch').and.callThrough(); typeToSearchBox('a'); @@ -563,7 +549,7 @@ describe('ContentNodeSelectorComponent', () => { expect(documentList.componentInstance.imageResolver).toBe(resolver); }); - xit('should show the result list when search was performed', (done) => { + it('should show the result list when search was performed', (done) => { typeToSearchBox(); setTimeout(() => { @@ -577,7 +563,7 @@ describe('ContentNodeSelectorComponent', () => { }, 300); }); - xit('should highlight the results when search was performed in the next timeframe', fakeAsync(() => { + it('should highlight the results when search was performed in the next timeframe', fakeAsync(() => { spyOn(component.highlighter, 'highlight'); typeToSearchBox('shenron'); @@ -588,12 +574,10 @@ describe('ContentNodeSelectorComponent', () => { tick(debounceSearch); - expect(component.highlighter.highlight).not.toHaveBeenCalled(); - expect(component.highlighter.highlight).toHaveBeenCalledWith('shenron'); })); - xit('should show the default text instead of result list if search was cleared', (done) => { + it('should show the default text instead of result list if search was cleared', (done) => { typeToSearchBox(); setTimeout(() => { @@ -614,7 +598,7 @@ describe('ContentNodeSelectorComponent', () => { }, 300); }); - xit('should reload the original documentlist when clearing the search input', fakeAsync(() => { + it('should reload the original documentlist when clearing the search input', fakeAsync(() => { typeToSearchBox('shenron'); tick(debounceSearch); @@ -631,7 +615,7 @@ describe('ContentNodeSelectorComponent', () => { expect(documentList.componentInstance.currentFolderId).toBe('cat-girl-nuku-nuku'); })); - xit('should set the folderIdToShow to the default "currentFolderId" if siteId is undefined', (done) => { + it('should set the folderIdToShow to the default "currentFolderId" if siteId is undefined', (done) => { component.siteChanged( { entry: { guid: 'Kame-Sennin Muten Roshi' } }); fixture.detectChanges(); @@ -655,49 +639,13 @@ describe('ContentNodeSelectorComponent', () => { expect(pagination).toBeNull(); }); - xit('should be shown when diplaying search results', fakeAsync(() => { - typeToSearchBox('shenron'); - - tick(debounceSearch); - - respondWithSearchResults(ONE_FOLDER_RESULT); - - fixture.detectChanges(); - const pagination = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-search-pagination"]')); - expect(pagination).not.toBeNull(); - })); - - xit('button callback should load the next batch of results by calling the search api', async(() => { - const skipCount = 8; - component.searchTerm = 'kakarot'; - - component.getNextPageOfSearch({ skipCount }); - - fixture.whenStable().then(() => { - expect(searchSpy).toHaveBeenCalledWith('kakarot', undefined, skipCount, 25); - }); - })); - - it('should be shown when pagination\'s hasMoreItems is true', () => { - component.pagination = { - hasMoreItems: true - }; - fixture.detectChanges(); - - const pagination = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-search-pagination"]')); - expect(pagination).not.toBeNull(); - }); - it('button callback should load the next batch of folder results when there is no searchTerm', () => { const skipCount = 5; component.searchTerm = ''; - component.pagination = { - hasMoreItems: true - }; fixture.detectChanges(); - component.getNextPageOfSearch({ skipCount }); + component.updatePagination({ skipCount }); fixture.detectChanges(); expect(component.searchTerm).toBe(''); @@ -708,7 +656,6 @@ describe('ContentNodeSelectorComponent', () => { it('should set its loading state to true after search was started', fakeAsync(() => { component.showingSearchResults = true; - component.pagination = { hasMoreItems: true }; typeToSearchBox('shenron'); @@ -716,28 +663,12 @@ describe('ContentNodeSelectorComponent', () => { fixture.detectChanges(); + tick(debounceSearch); + const spinnerSelector = By.css('[data-automation-id="content-node-selector-search-pagination"] [data-automation-id="adf-infinite-pagination-spinner"]'); const paginationLoading = fixture.debugElement.query(spinnerSelector); expect(paginationLoading).not.toBeNull(); })); - - xit('should set its loading state to true after search was performed', fakeAsync(() => { - component.showingSearchResults = true; - component.pagination = { hasMoreItems: true }; - - typeToSearchBox('shenron'); - - tick(debounceSearch); - - fixture.detectChanges(); - - respondWithSearchResults(ONE_FOLDER_RESULT); - - fixture.detectChanges(); - const spinnerSelector = By.css('[data-automation-id="content-node-selector-search-pagination"] [data-automation-id="adf-infinite-pagination-spinner"]'); - const paginationLoading = fixture.debugElement.query(spinnerSelector); - expect(paginationLoading).toBeNull(); - })); }); }); diff --git a/lib/content-services/content-node-selector/content-node-selector-panel.component.ts b/lib/content-services/content-node-selector/content-node-selector-panel.component.ts index 00cb86a1a9..86d8f21488 100644 --- a/lib/content-services/content-node-selector/content-node-selector-panel.component.ts +++ b/lib/content-services/content-node-selector/content-node-selector-panel.component.ts @@ -15,19 +15,10 @@ * limitations under the License. */ +import { Component, EventEmitter, Input, OnInit, Output, ViewChild, ViewEncapsulation } from '@angular/core'; import { - Component, - EventEmitter, - Input, - OnInit, - Output, - ViewChild, - ViewEncapsulation -} from '@angular/core'; -import { - AlfrescoApiService, - HighlightDirective, - UserPreferencesService + AlfrescoApiService, HighlightDirective, UserPreferencesService, + PaginatedComponent, PaginationModel } from '@alfresco/adf-core'; import { FormControl } from '@angular/forms'; import { MinimalNodeEntryEntity, NodePaging, Pagination, SiteEntry, SitePaging } from 'alfresco-js-api'; @@ -36,6 +27,7 @@ import { RowFilter } from '../document-list/data/row-filter.model'; import { ImageResolver } from '../document-list/data/image-resolver.model'; import { ContentNodeSelectorService } from './content-node-selector.service'; import { debounceTime } from 'rxjs/operators'; +import { BehaviorSubject } from 'rxjs/BehaviorSubject'; export type ValidationFunction = (entry: MinimalNodeEntryEntity) => boolean; @@ -48,7 +40,7 @@ const defaultValidation = () => true; encapsulation: ViewEncapsulation.None, host: { 'class': 'adf-content-node-selector-panel' } }) -export class ContentNodeSelectorPanelComponent implements OnInit { +export class ContentNodeSelectorPanelComponent implements OnInit, PaginatedComponent { /** Node ID of the folder currently listed. */ @Input() @@ -118,8 +110,9 @@ export class ContentNodeSelectorPanelComponent implements OnInit { inDialog: boolean = false; _chosenNode: MinimalNodeEntryEntity = null; folderIdToShow: string | null = null; - paginationStrategy: PaginationStrategy; - pagination: Pagination; + paginationStrategy: PaginationStrategy = PaginationStrategy.Infinite; + pagination: BehaviorSubject; + skipCount: number = 0; infiniteScroll: boolean = false; debounceSearch: number = 200; @@ -136,6 +129,14 @@ export class ContentNodeSelectorPanelComponent implements OnInit { this.search(searchValue); }); this.pageSize = this.preferences.paginationSize; + + let defaultPagination = { + maxItems: this.pageSize, + skipCount: 0, + totalItems: 0, + hasMoreItems: false + }; + this.pagination = new BehaviorSubject(defaultPagination); } set chosenNode(value: MinimalNodeEntryEntity) { @@ -153,7 +154,6 @@ export class ContentNodeSelectorPanelComponent implements OnInit { ngOnInit() { this.folderIdToShow = this.currentFolderId; - this.paginationStrategy = PaginationStrategy.Infinite; this.breadcrumbTransform = this.breadcrumbTransform ? this.breadcrumbTransform : null; this.isSelectionValid = this.isSelectionValid ? this.isSelectionValid : defaultValidation; @@ -179,16 +179,6 @@ export class ContentNodeSelectorPanelComponent implements OnInit { this.updateResults(); } - /** - * Returns whether breadcrumb has to be shown or not - */ - needBreadcrumbs() { - const whenInFolderNavigation = !this.showingSearchResults, - whenInSelectingSearchResult = this.showingSearchResults && this.chosenNode; - - return whenInFolderNavigation || whenInSelectingSearchResult; - } - /** * Returns the actually selected|entered folder node or null in case of searching for the breadcrumb */ @@ -250,9 +240,9 @@ export class ContentNodeSelectorPanelComponent implements OnInit { * * @param event Pagination object */ - getNextPageOfSearch(event: Pagination): void { + updatePagination(pagination: Pagination): void { this.infiniteScroll = true; - this.skipCount = event.skipCount; + this.skipCount = pagination.skipCount; if (this.searchTerm.length > 0) { this.querySearch(); @@ -285,18 +275,18 @@ export class ContentNodeSelectorPanelComponent implements OnInit { * * @param results Search results */ - private showSearchResults(results: NodePaging): void { + private showSearchResults(nodePaging: NodePaging): void { this.showingSearchResults = true; this.loadingSearchResults = false; // Documentlist hack, since data displaying for preloaded nodes is a little bit messy there if (!this.nodes) { - this.nodes = results; + this.nodes = nodePaging; } else { - this.documentList.data.loadPage(results, true); + this.documentList.data.loadPage(nodePaging, true); } - this.pagination = results.list.pagination; + this.pagination.next(nodePaging.list.pagination); this.highlight(); } @@ -313,6 +303,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit { * Sets showingSearchResults state to be able to differentiate between search results or folder results */ onFolderChange(): void { + this.showingSearchResults = false; this.infiniteScroll = false; this.clearSearch(); } @@ -320,10 +311,17 @@ export class ContentNodeSelectorPanelComponent implements OnInit { /** * Attempts to set the currently loaded node */ - onFolderLoaded(nodePage: NodePaging): void { - this.attemptNodeSelection(this.documentList.folderNode); - this.pagination = nodePage.list.pagination; - this.skipCount = nodePage.list.pagination.skipCount; + onFolderLoaded(nodePaging: NodePaging): void { + if (!this.showingSearchResults) { + this.attemptNodeSelection(this.documentList.folderNode); + } + } + + /** + * Returns whether breadcrumb has to be shown or not + */ + showBreadcrumbs() { + return !this.showingSearchResults || this.chosenNode; } /** diff --git a/lib/content-services/document-list/components/document-list.component.spec.ts b/lib/content-services/document-list/components/document-list.component.spec.ts index 5da477d2e1..b1cf9176b0 100644 --- a/lib/content-services/document-list/components/document-list.component.spec.ts +++ b/lib/content-services/document-list/components/document-list.component.spec.ts @@ -786,15 +786,6 @@ describe('DocumentList', () => { expect(documentList.navigationMode).toBe(DocumentListComponent.SINGLE_CLICK_NAVIGATION); }); - xit('should emit error on wrong folder id', (done) => { - documentList.error.subscribe(() => { - done(); - }); - - documentList.currentFolderId = 'wrong-id'; - documentList.ngOnChanges({ currentFolderId: new SimpleChange(null, documentList.currentFolderId, true) }); - }); - it('should require dataTable to check empty template', () => { documentList.dataTable = null; expect(documentList.isEmptyTemplateDefined()).toBeFalsy(); diff --git a/lib/content-services/document-list/services/document-list.service.spec.ts b/lib/content-services/document-list/services/document-list.service.spec.ts index b269949410..5ff2213eb0 100644 --- a/lib/content-services/document-list/services/document-list.service.spec.ts +++ b/lib/content-services/document-list/services/document-list.service.spec.ts @@ -116,7 +116,7 @@ describe('DocumentListService', () => { }); }); - xit('should emit an error when the folder already exist', () => { + it('should emit an error when the folder already exist', () => { service.createFolder('fake-name', 'fake-path').subscribe( res => { diff --git a/lib/content-services/document-list/services/document-list.service.ts b/lib/content-services/document-list/services/document-list.service.ts index 2840ddeaf1..be186fd824 100644 --- a/lib/content-services/document-list/services/document-list.service.ts +++ b/lib/content-services/document-list/services/document-list.service.ts @@ -21,7 +21,6 @@ import { } from '@alfresco/adf-core'; import { Injectable } from '@angular/core'; -import { Response } from '@angular/http'; import { MinimalNodeEntity, MinimalNodeEntryEntity, NodePaging } from 'alfresco-js-api'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/throw'; @@ -109,8 +108,9 @@ export class DocumentListService { * @returns Details of the created folder node */ createFolder(name: string, parentId: string): Observable { - return Observable.fromPromise(this.apiService.getInstance().nodes.createFolder(name, '/', parentId)) - .catch(err => this.handleError(err)); + let observable = Observable.fromPromise(this.apiService.getInstance().nodes.createFolder(name, '/', parentId)); + observable.catch(err => this.handleError(err)); + return observable; } /** @@ -182,7 +182,7 @@ export class DocumentListService { return this.contentService.hasPermission(node, permission); } - private handleError(error: Response) { + private handleError(error: any) { // in a real world app, we may send the error to some remote logging infrastructure // instead of just logging it to the console this.logService.error(error); diff --git a/lib/core/pagination/infinite-pagination.component.html b/lib/core/pagination/infinite-pagination.component.html index 07ca167b76..aab590bcde 100644 --- a/lib/core/pagination/infinite-pagination.component.html +++ b/lib/core/pagination/infinite-pagination.component.html @@ -1,4 +1,4 @@ -
+