diff --git a/src/snapshot/tests/compute.rs b/src/snapshot/tests/compute.rs index 3478d484..8564ea34 100644 --- a/src/snapshot/tests/compute.rs +++ b/src/snapshot/tests/compute.rs @@ -89,6 +89,74 @@ fn remove_property() { assert_yaml_snapshot!(patch_value); } +#[test] +fn add_child() { + let mut redactions = RedactionMap::new(); + + let tree = empty_tree(); + redactions.intern(tree.get_root_id()); + + let snapshot = InstanceSnapshot { + snapshot_id: None, + metadata: Default::default(), + name: Cow::Borrowed("ROOT"), + class_name: Cow::Borrowed("ROOT"), + properties: Default::default(), + children: vec![InstanceSnapshot { + snapshot_id: None, + metadata: Default::default(), + name: Cow::Borrowed("New"), + class_name: Cow::Borrowed("Folder"), + properties: Default::default(), + children: Vec::new(), + }], + }; + + let patch_set = compute_patch_set(&snapshot, &tree, tree.get_root_id()); + let patch_value = redactions.redacted_yaml(patch_set); + + assert_yaml_snapshot!(patch_value); +} + +#[test] +fn remove_child() { + let mut redactions = RedactionMap::new(); + + let mut tree = empty_tree(); + redactions.intern(tree.get_root_id()); + + { + let root_id = tree.get_root_id(); + let new_id = tree.insert_instance( + InstancePropertiesWithMeta { + properties: RbxInstanceProperties { + name: "Should not appear in snapshot".to_owned(), + class_name: "Folder".to_owned(), + properties: Default::default(), + }, + metadata: Default::default(), + }, + root_id, + ); + + redactions.intern(new_id); + } + + let snapshot = InstanceSnapshot { + snapshot_id: None, + metadata: Default::default(), + name: Cow::Borrowed("ROOT"), + class_name: Cow::Borrowed("ROOT"), + properties: Default::default(), + children: Vec::new(), + }; + + let patch_set = compute_patch_set(&snapshot, &tree, tree.get_root_id()); + let patch_value = redactions.redacted_yaml(patch_set); + + assert_yaml_snapshot!(patch_value); +} + fn empty_tree() -> RojoTree { RojoTree::new(InstancePropertiesWithMeta { properties: RbxInstanceProperties { diff --git a/src/snapshot/tests/snapshots/compute__add_child.snap b/src/snapshot/tests/snapshots/compute__add_child.snap new file mode 100644 index 00000000..7ea5e6c2 --- /dev/null +++ b/src/snapshot/tests/snapshots/compute__add_child.snap @@ -0,0 +1,18 @@ +--- +source: src/snapshot/tests/compute.rs +expression: patch_value +--- +removed_instances: [] +added_instances: + - parent_id: id-1 + instance: + snapshot_id: ~ + metadata: + ignore_unknown_instances: false + source_path: ~ + project_node: ~ + name: New + class_name: Folder + properties: {} + children: [] +updated_instances: [] diff --git a/src/snapshot/tests/snapshots/compute__remove_child.snap b/src/snapshot/tests/snapshots/compute__remove_child.snap new file mode 100644 index 00000000..16295d07 --- /dev/null +++ b/src/snapshot/tests/snapshots/compute__remove_child.snap @@ -0,0 +1,8 @@ +--- +source: src/snapshot/tests/compute.rs +expression: patch_value +--- +removed_instances: + - id-2 +added_instances: [] +updated_instances: []