mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-24 22:56:02 +00:00
Improve patch application test
This commit is contained in:
@@ -1,10 +1,13 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use insta::assert_yaml_snapshot;
|
use insta::assert_yaml_snapshot;
|
||||||
use rbx_dom_weak::RbxInstanceProperties;
|
use rbx_dom_weak::{RbxId, RbxInstanceProperties, RbxValue};
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
use rojo_insta_ext::RedactionMap;
|
use rojo_insta_ext::RedactionMap;
|
||||||
|
|
||||||
use crate::snapshot::{
|
use crate::snapshot::{
|
||||||
apply_patch_set, InstancePropertiesWithMeta, PatchSet, PatchUpdate, RojoTree,
|
apply_patch_set, InstanceMetadata, InstancePropertiesWithMeta, PatchSet, PatchUpdate, RojoTree,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -27,7 +30,9 @@ fn set_name_and_class_name() {
|
|||||||
|
|
||||||
let applied_patch_set = apply_patch_set(&mut tree, patch_set);
|
let applied_patch_set = apply_patch_set(&mut tree, patch_set);
|
||||||
|
|
||||||
// TODO: Snapshot tree, requires RojoTree: Serialize (but not Deserialize!)
|
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);
|
let applied_patch_value = redactions.redacted_yaml(applied_patch_set);
|
||||||
assert_yaml_snapshot!(applied_patch_value);
|
assert_yaml_snapshot!(applied_patch_value);
|
||||||
@@ -43,3 +48,35 @@ fn empty_tree() -> RojoTree {
|
|||||||
metadata: Default::default(),
|
metadata: Default::default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
struct InstanceView {
|
||||||
|
id: RbxId,
|
||||||
|
name: String,
|
||||||
|
class_name: String,
|
||||||
|
properties: HashMap<String, RbxValue>,
|
||||||
|
metadata: InstanceMetadata,
|
||||||
|
children: Vec<InstanceView>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view_tree(tree: &RojoTree) -> InstanceView {
|
||||||
|
view_instance(tree, tree.get_root_id())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view_instance(tree: &RojoTree, id: RbxId) -> InstanceView {
|
||||||
|
let instance = tree.get_instance(id).unwrap();
|
||||||
|
|
||||||
|
InstanceView {
|
||||||
|
id: instance.id(),
|
||||||
|
name: instance.name().to_owned(),
|
||||||
|
class_name: instance.class_name().to_owned(),
|
||||||
|
properties: instance.properties().clone(),
|
||||||
|
metadata: instance.metadata().clone(),
|
||||||
|
children: instance
|
||||||
|
.children()
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.map(|id| view_instance(tree, id))
|
||||||
|
.collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
source: src/snapshot/tests/apply.rs
|
||||||
|
expression: applied_patch_value
|
||||||
|
---
|
||||||
|
removed: []
|
||||||
|
added: []
|
||||||
|
updated:
|
||||||
|
- id: id-1
|
||||||
|
changed_name: "Hello, world!"
|
||||||
|
changed_class_name: Folder
|
||||||
|
changed_properties: {}
|
||||||
|
changed_metadata: ~
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
---
|
---
|
||||||
source: src/snapshot/tests/apply.rs
|
source: src/snapshot/tests/apply.rs
|
||||||
expression: applied_patch_value
|
expression: tree_value
|
||||||
---
|
---
|
||||||
removed: []
|
id: id-1
|
||||||
added: []
|
name: "Hello, world!"
|
||||||
updated:
|
class_name: Folder
|
||||||
- id: id-1
|
properties: {}
|
||||||
changed_name: "Hello, world!"
|
metadata:
|
||||||
changed_class_name: Folder
|
ignore_unknown_instances: false
|
||||||
changed_properties: {}
|
source_path: ~
|
||||||
changed_metadata: ~
|
project_node: ~
|
||||||
|
children: []
|
||||||
|
|||||||
Reference in New Issue
Block a user