First round of snapshot tests for patch_compute

This commit is contained in:
Lucien Greathouse
2019-09-30 17:00:12 -07:00
parent 3678ddfa36
commit b512e707a5
9 changed files with 128 additions and 12 deletions

View File

@@ -1,14 +1,21 @@
use std::borrow::Cow;
use rbx_dom_weak::RbxInstanceProperties;
use insta::assert_yaml_snapshot;
use maplit::hashmap;
use rbx_dom_weak::{RbxInstanceProperties, RbxValue};
use rojo_insta_ext::RedactionMap;
use crate::snapshot::{compute_patch_set, InstancePropertiesWithMeta, InstanceSnapshot, RojoTree};
#[test]
fn reify_folder() {
let tree = empty_tree();
fn set_name_and_class_name() {
let mut redactions = RedactionMap::new();
let folder = InstanceSnapshot {
let tree = empty_tree();
redactions.intern(tree.get_root_id());
let snapshot = InstanceSnapshot {
snapshot_id: None,
metadata: Default::default(),
name: Cow::Borrowed("Some Folder"),
@@ -17,10 +24,69 @@ fn reify_folder() {
children: Vec::new(),
};
let _patch_set = compute_patch_set(&folder, &tree, tree.get_root_id());
let patch_set = compute_patch_set(&snapshot, &tree, tree.get_root_id());
let patch_value = redactions.redacted_yaml(patch_set);
// TODO: Make assertions about patch set using snapshots. This needs patches
// to be serializable and also to have ID redactions more readily available.
assert_yaml_snapshot!(patch_value);
}
#[test]
fn set_property() {
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: hashmap! {
"PropertyName".to_owned() => RbxValue::String {
value: "Hello, world!".to_owned(),
},
},
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_property() {
let mut redactions = RedactionMap::new();
let mut tree = empty_tree();
redactions.intern(tree.get_root_id());
{
let root_id = tree.get_root_id();
let mut root_instance = tree.get_instance_mut(root_id).unwrap();
root_instance.properties_mut().insert(
"Foo".to_owned(),
RbxValue::String {
value: "This should be removed by the patch.".to_owned(),
},
);
}
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 {

View File

@@ -0,0 +1,13 @@
---
source: src/snapshot/tests/compute.rs
expression: patch_value
---
removed_instances: []
added_instances: []
updated_instances:
- id: id-1
changed_name: ~
changed_class_name: ~
changed_properties:
Foo: ~
changed_metadata: ~

View File

@@ -0,0 +1,12 @@
---
source: src/snapshot/tests/compute.rs
expression: patch_value
---
removed_instances: []
added_instances: []
updated_instances:
- id: id-1
changed_name: Some Folder
changed_class_name: Folder
changed_properties: {}
changed_metadata: ~

View File

@@ -0,0 +1,15 @@
---
source: src/snapshot/tests/compute.rs
expression: patch_value
---
removed_instances: []
added_instances: []
updated_instances:
- id: id-1
changed_name: ~
changed_class_name: ~
changed_properties:
PropertyName:
Type: String
Value: "Hello, world!"
changed_metadata: ~