Skip to content

Commit 177352f

Browse files
committed
Presentation tests cleanup
1 parent bad941d commit 177352f

2 files changed

Lines changed: 243 additions & 375 deletions

File tree

full-stack-tests/presentation/src/backend/DefaultSupplementalRules.test.ts

Lines changed: 165 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,18 @@ describe("Default supplemental rules", async () => {
2828
it("loads `Element -> ExternalSourceAspect.Identifier` property into 'Source Information' group", async function () {
2929
let elementKey: InstanceKey | undefined;
3030
const { db: imodel } = await buildTestIModelDb(this.test!.fullTitle(), async (db) => {
31-
const insertedElementKey = insertPhysicalElement(db);
32-
elementKey = insertedElementKey;
33-
withEditTxn(db, (txn) => txn.insertAspect({
34-
classFullName: "BisCore:ExternalSourceAspect",
35-
element: {
36-
relClassName: "BisCore:ElementOwnsExternalSourceAspects",
37-
id: insertedElementKey.id,
38-
},
39-
kind: "",
40-
identifier: "test identifier",
41-
} as ElementAspectProps));
31+
withEditTxn(db, (txn) => {
32+
elementKey = insertPhysicalElementWithTxn(txn, db);
33+
txn.insertAspect({
34+
classFullName: "BisCore:ExternalSourceAspect",
35+
element: {
36+
relClassName: "BisCore:ElementOwnsExternalSourceAspects",
37+
id: elementKey.id,
38+
},
39+
kind: "",
40+
identifier: "test identifier",
41+
} as ElementAspectProps);
42+
});
4243
});
4344
const rules: Ruleset = {
4445
id: "test",
@@ -88,40 +89,41 @@ describe("Default supplemental rules", async () => {
8889
<ECProperty propertyName="MyProperty" displayLabel="My Property" typeName="string" />
8990
</ECEntityClass>
9091
</ECSchema>`;
91-
await withEditTxn(db, async () => db.importSchemaStrings([schema]));
92+
await db.importSchemaStrings([schema]);
9293

93-
const insertedElementKey = insertPhysicalElement(db);
94-
elementKey = insertedElementKey;
95-
const repositoryLinkId = withEditTxn(db, (txn) => txn.insertElement({
96-
classFullName: "TestDomain:MyRepositoryLink",
97-
model: IModel.repositoryModelId,
98-
code: Code.createEmpty(),
99-
userLabel: "test user label",
100-
url: "test url",
101-
myProperty: "test my property",
102-
} as ElementProps));
103-
const externalSourceId = withEditTxn(db, (txn) => txn.insertElement({
104-
classFullName: "BisCore:ExternalSource",
105-
model: IModel.dictionaryId,
106-
code: Code.createEmpty(),
107-
repository: {
108-
relClassName: "BisCore:ExternalSourceIsInRepository",
109-
id: repositoryLinkId,
110-
},
111-
} as ElementProps));
112-
withEditTxn(db, (txn) => txn.insertAspect({
113-
classFullName: "BisCore:ExternalSourceAspect",
114-
element: {
115-
relClassName: "BisCore:ElementOwnsExternalSourceAspects",
116-
id: insertedElementKey.id,
117-
},
118-
source: {
119-
relClassName: "BisCore:ElementIsFromSource",
120-
id: externalSourceId,
121-
},
122-
kind: "",
123-
identifier: "test identifier",
124-
} as ElementAspectProps));
94+
withEditTxn(db, (txn) => {
95+
elementKey = insertPhysicalElementWithTxn(txn, db);
96+
const repositoryLinkId = txn.insertElement({
97+
classFullName: "TestDomain:MyRepositoryLink",
98+
model: IModel.repositoryModelId,
99+
code: Code.createEmpty(),
100+
userLabel: "test user label",
101+
url: "test url",
102+
myProperty: "test my property",
103+
} as ElementProps);
104+
const externalSourceId = txn.insertElement({
105+
classFullName: "BisCore:ExternalSource",
106+
model: IModel.dictionaryId,
107+
code: Code.createEmpty(),
108+
repository: {
109+
relClassName: "BisCore:ExternalSourceIsInRepository",
110+
id: repositoryLinkId,
111+
},
112+
} as ElementProps);
113+
txn.insertAspect({
114+
classFullName: "BisCore:ExternalSourceAspect",
115+
element: {
116+
relClassName: "BisCore:ElementOwnsExternalSourceAspects",
117+
id: elementKey.id,
118+
},
119+
source: {
120+
relClassName: "BisCore:ElementIsFromSource",
121+
id: externalSourceId,
122+
},
123+
kind: "",
124+
identifier: "test identifier",
125+
} as ElementAspectProps);
126+
});
125127
});
126128
const rules: Ruleset = {
127129
id: "test",
@@ -179,17 +181,18 @@ describe("Default supplemental rules", async () => {
179181
it("allows removing 'Source Element ID' property", async function () {
180182
let elementKey: InstanceKey | undefined;
181183
const { db: imodel } = await buildTestIModelDb(this.test!.fullTitle(), async (db) => {
182-
const insertedElementKey = insertPhysicalElement(db);
183-
elementKey = insertedElementKey;
184-
withEditTxn(db, (txn) => txn.insertAspect({
185-
classFullName: "BisCore:ExternalSourceAspect",
186-
element: {
187-
relClassName: "BisCore:ElementOwnsExternalSourceAspects",
188-
id: insertedElementKey.id,
189-
},
190-
kind: "",
191-
identifier: "test identifier",
192-
} as ElementAspectProps));
184+
withEditTxn(db, (txn) => {
185+
elementKey = insertPhysicalElementWithTxn(txn, db);
186+
txn.insertAspect({
187+
classFullName: "BisCore:ExternalSourceAspect",
188+
element: {
189+
relClassName: "BisCore:ElementOwnsExternalSourceAspects",
190+
id: elementKey.id,
191+
},
192+
kind: "",
193+
identifier: "test identifier",
194+
} as ElementAspectProps);
195+
});
193196
});
194197
const rules: Ruleset = {
195198
id: "test",
@@ -244,36 +247,38 @@ describe("Default supplemental rules", async () => {
244247
it("allows removing 'Source Information -> Model Source' properties", async function () {
245248
let elementKey: InstanceKey | undefined;
246249
const { db: imodel } = await buildTestIModelDb(this.test!.fullTitle(), async (db) => {
247-
const partitionId = withEditTxn(db, (txn) => txn.insertElement({
248-
classFullName: "BisCore:PhysicalPartition",
249-
model: IModel.repositoryModelId,
250-
parent: {
251-
relClassName: "BisCore:SubjectOwnsPartitionElements",
252-
id: IModel.rootSubjectId,
253-
},
254-
code: new Code({
255-
spec: db.codeSpecs.getByName(BisCodeSpec.informationPartitionElement).id,
256-
scope: IModel.rootSubjectId,
257-
value: "physical model",
258-
}),
259-
}));
260-
const repositoryLinkId = withEditTxn(db, (txn) => txn.insertElement({
261-
classFullName: "BisCore:RepositoryLink",
262-
model: IModel.repositoryModelId,
263-
code: Code.createEmpty(),
264-
userLabel: "test user label",
265-
url: "test url",
266-
} as ElementProps));
267-
withEditTxn(db, (txn) => txn.insertRelationship({
268-
classFullName: "BisCore:ElementHasLinks",
269-
sourceId: partitionId,
270-
targetId: repositoryLinkId,
271-
}));
272-
const modelId = withEditTxn(db, (txn) => txn.insertModel({
273-
classFullName: "BisCore:PhysicalModel",
274-
modeledElement: { id: partitionId },
275-
}));
276-
elementKey = insertPhysicalElement(db, modelId);
250+
withEditTxn(db, (txn) => {
251+
const partitionId = txn.insertElement({
252+
classFullName: "BisCore:PhysicalPartition",
253+
model: IModel.repositoryModelId,
254+
parent: {
255+
relClassName: "BisCore:SubjectOwnsPartitionElements",
256+
id: IModel.rootSubjectId,
257+
},
258+
code: new Code({
259+
spec: db.codeSpecs.getByName(BisCodeSpec.informationPartitionElement).id,
260+
scope: IModel.rootSubjectId,
261+
value: "physical model",
262+
}),
263+
});
264+
const repositoryLinkId = txn.insertElement({
265+
classFullName: "BisCore:RepositoryLink",
266+
model: IModel.repositoryModelId,
267+
code: Code.createEmpty(),
268+
userLabel: "test user label",
269+
url: "test url",
270+
} as ElementProps);
271+
txn.insertRelationship({
272+
classFullName: "BisCore:ElementHasLinks",
273+
sourceId: partitionId,
274+
targetId: repositoryLinkId,
275+
});
276+
const modelId = txn.insertModel({
277+
classFullName: "BisCore:PhysicalModel",
278+
modeledElement: { id: partitionId },
279+
});
280+
elementKey = insertPhysicalElementWithTxn(txn, db, modelId);
281+
});
277282
});
278283
const rules: Ruleset = {
279284
id: "test",
@@ -348,37 +353,39 @@ describe("Default supplemental rules", async () => {
348353
it("allows removing 'Source Information' ExternalSource properties", async function () {
349354
let elementKey: InstanceKey | undefined;
350355
const { db: imodel } = await buildTestIModelDb(this.test!.fullTitle(), async (db) => {
351-
const insertedElementKey = insertPhysicalElement(db);
352-
elementKey = insertedElementKey;
353-
const repositoryLinkId = withEditTxn(db, (txn) => txn.insertElement({
354-
classFullName: "BisCore:RepositoryLink",
355-
model: IModel.repositoryModelId,
356-
code: Code.createEmpty(),
357-
userLabel: "test user label",
358-
url: "test url",
359-
} as ElementProps));
360-
const externalSourceId = withEditTxn(db, (txn) => txn.insertElement({
361-
classFullName: "BisCore:ExternalSource",
362-
model: IModel.dictionaryId,
363-
code: Code.createEmpty(),
364-
repository: {
365-
relClassName: "BisCore:ExternalSourceIsInRepository",
366-
id: repositoryLinkId,
367-
},
368-
} as ElementProps));
369-
withEditTxn(db, (txn) => txn.insertAspect({
370-
classFullName: "BisCore:ExternalSourceAspect",
371-
element: {
372-
relClassName: "BisCore:ElementOwnsExternalSourceAspects",
373-
id: insertedElementKey.id,
374-
},
375-
source: {
376-
relClassName: "BisCore:ElementIsFromSource",
377-
id: externalSourceId,
378-
},
379-
kind: "",
380-
identifier: "test identifier",
381-
} as ElementAspectProps));
356+
withEditTxn(db, (txn) => {
357+
elementKey = insertPhysicalElementWithTxn(txn, db);
358+
const repositoryLinkId = txn.insertElement({
359+
classFullName: "BisCore:RepositoryLink",
360+
model: IModel.repositoryModelId,
361+
code: Code.createEmpty(),
362+
userLabel: "test user label",
363+
url: "test url",
364+
} as ElementProps);
365+
const externalSourceId = txn.insertElement({
366+
classFullName: "BisCore:ExternalSource",
367+
model: IModel.dictionaryId,
368+
code: Code.createEmpty(),
369+
repository: {
370+
relClassName: "BisCore:ExternalSourceIsInRepository",
371+
id: repositoryLinkId,
372+
},
373+
} as ElementProps);
374+
375+
txn.insertAspect({
376+
classFullName: "BisCore:ExternalSourceAspect",
377+
element: {
378+
relClassName: "BisCore:ElementOwnsExternalSourceAspects",
379+
id: elementKey.id,
380+
},
381+
source: {
382+
relClassName: "BisCore:ElementIsFromSource",
383+
id: externalSourceId,
384+
},
385+
kind: "",
386+
identifier: "test identifier",
387+
} as ElementAspectProps);
388+
});
382389
});
383390
const rules: Ruleset = {
384391
id: "test",
@@ -455,47 +462,48 @@ describe("Default supplemental rules", async () => {
455462
it("allows removing 'Source Information -> Secondary Sources' properties", async function () {
456463
let elementKey: InstanceKey | undefined;
457464
const { db: imodel } = await buildTestIModelDb(this.test!.fullTitle(), async (db) => {
458-
const insertedElementKey = insertPhysicalElement(db);
459-
elementKey = insertedElementKey;
460-
const repositoryLinkId = withEditTxn(db, (txn) => txn.insertElement({
461-
classFullName: "BisCore:RepositoryLink",
462-
model: IModel.repositoryModelId,
463-
code: Code.createEmpty(),
464-
userLabel: "test user label",
465-
url: "test url",
466-
} as ElementProps));
467-
const externalSourceId = withEditTxn(db, (txn) => txn.insertElement({
468-
classFullName: "BisCore:ExternalSource",
469-
model: IModel.dictionaryId,
470-
code: Code.createEmpty(),
471-
repository: {
472-
relClassName: "BisCore:ExternalSourceIsInRepository",
473-
id: repositoryLinkId,
474-
},
475-
} as ElementProps));
476-
const externalSourceGroupId = withEditTxn(db, (txn) => txn.insertElement({
477-
classFullName: "BisCore:ExternalSourceGroup",
478-
model: IModel.dictionaryId,
479-
code: Code.createEmpty(),
480-
} as ElementProps));
481-
withEditTxn(db, (txn) => txn.insertRelationship({
482-
classFullName: "BisCore:ExternalSourceGroupGroupsSources",
483-
sourceId: externalSourceGroupId,
484-
targetId: externalSourceId,
485-
}));
486-
withEditTxn(db, (txn) => txn.insertAspect({
487-
classFullName: "BisCore:ExternalSourceAspect",
488-
element: {
489-
relClassName: "BisCore:ElementOwnsExternalSourceAspects",
490-
id: insertedElementKey.id,
491-
},
492-
source: {
493-
relClassName: "BisCore:ElementIsFromSource",
494-
id: externalSourceGroupId,
495-
},
496-
kind: "",
497-
identifier: "test identifier",
498-
} as ElementAspectProps));
465+
withEditTxn(db, (txn) => {
466+
elementKey = insertPhysicalElementWithTxn(txn, db);
467+
const repositoryLinkId = txn.insertElement({
468+
classFullName: "BisCore:RepositoryLink",
469+
model: IModel.repositoryModelId,
470+
code: Code.createEmpty(),
471+
userLabel: "test user label",
472+
url: "test url",
473+
} as ElementProps);
474+
const externalSourceId = txn.insertElement({
475+
classFullName: "BisCore:ExternalSource",
476+
model: IModel.dictionaryId,
477+
code: Code.createEmpty(),
478+
repository: {
479+
relClassName: "BisCore:ExternalSourceIsInRepository",
480+
id: repositoryLinkId,
481+
},
482+
} as ElementProps);
483+
const externalSourceGroupId = txn.insertElement({
484+
classFullName: "BisCore:ExternalSourceGroup",
485+
model: IModel.dictionaryId,
486+
code: Code.createEmpty(),
487+
} as ElementProps);
488+
txn.insertRelationship({
489+
classFullName: "BisCore:ExternalSourceGroupGroupsSources",
490+
sourceId: externalSourceGroupId,
491+
targetId: externalSourceId,
492+
}),
493+
txn.insertAspect({
494+
classFullName: "BisCore:ExternalSourceAspect",
495+
element: {
496+
relClassName: "BisCore:ElementOwnsExternalSourceAspects",
497+
id: elementKey.id,
498+
},
499+
source: {
500+
relClassName: "BisCore:ElementIsFromSource",
501+
id: externalSourceGroupId,
502+
},
503+
kind: "",
504+
identifier: "test identifier",
505+
} as ElementAspectProps);
506+
});
499507
});
500508
const rules: Ruleset = {
501509
id: "test",
@@ -629,7 +637,3 @@ function insertPhysicalElementWithTxn(txn: EditTxn, db: IModelDb, modelId?: Id64
629637
} as ElementProps);
630638
return { className: elementClassName, id: elementId };
631639
}
632-
633-
function insertPhysicalElement(db: IModelDb, modelId?: Id64String, categoryId?: Id64String): InstanceKey {
634-
return withEditTxn(db, (txn) => insertPhysicalElementWithTxn(txn, db, modelId, categoryId));
635-
}

0 commit comments

Comments
 (0)