[ADF-2465] Sometimes, navigating using the breadcrumb opens another folder instead of the clicked one - after search performed on the Content Node Selector (#3054)

* [ADF-2465] Sometimes, navigating using the breadcrumb opens another folder instead of the clicked one - after search performed on the Content Node Selector

fixed bug
added tests
made sure that deleting search input field clears all search related data

* [ADF-2465] change tests not to use setTimeouts
This commit is contained in:
suzanadirla
2018-03-13 19:34:56 +02:00
committed by Eugenio Romano
parent 6dc758889f
commit 3a68382be0
3 changed files with 52 additions and 7 deletions

View File

@@ -38,7 +38,7 @@
</ng-container>
<adf-dropdown-breadcrumb *ngIf="needBreadcrumbs()"
class="adf-content-node-selector-content-breadcrumb"
(navigate)="clear()"
(navigate)="clearSearch()"
[target]="documentList"
[transform]="breadcrumbTransform"
[folderNode]="breadcrumbFolderNode"

View File

@@ -16,7 +16,7 @@
*/
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { async, fakeAsync, tick, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { MinimalNodeEntryEntity, SiteEntry, SitePaging } from 'alfresco-js-api';
import {
@@ -54,6 +54,7 @@ const ONE_FOLDER_RESULT = {
};
describe('ContentNodeSelectorComponent', () => {
const debounceSearch = 200;
let component: ContentNodeSelectorPanelComponent;
let fixture: ComponentFixture<ContentNodeSelectorPanelComponent>;
let searchService: SearchService;
@@ -483,6 +484,44 @@ describe('ContentNodeSelectorComponent', () => {
expect(component.showingSearchResults).toBeFalsy();
});
it('should clear the search field, nodes and chosenNode when deleting the search input', fakeAsync(() => {
spyOn(component, 'clear').and.callThrough();
typeToSearchBox('a');
tick(debounceSearch);
fixture.detectChanges();
expect(searchSpy.calls.count()).toBe(1);
typeToSearchBox('');
tick(debounceSearch);
fixture.detectChanges();
expect(searchSpy.calls.count()).toBe(1, 'no other search has been performed');
expect(component.clear).toHaveBeenCalled();
expect(component.folderIdToShow).toBe('cat-girl-nuku-nuku', 'back to the folder in which the search was performed');
}));
it('should clear the search field, nodes and chosenNode on folder navigation in the results list', fakeAsync(() => {
spyOn(component, 'clearSearch').and.callThrough();
typeToSearchBox('a');
tick(debounceSearch);
fixture.detectChanges();
respondWithSearchResults(ONE_FOLDER_RESULT);
tick();
fixture.detectChanges();
component.onFolderChange();
fixture.detectChanges();
expect(component.clearSearch).toHaveBeenCalled();
}));
it('should show nodes from the same folder as selected in the dropdown on clearing the search input', (done) => {
typeToSearchBox('piccolo');

View File

@@ -205,15 +205,22 @@ export class ContentNodeSelectorPanelComponent implements OnInit {
}
/**
* Clear the search input
* Clear the search input and reset to last folder node in which search was performed
*/
clear(): void {
this.clearSearch();
this.folderIdToShow = this.siteId || this.currentFolderId;
}
/**
* Clear the search input and search related data
*/
clearSearch() {
this.searchTerm = '';
this.nodes = null;
this.skipCount = 0;
this.chosenNode = null;
this.showingSearchResults = false;
this.folderIdToShow = this.siteId || this.currentFolderId;
}
/**
@@ -221,7 +228,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit {
*/
private updateResults(): void {
if (this.searchTerm.length === 0) {
this.folderIdToShow = this.siteId || this.currentFolderId;
this.clear();
} else {
this.startNewSearch();
}
@@ -306,9 +313,8 @@ export class ContentNodeSelectorPanelComponent implements OnInit {
* Sets showingSearchResults state to be able to differentiate between search results or folder results
*/
onFolderChange(): void {
this.skipCount = 0;
this.infiniteScroll = false;
this.showingSearchResults = false;
this.clearSearch();
}
/**