From 0a1fa9588fb89142e5404f6565b6393204b314e2 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Mon, 30 Sep 2019 17:13:56 -0700 Subject: [PATCH] Test for AppliedPatchSet result --- src/snapshot/patch.rs | 4 ++-- src/snapshot/tests/apply.rs | 16 ++++++++++++---- .../apply__set_name_and_class_name.snap | 12 ++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 src/snapshot/tests/snapshots/apply__set_name_and_class_name.snap diff --git a/src/snapshot/patch.rs b/src/snapshot/patch.rs index f7ce22b0..8be68c47 100644 --- a/src/snapshot/patch.rs +++ b/src/snapshot/patch.rs @@ -61,7 +61,7 @@ pub struct PatchUpdate { /// // TODO: Introduce machinery to detect conflicts, like keeping previous + // current values in all fields. -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct AppliedPatchSet { pub removed: Vec, pub added: Vec, @@ -78,7 +78,7 @@ impl AppliedPatchSet { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct AppliedPatchUpdate { pub id: RbxId, diff --git a/src/snapshot/tests/apply.rs b/src/snapshot/tests/apply.rs index f06fa271..a31c392e 100644 --- a/src/snapshot/tests/apply.rs +++ b/src/snapshot/tests/apply.rs @@ -1,12 +1,18 @@ +use insta::assert_yaml_snapshot; use rbx_dom_weak::RbxInstanceProperties; +use rojo_insta_ext::RedactionMap; + use crate::snapshot::{ apply_patch_set, InstancePropertiesWithMeta, PatchSet, PatchUpdate, RojoTree, }; #[test] -fn reify_folder() { +fn set_name_and_class_name() { + let mut redactions = RedactionMap::new(); + let mut tree = empty_tree(); + redactions.intern(tree.get_root_id()); let patch_set = PatchSet { updated_instances: vec![PatchUpdate { @@ -19,10 +25,12 @@ fn reify_folder() { ..Default::default() }; - let _applied_patch_set = apply_patch_set(&mut tree, patch_set); + let applied_patch_set = apply_patch_set(&mut tree, patch_set); - // TODO: Make assertions about tree using snapshots - // TODO: make assertions about applied patch set using snapshots + // TODO: Snapshot tree, requires RojoTree: Serialize (but not Deserialize!) + + let applied_patch_value = redactions.redacted_yaml(applied_patch_set); + assert_yaml_snapshot!(applied_patch_value); } fn empty_tree() -> RojoTree { diff --git a/src/snapshot/tests/snapshots/apply__set_name_and_class_name.snap b/src/snapshot/tests/snapshots/apply__set_name_and_class_name.snap new file mode 100644 index 00000000..25a10131 --- /dev/null +++ b/src/snapshot/tests/snapshots/apply__set_name_and_class_name.snap @@ -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: ~