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 @@ -73,6 +73,12 @@ impl Tree {
ids.filter(|id| id.starts_with(start)).collect()
}

/// The node whose id begins so and that says `name`.
pub(crate) fn named(&self, start: &str, name: &str) -> Option<&Node> {
let mut nodes = self.nodes.iter().map(|(_, node)| node);
nodes.find(|node| node.author_id().is_some_and(|id| id.starts_with(start)) && said(node) == name)
}

/// What each node wearing `id` says, in reading order.
pub(crate) fn texts(&self, id: &str) -> Vec<String> {
self.all(id).into_iter().map(said).collect()
Expand Down
6 changes: 5 additions & 1 deletion e2e/src/sdk/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Clipboard<'_> {
pub(super) fn expect_that(&mut self, says: &str, holds: impl Fn(&str) -> bool) {
let until = Instant::now() + PATIENCE;
loop {
let held = platform::clipboard::System.text().unwrap_or_default();
let held = held();
if holds(&held) {
return;
}
Expand All @@ -37,3 +37,7 @@ impl Clipboard<'_> {
}
}
}

pub(super) fn held() -> String {
platform::clipboard::System.text().unwrap_or_default()
}
16 changes: 13 additions & 3 deletions e2e/src/sdk/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ impl Editor<'_> {
pub fn add_tag(&mut self, tag: &str) {
self.0.fill("editor-tag-add", "the field of a new tag", tag);
self.0.press(Shortcut::Enter);
self.0.expect("the tag is added", |tree| {
tree.texts("editor-tag").iter().any(|worn| worn.contains(tag))
});
self.expect_tag(tag, "the tag is added");
}

/// Chooses the language from the keyboard, in its menu's filter.
Expand Down Expand Up @@ -259,6 +257,18 @@ impl Editor<'_> {
self.0.expect(says, |tree| held(tree).contains(code));
}

/// The code holds nothing of this.
pub fn expect_code_without(&mut self, code: &str, says: &str) {
self.0
.expect(says, |tree| tree.has("editor-body") && !held(tree).contains(code));
}

/// The note wears this tag.
pub fn expect_tag(&mut self, tag: &str, says: &str) {
self.0
.expect(says, |tree| tree.texts("editor-tag").iter().any(|worn| worn.contains(tag)));
}

/// The note's kind is said, and cannot be changed.
pub fn expect_no_kind_to_choose(&mut self, says: &str) {
self.0.click("editor-kind", "the note's kind");
Expand Down
12 changes: 12 additions & 0 deletions e2e/src/sdk/files.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::{Path, PathBuf};

use super::App;
use crate::server;

/// The person's own files, and what they answer to the system's file dialogs: no driver reaches the
/// dialog itself.
Expand All @@ -12,6 +13,11 @@ impl Files<'_> {
std::fs::write(self.path(name), bytes).expect("the person's file is written");
}

/// Puts a picture of one pixel, a PNG, among the person's own files.
pub fn put_picture(&mut self, name: &str) {
self.put(name, server::PIXEL);
}

/// 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 All @@ -24,6 +30,12 @@ impl Files<'_> {
self.0.expect(says, |_| std::fs::read(&path).is_ok_and(|bytes| holds(&bytes)));
}

/// A file was written, the same as another.
pub fn expect_same(&mut self, name: &str, as_name: &str, says: &str) {
let wanted = std::fs::read(self.path(as_name)).expect("the other file is read");
self.expect(name, says, |bytes| bytes == wanted);
}

