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
6 changes: 6 additions & 0 deletions e2e/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ impl Tree {
self.focused().is_some_and(|node| node.author_id() == Some(id))
}

/// Whether the `n`th control wearing `id` has the keyboard, in reading order.
pub(crate) fn nth_has_focus(&self, id: &str, n: usize) -> bool {
let nth = self.all(id).get(n).copied();
nth.zip(self.focused()).is_some_and(|(nth, focused)| std::ptr::eq(nth, focused))
}

/// What the control that has the keyboard says.
pub(crate) fn focused_says(&self) -> String {
self.focused().map(said).unwrap_or_default()
Expand Down
20 changes: 18 additions & 2 deletions e2e/src/sdk/act.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ impl App {
self.click_at(middle(bounds), PointerButton::Secondary);
}

/// The middle button, on the `n`th `id` in reading order, counting from 0.
pub(super) fn middle_click_nth(&mut self, id: &str, n: usize, name: &str) {
let bounds = self.place(name, |tree| tree.all(id).get(n).and_then(|node| node.bounds()));
self.click_at(middle(bounds), PointerButton::Middle);
}

/// A press and a release elsewhere, the pointer moved half way between: what a gesture needs to
/// tell a drag from a click.
pub(super) fn drag(&mut self, from: Pos2, to: Pos2) {
Expand Down Expand Up @@ -203,6 +209,12 @@ impl App {
self.type_text(text);
}

/// As `fill`, the `n`th field wearing `id`, in reading order, counting from 0.
pub(super) fn fill_nth(&mut self, id: &str, n: usize, name: &str, text: &str) {
self.take_nth_keyboard(id, n, name);
self.type_text(text);
}

/// Types over what a field holds. ⚠️ Not by a second click, which selects a word only within
/// the double click's delay: the machine's speed.
pub(super) fn replace(&mut self, id: &str, name: &str, text: &str) {
Expand All @@ -215,10 +227,14 @@ impl App {
/// click can land in a frame that drops it; the next comes a few frames later — two at once
/// would be a double click.
pub(super) fn take_keyboard(&mut self, id: &str, name: &str) {
self.take_nth_keyboard(id, 0, name);
}

fn take_nth_keyboard(&mut self, id: &str, n: usize, name: &str) {
let until = Instant::now() + PATIENCE;
loop {
self.click(id, name);
if (0..5).any(|_| self.tree().has_focus(id)) {
self.click_nth(id, n, name);
if (0..5).any(|_| self.tree().nth_has_focus(id, n)) {
return;
}
assert!(Instant::now() < until, "« {} »: {name} never took the keyboard", current_step());
Expand Down
65 changes: 65 additions & 0 deletions e2e/src/sdk/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use egui::accesskit::Node;

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

/// The request open, written as code.
pub struct Code<'a>(pub(super) &'a mut App);

impl Code<'_> {
/// Opens the dialog.
pub fn open(&mut self) {
self.0.click("http-code-open", "« Code »");
self.0.expect("the code is written", |tree| tree.has("http-code-output"));
}

/// Closes it.
pub fn close(&mut self) {
self.0.press(Shortcut::Escape);
self.0.expect("the dialog closes", |tree| !tree.has("http-code-dialog"));
}

/// Writes it for another target, found by the filter.
pub fn choose(&mut self, typed: &str, target: &str) {
self.0.replace("http-code-filter", "the filter of the targets", typed);
self.0.click_where("http-code-target", "the target", |row| said(row) == target);
}

/// Resolves the variables, or leaves them as they are written.
pub fn flip_resolved(&mut self) {
self.0.click("http-code-resolve", "« Resolve the variables »");
}

/// Asks for the secrets in clear: the dialog asks before.
pub fn ask_secrets(&mut self) {
self.0.click("http-code-secrets", "« Include the secrets »");
self.0
.expect("the dialog asks before writing them", |tree| tree.has("http-code-secrets-ask"));
}

/// Answers yes.
pub fn include_secrets(&mut self) {
self.0.click("http-code-secrets-yes", "the yes");
}

/// Copies the code.
pub fn copy(&mut self) {
self.0.click("http-code-copy", "« Copy »");
}

/// The code says this.
pub fn expect(&mut self, words: &str, says: &str) {
self.0.expect(says, |tree| {
let code = tree.find("http-code-output").and_then(Node::label);
code.is_some_and(|code| code.contains(words))
});
}

/// The code says nothing of this.
pub fn expect_without(&mut self, words: &str, says: &str) {
self.0.expect(says, |tree| {
let code = tree.find("http-code-output").and_then(Node::label);
code.is_some_and(|code| !code.contains(words))
});
}
}
106 changes: 106 additions & 0 deletions e2e/src/sdk/environments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
use egui::accesskit::Node;

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

/// The environments requests are sent with: their page, and the menu that chooses one.
pub struct Environments<'a>(pub(super) &'a mut App);

impl Environments<'_> {
/// Opens their page, from the menu of the environments.
pub fn open(&mut self) {
self.0.click("http-environment-picker", "the menu of the environments");
self.0.click("http-environment-manage", "« Manage »");
self.0.expect("the environments open", |tree| tree.has("http-environments"));
}

/// Goes back to the requests.
pub fn leave(&mut self) {
self.0.click("http-environments-open", "« Environments » in the rail");
self.0.expect("the requests are back", |tree| !tree.has("http-environments"));
}

/// Makes an environment.
pub fn create(&mut self, name: &str) {
self.0.click("http-environment-create-open", "« New environment »");
self.0.fill("http-environment-create-input", "its name", name);
self.0.click("http-environment-create-submit", "« Create »");
self.0.expect("it is shown", |tree| {
tree.find("http-environment-name").and_then(Node::value) == Some(name)
});
}

/// Gives the environment shown another colour, counted from 0.
pub fn choose_colour(&mut self, n: usize) {
self.0.click_nth("http-environment-colour", n, "a colour");
self.0.expect("the colour is chosen", |tree| {
let colours = tree.all("http-environment-colour");
colours
.get(n)
.is_some_and(|colour| crate::driver::is_on(colour) || colour.is_selected() == Some(true))
});
}

/// Adds a variable to what is shown.
pub fn add_variable(&mut self, name: &str, value: &str) {
let at = self.0.tree().count("http-variable-name") - 1;
self.0.fill_nth("http-variable-name", at, "the variable's name", name);
self.type_value(at, value);
}

/// Adds a secret to the environment shown: its value is masked.
pub fn add_secret(&mut self, name: &str, value: &str) {
let at = self.0.tree().count("http-variable-name") - 1;
self.add_variable(name, value);
self.0.click_nth("http-variable-kind", at, "the variable's kind");
self.0.click("http-variable-kind-2", "« Secret »");
self.0.expect("its value is masked", |tree| {
tree.has("http-variable-reveal") && nth_value(tree, at).is_some_and(|held| held != value)
});
}

/// Types the value of the variable a *Set in…* made.
pub fn type_value_of(&mut self, name: &str, value: &str) {
let at = self.0.seen("the variable is in the table", |tree| {
let mut names = tree.all("http-variable-name").into_iter();
names.position(|field| field.value() == Some(name))
});
self.type_value(at, value);
}

/// Asks before a request that could change something leaves with the environment shown.
pub fn protect(&mut self) {
self.0.click("http-environment-protected", "« Protected »");
self.0
.expect("the page says what it changes", |tree| tree.has("http-environment-protected-note"));
}

/// Chooses the environment the requests are sent with, from its menu.
pub fn choose(&mut self, name: &str) {
self.0.click("http-environment-picker", "the menu of the environments");
self.0
.click_where("http-environment-option", "the environment in the menu", |option| {
said(option).contains(name)
});
self.0.expect("it is the one chosen", |tree| {
tree.text("http-environment-picker").is_some_and(|said| said.contains(name))
});
}

/// A variable of what is shown has this value, in clear.
pub fn expect_value(&mut self, value: &str, says: &str) {
self.0.expect(says, |tree| {
let mut values = tree.all("http-variable-value").into_iter();
values.any(|field| field.value() == Some(value))
});
}

fn type_value(&mut self, at: usize, value: &str) {
self.0.fill_nth("http-variable-value", at, "the variable's value", value);
self.0.expect("the value is typed", |tree| nth_value(tree, at) == Some(value));
}
}

fn nth_value(tree: &Tree, at: usize) -> Option<&str> {
tree.all("http-variable-value").get(at).copied().and_then(Node::value)
}
6 changes: 6 additions & 0 deletions e2e/src/sdk/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ impl Files<'_> {
self.put(name, server::PIXEL);
}

/// Puts a file among the person's own: its path, as a script writes it.
pub fn put_apart(&mut self, name: &str, bytes: &[u8]) -> String {
self.put(name, bytes);
self.path(name).display().to_string().replace('\\', "/")
}

/// Answers this file to the dialogs from now on: the one to read, or the one to write.
pub fn answer(&mut self, name: &str) {
let path = self.path(name).display().to_string();
Expand Down
Loading
Loading