-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add definitionContainers to categories tree #1172
base: master
Are you sure you want to change the base?
Add definitionContainers to categories tree #1172
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Impressive set of tests - great work!
...et/src/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.ts
Outdated
Show resolved
Hide resolved
...et/src/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.ts
Outdated
Show resolved
Hide resolved
...et/src/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.ts
Outdated
Show resolved
Hide resolved
...et/src/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.ts
Outdated
Show resolved
Hide resolved
...et/src/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.ts
Outdated
Show resolved
Hide resolved
...twin/tree-widget/src/test/trees/categories-tree/internal/CategoriesVisibilityHandler.test.ts
Show resolved
Hide resolved
...twin/tree-widget/src/test/trees/categories-tree/internal/CategoriesVisibilityHandler.test.ts
Outdated
Show resolved
Hide resolved
...twin/tree-widget/src/test/trees/categories-tree/internal/CategoriesVisibilityHandler.test.ts
Outdated
Show resolved
Hide resolved
mergeMap(async (node) => validateNodeVisibility({ ...props, node })), | ||
), | ||
); | ||
expect(props.nodesToExpect.every((nodeId) => nodesFound.includes(nodeId))).to.be.true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this check? we're testing visibility here, not the hierarchy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we do. I think we need to confirm that visibility of expected nodes is checked. Theoretically, without this check, validateHierarchyVisibility
could not check anything and it wouldn't fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without this check,
validateHierarchyVisibility
could not check anything and it wouldn't fail
Yes, but that should be tested in our hierarchy tests, not visibility ones. This check unnecessarily complicates the tests, e.g.:
// this is only needed for checking what we got in the hierarchy
const expectedIds = [
keys.definitionContainerRoot.id,
keys.definitionContainerChild.id,
keys.directCategory.id,
keys.indirectCategory.id,
keys.indirectSubCategory.id,
];
using visibilityTestData = await createVisibilityTestData({ imodel, isVisibleOnInitialize });
const { handler, provider, viewport } = visibilityTestData;
await handler.changeVisibility(createDefinitionContainerHierarchyNode(keys.definitionContainerRoot.id), true);
await validateHierarchyVisibility({
provider,
handler,
viewport,
visibilityExpectations: {},
expectedIds,
all: "visible",
});
...twin/tree-widget/src/test/trees/categories-tree/internal/CategoriesVisibilityHandler.test.ts
Outdated
Show resolved
Hide resolved
…ees/categories-tree/internal/CategoriesTreeIdsCache.ts Co-authored-by: Grigas <[email protected]>
…ees/categories-tree/internal/CategoriesTreeIdsCache.ts Co-authored-by: Grigas <[email protected]>
…ees/categories-tree/internal/CategoriesTreeIdsCache.ts Co-authored-by: Grigas <[email protected]>
…ees/categories-tree/internal/CategoriesTreeNode.ts Co-authored-by: Grigas <[email protected]>
…ees/categories-tree/internal/CategoriesTreeNode.ts Co-authored-by: Grigas <[email protected]>
…rnal/CategoriesTreeIdsCache.test.ts Co-authored-by: Grigas <[email protected]>
…ttps://github.com/iTwin/viewer-components-react into JonasD/categories-tree-with-definition-containers
…ees/categories-tree/CategoriesTreeDefinition.ts Co-authored-by: Grigas <[email protected]>
…ttps://github.com/iTwin/viewer-components-react into JonasD/categories-tree-with-definition-containers
const getCategoriesTreeIdsCache = useCallback(() => { | ||
if (!idsCacheRef.current) { | ||
idsCacheRef.current = new CategoriesTreeIdsCache(createECSqlQueryExecutor(iModel), viewType); | ||
} | ||
return idsCacheRef.current; | ||
}, [viewType, iModel]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see where idsCacheRef.current
is reset when view type or iModel changes so it will always return same cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, missed that, removed the condition, changed to useMemo
private static getInstanceIdFromHierarchyNode(node: HierarchyNode) { | ||
return HierarchyNode.isInstancesNode(node) && node.key.instanceKeys.length > 0 ? node.key.instanceKeys[0].id : /* istanbul ignore next */ ""; | ||
private static getInstanceIdsFromHierarchyNode(node: HierarchyNode) { | ||
return HierarchyNode.isInstancesNode(node) && node.key.instanceKeys.length > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need && node.key.instanceKeys.length > 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, removed
!HierarchyNodeIdentifier.isInstanceNodeIdentifier(secondToLastNode) || | ||
secondToLastNode.className === DEFINITION_CONTAINER_CLASS | ||
) { | ||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't hide those bugs. I suggest changing this to an assert
.
export class ViewportMock { | ||
private _idsCache: CategoriesTreeIdsCache; | ||
private _subCategories: Map<Id64String, boolean>; | ||
export async function createViewportStub(idsCache: CategoriesTreeIdsCache, isVisibleOnInitialize = false): Promise<Viewport & ViewportStubValidation> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest changing args to props - easier to maintain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
}: Omit<ValidateNodeProps, "visibilityExpectations"> & { | ||
visibilityExpectations: VisibilityExpectations; | ||
provider: HierarchyProvider; | ||
}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this?
Omit<ValidateNodeProps, "visibilityExpectations"> & { visibilityExpectations: VisibilityExpectations }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No purpose, removed
private _implWithoutDefinitionContainers: HierarchyDefinition; | ||
private _implWithDefinitionContainers: HierarchyDefinition; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really need both of these? maybe one would be enough, with one of the childNodes
specs being added conditionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't, removed
const CATEGORIES_CTE = "AllVisibleCategories"; | ||
const isDefinitionContainerSupported = await this.getIsDefinitionContainerSupported(); | ||
const ctes = [ | ||
`${CATEGORIES_CTE}(ECInstanceId, ChildCount, ModelId ${isDefinitionContainerSupported ? ", ParentDefinitionContainerExists" : ""}) AS ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe the ParentDefinitionContainerExists
property could always be there, but it's value would always be false
if the class doesn't exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
mergeMap(async (node) => validateNodeVisibility({ ...props, node })), | ||
), | ||
); | ||
expect(props.nodesToExpect.every((nodeId) => nodesFound.includes(nodeId))).to.be.true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without this check,
validateHierarchyVisibility
could not check anything and it wouldn't fail
Yes, but that should be tested in our hierarchy tests, not visibility ones. This check unnecessarily complicates the tests, e.g.:
// this is only needed for checking what we got in the hierarchy
const expectedIds = [
keys.definitionContainerRoot.id,
keys.definitionContainerChild.id,
keys.directCategory.id,
keys.indirectCategory.id,
keys.indirectSubCategory.id,
];
using visibilityTestData = await createVisibilityTestData({ imodel, isVisibleOnInitialize });
const { handler, provider, viewport } = visibilityTestData;
await handler.changeVisibility(createDefinitionContainerHierarchyNode(keys.definitionContainerRoot.id), true);
await validateHierarchyVisibility({
provider,
handler,
viewport,
visibilityExpectations: {},
expectedIds,
all: "visible",
});
visibilityExpectations: VisibilityExpectations; | ||
expectedIds: Id64Array; | ||
all?: "visible" | "hidden"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about changing { visibilityExpectations: VisibilityExpectations; all?: "visible" | "hidden"; }
to { expect: "all-visible" | "all-hidden" | VisibilityExpectations }
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better, changed to your suggestion, just instead of naming expect
named to expectations
since we are importing expect
from chai
closes #1126