Skip to content
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

test(tree): event test clean up #23101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,40 @@ describe("SchematizingSimpleTreeView", () => {
assert.equal(redoStack.length, 1);
});

it("schemaChanged event", () => {
const content = {
schema: toStoredSchema([]),
initialTree: undefined,
};
const checkout = checkoutWithContent(content);
const view = new SchematizingSimpleTreeView(checkout, config, new MockNodeKeyManager());
const log: string[] = [];
view.events.on("schemaChanged", () => log.push("changed"));
assert.deepEqual(log, []);
view.upgradeSchema();
assert.deepEqual(log, ["changed"]);
describe("events", () => {
it("schemaChanged", () => {
const content = {
schema: toStoredSchema([]),
initialTree: undefined,
};
const checkout = checkoutWithContent(content);
const view = new SchematizingSimpleTreeView(checkout, config, new MockNodeKeyManager());
const log: string[] = [];
view.events.on("schemaChanged", () => log.push("changed"));
assert.deepEqual(log, []);
view.upgradeSchema();
assert.deepEqual(log, ["changed"]);
});

it("emits changed events for local edits", () => {
const emptyContent = {
schema: emptySchema,
initialTree: undefined,
};
const checkout = checkoutWithContent(emptyContent);
const view = new SchematizingSimpleTreeView(checkout, config, new MockNodeKeyManager());

let localChanges = 0;

const unsubscribe = view.events.on("changed", (data) => {
if (data.isLocal) {
localChanges++;
}
});

insert(checkout, 0, "a");
assert.equal(localChanges, 1);
unsubscribe();
});
});
});
100 changes: 1 addition & 99 deletions packages/dds/tree/src/test/shared-tree/sharedTree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ import {
treeTestFactory,
validateTreeConsistency,
validateTreeContent,
validateViewConsistency,
validateUsageError,
StringArray,
NumberArray,
validateViewConsistency,
} from "../utils.js";
import { configuredSharedTree } from "../../treeFactory.js";
import type { ISharedObjectKind } from "@fluidframework/shared-object-base/internal";
Expand Down Expand Up @@ -1442,69 +1442,7 @@ describe("SharedTree", () => {
});
});

// TODO: many of these events tests should be tests of SharedTreeView instead.
describe("Events", () => {
it("triggers revertible events for local changes", () => {
const value = "42";
const provider = new TestTreeProviderLite(2);
const tree1 = provider.trees[0];
const view1 = tree1.viewWith(
new TreeViewConfiguration({ schema: StringArray, enableSchemaValidation }),
);
view1.initialize([]);
provider.processMessages();
const tree2 = provider.trees[1];
const view2 = tree2.viewWith(
new TreeViewConfiguration({
schema: StringArray,
enableSchemaValidation,
}),
);

const {
undoStack: undoStack1,
redoStack: redoStack1,
unsubscribe: unsubscribe1,
} = createTestUndoRedoStacks(tree1.checkout.events);
const {
undoStack: undoStack2,
redoStack: redoStack2,
unsubscribe: unsubscribe2,
} = createTestUndoRedoStacks(tree2.checkout.events);

// Insert node
view1.root.insertAtStart(value);
provider.processMessages();

// Validate insertion
assert.deepEqual([...view2.root], [value]);
assert.equal(undoStack1.length, 1);
assert.equal(undoStack2.length, 0);

undoStack1.pop()?.revert();
provider.processMessages();

// Insert node
view2.root.insertAtStart("43");
provider.processMessages();

assert.equal(undoStack1.length, 0);
assert.equal(redoStack1.length, 1);
assert.equal(undoStack2.length, 1);
assert.equal(redoStack2.length, 0);

redoStack1.pop()?.revert();
provider.processMessages();

assert.equal(undoStack1.length, 1);
assert.equal(redoStack1.length, 0);
assert.equal(undoStack2.length, 1);
assert.equal(redoStack2.length, 0);

unsubscribe1();
unsubscribe2();
});

it("doesn't trigger a revertible event for rebases", () => {
const provider = new TestTreeProviderLite(2);
// Initialize the tree
Expand Down Expand Up @@ -1552,42 +1490,6 @@ describe("SharedTree", () => {
unsubscribe2();
});

// TODO: move this event test to the tree view tests
it("emits a changed event for local edits", () => {
const value = "42";
const provider = new TestTreeProviderLite(2);
const tree1 = provider.trees[0];
const view1 = tree1.viewWith(
new TreeViewConfiguration({ schema: StringArray, enableSchemaValidation }),
);
view1.initialize([]);
provider.processMessages();

let localEdits = 0;
let remoteEdits = 0;

const unsubscribe = view1.events.on("changed", (metadata) => {
if (metadata.isLocal === true) {
localEdits++;
} else {
remoteEdits++;
}
});

// Insert node
view1.root.insertAtStart(value);
provider.processMessages();

// Validate insertion
assert.deepEqual([...view1.root], [value]);

assert.equal(localEdits, 1);
// check that the edit is not counted twice
assert.equal(remoteEdits, 0);

unsubscribe();
});

it("emits a changed event for remote edits", () => {
const value = "42";
const provider = new TestTreeProviderLite(2);
Expand Down
Loading