mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-23 14:15:24 +00:00
Expand patch_apply tests
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use insta::assert_yaml_snapshot;
|
use insta::assert_yaml_snapshot;
|
||||||
|
use maplit::hashmap;
|
||||||
use rbx_dom_weak::{RbxId, RbxInstanceProperties, RbxValue};
|
use rbx_dom_weak::{RbxId, RbxInstanceProperties, RbxValue};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
@@ -38,6 +39,84 @@ fn set_name_and_class_name() {
|
|||||||
assert_yaml_snapshot!(applied_patch_value);
|
assert_yaml_snapshot!(applied_patch_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn add_property() {
|
||||||
|
let mut redactions = RedactionMap::new();
|
||||||
|
|
||||||
|
let mut tree = empty_tree();
|
||||||
|
redactions.intern(tree.get_root_id());
|
||||||
|
|
||||||
|
let patch_set = PatchSet {
|
||||||
|
updated_instances: vec![PatchUpdate {
|
||||||
|
id: tree.get_root_id(),
|
||||||
|
changed_name: None,
|
||||||
|
changed_class_name: None,
|
||||||
|
changed_properties: hashmap! {
|
||||||
|
"Foo".to_owned() => Some(RbxValue::String {
|
||||||
|
value: "Value of Foo".to_owned(),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
changed_metadata: None,
|
||||||
|
}],
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let applied_patch_set = apply_patch_set(&mut tree, patch_set);
|
||||||
|
|
||||||
|
let tree_view = view_tree(&tree);
|
||||||
|
let tree_value = redactions.redacted_yaml(tree_view);
|
||||||
|
assert_yaml_snapshot!(tree_value);
|
||||||
|
|
||||||
|
let applied_patch_value = redactions.redacted_yaml(applied_patch_set);
|
||||||
|
assert_yaml_snapshot!(applied_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: "Should be removed".to_owned(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let tree_view = view_tree(&tree);
|
||||||
|
let tree_value = redactions.redacted_yaml(tree_view);
|
||||||
|
assert_yaml_snapshot!("remove_property_initial", tree_value);
|
||||||
|
|
||||||
|
let patch_set = PatchSet {
|
||||||
|
updated_instances: vec![PatchUpdate {
|
||||||
|
id: tree.get_root_id(),
|
||||||
|
changed_name: None,
|
||||||
|
changed_class_name: None,
|
||||||
|
changed_properties: hashmap! {
|
||||||
|
"Foo".to_owned() => None,
|
||||||
|
},
|
||||||
|
changed_metadata: None,
|
||||||
|
}],
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let applied_patch_set = apply_patch_set(&mut tree, patch_set);
|
||||||
|
|
||||||
|
let tree_view = view_tree(&tree);
|
||||||
|
let tree_value = redactions.redacted_yaml(tree_view);
|
||||||
|
assert_yaml_snapshot!("remove_property_after_patch", tree_value);
|
||||||
|
|
||||||
|
let applied_patch_value = redactions.redacted_yaml(applied_patch_set);
|
||||||
|
assert_yaml_snapshot!("remove_property_appied_patch", applied_patch_value);
|
||||||
|
}
|
||||||
|
|
||||||
fn empty_tree() -> RojoTree {
|
fn empty_tree() -> RojoTree {
|
||||||
RojoTree::new(InstancePropertiesWithMeta {
|
RojoTree::new(InstancePropertiesWithMeta {
|
||||||
properties: RbxInstanceProperties {
|
properties: RbxInstanceProperties {
|
||||||
@@ -49,6 +128,7 @@ fn empty_tree() -> RojoTree {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Copy of data from RojoTree in the right shape to have useful snapshots.
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
struct InstanceView {
|
struct InstanceView {
|
||||||
id: RbxId,
|
id: RbxId,
|
||||||
|
|||||||
15
src/snapshot/tests/snapshots/apply__add_property-2.snap
Normal file
15
src/snapshot/tests/snapshots/apply__add_property-2.snap
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
source: src/snapshot/tests/apply.rs
|
||||||
|
expression: applied_patch_value
|
||||||
|
---
|
||||||
|
removed: []
|
||||||
|
added: []
|
||||||
|
updated:
|
||||||
|
- id: id-1
|
||||||
|
changed_name: ~
|
||||||
|
changed_class_name: ~
|
||||||
|
changed_properties:
|
||||||
|
Foo:
|
||||||
|
Type: String
|
||||||
|
Value: Value of Foo
|
||||||
|
changed_metadata: ~
|
||||||
16
src/snapshot/tests/snapshots/apply__add_property.snap
Normal file
16
src/snapshot/tests/snapshots/apply__add_property.snap
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
source: src/snapshot/tests/apply.rs
|
||||||
|
expression: tree_value
|
||||||
|
---
|
||||||
|
id: id-1
|
||||||
|
name: ROOT
|
||||||
|
class_name: ROOT
|
||||||
|
properties:
|
||||||
|
Foo:
|
||||||
|
Type: String
|
||||||
|
Value: Value of Foo
|
||||||
|
metadata:
|
||||||
|
ignore_unknown_instances: false
|
||||||
|
source_path: ~
|
||||||
|
project_node: ~
|
||||||
|
children: []
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
source: src/snapshot/tests/apply.rs
|
||||||
|
expression: tree_value
|
||||||
|
---
|
||||||
|
id: id-1
|
||||||
|
name: ROOT
|
||||||
|
class_name: ROOT
|
||||||
|
properties: {}
|
||||||
|
metadata:
|
||||||
|
ignore_unknown_instances: false
|
||||||
|
source_path: ~
|
||||||
|
project_node: ~
|
||||||
|
children: []
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
source: src/snapshot/tests/apply.rs
|
||||||
|
expression: applied_patch_value
|
||||||
|
---
|
||||||
|
removed: []
|
||||||
|
added: []
|
||||||
|
updated:
|
||||||
|
- id: id-1
|
||||||
|
changed_name: ~
|
||||||
|
changed_class_name: ~
|
||||||
|
changed_properties:
|
||||||
|
Foo: ~
|
||||||
|
changed_metadata: ~
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
source: src/snapshot/tests/apply.rs
|
||||||
|
expression: tree_value
|
||||||
|
---
|
||||||
|
id: id-1
|
||||||
|
name: ROOT
|
||||||
|
class_name: ROOT
|
||||||
|
properties:
|
||||||
|
Foo:
|
||||||
|
Type: String
|
||||||
|
Value: Should be removed
|
||||||
|
metadata:
|
||||||
|
ignore_unknown_instances: false
|
||||||
|
source_path: ~
|
||||||
|
project_node: ~
|
||||||
|
children: []
|
||||||
Reference in New Issue
Block a user