Fix keyboard focus tests
Some checks failed
CI (Pinnacle) / Build (push) Waiting to run
CI (Pinnacle) / Run tests (push) Waiting to run
CI (Pinnacle) / Check formatting (push) Waiting to run
CI (Pinnacle) / Clippy check (push) Waiting to run
Build Lua Docs / Build Lua docs (push) Has been cancelled
Build Rust Docs / Build docs (push) Has been cancelled

Wait a bit for each window to spawn fully
This commit is contained in:
Ottatop 2024-06-23 20:37:39 -05:00
parent eb333cb4c6
commit 8d0da8ccfc
3 changed files with 51 additions and 19 deletions

View file

@ -23,6 +23,10 @@ pub fn sleep_secs(secs: u64) {
std::thread::sleep(Duration::from_secs(secs));
}
pub fn sleep_millis(millis: u64) {
std::thread::sleep(Duration::from_millis(millis));
}
pub fn test_api<F>(test: F) -> anyhow::Result<()>
where
F: FnOnce(Sender<Box<dyn FnOnce(&mut State) + Send>>) -> anyhow::Result<()>

View file

@ -442,6 +442,8 @@ mod output {
use super::*;
mod handle {
use common::sleep_millis;
use super::*;
#[tokio::main]
@ -551,16 +553,24 @@ mod output {
run_lua! { |Pinnacle|
Pinnacle.process.spawn("foot")
}
sleep_millis(250);
run_lua! { |Pinnacle|
Pinnacle.process.spawn("foot")
}
sleep_millis(250);
run_lua! { |Pinnacle|
Pinnacle.process.spawn("foot")
}
sleep_secs(1);
sleep_millis(250);
run_lua! { |Pinnacle|
Pinnacle.tag.get("2"):switch_to()
Pinnacle.process.spawn("foot")
}
sleep_millis(250);
run_lua! { |Pinnacle|
Pinnacle.process.spawn("foot")
}
@ -576,7 +586,7 @@ mod output {
print(focus_stack[3].id)
print(focus_stack[4].id)
print(focus_stack[5].id)
// FIXME: the below statement failed in github CI, idk why
assert(focus_stack[1].id == 0, "focus stack at 1 id != 0")
assert(focus_stack[2].id == 1, "focus stack at 2 id != 1")
assert(focus_stack[3].id == 2, "focus stack at 3 id != 2")

View file

@ -318,6 +318,7 @@ mod output {
}
mod handle {
use common::sleep_millis;
use pinnacle::window::window_state::WindowId;
use pinnacle_api::output::Transform;
@ -406,15 +407,24 @@ mod output {
run_rust(|api| {
api.process.spawn(["foot"]);
})?;
sleep_millis(250);
run_rust(|api| {
api.process.spawn(["foot"]);
})?;
sleep_millis(250);
run_rust(|api| {
api.process.spawn(["foot"]);
})?;
sleep_secs(1);
sleep_millis(250);
run_rust(|api| {
api.tag.get("2").unwrap().switch_to();
api.process.spawn(["foot"]);
})?;
sleep_millis(250);
run_rust(|api| {
api.process.spawn(["foot"]);
})?;
@ -424,12 +434,12 @@ mod output {
api.tag.get("1").unwrap().switch_to();
let focus_stack = api.output.get_focused().unwrap().keyboard_focus_stack();
assert!(dbg!(focus_stack.len()) == 5);
assert!(focus_stack[0].id() == 0);
assert!(focus_stack[1].id() == 1);
assert!(focus_stack[2].id() == 2);
assert!(focus_stack[3].id() == 3);
assert!(focus_stack[4].id() == 4);
assert_eq!(focus_stack.len(), 5);
assert_eq!(focus_stack[0].id(), 0);
assert_eq!(focus_stack[1].id(), 1);
assert_eq!(focus_stack[2].id(), 2);
assert_eq!(focus_stack[3].id(), 3);
assert_eq!(focus_stack[4].id(), 4);
})?;
// Terminate all windows related to this test
@ -465,17 +475,25 @@ mod output {
sleep_secs(1);
run_rust(|api| {
api.tag.get("1").unwrap().switch_to();
api.process.spawn(["foot"]);
})?;
sleep_millis(250);
run_rust(|api| {
api.process.spawn(["foot"]);
})?;
sleep_millis(250);
run_rust(|api| {
api.process.spawn(["foot"]);
})?;
sleep_secs(1);
sleep_millis(250);
run_rust(|api| {
api.tag.get("2").unwrap().switch_to();
api.process.spawn(["foot"]);
})?;
sleep_millis(250);
run_rust(|api| {
api.process.spawn(["foot"]);
})?;
@ -489,10 +507,10 @@ mod output {
.get_focused()
.unwrap()
.keyboard_focus_stack_visible();
assert!(focus_stack.len() == 3);
assert!(focus_stack[0].id() == 0);
assert!(focus_stack[1].id() == 1);
assert!(focus_stack[2].id() == 2);
assert_eq!(focus_stack.len(), 3);
assert_eq!(focus_stack[0].id(), 0);
assert_eq!(focus_stack[1].id(), 1);
assert_eq!(focus_stack[2].id(), 2);
api.tag.get("2").unwrap().switch_to();
@ -501,9 +519,9 @@ mod output {
.get_focused()
.unwrap()
.keyboard_focus_stack_visible();
assert!(focus_stack.len() == 2);
assert!(focus_stack[0].id() == 3);
assert!(focus_stack[1].id() == 4);
assert_eq!(focus_stack.len(), 2);
assert_eq!(focus_stack[0].id(), 3);
assert_eq!(focus_stack[1].id(), 4);
})?;
// Terminate all windows related to this test