fix: automatically reconnect after losing a WebSocket connection
Some checks failed
actionlint check / actionlint check (pull_request) Successful in 7s
conventional pull request title check / conventional pull request title check (pull_request) Successful in 3s
conventional commit messages check / conventional commit messages check (pull_request) Successful in 6s
dotenv-linter check / dotenv-linter check (pull_request) Successful in 9s
GitLeaks check / GitLeaks check (pull_request) Successful in 11s
hadolint check / hadolint check (pull_request) Successful in 14s
Prettier check / Prettier check (pull_request) Failing after 35s
markdownlint check / markdownlint check (pull_request) Failing after 40s
htmlhint check / htmlhint check (pull_request) Successful in 44s
checkov check / checkov check (pull_request) Failing after 1m20s
ShellCheck check / ShellCheck check (pull_request) Successful in 23s
Stylelint check / Stylelint check (pull_request) Successful in 24s
yamllint check / yamllint check (pull_request) Successful in 22s
Rust check / Rust check (pull_request) Failing after 57m45s
Some checks failed
actionlint check / actionlint check (pull_request) Successful in 7s
conventional pull request title check / conventional pull request title check (pull_request) Successful in 3s
conventional commit messages check / conventional commit messages check (pull_request) Successful in 6s
dotenv-linter check / dotenv-linter check (pull_request) Successful in 9s
GitLeaks check / GitLeaks check (pull_request) Successful in 11s
hadolint check / hadolint check (pull_request) Successful in 14s
Prettier check / Prettier check (pull_request) Failing after 35s
markdownlint check / markdownlint check (pull_request) Failing after 40s
htmlhint check / htmlhint check (pull_request) Successful in 44s
checkov check / checkov check (pull_request) Failing after 1m20s
ShellCheck check / ShellCheck check (pull_request) Successful in 23s
Stylelint check / Stylelint check (pull_request) Successful in 24s
yamllint check / yamllint check (pull_request) Successful in 22s
Rust check / Rust check (pull_request) Failing after 57m45s
This commit is contained in:
85
dioxus-i18n/tests/common/test_hook.rs
Normal file
85
dioxus-i18n/tests/common/test_hook.rs
Normal file
@@ -0,0 +1,85 @@
|
||||
// Lifted from: https://dioxuslabs.com/learn/0.6/cookbook/testing
|
||||
//
|
||||
// Much curtialed functionality and massaged to use in the local testing
|
||||
// here. This hook isn't intended for reuse.
|
||||
//
|
||||
|
||||
use dioxus::{dioxus_core::NoOpMutations, prelude::*};
|
||||
use futures::FutureExt;
|
||||
|
||||
use std::{cell::RefCell, fmt::Debug, rc::Rc};
|
||||
|
||||
pub(crate) fn test_hook<V: 'static>(
|
||||
initialize: impl FnMut() -> V + 'static,
|
||||
check: impl FnMut(V, &mut Assertions) + 'static,
|
||||
) {
|
||||
#[derive(Props)]
|
||||
struct MockAppComponent<I: 'static, C: 'static> {
|
||||
hook: Rc<RefCell<I>>,
|
||||
check: Rc<RefCell<C>>,
|
||||
}
|
||||
|
||||
impl<I, C> PartialEq for MockAppComponent<I, C> {
|
||||
fn eq(&self, _: &Self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, C> Clone for MockAppComponent<I, C> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
hook: self.hook.clone(),
|
||||
check: self.check.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn mock_app<I: FnMut() -> V, C: FnMut(V, &mut Assertions), V>(
|
||||
props: MockAppComponent<I, C>,
|
||||
) -> Element {
|
||||
let value = props.hook.borrow_mut()();
|
||||
|
||||
let mut assertions = Assertions::new();
|
||||
|
||||
props.check.borrow_mut()(value, &mut assertions);
|
||||
|
||||
rsx! { div {} }
|
||||
}
|
||||
|
||||
let mut vdom = VirtualDom::new_with_props(
|
||||
mock_app,
|
||||
MockAppComponent {
|
||||
hook: Rc::new(RefCell::new(initialize)),
|
||||
check: Rc::new(RefCell::new(check)),
|
||||
},
|
||||
);
|
||||
|
||||
vdom.rebuild_in_place();
|
||||
|
||||
while vdom.wait_for_work().now_or_never().is_some() {
|
||||
vdom.render_immediate(&mut NoOpMutations);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Assertions {}
|
||||
|
||||
impl Assertions {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
pub fn assert<T>(&mut self, actual: T, expected: T, id: &str)
|
||||
where
|
||||
T: PartialEq + Debug,
|
||||
{
|
||||
if actual != expected {
|
||||
eprintln!(
|
||||
"***** ERROR in {}: actual: '{:?}' != expected: '{:?}' *****\n",
|
||||
id, actual, expected
|
||||
);
|
||||
std::process::exit(-1);
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user