Add ServeSession test for changing text file

This commit is contained in:
Lucien Greathouse
2019-10-07 18:23:39 -07:00
parent 7b82e3d641
commit ffc146ff9b
3 changed files with 61 additions and 1 deletions

View File

@@ -194,11 +194,13 @@ impl<F: ImfsFetcher> ServeSession<F> {
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));
}
}

View File

@@ -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: []

View File

@@ -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: []