/// What a file holds, once it is written.
pub(super) fn read(&mut self, name: &str, says: &str) -> Vec<u8> {
let path = self.path(name);
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/sdk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub use selection::Selection;
pub use shortcut::Shortcut;
pub use tags::Tags;
pub use todo::Todo;
pub use tools::Tools;
pub use tools::{Copied, Given, Tools};
pub use trash::Trash;
pub use tray::{Tray, TrayEntry};
pub use window::{Area, Window};
Expand Down
3 changes: 3 additions & 0 deletions e2e/src/sdk/shortcut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub enum Shortcut {
Palette,
/// Ctrl+K: the search.
Search,
/// Ctrl+Shift+T: the search of the tools.
SearchTools,
/// Ctrl+F.
Find,
/// Ctrl+Alt+G.
Expand Down Expand Up @@ -88,6 +90,7 @@ impl Shortcut {
Self::SelectAll => (Key::A, Modifiers::COMMAND),
Self::Palette => (Key::P, Modifiers::COMMAND | Modifiers::ALT),
Self::Search => (Key::K, Modifiers::COMMAND),
Self::SearchTools => (Key::T, Modifiers::COMMAND | Modifiers::SHIFT),
Self::Find => (Key::F, Modifiers::COMMAND),
Self::GoToLine => (Key::G, Modifiers::COMMAND | Modifiers::ALT),
Self::Format => (Key::F, Modifiers::SHIFT | Modifiers::ALT),
Expand Down
260 changes: 259 additions & 1 deletion e2e/src/sdk/tools.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,275 @@
use super::App;
use egui::accesskit::Node;

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

/// The tools area: its home and the tool that is open.
pub struct Tools<'a>(pub(super) &'a mut App);

/// What a tool is given to answer.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Given {
/// Its *Example*.
Example,
/// Words searched in its table.
Search(&'static str),
}

/// What copying one of a tool's answers gives, each answer by its name.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Copied {
/// What is shown.
Shown(&'static str),
/// What is shown, and by *Raw* what is written here.
Raw(&'static str, &'static str),
/// A text holding what is written here, shown otherwise.
Holding(&'static str, &'static str),
/// Nothing is to be copied.
Nothing,
}

impl Tools<'_> {
/// Goes to the tools and their search, Ctrl+Shift+T.
pub fn go_to_search(&mut self) {
self.0.press(Shortcut::SearchTools);
self.expect_search_ready("the tools' search has the keyboard");
}

/// Searches the tools and their references, over what was searched.
pub fn search(&mut self, words: &str) {
self.0.press(Shortcut::SelectAll);
self.0.type_text(words);
self.0.expect("the search answers", |tree| tree.has("tools-first-result"));
}

/// Opens the first answer of the search, by Enter.
pub fn open_first(&mut self) {
self.0.press(Shortcut::Enter);
self.expect_tool_open("the first answer opens");
}

/// Empties the search, by Esc.
pub fn clear_search(&mut self) {
self.0.press(Shortcut::Escape);
self.0
.expect("the whole catalogue is back", |tree| !tree.has("tools-first-result"));
}

/// Leaves one category on the home, from the rail.
pub fn choose_category(&mut self, name: &str) {
self.click_named("tools-rail-category-", name, "the category in the rail");
}

/// Goes back to every tool, from the rail.
pub fn show_all(&mut self) {
self.0.click("tools-rail-all", "« All tools »");
}

/// Opens a tool from the home, by the name it goes by in the catalogue.
pub fn open(&mut self, tool: &str) {
self.0.click(&format!("tools-entry-{tool}"), "the tool on the home");
self.expect_tool_open("the tool opens");
}

/// Opens a tool from the keyboard: its name searched, walked down to and opened.
pub fn open_from_the_keyboard(&mut self, name: &str) {
self.go_to_search();
self.search(name);
self.expect_listed(name, "the search finds the tool");
for _ in 0..40 {
if self.0.tree().focused_says() == name {
break;
}
self.0.press(Shortcut::Down);
}
self.0.press(Shortcut::Enter);
self.expect_open(name, "the tool opens");
}

/// Stars the tool open, or takes its star off.
pub fn flip_star(&mut self) {
self.0.click("tool-favourite", "the tool's star");
}

/// Gives the tool what it answers.
pub fn give(&mut self, given: Given) {
match given {
Given::Example => self.0.click("tool-sample", "« Example »"),
Given::Search(words) => {
self.0.expect("the table is shown", |tree| tree.has("reference-row"));
let rows = self.0.tree().count("reference-row");
self.0.replace("reference-search", "the table's search", words);
self.0.expect("the search narrows the table", |tree| {
(1..rows).contains(&tree.count("reference-row"))
});
}
}
}

/// The tool answers this, among other things.
pub fn expect_answer(&mut self, words: &str, says: &str) {
self.0.expect(says, |tree| tree.mentions(words));
}

/// An answer is copied as it should.
pub fn expect_copied(&mut self, copied: Copied, says: &str) {
match copied {
Copied::Shown(name) => self.expect_copied_as_shown(name),
Copied::Raw(name, raw) => {
self.expect_copied_as_shown(name);
let named = format!(" {name},");
self.0.click_where("copy-raw", "the answer's « Raw »", |button| {
said(button).contains(&named)
});
self.0.clipboard().expect(raw, says);
}
Copied::Holding(name, words) => {
self.copy(name);
self.0.clipboard().expect_saying(words, says);
}
Copied::Nothing => {}
}
}

/// *Save as note*: the answer filed with a title, in a folder of a space, with a tag.
pub fn save_as_note(&mut self, title: &str, (space, folder): (&str, &str), tag: &str) {
self.0.click("tool-save-as-note", "« Save as note »");
self.0.replace("save-as-note-title", "the note's title", title);
self.choose("save-as-note-space", "the note's space", space);
self.choose("save-as-note-folder", "the note's folder", folder);
self.0.fill("save-as-note-tags", "the note's tags", tag);
self.0.click("save-as-note-submit", "« Save »");
self.0.expect("the note is saved", |tree| !tree.has("save-as-note-title"));
}

/// Fills the tool's text from a note, found in the picker by its title.
pub fn fill_from_note(&mut self, title: &str) {
self.0.click("note-import-text", "« Import from a note »");
self.0.fill("note-picker-search", "the picker's search", title);
self.0
.click_where("note-picker-option", "the note in the picker", |note| said(note) == title);
}

/// Hashes the file answered to the dialog.
pub fn hash_file(&mut self) {
self.0.click("hash-source-1", "« File »");
self.0.click("hash-pick-file", "the button that picks a file");
}

/// Reads the file answered to the dialog into Base64.
pub fn encode_file(&mut self) {
self.0.click("base64-source-1", "« File »");
self.0.click("base64-pick-file", "the button that picks a file");
self.0.expect("the file is read", |tree| tree.has("base64-file"));
}

/// Decodes what the clipboard holds.
pub fn decode_what_was_copied(&mut self) {
let copied = clipboard::held();
self.0.click("base64-direction-1", "« Decode »");
self.0.take_keyboard("base64-input", "the text to decode");
self.0.paste(&copied);
}

/// Saves the bytes decoded as the file answered to the dialog.
pub fn save_decoded(&mut self) {
self.0.click("base64-save-file", "the button that saves the bytes");
}

/// Saves the code drawn as a PNG, in the file answered to the dialog.
pub fn save_code_as_png(&mut self) {
self.0.click("qr-png", "« PNG »");
}

/// Saves the code drawn as an SVG, in the file answered to the dialog.
pub fn save_code_as_svg(&mut self) {
self.0.click("qr-svg", "« Download SVG »");
}

/// Saves the people drawn, in the file answered to the dialog.
pub fn export_people(&mut self) {
self.0.click("identity-export", "« Export… »");
}

/// The tools are on the screen, the keyboard in their search.
pub fn expect_search_ready(&mut self, says: &str) {
self.0
.expect(says, |tree| tree.has("area-tools") && tree.has_focus("tools-search"));
}

/// A tool is listed on the home.
pub fn expect_listed(&mut self, name: &str, says: &str) {
self.0.expect(says, |tree| tree.named("tools-entry-", name).is_some());
}

/// A tool is not listed on the home.
pub fn expect_not_listed(&mut self, name: &str, says: &str) {
self.0
.expect(says, |tree| tree.has("tools-search") && tree.named("tools-entry-", name).is_none());
}

/// The whole catalogue is listed, and it holds as many tools.
pub fn expect_catalogue_of(&mut self, count: usize, says: &str) {
self.0.expect(says, |tree| {
let entries = tree.all_starting("tools-entry-").into_iter();
entries.filter(|id| !id.starts_with("tools-entry-star-")).count() == count
});
}

/// A tool is open.
pub fn expect_tool_open(&mut self, says: &str) {
self.0.expect(says, |tree| tree.has("area-tools") && tree.has("tool-title"));
}

/// The tool of this name is open.
pub fn expect_open(&mut self, name: &str, says: &str) {
self.0.expect(says, |tree| tree.text("tool-title").as_deref() == Some(name));
}

/// A tool is among the favourites on the home.
pub fn expect_favourite(&mut self, name: &str, says: &str) {
self.0.expect(says, |tree| tree.named("tools-favourite-", name).is_some());
}

/// The last tools opened, on the home.
pub fn expect_recent(&mut self, names: &[&str], says: &str) {
self.0
.expect(says, |tree| names.iter().all(|name| tree.named("tools-recent-", name).is_some()));
}

/// The picture decoded is shown, with what it is.
pub fn expect_picture(&mut self, what: &str, says: &str) {
self.0
.expect(says, |tree| tree.text("base64-image-facts").is_some_and(|facts| facts.contains(what)));
}

/// Copies an answer: every line of what is copied is on the screen.
/// Copied again while the clipboard holds another answer than the one shown: one still on
/// its way lands after the first click.
fn expect_copied_as_shown(&mut self, name: &str) {
let answered = |tree: &crate::driver::Tree| {
let held = clipboard::held();
!held.is_empty() && held.lines().all(|line| tree.mentions(line))
};
self.0.click_until("the answer's copy", |app| Tools(app).copy(name), answered);
}

fn copy(&mut self, name: &str) {
let named = format!(" {name}");
self.0
.click_where("copy-value", "the answer's copy", |button| said(button).ends_with(&named));
}

/// Chooses a place in a menu of *Save as note*.
fn choose(&mut self, menu: &str, name: &str, place: &str) {
self.0.click(menu, name);
self.click_named(&format!("{menu}-"), place, "the place in the menu");
}

fn click_named(&mut self, start: &str, label: &str, name: &str) {
let id = self.0.seen(&format!("{name} is on the screen"), |tree| {
tree.named(start, label).and_then(Node::author_id).map(str::to_owned)
});
self.0.click(&id, name);
}
}
Loading
Loading