-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API refactor, bug fixes and enhancements (#62)
- Loading branch information
Showing
30 changed files
with
445 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "tests-helpers" | ||
edition = "2021" | ||
version = "0.1.0" | ||
|
||
[dependencies] | ||
leptos = "0.6" | ||
web-sys = { version = "0.3", features = ["Navigator", "Storage"] } | ||
js-sys = "0.3" | ||
wasm-bindgen-futures = "0.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#[macro_export] | ||
macro_rules! mount { | ||
($app:ident) => {{ | ||
::leptos::mount_to_body( | ||
move || ::leptos::view! { <div id="wrapper"><$app/></div> }, | ||
); | ||
}}; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! unmount { | ||
() => {{ | ||
use leptos::wasm_bindgen::JsCast; | ||
::leptos::document() | ||
.body() | ||
.unwrap() | ||
.remove_child( | ||
::leptos::document() | ||
.get_element_by_id("wrapper") | ||
.unwrap() | ||
.unchecked_ref(), | ||
) | ||
.unwrap(); | ||
}}; | ||
} | ||
|
||
pub async fn sleep(delay: i32) { | ||
let mut cb = |resolve: js_sys::Function, _reject: js_sys::Function| { | ||
::web_sys::window() | ||
.unwrap() | ||
.set_timeout_with_callback_and_timeout_and_arguments_0( | ||
&resolve, delay, | ||
) | ||
.unwrap(); | ||
}; | ||
|
||
let p = ::js_sys::Promise::new(&mut cb); | ||
::wasm_bindgen_futures::JsFuture::from(p).await.unwrap(); | ||
} | ||
|
||
pub fn element_text(selector: &str) -> String { | ||
::leptos::document() | ||
.query_selector(selector) | ||
.unwrap() | ||
.unwrap() | ||
.text_content() | ||
.unwrap() | ||
} | ||
|
||
pub fn input_by_id(id: &str) -> web_sys::HtmlInputElement { | ||
use leptos::wasm_bindgen::JsCast; | ||
::leptos::document() | ||
.get_element_by_id(id) | ||
.unwrap() | ||
.unchecked_into::<web_sys::HtmlInputElement>() | ||
} | ||
|
||
pub fn html() -> web_sys::HtmlHtmlElement { | ||
use leptos::wasm_bindgen::JsCast; | ||
::leptos::document() | ||
.document_element() | ||
.unwrap() | ||
.unchecked_into::<web_sys::HtmlHtmlElement>() | ||
} | ||
|
||
pub mod localstorage { | ||
pub fn delete(key: &str) { | ||
::leptos::window() | ||
.local_storage() | ||
.unwrap() | ||
.unwrap() | ||
.remove_item(key) | ||
.unwrap(); | ||
} | ||
|
||
pub fn set(key: &str, value: &str) { | ||
::leptos::window() | ||
.local_storage() | ||
.unwrap() | ||
.unwrap() | ||
.set_item(key, value) | ||
.unwrap(); | ||
} | ||
|
||
pub fn get(key: &str) -> Option<String> { | ||
::leptos::window() | ||
.local_storage() | ||
.unwrap() | ||
.unwrap() | ||
.get_item(key) | ||
.unwrap() | ||
} | ||
} |
Oops, something went wrong.