-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathIModelContentTree.test.tsx
93 lines (86 loc) · 4.01 KB
/
IModelContentTree.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { join } from "path";
import sinon from "sinon";
import { UiFramework } from "@itwin/appui-react";
import { IModel, IModelReadRpcInterface, SnapshotIModelRpcInterface } from "@itwin/core-common";
import { IModelApp, NoRenderApp } from "@itwin/core-frontend";
import { ECSchemaRpcInterface } from "@itwin/ecschema-rpcinterface-common";
import { ECSchemaRpcImpl } from "@itwin/ecschema-rpcinterface-impl";
import { PresentationRpcInterface } from "@itwin/presentation-common";
import { HierarchyCacheMode, initialize as initializePresentationTesting, terminate as terminatePresentationTesting } from "@itwin/presentation-testing";
// __PUBLISH_EXTRACT_START__ Presentation.TreeWidget.ImodelContentTreeExampleImports
import { IModelContentTreeComponent } from "@itwin/tree-widget-react";
// __PUBLISH_EXTRACT_END__
import { createStorage } from "@itwin/unified-selection";
import { cleanup, render, waitFor } from "@testing-library/react";
import { buildIModel, insertSubject } from "../../utils/IModelUtils";
import { getSchemaContext, getTestViewer, mockGetBoundingClientRect, TestUtils } from "../../utils/TestUtils";
describe("Tree widget", () => {
describe("Learning snippets", () => {
describe("Components", () => {
describe("Imodel content tree", () => {
before(async function () {
await initializePresentationTesting({
backendProps: {
caching: {
hierarchies: {
mode: HierarchyCacheMode.Memory,
},
},
},
testOutputDir: join(__dirname, "output"),
backendHostProps: {
cacheDir: join(__dirname, "cache"),
},
rpcs: [SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface, ECSchemaRpcInterface],
});
// eslint-disable-next-line @itwin/no-internal
ECSchemaRpcImpl.register();
});
after(async function () {
await terminatePresentationTesting();
});
beforeEach(async () => {
await NoRenderApp.startup();
await TestUtils.initialize();
});
afterEach(async () => {
TestUtils.terminate();
await IModelApp.shutdown();
sinon.restore();
});
it("Renders <IModelContentTreeComponent />", async function () {
const imodel = (
await buildIModel(this, async (builder) => {
const subjectA = insertSubject({ builder, codeValue: "A", parentId: IModel.rootSubjectId });
return { subjectA };
})
).imodel;
const testViewport = getTestViewer(imodel);
const unifiedSelectionStorage = createStorage();
sinon.stub(IModelApp.viewManager, "selectedView").get(() => testViewport);
sinon.stub(UiFramework, "getIModelConnection").returns(imodel);
mockGetBoundingClientRect();
// __PUBLISH_EXTRACT_START__ Presentation.TreeWidget.ImodelContentTreeExample
function MyWidget() {
return (
<IModelContentTreeComponent
// see "Creating schema context" section for example implementation
getSchemaContext={getSchemaContext}
// see "Creating unified selection storage" section for example implementation
selectionStorage={unifiedSelectionStorage}
/>
);
}
// __PUBLISH_EXTRACT_END__
const { getByText } = render(<MyWidget />);
await waitFor(() => getByText("tree-widget-learning-snippets-components-imodel-content-tree-renders-imodelcontenttreecomponent-"));
cleanup();
});
});
});
});
});