diff --git a/src/serve_session.rs b/src/serve_session.rs index 54e23c5f..03bc8f02 100644 --- a/src/serve_session.rs +++ b/src/serve_session.rs @@ -194,11 +194,13 @@ impl ServeSession { mod serve_session { use super::*; + use std::{path::PathBuf, thread::sleep, time::Duration}; + use insta::assert_yaml_snapshot; use rojo_insta_ext::RedactionMap; use crate::{ - imfs::{ImfsDebug, ImfsSnapshot, NoopFetcher}, + imfs::{ImfsDebug, ImfsEvent, ImfsSnapshot, NoopFetcher, TestFetcher}, tree_view::view_tree, }; @@ -213,4 +215,26 @@ mod serve_session { let mut rm = RedactionMap::new(); assert_yaml_snapshot!(view_tree(&session.tree(), &mut rm)); } + + #[test] + fn change_txt_file() { + let (state, fetcher) = TestFetcher::new(); + + state.load_snapshot("/foo.txt", ImfsSnapshot::file("Hello!")); + + let imfs = Imfs::new(fetcher); + let session = ServeSession::new(imfs, "/foo.txt", None); + + let mut redactions = RedactionMap::new(); + assert_yaml_snapshot!(view_tree(&session.tree(), &mut redactions)); + + state.load_snapshot("/foo.txt", ImfsSnapshot::file("World!")); + state.raise_event(ImfsEvent::Modified(PathBuf::from("/foo.txt"))); + + // TODO: Listen for a signal that the tree changed instead, using the + // message queue + sleep(Duration::from_millis(20)); + + assert_yaml_snapshot!(view_tree(&session.tree(), &mut redactions)); + } } diff --git a/src/snapshots/serve_session__change_txt_file-2.snap b/src/snapshots/serve_session__change_txt_file-2.snap new file mode 100644 index 00000000..cf4d332d --- /dev/null +++ b/src/snapshots/serve_session__change_txt_file-2.snap @@ -0,0 +1,18 @@ +--- +source: src/serve_session.rs +expression: "view_tree(&session.tree(), &mut redactions)" +--- +id: id-1 +name: foo +class_name: StringValue +properties: + Value: + Type: String + Value: World! +metadata: + ignore_unknown_instances: false + instigating_source: + Path: /foo.txt + relevant_paths: + - /foo.txt +children: [] diff --git a/src/snapshots/serve_session__change_txt_file.snap b/src/snapshots/serve_session__change_txt_file.snap new file mode 100644 index 00000000..ee051327 --- /dev/null +++ b/src/snapshots/serve_session__change_txt_file.snap @@ -0,0 +1,18 @@ +--- +source: src/serve_session.rs +expression: "view_tree(&session.tree(), &mut redactions)" +--- +id: id-1 +name: foo +class_name: StringValue +properties: + Value: + Type: String + Value: Hello! +metadata: + ignore_unknown_instances: false + instigating_source: + Path: /foo.txt + relevant_paths: + - /foo.txt +children: []