@itwin/presentation-testing 4.0.0-dev.7 → 4.0.0-dev.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +927 -959
- package/LICENSE.md +9 -9
- package/README.md +7 -7
- package/lib/cjs/presentation-testing/ContentBuilder.d.ts +92 -89
- package/lib/cjs/presentation-testing/ContentBuilder.d.ts.map +1 -1
- package/lib/cjs/presentation-testing/ContentBuilder.js +178 -149
- package/lib/cjs/presentation-testing/ContentBuilder.js.map +1 -1
- package/lib/cjs/presentation-testing/Helpers.d.ts +45 -42
- package/lib/cjs/presentation-testing/Helpers.d.ts.map +1 -1
- package/lib/cjs/presentation-testing/Helpers.js +138 -139
- package/lib/cjs/presentation-testing/Helpers.js.map +1 -1
- package/lib/cjs/presentation-testing/HierarchyBuilder.d.ts +69 -66
- package/lib/cjs/presentation-testing/HierarchyBuilder.d.ts.map +1 -1
- package/lib/cjs/presentation-testing/HierarchyBuilder.js +78 -67
- package/lib/cjs/presentation-testing/HierarchyBuilder.js.map +1 -1
- package/lib/cjs/presentation-testing/IModelUtilities.d.ts +46 -46
- package/lib/cjs/presentation-testing/IModelUtilities.d.ts.map +1 -1
- package/lib/cjs/presentation-testing/IModelUtilities.js +83 -77
- package/lib/cjs/presentation-testing/IModelUtilities.js.map +1 -1
- package/lib/cjs/presentation-testing.d.ts +28 -28
- package/lib/cjs/presentation-testing.d.ts.map +1 -1
- package/lib/cjs/presentation-testing.js +44 -44
- package/lib/cjs/presentation-testing.js.map +1 -1
- package/lib/esm/presentation-testing/ContentBuilder.d.ts +92 -89
- package/lib/esm/presentation-testing/ContentBuilder.d.ts.map +1 -1
- package/lib/esm/presentation-testing/ContentBuilder.js +174 -145
- package/lib/esm/presentation-testing/ContentBuilder.js.map +1 -1
- package/lib/esm/presentation-testing/Helpers.d.ts +45 -42
- package/lib/esm/presentation-testing/Helpers.d.ts.map +1 -1
- package/lib/esm/presentation-testing/Helpers.js +113 -114
- package/lib/esm/presentation-testing/Helpers.js.map +1 -1
- package/lib/esm/presentation-testing/HierarchyBuilder.d.ts +69 -66
- package/lib/esm/presentation-testing/HierarchyBuilder.d.ts.map +1 -1
- package/lib/esm/presentation-testing/HierarchyBuilder.js +73 -62
- package/lib/esm/presentation-testing/HierarchyBuilder.js.map +1 -1
- package/lib/esm/presentation-testing/IModelUtilities.d.ts +46 -46
- package/lib/esm/presentation-testing/IModelUtilities.d.ts.map +1 -1
- package/lib/esm/presentation-testing/IModelUtilities.js +75 -69
- package/lib/esm/presentation-testing/IModelUtilities.js.map +1 -1
- package/lib/esm/presentation-testing.d.ts +28 -28
- package/lib/esm/presentation-testing.d.ts.map +1 -1
- package/lib/esm/presentation-testing.js +32 -32
- package/lib/esm/presentation-testing.js.map +1 -1
- package/package.json +53 -53
|
@@ -1,146 +1,175 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
/** @packageDocumentation
|
|
6
|
-
* @module Content
|
|
7
|
-
*/
|
|
8
|
-
import { using } from "@itwin/core-bentley";
|
|
9
|
-
import { QueryRowFormat } from "@itwin/core-common";
|
|
10
|
-
import { DefaultContentDisplayTypes, KeySet, traverseContent, } from "@itwin/presentation-common";
|
|
11
|
-
import { ContentDataProvider, PropertyRecordsBuilder } from "@itwin/presentation-components";
|
|
12
|
-
import { Presentation } from "@itwin/presentation-frontend";
|
|
13
|
-
/**
|
|
14
|
-
* A class that constructs content from specified imodel and ruleset.
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
export class ContentBuilder {
|
|
18
|
-
/**
|
|
19
|
-
* Constructor
|
|
20
|
-
* @param iModel
|
|
21
|
-
* @param dataProvider
|
|
22
|
-
*/
|
|
23
|
-
constructor(props) {
|
|
24
|
-
this
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
this.
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Content
|
|
7
|
+
*/
|
|
8
|
+
import { using } from "@itwin/core-bentley";
|
|
9
|
+
import { QueryRowFormat } from "@itwin/core-common";
|
|
10
|
+
import { DefaultContentDisplayTypes, KeySet, traverseContent, } from "@itwin/presentation-common";
|
|
11
|
+
import { ContentDataProvider, PropertyRecordsBuilder } from "@itwin/presentation-components";
|
|
12
|
+
import { Presentation } from "@itwin/presentation-frontend";
|
|
13
|
+
/**
|
|
14
|
+
* A class that constructs content from specified imodel and ruleset.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export class ContentBuilder {
|
|
18
|
+
/**
|
|
19
|
+
* Constructor
|
|
20
|
+
* @param iModel
|
|
21
|
+
* @param dataProvider
|
|
22
|
+
*/
|
|
23
|
+
constructor(props) {
|
|
24
|
+
Object.defineProperty(this, "_iModel", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true,
|
|
28
|
+
value: void 0
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(this, "_dataProvider", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true,
|
|
34
|
+
value: void 0
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(this, "_decimalPrecision", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true,
|
|
40
|
+
value: void 0
|
|
41
|
+
});
|
|
42
|
+
this._iModel = props.imodel;
|
|
43
|
+
this._dataProvider = props.dataProvider;
|
|
44
|
+
this._decimalPrecision = props.decimalPrecision;
|
|
45
|
+
}
|
|
46
|
+
async doCreateContent(rulesetId, instanceKeys, displayType) {
|
|
47
|
+
const dataProvider = this._dataProvider ? this._dataProvider : new ContentDataProvider({ imodel: this._iModel, ruleset: rulesetId, displayType });
|
|
48
|
+
dataProvider.keys = new KeySet(instanceKeys);
|
|
49
|
+
const content = await dataProvider.getContent();
|
|
50
|
+
if (!content)
|
|
51
|
+
return [];
|
|
52
|
+
const accumulator = new PropertyRecordsAccumulator(this._decimalPrecision);
|
|
53
|
+
traverseContent(accumulator, content);
|
|
54
|
+
return accumulator.records;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create a list of property records using the supplied presentation ruleset.
|
|
58
|
+
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
59
|
+
* @param instanceKeys Keys of instances that should be queried.
|
|
60
|
+
* @param displayType Type of content container display. For example:
|
|
61
|
+
* "PropertyPane", "Grid", "List" etc.
|
|
62
|
+
*/
|
|
63
|
+
async createContent(rulesetOrId, instanceKeys, displayType = DefaultContentDisplayTypes.PropertyPane) {
|
|
64
|
+
if (typeof rulesetOrId === "string")
|
|
65
|
+
return this.doCreateContent(rulesetOrId, instanceKeys, displayType);
|
|
66
|
+
return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset) => {
|
|
67
|
+
return this.doCreateContent(ruleset.id, instanceKeys, displayType);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async getECClassNames() {
|
|
71
|
+
const rows = [];
|
|
72
|
+
for await (const row of this._iModel.query(`
|
|
73
|
+
SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c
|
|
74
|
+
INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId
|
|
75
|
+
WHERE c.Modifier <> 1 AND c.Type = 0
|
|
76
|
+
ORDER BY s.Name, c.Name
|
|
77
|
+
`, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames })) {
|
|
78
|
+
rows.push(row);
|
|
79
|
+
}
|
|
80
|
+
return rows;
|
|
81
|
+
}
|
|
82
|
+
async createContentForClasses(rulesetOrId, limitInstances, displayType) {
|
|
83
|
+
const classNameEntries = await this.getECClassNames();
|
|
84
|
+
const contents = [];
|
|
85
|
+
for (const nameEntry of classNameEntries) {
|
|
86
|
+
// try {
|
|
87
|
+
const instanceIds = [];
|
|
88
|
+
for await (const row of this._iModel.query(`
|
|
89
|
+
SELECT ECInstanceId FROM ONLY "${nameEntry.schemaName}"."${nameEntry.className}"
|
|
90
|
+
ORDER BY ECInstanceId`, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } })) {
|
|
91
|
+
instanceIds.push(row.id);
|
|
92
|
+
}
|
|
93
|
+
if (!instanceIds.length)
|
|
94
|
+
continue;
|
|
95
|
+
const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry }));
|
|
96
|
+
contents.push({
|
|
97
|
+
className: `${nameEntry.schemaName}:${nameEntry.className}`,
|
|
98
|
+
records: await this.createContent(rulesetOrId, instanceKeys, displayType),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return contents;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create a list of grouped property records using the supplied presentation ruleset.
|
|
105
|
+
* Each group includes all of the class instances.
|
|
106
|
+
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
107
|
+
* @param displayType Type of content container display. For example:
|
|
108
|
+
* "PropertyPane", "Grid", "List" etc.
|
|
109
|
+
* @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.
|
|
110
|
+
*/
|
|
111
|
+
async createContentForAllInstances(rulesetOrId, displayType = DefaultContentDisplayTypes.PropertyPane) {
|
|
112
|
+
return this.createContentForClasses(rulesetOrId, false, displayType);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create a list of grouped property records using the supplied presentation ruleset.
|
|
116
|
+
* Each group includes at most one class instance.
|
|
117
|
+
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
118
|
+
* @param displayType Type of content container display. For example:
|
|
119
|
+
* "PropertyPane", "Grid", "List" etc.
|
|
120
|
+
* @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.
|
|
121
|
+
*/
|
|
122
|
+
async createContentForInstancePerClass(rulesetOrId, displayType = DefaultContentDisplayTypes.PropertyPane) {
|
|
123
|
+
return this.createContentForClasses(rulesetOrId, true, displayType);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
class PropertyRecordsAccumulator extends PropertyRecordsBuilder {
|
|
127
|
+
constructor(decimalPrecision) {
|
|
128
|
+
super();
|
|
129
|
+
Object.defineProperty(this, "_records", {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
configurable: true,
|
|
132
|
+
writable: true,
|
|
133
|
+
value: []
|
|
134
|
+
});
|
|
135
|
+
Object.defineProperty(this, "_decimalPrecision", {
|
|
136
|
+
enumerable: true,
|
|
137
|
+
configurable: true,
|
|
138
|
+
writable: true,
|
|
139
|
+
value: void 0
|
|
140
|
+
});
|
|
141
|
+
this._decimalPrecision = decimalPrecision;
|
|
142
|
+
}
|
|
143
|
+
get records() {
|
|
144
|
+
return this._records;
|
|
145
|
+
}
|
|
146
|
+
createRootPropertiesAppender() {
|
|
147
|
+
return {
|
|
148
|
+
append: (record) => {
|
|
149
|
+
this._records.push(record.record);
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
processRawValue(value) {
|
|
154
|
+
if (this._decimalPrecision === undefined)
|
|
155
|
+
return value;
|
|
156
|
+
if (typeof value === "number") {
|
|
157
|
+
return +(Number(value)).toFixed(this._decimalPrecision);
|
|
158
|
+
}
|
|
159
|
+
if (Array.isArray(value)) {
|
|
160
|
+
return value.map((item) => this.processRawValue(item));
|
|
161
|
+
}
|
|
162
|
+
if (value instanceof Object) {
|
|
163
|
+
const res = {};
|
|
164
|
+
Object.entries(value).forEach(([key, memberValue]) => {
|
|
165
|
+
res[key] = this.processRawValue(memberValue);
|
|
166
|
+
});
|
|
167
|
+
return res;
|
|
168
|
+
}
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
processPrimitiveValue(props) {
|
|
172
|
+
super.processPrimitiveValue({ ...props, rawValue: this.processRawValue(props.rawValue) });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
146
175
|
//# sourceMappingURL=ContentBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAG/F;;GAEG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EACI,0BAA0B,EAAe,MAAM,EAAuE,eAAe,GAE/I,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAwB,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACnH,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAiD5D;;;GAGG;AACH,MAAM,OAAO,cAAc;IAKzB;;;;OAIG;IACH,YAAY,KAA0B;QACpC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,gBAAgB,CAAC;IAClD,CAAC;IAEO,KAAK,CAAC,eAAe,CAAC,SAAiB,EAAE,YA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AC,IAAI,CAAC,CAAC,CAAC;SACxD;QAED,IAAI,KAAK,YAAY,MAAM,EAAE;YAC3B,MAAM,GAAG,GAAc,EAAE,CAAC;YAC1B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,EAAE;gBACnD,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;YAC/C,CAAC,CAAC,CAAC;YACH,OAAO,GAAG,CAAC;SACZ;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEe,qBAAqB,CAAC,KAAiC;QACrE,KAAK,CAAC,qBAAqB,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC5F,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { PropertyRecord } from \"@itwin/appui-abstract\";\r\n/** @packageDocumentation\r\n * @module Content\r\n */\r\nimport { using } from \"@itwin/core-bentley\";\r\nimport { QueryRowFormat } from \"@itwin/core-common\";\r\nimport { IModelConnection } from \"@itwin/core-frontend\";\r\nimport {\r\n Content, DefaultContentDisplayTypes, InstanceKey, KeySet, PageOptions, ProcessPrimitiveValueProps, RegisteredRuleset, Ruleset, traverseContent,\r\n Value, ValuesMap,\r\n} from \"@itwin/presentation-common\";\r\nimport { ContentDataProvider, FieldHierarchyRecord, PropertyRecordsBuilder } from \"@itwin/presentation-components\";\r\nimport { Presentation } from \"@itwin/presentation-frontend\";\r\n\r\n/**\r\n * Interface for a data provider, which is used by ContentBuilder.\r\n * @public\r\n */\r\nexport interface IContentBuilderDataProvider {\r\n /** Keys the data provider is creating content for */\r\n keys: Readonly<KeySet>;\r\n /** Get the size of content result set */\r\n getContentSetSize: () => Promise<number>;\r\n /** Get the content */\r\n getContent: (options?: PageOptions) => Promise<Readonly<Content> | undefined>;\r\n}\r\n\r\n/**\r\n * Property records grouped under a single className\r\n * @public\r\n */\r\nexport interface ContentBuilderResult {\r\n /** Full name of ECClass whose records are contained in this data structure */\r\n className: string;\r\n /** Property records for the ECClass instance */\r\n records: PropertyRecord[];\r\n}\r\n\r\n/**\r\n * Properties for creating a `ContentBuilder` instance.\r\n * @public\r\n */\r\nexport interface ContentBuilderProps {\r\n /** The iModel to pull data from */\r\n imodel: IModelConnection;\r\n\r\n /** Custom data provider that allows mocking data ContentBuilder receives */\r\n dataProvider?: IContentBuilderDataProvider;\r\n\r\n /**\r\n * Decimal precision or numeric types.\r\n *\r\n * Raw numeric values with high precision may slightly differ from platform to platform due to\r\n * rounding differences on different platforms. This may be a problem when used with snapshot testing,\r\n * in which case this attribute may be set to supply the maximum precision of raw numeric values.\r\n *\r\n * By default no rounding is applied.\r\n */\r\n decimalPrecision?: number;\r\n}\r\n\r\n/**\r\n * A class that constructs content from specified imodel and ruleset.\r\n * @public\r\n */\r\nexport class ContentBuilder {\r\n private readonly _iModel: IModelConnection;\r\n private _dataProvider: IContentBuilderDataProvider | undefined;\r\n private _decimalPrecision?: number;\r\n\r\n /**\r\n * Constructor\r\n * @param iModel\r\n * @param dataProvider\r\n */\r\n constructor(props: ContentBuilderProps) {\r\n this._iModel = props.imodel;\r\n this._dataProvider = props.dataProvider;\r\n this._decimalPrecision = props.decimalPrecision;\r\n }\r\n\r\n private async doCreateContent(rulesetId: string, instanceKeys: InstanceKey[], displayType: string): Promise<PropertyRecord[]> {\r\n const dataProvider = this._dataProvider ? this._dataProvider : new ContentDataProvider({ imodel: this._iModel, ruleset: rulesetId, displayType });\r\n dataProvider.keys = new KeySet(instanceKeys);\r\n\r\n const content = await dataProvider.getContent();\r\n if (!content)\r\n return [];\r\n\r\n const accumulator = new PropertyRecordsAccumulator(this._decimalPrecision);\r\n traverseContent(accumulator, content);\r\n return accumulator.records;\r\n }\r\n\r\n /**\r\n * Create a list of property records using the supplied presentation ruleset.\r\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\r\n * @param instanceKeys Keys of instances that should be queried.\r\n * @param displayType Type of content container display. For example:\r\n * \"PropertyPane\", \"Grid\", \"List\" etc.\r\n */\r\n public async createContent(rulesetOrId: Ruleset | string, instanceKeys: InstanceKey[], displayType: string = DefaultContentDisplayTypes.PropertyPane) {\r\n if (typeof rulesetOrId === \"string\")\r\n return this.doCreateContent(rulesetOrId, instanceKeys, displayType);\r\n\r\n return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset: RegisteredRuleset) => {\r\n return this.doCreateContent(ruleset.id, instanceKeys, displayType);\r\n });\r\n }\r\n\r\n private async getECClassNames(): Promise<Array<{ schemaName: string, className: string }>> {\r\n const rows = [];\r\n for await (const row of this._iModel.query(`\r\n SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c\r\n INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId\r\n WHERE c.Modifier <> 1 AND c.Type = 0\r\n ORDER BY s.Name, c.Name\r\n `, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames })) {\r\n rows.push(row);\r\n }\r\n return rows;\r\n }\r\n\r\n private async createContentForClasses(rulesetOrId: Ruleset | string, limitInstances: boolean, displayType: string) {\r\n const classNameEntries = await this.getECClassNames();\r\n\r\n const contents: ContentBuilderResult[] = [];\r\n\r\n for (const nameEntry of classNameEntries) {\r\n // try {\r\n const instanceIds = [];\r\n for await (const row of this._iModel.query(`\r\n SELECT ECInstanceId FROM ONLY \"${nameEntry.schemaName}\".\"${nameEntry.className}\"\r\n ORDER BY ECInstanceId`, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } })) {\r\n instanceIds.push(row.id);\r\n }\r\n\r\n if (!instanceIds.length)\r\n continue;\r\n\r\n const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry } as InstanceKey));\r\n\r\n contents.push({\r\n className: `${nameEntry.schemaName}:${nameEntry.className}`,\r\n records: await this.createContent(rulesetOrId, instanceKeys, displayType),\r\n });\r\n }\r\n\r\n return contents;\r\n }\r\n\r\n /**\r\n * Create a list of grouped property records using the supplied presentation ruleset.\r\n * Each group includes all of the class instances.\r\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\r\n * @param displayType Type of content container display. For example:\r\n * \"PropertyPane\", \"Grid\", \"List\" etc.\r\n * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.\r\n */\r\n public async createContentForAllInstances(rulesetOrId: Ruleset | string, displayType: string = DefaultContentDisplayTypes.PropertyPane) {\r\n return this.createContentForClasses(rulesetOrId, false, displayType);\r\n }\r\n\r\n /**\r\n * Create a list of grouped property records using the supplied presentation ruleset.\r\n * Each group includes at most one class instance.\r\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\r\n * @param displayType Type of content container display. For example:\r\n * \"PropertyPane\", \"Grid\", \"List\" etc.\r\n * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.\r\n */\r\n public async createContentForInstancePerClass(rulesetOrId: Ruleset | string, displayType: string = DefaultContentDisplayTypes.PropertyPane) {\r\n return this.createContentForClasses(rulesetOrId, true, displayType);\r\n }\r\n}\r\n\r\nclass PropertyRecordsAccumulator extends PropertyRecordsBuilder {\r\n private _records: PropertyRecord[] = [];\r\n private _decimalPrecision?: number;\r\n\r\n public constructor(decimalPrecision?: number) {\r\n super();\r\n this._decimalPrecision = decimalPrecision;\r\n }\r\n\r\n public get records(): PropertyRecord[] {\r\n return this._records;\r\n }\r\n\r\n protected createRootPropertiesAppender() {\r\n return {\r\n append: (record: FieldHierarchyRecord) => {\r\n this._records.push(record.record);\r\n },\r\n };\r\n }\r\n\r\n private processRawValue(value: Value): Value {\r\n if (this._decimalPrecision === undefined)\r\n return value;\r\n\r\n if (typeof value === \"number\") {\r\n return +(Number(value)).toFixed(this._decimalPrecision);\r\n }\r\n\r\n if (Array.isArray(value)) {\r\n return value.map((item) => this.processRawValue(item));\r\n }\r\n\r\n if (value instanceof Object) {\r\n const res: ValuesMap = {};\r\n Object.entries(value).forEach(([key, memberValue]) => {\r\n res[key] = this.processRawValue(memberValue);\r\n });\r\n return res;\r\n }\r\n\r\n return value;\r\n }\r\n\r\n public override processPrimitiveValue(props: ProcessPrimitiveValueProps) {\r\n super.processPrimitiveValue({ ...props, rawValue: this.processRawValue(props.rawValue) });\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ContentBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/ContentBuilder.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EACI,0BAA0B,EAAe,MAAM,EAAuE,eAAe,GAE/I,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAwB,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACnH,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAiD5D;;;GAGG;AACH,MAAM,OAAO,cAAc;IAKzB;;;;OAIG;IACH,YAAY,KAA0B;QATtC;;;;;WAA2C;QAC3C;;;;;WAA+D;QAC/D;;;;;WAAmC;QAQjC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,gBAAgB,CAAC;IAClD,CAAC;IAEO,KAAK,CAAC,eAAe,CAAC,SAAiB,EAAE,YAA2B,EAAE,WAAmB;QAC/F,MAAM,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CAAC,CAAC;SACxD;QAED,IAAI,KAAK,YAAY,MAAM,EAAE;YAC3B,MAAM,GAAG,GAAc,EAAE,CAAC;YAC1B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,EAAE;gBACnD,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;YAC/C,CAAC,CAAC,CAAC;YACH,OAAO,GAAG,CAAC;SACZ;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEe,qBAAqB,CAAC,KAAiC;QACrE,KAAK,CAAC,qBAAqB,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC5F,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Content\n */\n\nimport { PropertyRecord } from \"@itwin/appui-abstract\";\nimport { using } from \"@itwin/core-bentley\";\nimport { QueryRowFormat } from \"@itwin/core-common\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport {\n Content, DefaultContentDisplayTypes, InstanceKey, KeySet, PageOptions, ProcessPrimitiveValueProps, RegisteredRuleset, Ruleset, traverseContent,\n Value, ValuesMap,\n} from \"@itwin/presentation-common\";\nimport { ContentDataProvider, FieldHierarchyRecord, PropertyRecordsBuilder } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\n\n/**\n * Interface for a data provider, which is used by ContentBuilder.\n * @public\n */\nexport interface IContentBuilderDataProvider {\n /** Keys the data provider is creating content for */\n keys: Readonly<KeySet>;\n /** Get the size of content result set */\n getContentSetSize: () => Promise<number>;\n /** Get the content */\n getContent: (options?: PageOptions) => Promise<Readonly<Content> | undefined>;\n}\n\n/**\n * Property records grouped under a single className\n * @public\n */\nexport interface ContentBuilderResult {\n /** Full name of ECClass whose records are contained in this data structure */\n className: string;\n /** Property records for the ECClass instance */\n records: PropertyRecord[];\n}\n\n/**\n * Properties for creating a `ContentBuilder` instance.\n * @public\n */\nexport interface ContentBuilderProps {\n /** The iModel to pull data from */\n imodel: IModelConnection;\n\n /** Custom data provider that allows mocking data ContentBuilder receives */\n dataProvider?: IContentBuilderDataProvider;\n\n /**\n * Decimal precision or numeric types.\n *\n * Raw numeric values with high precision may slightly differ from platform to platform due to\n * rounding differences on different platforms. This may be a problem when used with snapshot testing,\n * in which case this attribute may be set to supply the maximum precision of raw numeric values.\n *\n * By default no rounding is applied.\n */\n decimalPrecision?: number;\n}\n\n/**\n * A class that constructs content from specified imodel and ruleset.\n * @public\n */\nexport class ContentBuilder {\n private readonly _iModel: IModelConnection;\n private _dataProvider: IContentBuilderDataProvider | undefined;\n private _decimalPrecision?: number;\n\n /**\n * Constructor\n * @param iModel\n * @param dataProvider\n */\n constructor(props: ContentBuilderProps) {\n this._iModel = props.imodel;\n this._dataProvider = props.dataProvider;\n this._decimalPrecision = props.decimalPrecision;\n }\n\n private async doCreateContent(rulesetId: string, instanceKeys: InstanceKey[], displayType: string): Promise<PropertyRecord[]> {\n const dataProvider = this._dataProvider ? this._dataProvider : new ContentDataProvider({ imodel: this._iModel, ruleset: rulesetId, displayType });\n dataProvider.keys = new KeySet(instanceKeys);\n\n const content = await dataProvider.getContent();\n if (!content)\n return [];\n\n const accumulator = new PropertyRecordsAccumulator(this._decimalPrecision);\n traverseContent(accumulator, content);\n return accumulator.records;\n }\n\n /**\n * Create a list of property records using the supplied presentation ruleset.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n * @param instanceKeys Keys of instances that should be queried.\n * @param displayType Type of content container display. For example:\n * \"PropertyPane\", \"Grid\", \"List\" etc.\n */\n public async createContent(rulesetOrId: Ruleset | string, instanceKeys: InstanceKey[], displayType: string = DefaultContentDisplayTypes.PropertyPane) {\n if (typeof rulesetOrId === \"string\")\n return this.doCreateContent(rulesetOrId, instanceKeys, displayType);\n\n return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset: RegisteredRuleset) => {\n return this.doCreateContent(ruleset.id, instanceKeys, displayType);\n });\n }\n\n private async getECClassNames(): Promise<Array<{ schemaName: string, className: string }>> {\n const rows = [];\n for await (const row of this._iModel.query(`\n SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c\n INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId\n WHERE c.Modifier <> 1 AND c.Type = 0\n ORDER BY s.Name, c.Name\n `, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames })) {\n rows.push(row);\n }\n return rows;\n }\n\n private async createContentForClasses(rulesetOrId: Ruleset | string, limitInstances: boolean, displayType: string) {\n const classNameEntries = await this.getECClassNames();\n\n const contents: ContentBuilderResult[] = [];\n\n for (const nameEntry of classNameEntries) {\n // try {\n const instanceIds = [];\n for await (const row of this._iModel.query(`\n SELECT ECInstanceId FROM ONLY \"${nameEntry.schemaName}\".\"${nameEntry.className}\"\n ORDER BY ECInstanceId`, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } })) {\n instanceIds.push(row.id);\n }\n\n if (!instanceIds.length)\n continue;\n\n const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry } as InstanceKey));\n\n contents.push({\n className: `${nameEntry.schemaName}:${nameEntry.className}`,\n records: await this.createContent(rulesetOrId, instanceKeys, displayType),\n });\n }\n\n return contents;\n }\n\n /**\n * Create a list of grouped property records using the supplied presentation ruleset.\n * Each group includes all of the class instances.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n * @param displayType Type of content container display. For example:\n * \"PropertyPane\", \"Grid\", \"List\" etc.\n * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.\n */\n public async createContentForAllInstances(rulesetOrId: Ruleset | string, displayType: string = DefaultContentDisplayTypes.PropertyPane) {\n return this.createContentForClasses(rulesetOrId, false, displayType);\n }\n\n /**\n * Create a list of grouped property records using the supplied presentation ruleset.\n * Each group includes at most one class instance.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n * @param displayType Type of content container display. For example:\n * \"PropertyPane\", \"Grid\", \"List\" etc.\n * @deprecated in 3.x. This method turned out to be useless as it creates content for too many instances. Should use [[createContent]] instead.\n */\n public async createContentForInstancePerClass(rulesetOrId: Ruleset | string, displayType: string = DefaultContentDisplayTypes.PropertyPane) {\n return this.createContentForClasses(rulesetOrId, true, displayType);\n }\n}\n\nclass PropertyRecordsAccumulator extends PropertyRecordsBuilder {\n private _records: PropertyRecord[] = [];\n private _decimalPrecision?: number;\n\n public constructor(decimalPrecision?: number) {\n super();\n this._decimalPrecision = decimalPrecision;\n }\n\n public get records(): PropertyRecord[] {\n return this._records;\n }\n\n protected createRootPropertiesAppender() {\n return {\n append: (record: FieldHierarchyRecord) => {\n this._records.push(record.record);\n },\n };\n }\n\n private processRawValue(value: Value): Value {\n if (this._decimalPrecision === undefined)\n return value;\n\n if (typeof value === \"number\") {\n return +(Number(value)).toFixed(this._decimalPrecision);\n }\n\n if (Array.isArray(value)) {\n return value.map((item) => this.processRawValue(item));\n }\n\n if (value instanceof Object) {\n const res: ValuesMap = {};\n Object.entries(value).forEach(([key, memberValue]) => {\n res[key] = this.processRawValue(memberValue);\n });\n return res;\n }\n\n return value;\n }\n\n public override processPrimitiveValue(props: ProcessPrimitiveValueProps) {\n super.processPrimitiveValue({ ...props, rawValue: this.processRawValue(props.rawValue) });\n }\n}\n"]}
|
|
@@ -1,43 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/** @
|
|
9
|
-
export
|
|
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
|
-
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Helpers
|
|
3
|
+
*/
|
|
4
|
+
import { IModelHostOptions } from "@itwin/core-backend";
|
|
5
|
+
import { IModelApp, IModelAppOptions } from "@itwin/core-frontend";
|
|
6
|
+
import { HierarchyCacheMode, PresentationManagerProps as PresentationBackendProps, PresentationManagerMode } from "@itwin/presentation-backend";
|
|
7
|
+
import { PresentationProps as PresentationFrontendProps } from "@itwin/presentation-frontend";
|
|
8
|
+
/** @internal */
|
|
9
|
+
export declare const getTestOutputDir: () => string;
|
|
10
|
+
export { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };
|
|
11
|
+
/** @public */
|
|
12
|
+
export interface PresentationTestingInitProps {
|
|
13
|
+
/** Properties for backend initialization */
|
|
14
|
+
backendProps?: PresentationBackendProps;
|
|
15
|
+
/** Properties for `IModelHost` */
|
|
16
|
+
backendHostProps?: IModelHostOptions;
|
|
17
|
+
/** Properties for frontend initialization */
|
|
18
|
+
frontendProps?: PresentationFrontendProps;
|
|
19
|
+
/** IModelApp implementation */
|
|
20
|
+
frontendApp?: {
|
|
21
|
+
startup: (opts?: IModelAppOptions) => Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
/** `IModelApp` options */
|
|
24
|
+
frontendAppOptions?: IModelAppOptions;
|
|
25
|
+
/** Custom test output directory. Defaults to temporary directory provided by the OS. */
|
|
26
|
+
testOutputDir?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Initialize the framework for presentation testing. The function sets up backend,
|
|
30
|
+
* frontend and RPC communication between them.
|
|
31
|
+
*
|
|
32
|
+
* @see `terminate`
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export declare const initialize: (props?: PresentationTestingInitProps | undefined) => Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Undoes the setup made by `initialize`.
|
|
39
|
+
* @param frontendApp IModelApp implementation
|
|
40
|
+
*
|
|
41
|
+
* @see `initialize`
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export declare const terminate: (frontendApp?: typeof IModelApp) => Promise<void>;
|
|
43
46
|
//# sourceMappingURL=Helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAIA;;GAEG;AAOH,OAAO,EAAc,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAKpE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AAChF,OAAO,EACL,kBAAkB,EAAuC,wBAAwB,IAAI,wBAAwB,EAAE,uBAAuB,EACvI,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAwC,iBAAiB,IAAI,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAyBpI,gBAAgB;AAChB,eAAO,MAAM,gBAAgB,QAAO,MAEnC,CAAC;AAGF,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,CAAC;AAEjF,cAAc;AACd,MAAM,WAAW,4BAA4B;IAC3C,4CAA4C;IAC5C,YAAY,CAAC,EAAE,wBAAwB,CAAC;IACxC,kCAAkC;IAClC,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;IACrC,6CAA6C;IAC7C,aAAa,CAAC,EAAE,yBAAyB,CAAC;IAC1C,+BAA+B;IAC/B,WAAW,CAAC,EAAE;QAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,CAAC;IACtE,0BAA0B;IAC1B,kBAAkB,CAAC,EAAE,gBAAgB,CAAC;IACtC,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,qEA+BtB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mDAuBrB,CAAC"}
|