mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-16 18:13:06 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c05cd8617b | ||
|
|
10039ff711 | ||
|
|
7f4fd3e2d4 |
+19
-38
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { CUSTOM_ELEMENTS_SCHEMA, DebugElement } from '@angular/core';
|
||||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { ComponentFixture, fakeAsync, flush, TestBed, tick } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { Node, NodeEntry, NodePaging, RequestScope, ResultSetPaging, SiteEntry, SitePaging, SitePagingList } from '@alfresco/js-api';
|
||||
@@ -30,7 +30,6 @@ import { SearchQueryBuilderService } from '../../search';
|
||||
import { mockSearchRequest } from '../../mock/search-query.mock';
|
||||
import { SitesService } from '../../common/services/sites.service';
|
||||
import { NodesApiService } from '../../common/services/nodes-api.service';
|
||||
import { UnitTestingUtils } from '../../../../../core/src/lib/testing/unit-testing-utils';
|
||||
|
||||
const fakeResultSetPaging: ResultSetPaging = {
|
||||
list: {
|
||||
@@ -61,18 +60,15 @@ describe('ContentNodeSelectorPanelComponent', () => {
|
||||
const fakeNodeEntry = new Node({ id: 'fakeId' });
|
||||
const nodeEntryEvent = new NodeEntryEvent(fakeNodeEntry);
|
||||
let searchQueryBuilderService: SearchQueryBuilderService;
|
||||
let testingUtils: UnitTestingUtils;
|
||||
|
||||
const typeToSearchBox = (searchTerm = 'string-to-search'): void => {
|
||||
const searchInput = testingUtils.getByCSS('[data-automation-id="content-node-selector-search-input"]');
|
||||
const typeToSearchBox = (searchTerm = 'string-to-search') => {
|
||||
const searchInput = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-search-input"]'));
|
||||
searchInput.nativeElement.value = searchTerm;
|
||||
component.searchInput.setValue(searchTerm);
|
||||
fixture.detectChanges();
|
||||
};
|
||||
|
||||
const getSearchIcon = (type: string): DebugElement => testingUtils.getByCSS(`[data-automation-id="content-node-selector-search-${type}"]`);
|
||||
|
||||
const triggerSearchResults = (searchResults: ResultSetPaging): void => {
|
||||
const triggerSearchResults = (searchResults: ResultSetPaging) => {
|
||||
const service = fixture.debugElement.injector.get(SearchQueryBuilderService);
|
||||
service.executed.next(searchResults);
|
||||
};
|
||||
@@ -96,8 +92,6 @@ describe('ContentNodeSelectorPanelComponent', () => {
|
||||
searchQueryBuilderService = fixture.debugElement.injector.get(SearchQueryBuilderService);
|
||||
searchQueryBuilderService.resetToDefaults();
|
||||
|
||||
testingUtils = new UnitTestingUtils(fixture.debugElement);
|
||||
|
||||
spyOn(nodeService, 'getNode').and.returnValue(
|
||||
of(
|
||||
new Node({
|
||||
@@ -202,7 +196,7 @@ describe('ContentNodeSelectorPanelComponent', () => {
|
||||
spyOn(component, 'clearSearch');
|
||||
|
||||
fixture.detectChanges();
|
||||
const clearIcon = getSearchIcon('clear');
|
||||
const clearIcon = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-search-clear"]'));
|
||||
clearIcon.nativeElement.click();
|
||||
|
||||
fixture.detectChanges();
|
||||
@@ -363,8 +357,8 @@ describe('ContentNodeSelectorPanelComponent', () => {
|
||||
fixture.detectChanges();
|
||||
tick(debounceSearch);
|
||||
|
||||
const searchIcon = getSearchIcon('icon');
|
||||
const clearIcon = getSearchIcon('clear');
|
||||
const searchIcon = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-search-icon"]'));
|
||||
const clearIcon = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-search-clear"]'));
|
||||
|
||||
expect(searchIcon).not.toBeNull();
|
||||
expect(clearIcon).toBeNull();
|
||||
@@ -377,26 +371,13 @@ describe('ContentNodeSelectorPanelComponent', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
const searchIcon = getSearchIcon('icon');
|
||||
const clearIcon = getSearchIcon('clear');
|
||||
const searchIcon = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-search-icon"]'));
|
||||
const clearIcon = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-search-clear"]'));
|
||||
|
||||
expect(searchIcon).toBeNull();
|
||||
expect(clearIcon).not.toBeNull();
|
||||
}));
|
||||
|
||||
it('should call clear method on the X (clear) button click', fakeAsync(() => {
|
||||
fixture.detectChanges();
|
||||
typeToSearchBox('123');
|
||||
tick(debounceSearch);
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
spyOn(component, 'clear');
|
||||
const clearButton = getSearchIcon('clear');
|
||||
clearButton.nativeElement.click();
|
||||
expect(component.clear).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should clear the search field, nodes and chosenNode when clicking on the X (clear) icon', async () => {
|
||||
component.chosenNode = [entry];
|
||||
|
||||
@@ -572,7 +553,7 @@ describe('ContentNodeSelectorPanelComponent', () => {
|
||||
}));
|
||||
|
||||
it('should show the current folder content instead of search results if search was not performed', async () => {
|
||||
const documentList = testingUtils.getByDirective(DocumentListComponent);
|
||||
const documentList = fixture.debugElement.query(By.directive(DocumentListComponent));
|
||||
expect(documentList).not.toBeNull();
|
||||
expect(documentList.componentInstance.currentFolderId).toBe('cat-girl-nuku-nuku');
|
||||
});
|
||||
@@ -584,7 +565,7 @@ describe('ContentNodeSelectorPanelComponent', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
const documentList = testingUtils.getByDirective(DocumentListComponent);
|
||||
const documentList = fixture.debugElement.query(By.directive(DocumentListComponent));
|
||||
expect(documentList).not.toBeNull();
|
||||
expect(
|
||||
documentList.componentInstance.rowFilter({
|
||||
@@ -612,7 +593,7 @@ describe('ContentNodeSelectorPanelComponent', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
const documentList = testingUtils.getByDirective(DocumentListComponent);
|
||||
const documentList = fixture.debugElement.query(By.directive(DocumentListComponent));
|
||||
expect(documentList).not.toBeNull();
|
||||
expect(documentList.componentInstance.rowFilter).toBeTruthy();
|
||||
|
||||
@@ -626,7 +607,7 @@ describe('ContentNodeSelectorPanelComponent', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
const documentList = testingUtils.getByDirective(DocumentListComponent);
|
||||
const documentList = fixture.debugElement.query(By.directive(DocumentListComponent));
|
||||
expect(documentList).not.toBeNull();
|
||||
expect(documentList.componentInstance.imageResolver).toBe(resolver);
|
||||
});
|
||||
@@ -638,7 +619,7 @@ describe('ContentNodeSelectorPanelComponent', () => {
|
||||
triggerSearchResults(fakeResultSetPaging);
|
||||
|
||||
fixture.detectChanges();
|
||||
const documentList = testingUtils.getByCSS('[data-automation-id="content-node-selector-document-list"]');
|
||||
const documentList = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-document-list"]'));
|
||||
expect(documentList).not.toBeNull();
|
||||
expect(component.hasValidQuery).toEqual(true);
|
||||
expect(documentList.componentInstance.currentFolderId).toBeNull();
|
||||
@@ -683,12 +664,12 @@ describe('ContentNodeSelectorPanelComponent', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
const clearButton = getSearchIcon('clear');
|
||||
const clearButton = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-search-clear"]'));
|
||||
expect(clearButton).not.toBeNull();
|
||||
clearButton.triggerEventHandler('click', {});
|
||||
fixture.detectChanges();
|
||||
|
||||
const documentList = testingUtils.getByCSS('[data-automation-id="content-node-selector-document-list"]');
|
||||
const documentList = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-document-list"]'));
|
||||
expect(documentList).not.toBeNull();
|
||||
expect(documentList.componentInstance.currentFolderId).toBe('cat-girl-nuku-nuku');
|
||||
done();
|
||||
@@ -715,13 +696,13 @@ describe('ContentNodeSelectorPanelComponent', () => {
|
||||
component.siteChanged({ entry: { guid: 'Kame-Sennin Muten Roshi' } } as SiteEntry);
|
||||
fixture.detectChanges();
|
||||
|
||||
let documentList = testingUtils.getByCSS('[data-automation-id="content-node-selector-document-list"]');
|
||||
let documentList = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-document-list"]'));
|
||||
expect(documentList.componentInstance.currentFolderId).toBe('Kame-Sennin Muten Roshi');
|
||||
|
||||
component.siteChanged({ entry: { guid: undefined } } as SiteEntry);
|
||||
fixture.detectChanges();
|
||||
|
||||
documentList = testingUtils.getByCSS('[data-automation-id="content-node-selector-document-list"]');
|
||||
documentList = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-document-list"]'));
|
||||
expect(documentList.componentInstance.currentFolderId).toBe('cat-girl-nuku-nuku');
|
||||
|
||||
done();
|
||||
@@ -730,7 +711,7 @@ describe('ContentNodeSelectorPanelComponent', () => {
|
||||
describe('Pagination "Load more" button', () => {
|
||||
it('should NOT be shown by default', () => {
|
||||
fixture.detectChanges();
|
||||
const pagination = testingUtils.getByCSS('[data-automation-id="adf-infinite-pagination-button"]');
|
||||
const pagination = fixture.debugElement.query(By.css('[data-automation-id="adf-infinite-pagination-button"]'));
|
||||
expect(pagination).toBeNull();
|
||||
});
|
||||
|
||||
|
||||
+8
-16
@@ -13,26 +13,18 @@
|
||||
adf-auto-focus
|
||||
data-automation-id="content-node-selector-search-input">
|
||||
|
||||
<button
|
||||
matSuffix
|
||||
mat-icon-button
|
||||
*ngIf="searchTerm.length > 0"
|
||||
data-automation-id="content-node-selector-search-clear"
|
||||
class="adf-content-node-selector-search-clear-button"
|
||||
(click)="clear()"
|
||||
[attr.aria-label]="'COMMON.CLEAR' | translate"
|
||||
[attr.title]="'COMMON.CLEAR' | translate"
|
||||
>
|
||||
<mat-icon class="adf-content-node-selector-content-input-icon">clear</mat-icon>
|
||||
</button>
|
||||
<mat-icon *ngIf="searchTerm.length > 0"
|
||||
matSuffix (click)="clear()"
|
||||
class="adf-content-node-selector-content-input-icon"
|
||||
data-automation-id="content-node-selector-search-clear">clear
|
||||
</mat-icon>
|
||||
|
||||
<mat-icon
|
||||
*ngIf="searchTerm.length === 0"
|
||||
<mat-icon *ngIf="searchTerm.length === 0"
|
||||
matSuffix
|
||||
class="adf-content-node-selector-content-input-icon"
|
||||
data-automation-id="content-node-selector-search-icon"
|
||||
>search
|
||||
data-automation-id="content-node-selector-search-icon">search
|
||||
</mat-icon>
|
||||
|
||||
</mat-form-field>
|
||||
<adf-sites-dropdown
|
||||
*ngIf="showDropdownSiteList"
|
||||
|
||||
+4
-17
@@ -75,29 +75,16 @@ h2.adf-search-results-label {
|
||||
width: 100%;
|
||||
margin-bottom: 8px;
|
||||
|
||||
.adf-content-node-selector-content-input-icon:is(mat-icon) {
|
||||
.adf-content-node-selector-content-input-icon {
|
||||
color: var(--adf-theme-foreground-icon-color-054);
|
||||
cursor: pointer;
|
||||
padding: 0 0 8px;
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.adf-content-node-selector-search-clear-button {
|
||||
padding: 0;
|
||||
width: 20px;
|
||||
height: 28px;
|
||||
|
||||
&:focus {
|
||||
outline-offset: -1.5px;
|
||||
}
|
||||
|
||||
.adf-content-node-selector-content-input-icon:is(mat-icon) {
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
color: var(--adf-theme-foreground-base-color);
|
||||
}
|
||||
&:hover {
|
||||
color: var(--adf-theme-foreground-base-color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-17
@@ -1276,25 +1276,9 @@ describe('DocumentList', () => {
|
||||
documentList.onNodeDblClick(node);
|
||||
});
|
||||
|
||||
it('should load folder by ID on init if no filterValue is provided', async () => {
|
||||
it('should load folder by ID on init', async () => {
|
||||
spyOn(documentList, 'loadFolder').and.stub();
|
||||
|
||||
documentList.filterValue = {};
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
documentList.ngOnChanges({ currentFolderId: new SimpleChange(undefined, '1d26e465-dea3-42f3-b415-faa8364b9692', true) });
|
||||
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(documentList.loadFolder).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should NOT load folder by ID on init if filterValue is provided', async () => {
|
||||
spyOn(documentList, 'loadFolder').and.stub();
|
||||
|
||||
documentList.filterValue = undefined;
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
documentList.ngOnChanges({ currentFolderId: new SimpleChange(undefined, '1d26e465-dea3-42f3-b415-faa8364b9692', true) });
|
||||
|
||||
@@ -599,7 +599,7 @@ export class DocumentListComponent extends DataTableSchema implements OnInit, On
|
||||
}
|
||||
|
||||
if (this.currentFolderId && changes['currentFolderId']?.currentValue !== changes['currentFolderId']?.previousValue) {
|
||||
!this.filterValue && this.loadFolder();
|
||||
this.loadFolder();
|
||||
}
|
||||
|
||||
if (this.data) {
|
||||
@@ -816,6 +816,7 @@ export class DocumentListComponent extends DataTableSchema implements OnInit, On
|
||||
this.preserveExistingSelection();
|
||||
}
|
||||
this.onPreselectNodes();
|
||||
this.setLoadingState(false);
|
||||
this.onDataReady(nodePaging);
|
||||
}
|
||||
}
|
||||
@@ -1022,7 +1023,6 @@ export class DocumentListComponent extends DataTableSchema implements OnInit, On
|
||||
private onDataReady(nodePaging: NodePaging) {
|
||||
this.ready.emit(nodePaging);
|
||||
this.pagination.next(nodePaging.list.pagination);
|
||||
this.setLoadingState(false);
|
||||
}
|
||||
|
||||
updatePagination(requestPaginationModel: RequestPaginationModel) {
|
||||
|
||||
+3
-49
@@ -109,35 +109,7 @@ describe('FilterHeaderComponent', () => {
|
||||
expect(setCurrentRootFolderIdSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should set filters if initial value is provided', async () => {
|
||||
spyOn(queryBuilder, 'setCurrentRootFolderId');
|
||||
spyOn(queryBuilder, 'isCustomSourceNode').and.returnValue(false);
|
||||
spyOn(queryBuilder, 'setActiveFilter');
|
||||
|
||||
component.value = { name: 'pinocchio' };
|
||||
const currentFolderNodeIdChange = new SimpleChange('current-node-id', 'next-node-id', true);
|
||||
component.ngOnChanges({ currentFolderId: currentFolderNodeIdChange });
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(queryBuilder.setActiveFilter).toHaveBeenCalledWith('name', 'pinocchio');
|
||||
});
|
||||
|
||||
it('should NOT set filters if initial value is not provided', async () => {
|
||||
spyOn(queryBuilder, 'setCurrentRootFolderId');
|
||||
spyOn(queryBuilder, 'isCustomSourceNode').and.returnValue(false);
|
||||
spyOn(queryBuilder, 'setActiveFilter');
|
||||
|
||||
component.value = undefined;
|
||||
const currentFolderNodeIdChange = new SimpleChange('current-node-id', 'next-node-id', true);
|
||||
component.ngOnChanges({ currentFolderId: currentFolderNodeIdChange });
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(queryBuilder.setActiveFilter).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should set active filters correctly', async () => {
|
||||
it('should set active filters when an initial value is set', async () => {
|
||||
spyOn(queryBuilder, 'setCurrentRootFolderId');
|
||||
spyOn(queryBuilder, 'isCustomSourceNode').and.returnValue(false);
|
||||
|
||||
@@ -145,7 +117,8 @@ describe('FilterHeaderComponent', () => {
|
||||
await fixture.whenStable();
|
||||
expect(queryBuilder.getActiveFilters().length).toBe(0);
|
||||
|
||||
component.value = { name: 'pinocchio' };
|
||||
const initialFilterValue = { name: 'pinocchio' };
|
||||
component.value = initialFilterValue;
|
||||
const currentFolderNodeIdChange = new SimpleChange('current-node-id', 'next-node-id', true);
|
||||
component.ngOnChanges({ currentFolderId: currentFolderNodeIdChange });
|
||||
fixture.detectChanges();
|
||||
@@ -156,25 +129,6 @@ describe('FilterHeaderComponent', () => {
|
||||
expect(queryBuilder.getActiveFilters()[0].value).toBe('pinocchio');
|
||||
});
|
||||
|
||||
it('should update queryParams if initial value is provided', async () => {
|
||||
spyOn(queryBuilder, 'setCurrentRootFolderId');
|
||||
spyOn(queryBuilder, 'isCustomSourceNode').and.returnValue(false);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
expect(Object.keys(queryBuilder.filterRawParams).length).toBe(0);
|
||||
|
||||
component.value = { name: 'pinocchio' };
|
||||
const currentFolderNodeIdChange = new SimpleChange('current-node-id', 'next-node-id', true);
|
||||
component.ngOnChanges({ currentFolderId: currentFolderNodeIdChange });
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(Object.keys(queryBuilder.filterRawParams).length).toBe(1);
|
||||
expect(queryBuilder.filterRawParams['name']).toBe('pinocchio');
|
||||
expect(queryBuilder.queryFragments['name']).toBe('pinocchio');
|
||||
});
|
||||
|
||||
it('should emit filterSelection when a filter is changed', (done) => {
|
||||
spyOn(queryBuilder, 'getActiveFilters').and.returnValue([{ key: 'name', value: 'pinocchio' }]);
|
||||
|
||||
|
||||
+4
-13
@@ -46,10 +46,7 @@ export class FilterHeaderComponent implements OnInit, OnChanges {
|
||||
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
|
||||
constructor(
|
||||
@Inject(ADF_DOCUMENT_PARENT_COMPONENT) private readonly documentList: any,
|
||||
private readonly searchFilterQueryBuilder: SearchHeaderQueryBuilderService
|
||||
) {
|
||||
constructor(@Inject(ADF_DOCUMENT_PARENT_COMPONENT) private documentList: any, private searchFilterQueryBuilder: SearchHeaderQueryBuilderService) {
|
||||
this.isFilterServiceActive = this.searchFilterQueryBuilder.isFilterServiceActive();
|
||||
}
|
||||
|
||||
@@ -105,17 +102,11 @@ export class FilterHeaderComponent implements OnInit, OnChanges {
|
||||
}
|
||||
|
||||
private initSearchHeader(currentFolderId: string) {
|
||||
this.searchFilterQueryBuilder.setCurrentRootFolderId(currentFolderId);
|
||||
if (this.value) {
|
||||
Object.keys(this.value).forEach((key) => {
|
||||
this.searchFilterQueryBuilder.setActiveFilter(key, this.value[key]);
|
||||
|
||||
const operator = this.searchFilterQueryBuilder.getOperatorForFilterId(key) || 'OR';
|
||||
this.searchFilterQueryBuilder.filterRawParams[key] = this.value[key];
|
||||
this.searchFilterQueryBuilder.queryFragments[key] = Array.isArray(this.value[key])
|
||||
? this.value[key].join(` ${operator} `)
|
||||
: this.value[key];
|
||||
Object.keys(this.value).forEach((columnKey) => {
|
||||
this.searchFilterQueryBuilder.setActiveFilter(columnKey, this.value[columnKey]);
|
||||
});
|
||||
}
|
||||
this.searchFilterQueryBuilder.setCurrentRootFolderId(currentFolderId);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -19,8 +19,7 @@
|
||||
class="adf-permission-search-input-clear-button"
|
||||
(click)="clearSearch()"
|
||||
[attr.aria-label]="'COMMON.CLEAR' | translate"
|
||||
[attr.title]="'COMMON.CLEAR' | translate"
|
||||
>
|
||||
[attr.title]="'COMMON.CLEAR' | translate">
|
||||
<mat-icon class="adf-permission-search-icon">clear</mat-icon>
|
||||
</button>
|
||||
|
||||
|
||||
+5
-8
@@ -80,6 +80,11 @@ $search-result-height: calc(100% - 60px);
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
font-size: 20px;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
color: var(--adf-theme-foreground-base-color);
|
||||
}
|
||||
}
|
||||
|
||||
.adf-permission-search-input-clear-button {
|
||||
@@ -87,14 +92,6 @@ $search-result-height: calc(100% - 60px);
|
||||
width: 20px;
|
||||
height: 32px;
|
||||
margin-right: 1.5px;
|
||||
|
||||
.adf-permission-search-icon:is(mat-icon) {
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
color: var(--adf-theme-foreground-base-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-24
@@ -203,17 +203,18 @@ describe('SearchCheckListComponent', () => {
|
||||
expect(checkedElements.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should check the checkbox with startValue on init, if provided', () => {
|
||||
it('should update query with startValue on init, if provided', () => {
|
||||
component.id = 'checkList';
|
||||
component.options = new SearchFilterList<SearchListOption>([
|
||||
{ name: 'Folder', value: `TYPE:'cm:folder'`, checked: false },
|
||||
{ name: 'Document', value: `TYPE:'cm:content'`, checked: false }
|
||||
]);
|
||||
component.startValue = [`TYPE:'cm:folder'`];
|
||||
component.startValue = `TYPE:'cm:folder'`;
|
||||
component.context.queryFragments[component.id] = 'query';
|
||||
fixture.detectChanges();
|
||||
expect(component.options.items[0].checked).toBeTrue();
|
||||
expect(component.options.items[1].checked).toBeFalse();
|
||||
expect(component.isActive).toBeTrue();
|
||||
|
||||
expect(component.context.queryFragments[component.id]).toBe(`TYPE:'cm:folder'`);
|
||||
expect(component.context.update).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should set query context as blank and not call query update, if no start value was provided', () => {
|
||||
@@ -230,25 +231,6 @@ describe('SearchCheckListComponent', () => {
|
||||
expect(component.context.update).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should handle initial populateFilters emission and no filter state properly', () => {
|
||||
component.id = 'checkList';
|
||||
component.options = new SearchFilterList<SearchListOption>([
|
||||
{ name: 'Folder', value: `TYPE:'cm:folder'`, checked: false },
|
||||
{ name: 'Document', value: `TYPE:'cm:content'`, checked: false }
|
||||
]);
|
||||
|
||||
component.context.filterLoaded = new ReplaySubject(1);
|
||||
spyOn(component.context.filterLoaded, 'next').and.stub();
|
||||
spyOn(component.displayValue$, 'next').and.stub();
|
||||
fixture.detectChanges();
|
||||
|
||||
component.context.populateFilters.next({});
|
||||
component.context.populateFilters.next({ checkList: [`TYPE:'cm:content'`] });
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.context.filterLoaded.next).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should populate filter state when populate filters event has been observed', () => {
|
||||
component.id = 'checkList';
|
||||
component.options = new SearchFilterList<SearchListOption>([
|
||||
|
||||
+5
-5
@@ -23,7 +23,7 @@ import { SearchQueryBuilderService } from '../../services/search-query-builder.s
|
||||
import { SearchFilterList } from '../../models/search-filter-list.model';
|
||||
import { TranslationService } from '@alfresco/adf-core';
|
||||
import { ReplaySubject } from 'rxjs';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { TranslatePipe } from '@ngx-translate/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
@@ -50,7 +50,7 @@ export class SearchCheckListComponent implements SearchWidget, OnInit {
|
||||
context?: SearchQueryBuilderService;
|
||||
options: SearchFilterList<SearchListOption>;
|
||||
operator: string = 'OR';
|
||||
startValue: string | string[];
|
||||
startValue: string;
|
||||
pageSize = 5;
|
||||
isActive = false;
|
||||
enableChangeUpdate = true;
|
||||
@@ -81,9 +81,9 @@ export class SearchCheckListComponent implements SearchWidget, OnInit {
|
||||
}
|
||||
}
|
||||
this.context.populateFilters
|
||||
.asObservable()
|
||||
.pipe(
|
||||
map((filtersQueries) => filtersQueries[this.id]),
|
||||
filter((filterQuery) => filterQuery !== undefined),
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
)
|
||||
.subscribe((filterQuery) => {
|
||||
@@ -160,8 +160,8 @@ export class SearchCheckListComponent implements SearchWidget, OnInit {
|
||||
}
|
||||
|
||||
setValue(value: any) {
|
||||
this.options.items.forEach((item) => (item.checked = value.includes(item.value)));
|
||||
this.isActive = true;
|
||||
this.options.items.filter((item) => value.includes(item.value)).map((item) => (item.checked = true));
|
||||
this.submitValues();
|
||||
}
|
||||
|
||||
private getCheckedValues() {
|
||||
|
||||
+3
-3
@@ -94,7 +94,7 @@ describe('SearchFilterContainerComponent', () => {
|
||||
await applyButton.click();
|
||||
|
||||
expect(queryBuilder.getActiveFilters().length).toBe(1);
|
||||
expect(queryBuilder.getActiveFilters()[0].key).toBe('queryName');
|
||||
expect(queryBuilder.getActiveFilters()[0].key).toBe('name');
|
||||
expect(queryBuilder.getActiveFilters()[0].value).toBe('searchText');
|
||||
|
||||
await menu.open();
|
||||
@@ -103,12 +103,12 @@ describe('SearchFilterContainerComponent', () => {
|
||||
|
||||
await applyButton.click();
|
||||
expect(queryBuilder.getActiveFilters().length).toBe(1);
|
||||
expect(queryBuilder.getActiveFilters()[0].key).toBe('queryName');
|
||||
expect(queryBuilder.getActiveFilters()[0].key).toBe('name');
|
||||
expect(queryBuilder.getActiveFilters()[0].value).toBe('updated text');
|
||||
});
|
||||
|
||||
it('should remove active filter after the Clear button is clicked', async () => {
|
||||
queryBuilder.setActiveFilter('queryName', 'searchText');
|
||||
queryBuilder.setActiveFilter('name', 'searchText');
|
||||
|
||||
const menu = await loader.getHarness(MatMenuHarness);
|
||||
await menu.open();
|
||||
|
||||
+4
-4
@@ -76,7 +76,7 @@ export class SearchFilterContainerComponent implements OnInit {
|
||||
|
||||
ngOnInit() {
|
||||
this.category = this.searchFilterQueryBuilder.getCategoryForColumn(this.col.key);
|
||||
this.initialValue = this.value?.[this.category?.id];
|
||||
this.initialValue = this.value?.[this.col.key] ? this.value[this.col.key] : undefined;
|
||||
}
|
||||
|
||||
onKeyPressed(event: KeyboardEvent, menuTrigger: MatMenuTrigger) {
|
||||
@@ -88,7 +88,7 @@ export class SearchFilterContainerComponent implements OnInit {
|
||||
|
||||
onApply() {
|
||||
if (this.widgetContainer.hasValueSelected()) {
|
||||
this.searchFilterQueryBuilder.setActiveFilter(this.category.id, this.widgetContainer.getCurrentValue());
|
||||
this.searchFilterQueryBuilder.setActiveFilter(this.category.columnKey, this.widgetContainer.getCurrentValue());
|
||||
this.filterChange.emit();
|
||||
this.widgetContainer.applyInnerWidget();
|
||||
} else {
|
||||
@@ -103,7 +103,7 @@ export class SearchFilterContainerComponent implements OnInit {
|
||||
|
||||
resetSearchFilter() {
|
||||
this.widgetContainer.resetInnerWidget();
|
||||
this.searchFilterQueryBuilder.removeActiveFilter(this.category.id);
|
||||
this.searchFilterQueryBuilder.removeActiveFilter(this.category.columnKey);
|
||||
this.filterChange.emit();
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ export class SearchFilterContainerComponent implements OnInit {
|
||||
}
|
||||
|
||||
isActive(): boolean {
|
||||
return this.searchFilterQueryBuilder.getActiveFilters().findIndex((f: FilterSearch) => f.key === this.category.id) > -1;
|
||||
return this.searchFilterQueryBuilder.getActiveFilters().findIndex((f: FilterSearch) => f.key === this.category.columnKey) > -1;
|
||||
}
|
||||
|
||||
onMenuOpen() {
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ describe('SearchTextComponent', () => {
|
||||
|
||||
expect(component.value).toBe('');
|
||||
expect(component.context.queryFragments[component.id]).toBe('');
|
||||
expect(component.context.filterRawParams[component.id]).toBeUndefined();
|
||||
expect(component.context.filterRawParams[component.id]).toBeNull();
|
||||
});
|
||||
|
||||
it('should update query with startValue on init, if provided', () => {
|
||||
|
||||
@@ -99,8 +99,6 @@ export class SearchTextComponent implements SearchWidget, OnInit {
|
||||
|
||||
reset(updateContext = true) {
|
||||
this.value = '';
|
||||
this.context.filterRawParams[this.id] = undefined;
|
||||
this.context.queryFragments[this.id] = '';
|
||||
this.updateQuery(null, updateContext);
|
||||
}
|
||||
|
||||
@@ -113,10 +111,7 @@ export class SearchTextComponent implements SearchWidget, OnInit {
|
||||
}
|
||||
|
||||
private updateQuery(value: string, updateContext = true) {
|
||||
if (value !== null) {
|
||||
this.context.filterRawParams[this.id] = value;
|
||||
}
|
||||
|
||||
this.context.filterRawParams[this.id] = value;
|
||||
this.displayValue$.next(value);
|
||||
if (this.context && this.settings && this.settings.field) {
|
||||
this.context.queryFragments[this.id] = value ? `${this.settings.field}:'${this.getSearchPrefix()}${value}${this.getSearchSuffix()}'` : '';
|
||||
|
||||
+16
-45
@@ -22,7 +22,6 @@ import { TestBed } from '@angular/core/testing';
|
||||
import { ContentTestingModule } from '../../testing/content.testing.module';
|
||||
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { SearchCategory } from '../models';
|
||||
|
||||
describe('SearchHeaderQueryBuilderService', () => {
|
||||
let activatedRoute: ActivatedRoute;
|
||||
@@ -44,13 +43,10 @@ describe('SearchHeaderQueryBuilderService', () => {
|
||||
|
||||
it('should load the configuration from app config', () => {
|
||||
TestBed.runInInjectionContext(() => {
|
||||
const config = {
|
||||
categories: [
|
||||
{ id: 'cat1', enabled: true },
|
||||
{ id: 'cat2', enabled: true }
|
||||
],
|
||||
const config: SearchConfiguration = {
|
||||
categories: [{ id: 'cat1', enabled: true } as any, { id: 'cat2', enabled: true } as any],
|
||||
filterQueries: [{ query: 'query1' }, { query: 'query2' }]
|
||||
} as SearchConfiguration;
|
||||
};
|
||||
|
||||
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||
const builder = new SearchHeaderQueryBuilderService(buildConfig(config), alfrescoApiService, null);
|
||||
@@ -70,13 +66,13 @@ describe('SearchHeaderQueryBuilderService', () => {
|
||||
|
||||
it('should return the category assigned to a column key', () => {
|
||||
TestBed.runInInjectionContext(() => {
|
||||
const config = {
|
||||
const config: SearchConfiguration = {
|
||||
categories: [
|
||||
{ id: 'cat1', columnKey: 'fake-key-1', enabled: true },
|
||||
{ id: 'cat2', columnKey: 'fake-key-2', enabled: true }
|
||||
{ id: 'cat1', columnKey: 'fake-key-1', enabled: true } as any,
|
||||
{ id: 'cat2', columnKey: 'fake-key-2', enabled: true } as any
|
||||
],
|
||||
filterQueries: [{ query: 'query1' }, { query: 'query2' }]
|
||||
} as SearchConfiguration;
|
||||
};
|
||||
|
||||
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||
const service = new SearchHeaderQueryBuilderService(buildConfig(config), alfrescoApiService, null);
|
||||
@@ -88,25 +84,6 @@ describe('SearchHeaderQueryBuilderService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return operator for a category by id', () => {
|
||||
TestBed.runInInjectionContext(() => {
|
||||
const config: SearchConfiguration = {
|
||||
categories: [
|
||||
{ id: 'cat1', columnKey: 'fake-key-1', enabled: true, component: { settings: { operator: 'operator' } } },
|
||||
{ id: 'cat2', columnKey: 'fake-key-2', enabled: true }
|
||||
] as SearchCategory[]
|
||||
};
|
||||
|
||||
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||
const service = new SearchHeaderQueryBuilderService(buildConfig(config), alfrescoApiService, null);
|
||||
|
||||
const operator = service.getOperatorForFilterId('cat1');
|
||||
expect(operator).toBe('operator');
|
||||
const operator1 = service.getOperatorForFilterId('cat2');
|
||||
expect(operator1).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('should have empty user query by default', () => {
|
||||
TestBed.runInInjectionContext(() => {
|
||||
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||
@@ -117,13 +94,10 @@ describe('SearchHeaderQueryBuilderService', () => {
|
||||
|
||||
it('should add the extra filter for the parent node', () => {
|
||||
TestBed.runInInjectionContext(() => {
|
||||
const config = {
|
||||
categories: [
|
||||
{ id: 'cat1', enabled: true },
|
||||
{ id: 'cat2', enabled: true }
|
||||
],
|
||||
const config: SearchConfiguration = {
|
||||
categories: [{ id: 'cat1', enabled: true } as any, { id: 'cat2', enabled: true } as any],
|
||||
filterQueries: [{ query: 'query1' }, { query: 'query2' }]
|
||||
} as SearchConfiguration;
|
||||
};
|
||||
|
||||
const expectedResult = [{ query: 'PARENT:"workspace://SpacesStore/fake-node-id"' }];
|
||||
|
||||
@@ -140,13 +114,10 @@ describe('SearchHeaderQueryBuilderService', () => {
|
||||
TestBed.runInInjectionContext(() => {
|
||||
const expectedResult = [{ query: 'PARENT:"workspace://SpacesStore/fake-node-id"' }];
|
||||
|
||||
const config = {
|
||||
categories: [
|
||||
{ id: 'cat1', enabled: true },
|
||||
{ id: 'cat2', enabled: true }
|
||||
],
|
||||
const config: SearchConfiguration = {
|
||||
categories: [{ id: 'cat1', enabled: true } as any, { id: 'cat2', enabled: true } as any],
|
||||
filterQueries: expectedResult
|
||||
} as SearchConfiguration;
|
||||
};
|
||||
|
||||
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||
const searchHeaderService = new SearchHeaderQueryBuilderService(buildConfig(config), alfrescoApiService, null);
|
||||
@@ -161,10 +132,10 @@ describe('SearchHeaderQueryBuilderService', () => {
|
||||
TestBed.runInInjectionContext(() => {
|
||||
const activeFilter = 'FakeColumn';
|
||||
|
||||
const config = {
|
||||
categories: [{ id: 'cat1', enabled: true }],
|
||||
const config: SearchConfiguration = {
|
||||
categories: [{ id: 'cat1', enabled: true } as any],
|
||||
filterQueries: [{ query: 'PARENT:"workspace://SpacesStore/fake-node-id' }]
|
||||
} as SearchConfiguration;
|
||||
};
|
||||
|
||||
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||
const searchHeaderService = new SearchHeaderQueryBuilderService(buildConfig(config), alfrescoApiService, null);
|
||||
|
||||
+1
-11
@@ -36,11 +36,7 @@ export class SearchHeaderQueryBuilderService extends BaseQueryBuilderService {
|
||||
|
||||
activeFilters: FilterSearch[] = [];
|
||||
|
||||
constructor(
|
||||
appConfig: AppConfigService,
|
||||
alfrescoApiService: AlfrescoApiService,
|
||||
private readonly nodeApiService: NodesApiService
|
||||
) {
|
||||
constructor(appConfig: AppConfigService, alfrescoApiService: AlfrescoApiService, private nodeApiService: NodesApiService) {
|
||||
super(appConfig, alfrescoApiService);
|
||||
|
||||
this.updated.pipe(filter((query) => !!query)).subscribe(() => {
|
||||
@@ -131,12 +127,6 @@ export class SearchHeaderQueryBuilderService extends BaseQueryBuilderService {
|
||||
return foundCategory;
|
||||
}
|
||||
|
||||
getOperatorForFilterId(id: string): string | undefined {
|
||||
const foundCategory = this.categories?.find((category) => category.id === id);
|
||||
|
||||
return foundCategory?.component?.settings?.operator;
|
||||
}
|
||||
|
||||
setCurrentRootFolderId(currentFolderId: string) {
|
||||
const alreadyAddedFilter = this.filterQueries.find((filterQueries) => filterQueries.query.includes(currentFolderId));
|
||||
|
||||
|
||||
@@ -253,9 +253,7 @@
|
||||
[aria-label]="'ADF-DATATABLE.ACCESSIBILITY.SELECT_FILE' | translate"
|
||||
data-adf-datatable-row-checkbox
|
||||
(change)="onCheckboxChange(row, $event)"
|
||||
(keydown.enter)="$event.stopPropagation()"
|
||||
class="adf-checkbox-sr-only"
|
||||
>
|
||||
class="adf-checkbox-sr-only">
|
||||
{{ 'ADF-DATATABLE.ACCESSIBILITY.SELECT_FILE' | translate }}
|
||||
</mat-checkbox>
|
||||
</label>
|
||||
|
||||
@@ -1395,33 +1395,6 @@ describe('DataTable', () => {
|
||||
expect(rows[1].isSelected).toBeTrue();
|
||||
});
|
||||
|
||||
it('should call stopPropagation on checkbox keydown enter event', () => {
|
||||
const petRows = [{ pet: 'dog' }, { pet: 'cat' }];
|
||||
dataTable.multiselect = true;
|
||||
dataTable.data = new ObjectDataTableAdapter(petRows, [new ObjectDataColumn({ key: 'pet' })]);
|
||||
dataTable.ngOnChanges({ rows: new SimpleChange(null, petRows, false) });
|
||||
fixture.detectChanges();
|
||||
|
||||
const checkboxElement = testingUtils.getByCSS('[data-adf-datatable-row-checkbox]').nativeElement as HTMLElement;
|
||||
|
||||
const enterEvent = new KeyboardEvent('keydown', {
|
||||
key: 'Enter',
|
||||
code: 'Enter',
|
||||
bubbles: true,
|
||||
cancelable: true
|
||||
});
|
||||
|
||||
const stopPropagationSpy = jasmine.createSpy('stopPropagationSpy');
|
||||
|
||||
Object.assign(enterEvent, {
|
||||
stopPropagation: stopPropagationSpy
|
||||
});
|
||||
|
||||
checkboxElement.dispatchEvent(enterEvent);
|
||||
|
||||
expect(stopPropagationSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should be able to display column of type boolean', () => {
|
||||
dataTable.data = new ObjectDataTableAdapter(mockCarsData, mockCarsSchemaDefinition);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user