Skip to content

Commit 7eee05d

Browse files
authored
Update sharedTreeCore.spec.ts to use simple-tree API (#21912)
## Description This removes usages of the "flex layer" APIs from sharedTreeCore.spec.ts
1 parent 0bb9f76 commit 7eee05d

File tree

1 file changed

+60
-85
lines changed

1 file changed

+60
-85
lines changed

packages/dds/tree/src/test/shared-tree-core/sharedTreeCore.spec.ts

Lines changed: 60 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,18 @@ import {
2929
} from "@fluidframework/test-runtime-utils/internal";
3030

3131
import {
32-
AllowedUpdateType,
3332
type ChangeFamily,
3433
type ChangeFamilyEditor,
3534
type GraphCommit,
3635
rootFieldKey,
3736
} from "../../core/index.js";
38-
import { leaf } from "../../domains/index.js";
3937
import {
4038
type DefaultChangeset,
4139
type DefaultEditBuilder,
42-
FieldKinds,
43-
FlexFieldSchema,
4440
type ModularChangeset,
45-
SchemaBuilderBase,
4641
cursorForJsonableTreeNode,
47-
typeNameSymbol,
4842
} from "../../feature-libraries/index.js";
49-
import type { InitializeAndSchematizeConfiguration } from "../../shared-tree/index.js";
43+
import { Tree } from "../../shared-tree/index.js";
5044
import type {
5145
ChangeEnricherReadonlyCheckout,
5246
EditManager,
@@ -57,14 +51,12 @@ import type {
5751
SummaryElementStringifier,
5852
} from "../../shared-tree-core/index.js";
5953
import { brand, disposeSymbol } from "../../util/index.js";
60-
import {
61-
SharedTreeTestFactory,
62-
TestTreeProviderLite,
63-
schematizeFlexTree,
64-
stringSequenceRootSchema,
65-
} from "../utils.js";
54+
import { SharedTreeTestFactory, StringArray, TestTreeProviderLite } from "../utils.js";
6655

6756
import { TestSharedTreeCore } from "./utils.js";
57+
import { SchemaFactory } from "../../simple-tree/index.js";
58+
59+
const enableSchemaValidation = true;
6860

6961
describe("SharedTreeCore", () => {
7062
it("summarizes without indexes", async () => {
@@ -301,14 +293,10 @@ describe("SharedTreeCore", () => {
301293
objectStorage: new MockStorage(),
302294
});
303295

304-
const b = new SchemaBuilderBase(FieldKinds.optional, {
305-
scope: "0x4a6 repro",
306-
libraries: [leaf.library],
296+
const sf = new SchemaFactory("0x4a6 repro");
297+
const TestNode = sf.objectRecursive("test node", {
298+
child: sf.optionalRecursive([() => TestNode, sf.number]),
307299
});
308-
const node = b.objectRecursive("test node", {
309-
child: FlexFieldSchema.createUnsafe(FieldKinds.optional, [() => node, leaf.number]),
310-
});
311-
const schema = b.intoSchema(node);
312300

313301
const tree2 = await factory.load(
314302
dataStoreRuntime2,
@@ -320,107 +308,95 @@ describe("SharedTreeCore", () => {
320308
factory.attributes,
321309
);
322310

323-
const config = {
324-
schema,
325-
initialTree: undefined,
326-
allowedSchemaModifications: AllowedUpdateType.Initialize,
327-
} satisfies InitializeAndSchematizeConfiguration;
328-
329-
const view1 = schematizeFlexTree(tree1, config);
311+
const view1 = tree1.viewWith({ schema: TestNode, enableSchemaValidation });
312+
view1.initialize(new TestNode({}));
330313
containerRuntimeFactory.processAllMessages();
331-
const view2 = schematizeFlexTree(tree2, config);
332-
const editable1 = view1.flexTree;
333-
const editable2 = view2.flexTree;
334-
335-
editable2.content = { [typeNameSymbol]: node.name, child: undefined };
336-
editable1.content = { [typeNameSymbol]: node.name, child: undefined };
337-
const rootNode = editable2.content;
338-
assert(rootNode?.is(node), "Expected set operation to set root node");
339-
rootNode.boxedChild.content = 42;
340-
editable1.content = { [typeNameSymbol]: node.name, child: undefined };
341-
rootNode.boxedChild.content = 43;
314+
const view2 = tree2.viewWith({ schema: TestNode, enableSchemaValidation });
315+
316+
view2.root = new TestNode({});
317+
view1.root = new TestNode({});
318+
assert(Tree.is(view2.root, TestNode), "Expected set operation to set root node");
319+
view2.root.child = 42;
320+
view1.root = new TestNode({});
321+
view2.root.child = 43;
342322
containerRuntimeFactory.processAllMessages();
343323
assert.deepEqual(tree1.contentSnapshot().tree, [
344324
{
345-
type: node.name,
325+
type: TestNode.identifier,
346326
},
347327
]);
348328
assert.deepEqual(tree2.contentSnapshot().tree, [
349329
{
350-
type: node.name,
330+
type: TestNode.identifier,
351331
},
352332
]);
353333
});
354334

355335
it("Does not submit changes that were aborted in an outer transaction", async () => {
356336
const provider = new TestTreeProviderLite(2);
357-
const content = {
358-
schema: stringSequenceRootSchema,
359-
allowedSchemaModifications: AllowedUpdateType.Initialize,
360-
initialTree: ["A", "B"],
361-
} satisfies InitializeAndSchematizeConfiguration;
362-
const tree1 = schematizeFlexTree(provider.trees[0], content);
337+
const view1 = provider.trees[0].viewWith({
338+
schema: StringArray,
339+
enableSchemaValidation,
340+
});
341+
view1.initialize(["A", "B"]);
363342
provider.processMessages();
364-
const tree2 = schematizeFlexTree(provider.trees[1], content);
343+
const view2 = provider.trees[1].viewWith({
344+
schema: StringArray,
345+
enableSchemaValidation,
346+
});
365347

366-
const root1 = tree1.flexTree;
367-
const root2 = tree2.flexTree;
348+
const root1 = view1.root;
349+
const root2 = view2.root;
368350

369-
tree1.checkout.transaction.start();
370-
{
351+
Tree.runTransaction(root1, () => {
371352
// Remove A as part of the aborted transaction
372353
root1.removeAt(0);
373-
tree1.checkout.transaction.start();
374-
{
354+
Tree.runTransaction(root1, () => {
375355
// Remove B as part of the committed inner transaction
376356
root1.removeAt(0);
377-
}
378-
tree1.checkout.transaction.commit();
379-
}
380-
tree1.checkout.transaction.abort();
357+
});
358+
return Tree.runTransaction.rollback;
359+
});
381360

382361
provider.processMessages();
383-
assert.deepEqual([...root2], ["A", "B"]);
362+
assert.deepEqual([...root1], ["A", "B"]);
384363
assert.deepEqual([...root2], ["A", "B"]);
385364

386365
// Make an additional change to ensure that all changes from the previous transactions were flushed
387-
tree1.checkout.transaction.start();
388-
{
366+
Tree.runTransaction(root1, () => {
389367
root1.insertAtEnd("C");
390-
}
391-
tree1.checkout.transaction.commit();
368+
});
369+
392370
provider.processMessages();
393-
assert.deepEqual([...root2], ["A", "B", "C"]);
371+
assert.deepEqual([...root1], ["A", "B", "C"]);
394372
assert.deepEqual([...root2], ["A", "B", "C"]);
395373
});
396374

397375
it("Does not submit changes that were aborted in an inner transaction", async () => {
398376
const provider = new TestTreeProviderLite(2);
399-
const content = {
400-
schema: stringSequenceRootSchema,
401-
allowedSchemaModifications: AllowedUpdateType.Initialize,
402-
initialTree: ["A", "B"],
403-
} satisfies InitializeAndSchematizeConfiguration;
404-
const tree1 = schematizeFlexTree(provider.trees[0], content);
405-
377+
const view1 = provider.trees[0].viewWith({
378+
schema: StringArray,
379+
enableSchemaValidation,
380+
});
381+
view1.initialize(["A", "B"]);
406382
provider.processMessages();
407-
const tree2 = schematizeFlexTree(provider.trees[1], content);
383+
const view2 = provider.trees[1].viewWith({
384+
schema: StringArray,
385+
enableSchemaValidation,
386+
});
408387

409-
const root1 = tree1.flexTree;
410-
const root2 = tree2.flexTree;
388+
const root1 = view1.root;
389+
const root2 = view2.root;
411390

412-
tree1.checkout.transaction.start();
413-
{
391+
Tree.runTransaction(root1, () => {
414392
// Remove A as part of the committed transaction
415393
root1.removeAt(0);
416-
tree1.checkout.transaction.start();
417-
{
394+
Tree.runTransaction(root1, () => {
418395
// Remove B as part of the aborted transaction
419396
root1.removeAt(0);
420-
}
421-
tree1.checkout.transaction.abort();
422-
}
423-
tree1.checkout.transaction.commit();
397+
return Tree.runTransaction.rollback;
398+
});
399+
});
424400

425401
assert.deepEqual([...root1], ["B"]);
426402
assert.deepEqual([...root2], ["A", "B"]);
@@ -431,11 +407,10 @@ describe("SharedTreeCore", () => {
431407
assert.deepEqual([...root2], ["B"]);
432408

433409
// Make an additional change to ensure that all changes from the previous transactions were flushed
434-
tree1.checkout.transaction.start();
435-
{
410+
Tree.runTransaction(root1, () => {
436411
root1.insertAtEnd("C");
437-
}
438-
tree1.checkout.transaction.commit();
412+
});
413+
439414
provider.processMessages();
440415
assert.deepEqual([...root2], ["B", "C"]);
441416
assert.deepEqual([...root2], ["B", "C"]);

0 commit comments

Comments
 (0)