diff --git a/zia-lang.org/crate/Cargo.toml b/zia-lang.org/crate/Cargo.toml index 902c870c..5371f5b1 100644 --- a/zia-lang.org/crate/Cargo.toml +++ b/zia-lang.org/crate/Cargo.toml @@ -26,6 +26,19 @@ features = [ "KeyboardEvent" ] +[dev-dependencies.web-sys] +version = "^0.3.45" +features = [ + "Window", + "Document", + "Element", + "Event", + "EventTarget", + "EventInit", + "KeyboardEventInit", + "HtmlTextAreaElement" +] + [profile.release] lto = true opt-level = 's' diff --git a/zia-lang.org/crate/src/lib.rs b/zia-lang.org/crate/src/lib.rs index 31764609..c7ff396d 100644 --- a/zia-lang.org/crate/src/lib.rs +++ b/zia-lang.org/crate/src/lib.rs @@ -144,3 +144,72 @@ pub fn run() { log!("App started."); } + +#[cfg(test)] +mod test { + extern crate wasm_bindgen_test; + use super::run; + use seed::{prelude::JsCast, window}; + use wasm_bindgen_test::*; + use web_sys::{HtmlTextAreaElement, KeyboardEvent, KeyboardEventInit}; + + wasm_bindgen_test_configure!(run_in_browser); + + fn load_page() { + // Need to insert an element with id="app" to mimic the loading screen + // defined in ../../entries/index.hbs + let document = window().document().unwrap(); + let section = document.create_element("section").unwrap(); + section.set_id("app"); + document.body().unwrap().append_with_node_1(§ion).unwrap(); + + // Now we can run the WASM part + run(); + } + + #[wasm_bindgen_test] + fn keyboard_input_is_displayed_textarea_element() { + load_page(); + let keyboard_event = KeyboardEvent::new_with_keyboard_event_init_dict( + "KeyboardEvent", + KeyboardEventInit::new().key("x"), + ) + .unwrap(); + window().document().unwrap().dispatch_event(&keyboard_event).unwrap(); + let command_input: HtmlTextAreaElement = JsCast::dyn_into( + window() + .document() + .unwrap() + .get_element_by_id("command_input") + .unwrap(), + ) + .unwrap(); + assert_eq!(command_input.value(), "x"); + } + + #[wasm_bindgen_test] + fn submitted_command_moves_from_textarea_to_history() { + load_page(); + // TODO: focus textarea + + // TODO: simulate typing text + + // TODO: simulate pressing "Enter" + + // TODO: assert textarea is empty + + // TODO: assert text submitted appears in an element above textarea + } + + #[wasm_bindgen_test] + fn height_of_textarea_does_not_change_when_typing_one_line() { + load_page(); + // TODO: get the height of the textarea element + + // TODO: simulate typing text + + // TODO: get the height of the textarea element + + // TODO: assert height of textarea element has not changed + } +} diff --git a/zia-lang.org/crate/src/page/home.rs b/zia-lang.org/crate/src/page/home.rs index bc1e3511..45068906 100644 --- a/zia-lang.org/crate/src/page/home.rs +++ b/zia-lang.org/crate/src/page/home.rs @@ -82,7 +82,7 @@ pub fn view(model: &Model) -> impl IntoNodes { C.outline_none, C.overflow_hidden ], - attrs! {At::Type => "text", At::Name => "input"}, + attrs! {At::Type => "text", At::Name => "input", At::Id => "command_input"}, style! {St::Resize => "none", St::Height => model.command_input.get().map_or_else( // flatten textarea on first render to prevent it being // too tall on subsequent renders diff --git a/zia-lang.org/crate/tests/test.rs b/zia-lang.org/crate/tests/test.rs deleted file mode 100644 index 3ce8516a..00000000 --- a/zia-lang.org/crate/tests/test.rs +++ /dev/null @@ -1,7 +0,0 @@ -extern crate wasm_bindgen_test; -use wasm_bindgen_test::*; - -#[wasm_bindgen_test] -fn pass() { - assert_eq!(1, 1); -} diff --git a/zia-lang.org/crate/webdriver.json b/zia-lang.org/crate/webdriver.json new file mode 100644 index 00000000..76e9221e --- /dev/null +++ b/zia-lang.org/crate/webdriver.json @@ -0,0 +1,9 @@ +{ + "moz:firefoxOptions": { + "prefs": { + "media.navigator.streams.fake": true, + "media.navigator.permission.disabled": true + }, + "args": [] + } +} \ No newline at end of file diff --git a/zia/src/concepts/trait.rs b/zia/src/concepts/trait.rs index 625b0ff6..cfb660ae 100644 --- a/zia/src/concepts/trait.rs +++ b/zia/src/concepts/trait.rs @@ -18,8 +18,12 @@ use super::{ pub trait Concept: Sized { type Id: Copy + Display + Eq + Hash + Debug; - type IdPairIterator<'a>: Iterator; - type IdIterator<'a>: Iterator; + type IdPairIterator<'a>: Iterator + where + Self: 'a; + type IdIterator<'a>: Iterator + where + Self: 'a; fn id(&self) -> Self::Id; fn maybe_composition(&self) -> Option>; diff --git a/zia/src/context_snap_shot/concept.rs b/zia/src/context_snap_shot/concept.rs index 250aff6b..5de49afd 100644 --- a/zia/src/context_snap_shot/concept.rs +++ b/zia/src/context_snap_shot/concept.rs @@ -61,9 +61,14 @@ impl<'a, 'b> From<&'a NewDirectConceptDelta> impl<'a> ConceptTrait for Mixed<'a> { type Id = ConceptId; - type IdIterator<'b> = Box + 'b>; - type IdPairIterator<'b> = - Box + 'b>; + type IdIterator<'b> + where + Self: 'b, + = Box + 'b>; + type IdPairIterator<'b> + where + Self: 'b, + = Box + 'b>; fn id(&self) -> Self::Id { match self { diff --git a/zia/src/snap_shot.rs b/zia/src/snap_shot.rs index a4640880..f99d3c77 100644 --- a/zia/src/snap_shot.rs +++ b/zia/src/snap_shot.rs @@ -37,7 +37,9 @@ where + Debug + for<'b> From< &'b NewDirectConceptDelta, - >; + > + where + Self: 'a; fn get_concept( &self, concept_id: Self::ConceptId,