-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add autoExpand option * Add changeset * Update packages/full-stack-tests/src/hierarchy-builder/grouping/AutoExpand.test.ts Co-authored-by: Grigas <[email protected]> * Update packages/hierarchy-builder/src/hierarchy-builder/internal/operators/grouping/AutoExpand.ts Co-authored-by: Grigas <[email protected]> * Update packages/hierarchy-builder/src/hierarchy-builder/internal/operators/grouping/AutoExpand.ts Co-authored-by: Grigas <[email protected]> * Comment fixes * Change tests to suggestion * Group repetitive code * Fix tests * Add 100% test coverage * Fix getAutoExpandOptionsFromNodeProcessingParams * Update api * Resolve comments * Update packages/hierarchy-builder/src/hierarchy-builder/HierarchyNode.ts Co-authored-by: Grigas <[email protected]> * Apply suggestion --------- Co-authored-by: Grigas <[email protected]>
- Loading branch information
Showing
12 changed files
with
613 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
--- |
313 changes: 313 additions & 0 deletions
313
packages/full-stack-tests/src/hierarchy-builder/grouping/AutoExpand.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,313 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { Subject } from "@itwin/core-backend"; | ||
import { IModel } from "@itwin/core-common"; | ||
import { IModelConnection } from "@itwin/core-frontend"; | ||
import { ECSqlSelectClauseGroupingParams, IHierarchyLevelDefinitionsFactory, NodeSelectClauseFactory } from "@itwin/presentation-hierarchy-builder"; | ||
import { buildIModel, insertSubject } from "../../IModelUtils"; | ||
import { initialize, terminate } from "../../IntegrationTests"; | ||
import { NodeValidators, validateHierarchy } from "../HierarchyValidation"; | ||
import { createProvider } from "../Utils"; | ||
|
||
describe("Stateless hierarchy builder", () => { | ||
describe("Grouping nodes' autoExpand setting", () => { | ||
let selectClauseFactory: NodeSelectClauseFactory; | ||
let subjectClassName: string; | ||
let emptyIModel: IModelConnection; | ||
|
||
before(async function () { | ||
await initialize(); | ||
emptyIModel = (await buildIModel(this)).imodel; | ||
subjectClassName = Subject.classFullName.replace(":", "."); | ||
selectClauseFactory = new NodeSelectClauseFactory(); | ||
}); | ||
|
||
after(async () => { | ||
await terminate(); | ||
}); | ||
|
||
function createHierarchyWithSpecifiedGrouping(specifiedGrouping: ECSqlSelectClauseGroupingParams): IHierarchyLevelDefinitionsFactory { | ||
return { | ||
async defineHierarchyLevel(parentNode) { | ||
if (!parentNode) { | ||
return [ | ||
{ | ||
fullClassName: `BisCore.InformationContentElement`, | ||
query: { | ||
ecsql: ` | ||
SELECT ${await selectClauseFactory.createSelectClause({ | ||
ecClassId: { selector: `this.ECClassId` }, | ||
ecInstanceId: { selector: `this.ECInstanceId` }, | ||
nodeLabel: { selector: `this.UserLabel` }, | ||
grouping: specifiedGrouping, | ||
})} | ||
FROM ${subjectClassName} this | ||
`, | ||
}, | ||
}, | ||
]; | ||
} | ||
return []; | ||
}, | ||
}; | ||
} | ||
|
||
describe("Base class grouping", () => { | ||
const baseClassAutoExpandAlways: ECSqlSelectClauseGroupingParams = { | ||
byBaseClasses: { | ||
fullClassNames: ["BisCore.InformationReferenceElement"], | ||
autoExpand: "always", | ||
}, | ||
}; | ||
|
||
const baseClassAutoExpandSingleChild: ECSqlSelectClauseGroupingParams = { | ||
byBaseClasses: { | ||
fullClassNames: ["BisCore.InformationReferenceElement"], | ||
autoExpand: "single-child", | ||
}, | ||
}; | ||
|
||
it("grouping nodes' autoExpand option is true when some child has autoExpand set to 'always'", async function () { | ||
await validateHierarchy({ | ||
provider: createProvider({ imodel: emptyIModel, hierarchy: createHierarchyWithSpecifiedGrouping(baseClassAutoExpandAlways) }), | ||
expect: [ | ||
NodeValidators.createForClassGroupingNode({ | ||
label: "Information Reference", | ||
className: "BisCore.InformationReferenceElement", | ||
autoExpand: true, | ||
children: [ | ||
NodeValidators.createForInstanceNode({ | ||
instanceKeys: [{ className: "BisCore.Subject", id: IModel.rootSubjectId }], | ||
children: false, | ||
}), | ||
], | ||
}), | ||
], | ||
}); | ||
}); | ||
|
||
it("grouping nodes' autoExpand option is true when it has one child with autoExpand set to 'single-child'", async function () { | ||
await validateHierarchy({ | ||
provider: createProvider({ imodel: emptyIModel, hierarchy: createHierarchyWithSpecifiedGrouping(baseClassAutoExpandSingleChild) }), | ||
expect: [ | ||
NodeValidators.createForClassGroupingNode({ | ||
label: "Information Reference", | ||
className: "BisCore.InformationReferenceElement", | ||
autoExpand: true, | ||
children: [ | ||
NodeValidators.createForInstanceNode({ | ||
instanceKeys: [{ className: "BisCore.Subject", id: IModel.rootSubjectId }], | ||
children: false, | ||
}), | ||
], | ||
}), | ||
], | ||
}); | ||
}); | ||
|
||
it("grouping nodes' autoExpand option is undefined when none of the child nodes have autoExpand set to 'always'", async function () { | ||
const { imodel, ...keys } = await buildIModel(this, async (builder) => { | ||
const childSubject1 = insertSubject({ builder, codeValue: "A1", parentId: IModel.rootSubjectId }); | ||
const childSubject2 = insertSubject({ builder, codeValue: "A2", parentId: IModel.rootSubjectId }); | ||
return { childSubject1, childSubject2 }; | ||
}); | ||
|
||
await validateHierarchy({ | ||
provider: createProvider({ imodel, hierarchy: createHierarchyWithSpecifiedGrouping(baseClassAutoExpandSingleChild) }), | ||
expect: [ | ||
NodeValidators.createForClassGroupingNode({ | ||
label: "Information Reference", | ||
className: "BisCore.InformationReferenceElement", | ||
autoExpand: undefined, | ||
children: [ | ||
NodeValidators.createForInstanceNode({ | ||
instanceKeys: [{ className: "BisCore.Subject", id: IModel.rootSubjectId }], | ||
children: false, | ||
}), | ||
NodeValidators.createForInstanceNode({ | ||
instanceKeys: [keys.childSubject1], | ||
children: false, | ||
}), | ||
NodeValidators.createForInstanceNode({ | ||
instanceKeys: [keys.childSubject2], | ||
children: false, | ||
}), | ||
], | ||
}), | ||
], | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Class grouping", () => { | ||
const classAutoExpandAlways: ECSqlSelectClauseGroupingParams = { | ||
byClass: { | ||
autoExpand: "always", | ||
}, | ||
}; | ||
|
||
const classAutoExpandSingleChild: ECSqlSelectClauseGroupingParams = { | ||
byClass: { | ||
autoExpand: "single-child", | ||
}, | ||
}; | ||
|
||
it("grouping nodes' autoExpand option is true when some child has autoExpand set to 'always'", async function () { | ||
await validateHierarchy({ | ||
provider: createProvider({ imodel: emptyIModel, hierarchy: createHierarchyWithSpecifiedGrouping(classAutoExpandAlways) }), | ||
expect: [ | ||
NodeValidators.createForClassGroupingNode({ | ||
className: "BisCore.Subject", | ||
autoExpand: true, | ||
children: [ | ||
NodeValidators.createForInstanceNode({ | ||
instanceKeys: [{ className: "BisCore.Subject", id: IModel.rootSubjectId }], | ||
children: false, | ||
}), | ||
], | ||
}), | ||
], | ||
}); | ||
}); | ||
|
||
it("grouping nodes' autoExpand option is true when it has one child with autoExpand set to 'single-child'", async function () { | ||
await validateHierarchy({ | ||
provider: createProvider({ imodel: emptyIModel, hierarchy: createHierarchyWithSpecifiedGrouping(classAutoExpandSingleChild) }), | ||
expect: [ | ||
NodeValidators.createForClassGroupingNode({ | ||
className: "BisCore.Subject", | ||
autoExpand: true, | ||
children: [ | ||
NodeValidators.createForInstanceNode({ | ||
instanceKeys: [{ className: "BisCore.Subject", id: IModel.rootSubjectId }], | ||
children: false, | ||
}), | ||
], | ||
}), | ||
], | ||
}); | ||
}); | ||
|
||
it("grouping nodes' autoExpand option is undefined when none of the child nodes have autoExpand set to 'always'", async function () { | ||
const { imodel, ...keys } = await buildIModel(this, async (builder) => { | ||
const childSubject1 = insertSubject({ builder, codeValue: "A1", parentId: IModel.rootSubjectId }); | ||
const childSubject2 = insertSubject({ builder, codeValue: "A2", parentId: IModel.rootSubjectId }); | ||
return { childSubject1, childSubject2 }; | ||
}); | ||
|
||
await validateHierarchy({ | ||
provider: createProvider({ imodel, hierarchy: createHierarchyWithSpecifiedGrouping(classAutoExpandSingleChild) }), | ||
expect: [ | ||
NodeValidators.createForClassGroupingNode({ | ||
className: "BisCore.Subject", | ||
autoExpand: undefined, | ||
children: [ | ||
NodeValidators.createForInstanceNode({ | ||
instanceKeys: [{ className: "BisCore.Subject", id: IModel.rootSubjectId }], | ||
children: false, | ||
}), | ||
NodeValidators.createForInstanceNode({ | ||
instanceKeys: [keys.childSubject1], | ||
children: false, | ||
}), | ||
NodeValidators.createForInstanceNode({ | ||
instanceKeys: [keys.childSubject2], | ||
children: false, | ||
}), | ||
], | ||
}), | ||
], | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Label grouping", () => { | ||
const labelAutoExpandAlways: ECSqlSelectClauseGroupingParams = { | ||
byLabel: { | ||
autoExpand: "always", | ||
}, | ||
}; | ||
|
||
const labelAutoExpandSingleChild: ECSqlSelectClauseGroupingParams = { | ||
byLabel: { | ||
autoExpand: "single-child", | ||
}, | ||
}; | ||
|
||
it("grouping nodes' autoExpand option is true when some child has autoExpand set to 'always'", async function () { | ||
await validateHierarchy({ | ||
provider: createProvider({ imodel: emptyIModel, hierarchy: createHierarchyWithSpecifiedGrouping(labelAutoExpandAlways) }), | ||
expect: [ | ||
NodeValidators.createForLabelGroupingNode({ | ||
autoExpand: true, | ||
children: [ | ||
NodeValidators.createForInstanceNode({ | ||
instanceKeys: [{ className: "BisCore.Subject", id: IModel.rootSubjectId }], | ||
children: false, | ||
}), | ||
], | ||
}), | ||
], | ||
}); | ||
}); | ||
|
||
it("grouping nodes' autoExpand option is true when it has one child with autoExpand set to 'single-child'", async function () { | ||
await validateHierarchy({ | ||
provider: createProvider({ imodel: emptyIModel, hierarchy: createHierarchyWithSpecifiedGrouping(labelAutoExpandSingleChild) }), | ||
expect: [ | ||
NodeValidators.createForLabelGroupingNode({ | ||
autoExpand: true, | ||
children: [ | ||
NodeValidators.createForInstanceNode({ | ||
instanceKeys: [{ className: "BisCore.Subject", id: IModel.rootSubjectId }], | ||
children: false, | ||
}), | ||
], | ||
}), | ||
], | ||
}); | ||
}); | ||
|
||
it("grouping nodes' autoExpand option is undefined when none of the child nodes have autoExpand set to 'always'", async function () { | ||
const groupName = "test1"; | ||
const { imodel, ...keys } = await buildIModel(this, async (builder) => { | ||
const childSubject1 = insertSubject({ builder, codeValue: "A1", parentId: IModel.rootSubjectId, userLabel: groupName }); | ||
const childSubject2 = insertSubject({ builder, codeValue: "A2", parentId: IModel.rootSubjectId, userLabel: groupName }); | ||
return { childSubject1, childSubject2 }; | ||
}); | ||
|
||
await validateHierarchy({ | ||
provider: createProvider({ imodel, hierarchy: createHierarchyWithSpecifiedGrouping(labelAutoExpandSingleChild) }), | ||
expect: [ | ||
NodeValidators.createForLabelGroupingNode({ | ||
autoExpand: true, | ||
children: [ | ||
NodeValidators.createForInstanceNode({ | ||
instanceKeys: [{ className: "BisCore.Subject", id: IModel.rootSubjectId }], | ||
children: false, | ||
}), | ||
], | ||
}), | ||
NodeValidators.createForLabelGroupingNode({ | ||
label: groupName, | ||
autoExpand: undefined, | ||
children: [ | ||
NodeValidators.createForInstanceNode({ | ||
instanceKeys: [keys.childSubject1], | ||
children: false, | ||
}), | ||
NodeValidators.createForInstanceNode({ | ||
instanceKeys: [keys.childSubject2], | ||
children: false, | ||
}), | ||
], | ||
}), | ||
], | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.