Merge "Fix Chips missing on SF/WM traces when "Show Diff" toggled"

This commit is contained in:
Kean Mariotti
2022-05-16 06:17:42 +00:00
committed by Android (Google) Code Review
3 changed files with 75 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
import { DiffGenerator, DiffType } from "../src/utils/diff.js";
import { Node, DiffNode, toPlainObject } from "./utils/tree.js";
import { NodeBuilder, Node, DiffNode, toPlainObject } from "./utils/tree.js";
const treeOne = new Node({ id: 1 }, [
new Node({ id: 2 }, []),
@@ -244,4 +244,26 @@ describe("DiffGenerator", () => {
checkDiffTreeWithNoModifiedCheck(oldTree, newTree, expectedDiffTree);
});
it("preserves node chips", () => {
const oldTree = new NodeBuilder().setId(1).setChildren([
new NodeBuilder().setId(2).setChips(["CHIP2"]).build(),
new NodeBuilder().setId(3).build(),
]).build();
const newTree = new NodeBuilder().setId(1).setChildren([
new NodeBuilder().setId(2).setChips(["CHIP2"]).build(),
new NodeBuilder().setId(4).setChips(["CHIP4"]).build(),
]).build();
const expectedDiffTree = toPlainObject(
new NodeBuilder().setId(1).setDiffType(DiffType.NONE).setChildren([
new NodeBuilder().setId(2).setChips(["CHIP2"]).setDiffType(DiffType.NONE).build(),
new NodeBuilder().setId(3).setDiffType(DiffType.DELETED).build(),
new NodeBuilder().setId(4).setChips(["CHIP4"]).setDiffType(DiffType.ADDED).build(),
]).build()
);
checkDiffTreeWithNoModifiedCheck(oldTree, newTree, expectedDiffTree);
});
});

View File

@@ -1,3 +1,51 @@
class NodeBuilder {
setId(id) {
this.id = id;
this.chips = [];
return this;
}
setChildren(children) {
this.children = children;
return this;
}
setChips(chips) {
this.chips = chips;
return this;
}
setDiffType(diffType) {
this.diffType = diffType;
return this;
}
build() {
var node = {
name: undefined,
stableId: undefined,
kind: undefined,
shortName: undefined
};
if ('id' in this) {
node.id = this.id;
}
node.children = 'children' in this ? this.children : [];
if ('chips' in this) {
node.chips = this.chips;
}
if ('diffType' in this) {
node.diff = { type: this.diffType }
}
return node;
}
}
class Node {
constructor(nodeDef, children) {
Object.assign(this, nodeDef);
@@ -55,4 +103,4 @@ function toPlainObject(theClass) {
}
}
export { Node, DiffNode, ObjNode, ObjDiffNode, toPlainObject };
export { NodeBuilder, Node, DiffNode, ObjNode, ObjDiffNode, toPlainObject };

View File

@@ -119,6 +119,9 @@ export class DiffGenerator {
clone.kind = node.kind;
clone.stableId = node.stableId;
clone.shortName = node.shortName;
if ('chips' in node) {
clone.chips = node.chips.slice();
}
return clone;
}