Skip to content
Merged
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
18 changes: 17 additions & 1 deletion e2e/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ impl Tree {
said.flatten().any(|text| text.contains(words))
}

/// Whether anything inside a place says `words`.
pub(crate) fn says_within(&self, place: Rect, words: &str) -> bool {
self.nodes.iter().any(|(_, node)| {
within(node, place)
&& [node.label(), node.value()]
.into_iter()
.flatten()
.any(|text| text.contains(words))
})
}

/// What a node says: its name, or its value when it has no name.
pub(crate) fn text(&self, id: &str) -> Option<String> {
self.find(id).map(said)
Expand Down Expand Up @@ -262,7 +273,9 @@ impl Driver {
panic!("the application refused {request:?}: {message}")
}
Ok(response) => response,
Err(error) => panic!("the application stopped answering {request:?}: {error}"),
Err(error) => {
panic!("the application stopped answering {request:?} (waited up to {PATIENCE:?}): {error}")
}
}
}
}
Expand Down Expand Up @@ -315,6 +328,9 @@ pub(crate) fn connect(port: u16, child: &mut Child) -> TcpStream {
panic!("the application ended before it answered: {status}");
}
if let Ok(mut stream) = TcpStream::connect((Ipv4Addr::LOCALHOST, port)) {
// A window that stops drawing answers nothing: without this, the journey waits until
// the job is cancelled, and leaves neither its screen nor its log.
stream.set_read_timeout(Some(PATIENCE)).expect("the socket takes a timeout");
let version = protocol::read_handshake(&mut stream).expect("an inspection handshake");
assert_eq!(version, protocol::PROTOCOL_VERSION, "another protocol");
return stream;
Expand Down
48 changes: 43 additions & 5 deletions e2e/src/sdk/act.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ impl App {
/// place, and one still moving would be clicked where it no longer is.
pub(super) fn place(&mut self, name: &str, find: impl Fn(&Tree) -> Option<Rect>) -> Rect {
let says = format!("{name} is on the screen");
let until = Instant::now() + PATIENCE;
loop {
let first = self.seen(&says, &find);
if find(&self.tree()) == Some(first) {
return first;
}
assert!(Instant::now() < until, "« {} »: {name} never holds still", current_step());
}
}

Expand Down Expand Up @@ -89,6 +91,24 @@ impl App {
self.click_at(middle(bounds), PointerButton::Primary);
}

/// Clicks a control until it answers: a click is lost when the machine's own pointer moves, or
/// the screen does, between its press and its release.
pub(super) fn click_until(
&mut self,
name: &str,
click: impl Fn(&mut Self),
answered: impl Fn(&Tree) -> bool,
) {
let until = Instant::now() + PATIENCE;
loop {
click(self);
if (0..20).any(|_| answered(&self.tree())) {
return;
}
assert!(Instant::now() < until, "« {} »: {name} answers a click", current_step());
}
}

/// Takes a toast standing over a place off the screen: whether one was.
fn uncover(&mut self, place: Rect) -> bool {
let tree = self.tree();
Expand All @@ -103,10 +123,11 @@ impl App {
true
}

/// A card by its title's band: a todo list's is mostly the boxes of its items.
pub(super) fn click_card(&mut self, card: Rect) {
/// A place by its top: a todo list's card is mostly the boxes of its items, and a drawing can end
/// under the view.
pub(super) fn click_top(&mut self, place: Rect) {
#[expect(clippy::cast_possible_truncation, reason = "points on a screen")]
let band = Pos2::new(middle(card).x, card.y0 as f32 + CARD_BAND);
let band = Pos2::new(middle(place).x, place.y0 as f32 + CARD_BAND);
self.click_at(band, PointerButton::Primary);
}

Expand All @@ -119,9 +140,14 @@ impl App {

/// The `n`th `id` clicked with a key held, Ctrl or Shift.
pub(super) fn click_holding(&mut self, held: Modifiers, id: &str, n: usize, name: &str) {
self.driver.apply(vec![Event::ModifiersChanged(held)]);
self.hold(held);
self.click_nth(id, n, name);
self.driver.apply(vec![Event::ModifiersChanged(Modifiers::NONE)]);
self.hold(Modifiers::NONE);
}

/// Holds a key down, or lets it go.
pub(super) fn hold(&mut self, held: Modifiers) {
self.driver.apply(vec![Event::ModifiersChanged(held)]);
}

/// The right button, on a control.
Expand Down Expand Up @@ -199,6 +225,18 @@ impl App {
}
}

/// Takes the keyboard to a control by Tab.
pub(super) fn tab_to(&mut self, id: &str, label: &str, name: &str) {
for _ in 0..80 {
self.press(Shortcut::Tab);
let tree = self.tree();
if tree.has_focus(id) && tree.focused_says() == label {
return;
}
}
panic!("« {} »: Tab never reached {name}", current_step());
}

/// A key pressed and released at its place on the keyboard.
pub(super) fn key(&mut self, key: Key, modifiers: Modifiers) {
self.key_printed(key, key, modifiers);
Expand Down
235 changes: 235 additions & 0 deletions e2e/src/sdk/board.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
use egui::accesskit::{Node, Rect};
use egui::{Pos2, Vec2};

use super::{App, Shortcut};
use crate::driver::{Tree, middle, said, within};

/// The board: a space's folders drawn as zones holding their notes, the loose ones beside them.
pub struct Board<'a>(pub(super) &'a mut App);

/// Where a zone stands and how large it is, as a journey keeps it to compare.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Place {
x: f64,
y: f64,
width: f64,
height: f64,
}

impl Board<'_> {
/// Shows the space as a board.
pub fn show(&mut self) {
self.0.click("view-board", "« Board »");
self.0.expect("the board is drawn", |tree| tree.has("board"));
}

/// Shows the space as a list.
pub fn show_list(&mut self) {
self.0.click("view-list", "« List »");
self.0.expect("the list is back", |tree| !tree.has("board"));
}

/// Drags a card into a zone.
pub fn drag_card_into(&mut self, card: &str, zone: &str) {
let from = self.card(card);
let into = self.zone(zone);
// The card lands where its corner does, and the grab is its middle.
let to = corner(into) + Vec2::new(150.0, 120.0);
self.0.drag(middle(from), to);
}

/// Drags a card out of its zone, onto the ground under it.
pub fn drag_card_out(&mut self, card: &str) {
let from = middle(self.card(card));
self.0.drag(from, from + Vec2::new(0.0, 360.0));
}

/// Drags a card onto a folder of the rail.
pub fn drag_card_onto_folder(&mut self, card: &str, folder: &str) {
let from = self.card(card);
let to = self.0.place("the folder in the rail", |tree| {
let mut rows = tree.all("folder-option").into_iter();
rows.find(|row| said(row) == folder)?.bounds()
});
self.0.drag(middle(from), middle(to));
}

/// Moves a zone by its grip, down to free ground.
pub fn move_zone(&mut self, zone: &str) {
self.drag_control(zone, "board-zone-grip", Vec2::new(93.0, 221.0));
}

/// Widens a zone by its corner.
pub fn widen_zone(&mut self, zone: &str) {
self.drag_control(zone, "board-zone-resize", Vec2::new(260.0, 0.0));
}

/// Draws a folder on the ground, and names it.
pub fn draw_folder(&mut self, name: &str) {
let ground = self.0.place("the board", |tree| tree.find("board").and_then(Node::bounds));
let from = Pos2::new(corner(ground).x + 40.0, middle(ground).y * 2.0 - corner(ground).y - 260.0);
self.0.drag(from, from + Vec2::new(300.0, 220.0));
self.0.fill("folder-name-input", "the new folder's name", name);
self.0.press(Shortcut::Enter);
self.expect_zone(name, "the folder is a zone");
}

/// Opens a zone's folder by its title.
pub fn open_zone(&mut self, zone: &str) {
self.0
.click_where("board-zone-open", "the zone's title", |title| said(title) == zone);
}

/// Ticks every card of a zone, from its menu.
pub fn tick_zone(&mut self, zone: &str) {
self.0
.click_where("board-zone-menu", "the zone's « ⋯ »", |menu| said(menu).contains(zone));
self.0.click("folder-select-notes", "« Select its notes »");
}

/// *Align*.
pub fn align(&mut self) {
self.0.click("board-tidy", "« Align »");
}

/// *Other arrangements*, then the one that puts everything back in order.
pub fn reorganise(&mut self) {
self.0.click("board-tidy-more", "« Other arrangements »");
self.0.click("board-tidy-everything", "the arrangement of everything");
}

/// Where a zone stands.
pub fn place_of(&mut self, zone: &str) -> Place {
place(self.zone(zone))
}

/// The zones are these, in any order.
pub fn expect_zones(&mut self, zones: &[&str], says: &str) {
self.0.expect(says, |tree| {
let mut drawn = tree.texts("board-zone-open");
let mut wanted = zones.to_vec();
drawn.sort();
wanted.sort_unstable();
drawn == wanted
});
}

/// A zone is drawn.
pub fn expect_zone(&mut self, zone: &str, says: &str) {
self.0.expect(says, |tree| zone_of(tree, zone).is_some());
}

/// A zone holds these notes.
pub fn expect_in_zone(&mut self, zone: &str, notes: &[&str], says: &str) {
self.0.expect(says, |tree| held(tree, zone) == notes);
}

/// A zone holds this note, among others.
pub fn expect_holding(&mut self, zone: &str, note: &str, says: &str) {
self.0.expect(says, |tree| held(tree, zone).iter().any(|card| card == note));
}

/// These notes stand loose, beside the zones, in any order.
pub fn expect_loose(&mut self, notes: &[&str], says: &str) {
self.0.expect(says, |tree| {
let mut drawn = tree.texts("board-loose-card");
let mut wanted = notes.to_vec();
drawn.sort();
wanted.sort_unstable();
drawn == wanted
});
}

/// A zone is elsewhere than `before`, of the same size.
pub fn expect_moved(&mut self, zone: &str, before: Place, says: &str) {
self.0.expect(says, |tree| {
zone_of(tree, zone).map(place).is_some_and(|now| {
((now.x - before.x).abs() > 0.5 || (now.y - before.y).abs() > 0.5)
&& (now.width - before.width).abs() < 0.5
})
});
}

/// A zone is elsewhere than `before`, whatever its size.
pub fn expect_moved_anywhere(&mut self, zone: &str, before: Place, says: &str) {
self.0
.expect(says, |tree| zone_of(tree, zone).map(place).is_some_and(|now| now != before));
}

/// A zone is wider than `before`, where it was.
pub fn expect_wider(&mut self, zone: &str, before: Place, says: &str) {
self.0.expect(says, |tree| {
zone_of(tree, zone)
.map(place)
.is_some_and(|now| now.width > before.width + 100.0 && (now.x - before.x).abs() < 0.5)
});
}

/// A zone stands exactly where and as large as `before`.
pub fn expect_place(&mut self, zone: &str, before: Place, says: &str) {
self.0.expect(says, |tree| zone_of(tree, zone).map(place) == Some(before));
}

/// A note the search leaves out stays on the board, dimmed.
pub fn expect_dimmed(&mut self, note: &str, says: &str) {
self.0.expect(says, |tree| {
let loose = tree.all("board-loose-card").into_iter();
let mut cards = loose.chain(tree.all("board-zone-card"));
cards.any(|card| said(card) == note && card.is_disabled())
});
}

/// The board is on the screen.
pub fn expect(&mut self, says: &str) {
self.0.expect(says, |tree| tree.has("board"));
}

/// The space is listed, not on a board.
pub fn expect_list(&mut self, says: &str) {
self.0.expect(says, |tree| !tree.has("board") && tree.is_on("view-list"));
}

fn zone(&mut self, zone: &str) -> Rect {
self.0.place("the zone", |tree| zone_of(tree, zone))
}

fn card(&mut self, card: &str) -> Rect {
self.0.place("the card on the board", |tree| {
let loose = tree.all("board-loose-card").into_iter();
let mut cards = loose.chain(tree.all("board-zone-card"));
cards.find(|node| said(node) == card)?.bounds()
})
}

fn drag_control(&mut self, zone: &str, id: &str, by: Vec2) {
let frame = self.zone(zone);
let control = self.0.place("the zone's handle", |tree| {
let mut controls = tree.all(id).into_iter();
controls.find(|control| within(control, frame))?.bounds()
});
self.0.drag(middle(control), middle(control) + by);
}
}

fn zone_of(tree: &Tree, zone: &str) -> Option<Rect> {
let mut zones = tree.all("board-zone").into_iter();
zones.find(|node| said(node) == zone)?.bounds()
}

/// The titles of the cards inside a zone.
fn held(tree: &Tree, zone: &str) -> Vec<String> {
let Some(frame) = zone_of(tree, zone) else {
return Vec::new();
};
let cards = tree.all("board-zone-card").into_iter();
cards.filter(|card| within(card, frame)).map(said).collect()
}

fn place(zone: Rect) -> Place {
Place { x: zone.x0, y: zone.y0, width: zone.width(), height: zone.height() }
}

fn corner(place: Rect) -> Pos2 {
#[expect(clippy::cast_possible_truncation, reason = "points on a screen")]
Pos2::new(place.x0 as f32, place.y0 as f32)
}
Loading
Loading