[ACS-4662] Allow to see category children after search (#8494)

* [ACS-4662] intermediate progress

* [ACS-4662] Allow to see children of category after searching

* [ACS-4662] added unit test

* [ACS-4662] linting
This commit is contained in:
Nikita Maliarchuk
2023-04-21 09:08:13 +02:00
committed by GitHub
parent 9b2d433f2b
commit c68dd82279
3 changed files with 73 additions and 21 deletions

View File

@@ -32,6 +32,16 @@ export class CategoryServiceMock {
return parentNodeId ? of(this.getChildrenLevelResponse(skipCount, maxItems)) : of(this.getRootLevelResponse(skipCount, maxItems));
}
public getCategory(): Observable<CategoryEntry> {
return of({
entry: {
name: 'some name',
id: 'some id',
hasChildren: true
}
});
}
public searchCategories(): Observable<ResultSetPaging> {
const result = new ResultSetPaging();
result.list = new ResultSetPagingList();

View File

@@ -21,7 +21,7 @@ import { CategoryService } from '../services/category.service';
import { CategoryNode, CategoryTreeDatasourceService } from '@alfresco/adf-content-services';
import { CategoryServiceMock } from '../mock/category-mock.service';
import { TreeNodeType, TreeResponse } from '../../tree';
import { EMPTY } from 'rxjs';
import { EMPTY, of } from 'rxjs';
import { Pagination } from '@alfresco/js-api';
describe('CategoryTreeDatasourceService', () => {
@@ -83,7 +83,45 @@ describe('CategoryTreeDatasourceService', () => {
expect(categoryService.searchCategories).toHaveBeenCalledWith(name, skipCount, maxItems);
});
it('should call getCategory for every instance if value of name parameter is defined', (done) => {
spyOn(categoryService, 'getCategory').and.returnValues(of({
entry: {
name: 'name',
id: 'some id 1',
hasChildren: true
}
}),
of({
entry: {
name: 'Language/some other name',
id: 'some id 2',
hasChildren: false
}
}));
categoryTreeDatasourceService.getSubNodes('id', undefined, undefined, 'name')
.subscribe(() => {
expect(categoryService.getCategory).toHaveBeenCalledWith('some id 1');
expect(categoryService.getCategory).toHaveBeenCalledWith('some id 2');
done();
});
});
it('should return observable which emits correct categories', (done) => {
spyOn(categoryService, 'getCategory').and.returnValues(of({
entry: {
name: 'some name',
id: 'some id 1',
hasChildren: true
}
}),
of({
entry: {
name: 'Language/some other name',
id: 'some id 2',
hasChildren: false
}
}));
categoryTreeDatasourceService.getSubNodes('id', undefined, undefined, 'name')
.subscribe((response) => {
const pagination = new Pagination();
@@ -96,7 +134,7 @@ describe('CategoryTreeDatasourceService', () => {
parentId: 'parent id 1',
level: 0,
nodeType: TreeNodeType.RegularNode,
hasChildren: false,
hasChildren: true,
isLoading: false
}, {
id: 'some id 2',

View File

@@ -20,8 +20,8 @@ import { TreeNodeType, TreeResponse, TreeService } from '../../tree';
import { CategoryNode } from '../models/category-node.interface';
import { CategoryService } from './category.service';
import { CategoryEntry, CategoryPaging } from '@alfresco/js-api';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { from, Observable } from 'rxjs';
import { map, mergeMap, toArray } from 'rxjs/operators';
@Injectable({ providedIn: 'root' })
export class CategoryTreeDatasourceService extends TreeService<CategoryNode> {
@@ -56,25 +56,29 @@ export class CategoryTreeDatasourceService extends TreeService<CategoryNode> {
}
const treeResponse: TreeResponse<CategoryNode> = {entries: nodesList, pagination: response.list.pagination};
return treeResponse;
})) : this.categoryService.searchCategories(name, skipCount, maxItems).pipe(map((pagingResult) => {
})) : this.categoryService.searchCategories(name, skipCount, maxItems).pipe(mergeMap((pagingResult) => {
const nextAfterGeneralPathPartIndex = 3;
const pathSeparator = '/';
return {
entries: pagingResult.list.entries.map((category) => {
const path = category.entry.path.name.split(pathSeparator).slice(nextAfterGeneralPathPartIndex)
.join(pathSeparator);
return {
id: category.entry.id,
nodeName: path ? `${path}/${category.entry.name}` : category.entry.name,
parentId: category.entry.parentId,
level: 0,
nodeType: TreeNodeType.RegularNode,
hasChildren: false,
isLoading: false
};
}),
pagination: pagingResult.list.pagination
};
return from(pagingResult.list.entries).pipe(mergeMap((category) => {
const path = category.entry.path.name.split(pathSeparator).slice(nextAfterGeneralPathPartIndex)
.join(pathSeparator);
return this.categoryService.getCategory(category.entry.id).pipe(
map((res) => {
return {
id: category.entry.id,
nodeName: path ? `${path}/${category.entry.name}` : category.entry.name,
parentId: category.entry.parentId,
level: 0,
nodeType: TreeNodeType.RegularNode,
hasChildren: res.entry.hasChildren,
isLoading: false
};
})
);
}),
toArray(),
map(res => ({entries: res, pagination: pagingResult.list.pagination})));
}));
}
}