Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions zia-lang.org/crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
69 changes: 69 additions & 0 deletions zia-lang.org/crate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&section).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
}
}
2 changes: 1 addition & 1 deletion zia-lang.org/crate/src/page/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn view(model: &Model) -> impl IntoNodes<GlobalMsg> {
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
Expand Down
7 changes: 0 additions & 7 deletions zia-lang.org/crate/tests/test.rs

This file was deleted.

9 changes: 9 additions & 0 deletions zia-lang.org/crate/webdriver.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"moz:firefoxOptions": {
"prefs": {
"media.navigator.streams.fake": true,
"media.navigator.permission.disabled": true
},
"args": []
}
}
8 changes: 6 additions & 2 deletions zia/src/concepts/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ use super::{

pub trait Concept: Sized {
type Id: Copy + Display + Eq + Hash + Debug;
type IdPairIterator<'a>: Iterator<Item = (Self::Id, Self::Id)>;
type IdIterator<'a>: Iterator<Item = Self::Id>;
type IdPairIterator<'a>: Iterator<Item = (Self::Id, Self::Id)>
where
Self: 'a;
type IdIterator<'a>: Iterator<Item = Self::Id>
where
Self: 'a;
fn id(&self) -> Self::Id;

fn maybe_composition(&self) -> Option<MaybeComposition<Self::Id>>;
Expand Down
11 changes: 8 additions & 3 deletions zia/src/context_snap_shot/concept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ impl<'a, 'b> From<&'a NewDirectConceptDelta<ConceptId, ConceptId>>

impl<'a> ConceptTrait for Mixed<'a> {
type Id = ConceptId;
type IdIterator<'b> = Box<dyn Iterator<Item = Self::Id> + 'b>;
type IdPairIterator<'b> =
Box<dyn Iterator<Item = (Self::Id, Self::Id)> + 'b>;
type IdIterator<'b>
where
Self: 'b,
= Box<dyn Iterator<Item = Self::Id> + 'b>;
type IdPairIterator<'b>
where
Self: 'b,
= Box<dyn Iterator<Item = (Self::Id, Self::Id)> + 'b>;

fn id(&self) -> Self::Id {
match self {
Expand Down
4 changes: 3 additions & 1 deletion zia/src/snap_shot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ where
+ Debug
+ for<'b> From<
&'b NewDirectConceptDelta<Self::ConceptId, Self::ConceptId>,
>;
>
where
Self: 'a;
fn get_concept(
&self,
concept_id: Self::ConceptId,
Expand Down