test(tree): event test clean up (#23101)
moves some event tests to tree view test file and changes them to be less undo redo focused
This commit is contained in:
Родитель
30c7392704
Коммит
155a7e573a
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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";
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче