From 722083107bc757de2061486fcc3cf43a40237432 Mon Sep 17 00:00:00 2001 From: Valentin Millet Date: Fri, 4 Dec 2026 00:05:43 +0100 Subject: [PATCH 1/4] E2E: search, filter, space, folder and board journeys --- e2e/src/driver.rs | 11 + e2e/src/sdk/act.rs | 21 +- e2e/src/sdk/board.rs | 235 ++++++++++++ e2e/src/sdk/filters.rs | 172 +++++++++ e2e/src/sdk/mod.rs | 35 ++ e2e/src/sdk/notes.rs | 143 ++++++-- e2e/src/sdk/rail.rs | 267 ++++++++++++++ e2e/src/sdk/selection.rs | 79 ++++ e2e/src/sdk/shortcut.rs | 6 + e2e/src/sdk/tags.rs | 75 ++++ e2e/tests/02_snippet_to_paste.rs | 6 +- e2e/tests/05_finding.rs | 289 +++++++++++++++ e2e/tests/05_spaces.rs | 144 -------- e2e/tests/06_search_and_filters.rs | 270 -------------- e2e/tests/06_spaces_and_board.rs | 264 ++++++++++++++ e2e/tests/13_making_it_mine.rs | 2 +- e2e/tests/13_multiple_selection.rs | 82 ----- e2e/tests/14_tag_manager.rs | 130 ------- e2e/tests/17_folders.rs | 305 ---------------- e2e/tests/18_board.rs | 280 --------------- e2e/tests/19_board_gesture.rs | 306 ---------------- e2e/tests/20_folder_descent.rs | 184 ---------- e2e/tests/38_recette_notes.rs | 558 ----------------------------- 23 files changed, 1563 insertions(+), 2301 deletions(-) create mode 100644 e2e/src/sdk/board.rs create mode 100644 e2e/src/sdk/filters.rs create mode 100644 e2e/src/sdk/rail.rs create mode 100644 e2e/src/sdk/selection.rs create mode 100644 e2e/src/sdk/tags.rs create mode 100644 e2e/tests/05_finding.rs delete mode 100644 e2e/tests/05_spaces.rs delete mode 100644 e2e/tests/06_search_and_filters.rs create mode 100644 e2e/tests/06_spaces_and_board.rs delete mode 100644 e2e/tests/13_multiple_selection.rs delete mode 100644 e2e/tests/14_tag_manager.rs delete mode 100644 e2e/tests/17_folders.rs delete mode 100644 e2e/tests/18_board.rs delete mode 100644 e2e/tests/19_board_gesture.rs delete mode 100644 e2e/tests/20_folder_descent.rs delete mode 100644 e2e/tests/38_recette_notes.rs diff --git a/e2e/src/driver.rs b/e2e/src/driver.rs index 9219d698..65a779fe 100644 --- a/e2e/src/driver.rs +++ b/e2e/src/driver.rs @@ -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 { self.find(id).map(said) diff --git a/e2e/src/sdk/act.rs b/e2e/src/sdk/act.rs index a52e8058..b6c7b223 100644 --- a/e2e/src/sdk/act.rs +++ b/e2e/src/sdk/act.rs @@ -119,9 +119,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. @@ -199,6 +204,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); diff --git a/e2e/src/sdk/board.rs b/e2e/src/sdk/board.rs new file mode 100644 index 00000000..0d4dc23b --- /dev/null +++ b/e2e/src/sdk/board.rs @@ -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 { + 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 { + 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) +} diff --git a/e2e/src/sdk/filters.rs b/e2e/src/sdk/filters.rs new file mode 100644 index 00000000..d3066948 --- /dev/null +++ b/e2e/src/sdk/filters.rs @@ -0,0 +1,172 @@ +use super::{App, Kind, Shortcut}; +use crate::driver::said; + +/// The header's filters: their menus, and the order of the cards. +pub struct Filters<'a>(pub(super) &'a mut App); + +/// A menu of the filters. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum FilterMenu { + Type, + Priority, + Tags, + Format, +} + +/// What the cards are sorted by. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum SortBy { + Modified, + Priority, + Format, + Title, +} + +/// What the cards are grouped by. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum GroupBy { + Date, + Priority, + Format, + Nothing, +} + +impl Filters<'_> { + /// Shows the band of the filters' menus, or puts it away. + pub fn flip_band(&mut self) { + self.0.click("facets-toggle", "the filters' button"); + } + + /// Opens a menu of the band. + pub fn open(&mut self, menu: FilterMenu) { + let (id, name) = trigger(menu); + self.0.click(id, name); + } + + /// Closes the menu open. + pub fn close_menu(&mut self) { + self.0.press(Shortcut::Escape); + self.0 + .expect("the menu closes", |tree| MENUS.iter().all(|value| !tree.has(value))); + } + + /// Ticks or unticks a kind, in its menu. + pub fn tick_kind(&mut self, kind: Kind) { + self.0.click(kind_chip(kind), "the kind in the menu"); + } + + /// Ticks or unticks the urgent priority, in its menu. + pub fn tick_urgent(&mut self) { + self.0.click("priority-chip-urgent", "« Urgent » in the menu"); + } + + /// Ticks or unticks a tag, in its menu. + pub fn tick_tag(&mut self, tag: &str) { + self.0 + .click_where("tag-pill", "the tag in the menu", |value| said(value).contains(tag)); + } + + /// Ticks or unticks a format, in its menu, by the name it goes by. + pub fn tick_format(&mut self, format: &str) { + self.0 + .click_where("language-chip", "the format in the menu", |value| said(value) == format); + } + + /// *Manage the tags…*, at the foot of their menu. + pub fn manage_tags(&mut self) { + self.0.click("tag-manage", "« Manage the tags… »"); + self.0.expect("the tags are listed", |tree| tree.has("tag-manager-close")); + } + + /// *Clear the filters*, which takes the search with them. + pub fn clear(&mut self) { + self.0.click("clear-filters", "« Clear the filters »"); + } + + /// Sorts the cards. + pub fn sort_by(&mut self, key: SortBy) { + let at = match key { + SortBy::Modified => 0, + SortBy::Priority => 2, + SortBy::Format => 3, + SortBy::Title => 4, + }; + self.order("sort-key", at, "an order of the cards"); + } + + /// Groups the cards. + pub fn group_by(&mut self, grouping: GroupBy) { + let at = match grouping { + GroupBy::Date => 0, + GroupBy::Priority => 1, + GroupBy::Format => 2, + GroupBy::Nothing => 3, + }; + self.order("sort-grouping", at, "a grouping of the cards"); + } + + /// Turns *Pinned first* over. + pub fn flip_pinned_first(&mut self) { + self.order("sort-pinned-first", 0, "« Pinned first »"); + } + + /// The band says how many values are ticked, over all its menus. + pub fn expect_ticked(&mut self, count: usize, says: &str) { + let count = count.to_string(); + self.0 + .expect(says, |tree| tree.text("facets-count").as_deref() == Some(count.as_str())); + } + + /// No value is ticked, and nothing is left to clear. + pub fn expect_none(&mut self, says: &str) { + self.0 + .expect(says, |tree| !tree.has("facets-count") && !tree.has("clear-filters")); + } + + /// A menu says how many of its values are ticked. + pub fn expect_menu_counting(&mut self, menu: FilterMenu, ticked: usize, says: &str) { + let (id, _) = trigger(menu); + let ticked = ticked.to_string(); + self.0 + .expect(says, |tree| tree.text(id).is_some_and(|name| name.contains(&ticked))); + } + + /// The cards are in one list, under no heading of their own. + pub fn expect_one_list(&mut self, says: &str) { + self.0.expect(says, |tree| tree.count("note-section") <= 1); + } + + /// The cards are in at least so many groups. + pub fn expect_several_groups(&mut self, says: &str) { + self.0.expect(says, |tree| tree.count("note-section") > 1); + } + + fn order(&mut self, id: &str, n: usize, name: &str) { + self.0.click("sort-trigger", "the order's menu"); + self.0.click_nth(id, n, name); + self.0.press(Shortcut::Escape); + self.0.expect("the menu closes", |tree| !tree.has("sort-key")); + } +} + +/// A value of each menu: what is on the screen while it is open. +const MENUS: [&str; 5] = ["kind-chip-all", "priority-chip-all", "tag-all", "language-all", "tag-manage"]; + +fn trigger(menu: FilterMenu) -> (&'static str, &'static str) { + match menu { + FilterMenu::Type => ("facet-menu-kind", "the « Type » menu"), + FilterMenu::Priority => ("facet-menu-priority", "the « Priority » menu"), + FilterMenu::Tags => ("facet-menu-tag", "the « Tags » menu"), + FilterMenu::Format => ("facet-menu-language", "the « Format » menu"), + } +} + +fn kind_chip(kind: Kind) -> &'static str { + match kind { + Kind::Note => "kind-chip-note", + Kind::Snippet => "kind-chip-snippet", + Kind::TodoList => "kind-chip-checklist", + Kind::Calculation => "kind-chip-calc", + Kind::Drawing => "kind-chip-drawing", + } +} diff --git a/e2e/src/sdk/mod.rs b/e2e/src/sdk/mod.rs index 28f99cf2..ff32d8df 100644 --- a/e2e/src/sdk/mod.rs +++ b/e2e/src/sdk/mod.rs @@ -3,12 +3,14 @@ mod act; mod attachments; +mod board; mod calc; mod clipboard; mod drawing; mod editor; mod fields; mod files; +mod filters; mod gate; mod help; mod history; @@ -16,14 +18,18 @@ mod http; mod json; mod notes; mod prefs; +mod rail; mod rich; +mod selection; mod shortcut; +mod tags; mod todo; mod tools; mod trash; mod window; pub use attachments::Attachments; +pub use board::{Board, Place}; pub use calc::Calc; pub use clipboard::Clipboard; pub use drawing::{Drawing, Spot, Tool}; @@ -31,6 +37,7 @@ pub use editor::Editor; pub use egui::Key; pub use fields::Fields; pub use files::Files; +pub use filters::{FilterMenu, Filters, GroupBy, SortBy}; pub use gate::Gate; pub use help::Help; pub use history::History; @@ -38,8 +45,11 @@ pub use http::Http; pub use json::{Json, JsonView}; pub use notes::{Kind, Named, Notes, QuickFilter, Sample}; pub use prefs::{CardKey, DefaultKind, Density, Indent, Language, Page, Prefs, Switch, Theme}; +pub use rail::Rail; pub use rich::{DrawingSize, Presentation, Rich, RichTool}; +pub use selection::Selection; pub use shortcut::Shortcut; +pub use tags::Tags; pub use todo::Todo; pub use tools::Tools; pub use trash::Trash; @@ -108,6 +118,31 @@ impl App { Notes(self) } + /// The rail of the notes: its spaces and their folders. + pub fn rail(&mut self) -> Rail<'_> { + Rail(self) + } + + /// The board of the space shown. + pub fn board(&mut self) -> Board<'_> { + Board(self) + } + + /// The header's filters, and the order of the cards. + pub fn filters(&mut self) -> Filters<'_> { + Filters(self) + } + + /// The cards ticked together. + pub fn selection(&mut self) -> Selection<'_> { + Selection(self) + } + + /// The manager of the library's tags. + pub fn tags(&mut self) -> Tags<'_> { + Tags(self) + } + /// The note open. pub fn editor(&mut self) -> Editor<'_> { Editor(self) diff --git a/e2e/src/sdk/notes.rs b/e2e/src/sdk/notes.rs index c6b4fed0..b22e8fed 100644 --- a/e2e/src/sdk/notes.rs +++ b/e2e/src/sdk/notes.rs @@ -1,7 +1,7 @@ use egui::accesskit::{Node, Rect}; -use super::{App, Shortcut}; -use crate::driver::{Tree, is_on, said, within}; +use super::{App, Modifiers, Shortcut}; +use crate::driver::{Tree, said, within}; /// The notes area: its rail, its header and its cards. pub struct Notes<'a>(pub(super) &'a mut App); @@ -78,33 +78,6 @@ impl Notes<'_> { self.0.expect("a new note opens", |tree| tree.has("editor-title")); } - /// A space of its own, from the rail, shown once made: it is empty. - pub fn new_space(&mut self, name: &str) { - self.0.click("space-create-open", "the button of a new space"); - self.0.fill("space-create-input", "the new space's name", name); - self.0.press(Shortcut::Enter); - self.0.expect("the new space is shown, empty", |tree| { - !tree.has("note-card") - && tree.all("space-option").into_iter().any(|row| said(row) == name && is_on(row)) - }); - } - - /// *All spaces*, in the rail. - pub fn show_all_spaces(&mut self) { - self.0.click("space-option-all", "« All spaces »"); - self.0 - .expect("every space is shown", |tree| tree.find("space-option-all").is_some_and(is_on)); - } - - /// Shows one space, from the rail. - pub fn show_space(&mut self, name: &str) { - self.0 - .click_where("space-option", "the space in the rail", |row| said(row) == name); - self.0.expect("the space is shown", |tree| { - tree.all("space-option").into_iter().any(|row| said(row) == name && is_on(row)) - }); - } - /// Duplicates a note, from its card's menu: the copy opens. pub fn duplicate(&mut self, note: impl Named) { self.open_card_menu(note); @@ -120,6 +93,29 @@ impl Notes<'_> { .click_where("note-card-move-place", "the place to move to", |place| said(place) == space); } + /// Files a note into a folder, from its card's menu and the filter of its places. + pub fn file_into(&mut self, note: impl Named, folder: &str) { + self.open_card_menu(note); + self.0.click("note-card-move", "« Move to… »"); + self.0.fill("note-card-move-filter", "the filter of the places", folder); + self.0.press(Shortcut::Enter); + } + + /// A note made from the card that offers one, in the folder open. + pub fn write_from_the_ghost(&mut self, title: &str, code: &str) { + self.0.click("create-ghost", "the card that offers a note"); + self.0.editor().type_title(title); + self.0.editor().type_code(code); + self.0.editor().close(); + self.expect_card(title, "the note is a card"); + } + + /// Leaves the folder open by its breadcrumb. + pub fn leave_folder(&mut self) { + self.0.click("folder-breadcrumb-back", "the breadcrumb's way back"); + self.0.expect("the folder is left", |tree| !tree.has("folder-breadcrumb-name")); + } + /// Opens the menu of a card, by its ⋯. fn open_card_menu(&mut self, note: impl Named) { self.click_on_card(note, "note-card-menu", "the card's « ⋯ »"); @@ -231,6 +227,22 @@ impl Notes<'_> { self.expect_card(title, "the Note is a card"); } + /// Ticks or unticks a card by its box. + pub(super) fn click_box(&mut self, note: impl Named) { + let card = self.card(note); + self.0.move_over(card); + self.0 + .click_where("note-card-check", "the card's box", |node| within(node, card)); + } + + /// Clicks a card, a key held. + pub(super) fn click_holding(&mut self, held: Modifiers, note: impl Named) { + let card = self.card(note); + self.0.hold(held); + self.0.click_card(card); + self.0.hold(Modifiers::NONE); + } + /// Types in the search, over what it holds. pub fn search(&mut self, words: &str) { self.0.replace("search-input", "the search", words); @@ -307,6 +319,72 @@ impl Notes<'_> { .expect(says, |tree| tree.count("note-card") == count && !tree.has("editor-title")); } + /// A card quotes the words the search found, whatever part of the note holds them. + pub fn expect_quoting(&mut self, note: impl Named, words: &str, says: &str) { + self.0.expect(says, |tree| { + let Some(card) = card_of(tree, note) else { + return false; + }; + tree.has("search-matched") && tree.says_within(card, words) + }); + } + + /// The cards, by their titles, top to bottom then left to right. + pub fn expect_order(&mut self, titles: &[&str], says: &str) { + self.0.expect(says, |tree| tree.texts("note-card") == titles); + } + + /// The first card is this note's. + pub fn expect_first(&mut self, note: impl Named, says: &str) { + self.0 + .expect(says, |tree| tree.texts("note-card").first().is_some_and(|title| note.is(title))); + } + + /// As many cards wear a priority. + pub fn expect_urgent(&mut self, count: usize, says: &str) { + self.0.expect(says, |tree| tree.count("priority-bars") == count); + } + + /// A card wears the chip of the folder it is in, its path from the top. + pub fn expect_chip(&mut self, note: impl Named, path: &str, says: &str) { + self.0.expect(says, |tree| { + let Some(card) = card_of(tree, note) else { + return false; + }; + let mut chips = tree.all("note-card-folder").into_iter(); + chips.any(|chip| within(chip, card) && said(chip).ends_with(path)) + }); + } + + /// As many cards wear the chip of a folder. + pub fn expect_chips(&mut self, count: usize, says: &str) { + self.0 + .expect(says, |tree| tree.has("note-card") && tree.count("note-card-folder") == count); + } + + /// The folder open is empty, and offers the card a note is made from. + pub fn expect_ghost(&mut self, says: &str) { + self.0.expect(says, |tree| { + tree.has("create-ghost") && !tree.has("note-card") && !tree.has("canvas-no-results") + }); + } + + /// The search has the keyboard. + pub fn expect_keyboard_in_search(&mut self, says: &str) { + self.0.expect(says, |tree| tree.has_focus("search-input")); + } + + /// The undo bar says what was done, and offers it back. + pub fn expect_undo_offered(&mut self, says: &str) { + self.0 + .expect(says, |tree| tree.text("undo-text").is_some_and(|said| !said.is_empty())); + } + + /// The search is empty. + pub fn expect_search_empty(&mut self, says: &str) { + self.0.expect(says, |tree| !tree.has("search-clear")); + } + /// This card has the keyboard. pub fn expect_keyboard_on(&mut self, note: impl Named, says: &str) { self.0 @@ -399,13 +477,6 @@ impl Notes<'_> { self.0.expect(says, |tree| tree.has("canvas-no-results")); } - /// As many cards are selected, and counted. - pub fn expect_selected(&mut self, count: usize, says: &str) { - let count = count.to_string(); - self.0 - .expect(says, |tree| tree.text("selection-count").is_some_and(|said| said.contains(&count))); - } - /// A toast says what was done; its cross takes it off the screen. pub fn expect_acknowledged(&mut self, says: &str) { self.0.expect(says, |tree| tree.has("status-toast")); diff --git a/e2e/src/sdk/rail.rs b/e2e/src/sdk/rail.rs new file mode 100644 index 00000000..5d341447 --- /dev/null +++ b/e2e/src/sdk/rail.rs @@ -0,0 +1,267 @@ +use egui::accesskit::{Node, Rect}; + +use super::{App, Shortcut}; +use crate::driver::{Tree, is_on, middle, said}; + +/// The rail of the notes: its spaces and their folders. +pub struct Rail<'a>(pub(super) &'a mut App); + +impl Rail<'_> { + /// A space of its own, shown once made: it is empty. + pub fn new_space(&mut self, name: &str) { + self.0.click("space-create-open", "the button of a new space"); + self.0.fill("space-create-input", "the new space's name", name); + self.0.press(Shortcut::Enter); + self.0 + .expect("the new space is shown, empty", |tree| !tree.has("note-card") && is_shown(tree, name)); + } + + /// *All spaces*. + pub fn show_all_spaces(&mut self) { + self.0.click("space-option-all", "« All spaces »"); + self.0.expect("every space is shown", |tree| tree.is_on("space-option-all")); + } + + /// Shows one space. + pub fn show_space(&mut self, name: &str) { + self.0 + .click_where("space-option", "the space in the rail", |row| said(row) == name); + self.0.expect("the space is shown", |tree| is_shown(tree, name)); + } + + /// Renames a space, in its panel. + pub fn rename_space(&mut self, name: &str, into: &str) { + self.open_space_panel(name); + self.0.replace("space-rename-input", "the space's name", into); + self.0.press(Shortcut::Enter); + self.0.expect("the space wears its new name", |tree| { + let names = tree.texts("space-option"); + names.iter().any(|row| row == into) && !names.iter().any(|row| row == name) + }); + } + + /// Pins a space, in its panel, which is then put away. + pub fn pin_space(&mut self, name: &str) { + self.open_space_panel(name); + self.0.click("space-pin", "« Pin »"); + self.close_space_panel(name); + } + + /// Opens the panel of a space, where it would be deleted. + pub fn open_space_panel(&mut self, name: &str) { + self.0 + .click_where("space-edit", "the space's « ⋯ »", |row| said(row).contains(name)); + } + + /// Puts the panel of a space away, by what opened it. + pub fn close_space_panel(&mut self, name: &str) { + self.open_space_panel(name); + self.0.expect("the panel closes", |tree| !tree.has("space-rename-input")); + } + + /// Deletes the space whose panel is open, its notes moved where the panel says. + pub fn delete_space(&mut self) { + self.0.click("space-delete", "« Delete »"); + self.0.click("space-delete", "« Delete », again"); + } + + /// A folder in the space shown. + pub fn new_folder(&mut self, name: &str) { + self.ask_folder(name); + self.0 + .expect("the folder is listed", |tree| tree.texts("folder-option").iter().any(|row| row == name)); + } + + /// Asks for a folder, whatever is answered. + pub fn ask_folder(&mut self, name: &str) { + self.0.click("folder-create-open", "the button of a new folder"); + self.0.fill("folder-create-input", "the new folder's name", name); + self.0.press(Shortcut::Enter); + } + + /// A folder inside another, from its panel. + pub fn new_sub_folder(&mut self, parent: &str, name: &str) { + self.open_folder_panel(parent); + self.0.click("folder-subfolder-open", "« New sub-folder »"); + self.0.fill("folder-subfolder-input", "the sub-folder's name", name); + self.0.press(Shortcut::Enter); + self.expect_inside(name, parent, "the sub-folder is drawn inside its folder"); + } + + /// Renames a folder, in its panel. + pub fn rename_folder(&mut self, name: &str, into: &str) { + self.open_folder_panel(name); + self.0.replace("folder-rename-input", "the folder's name", into); + self.0.press(Shortcut::Enter); + self.0.expect("the folder wears its new name", |tree| { + tree.texts("folder-option").iter().any(|row| row == into) + }); + } + + /// Gives a folder the last colour of its panel. + pub fn recolour_folder(&mut self, name: &str) { + self.open_folder_panel(name); + let last = self + .0 + .seen("the colours are in the panel", |tree| tree.count("folder-colour").checked_sub(1)); + self.0.click_nth("folder-colour", last, "a colour"); + self.0.expect("the colour is the folder's", |tree| { + tree.all("folder-colour").last().is_some_and(|colour| is_on(colour)) + }); + self.open_folder_panel(name); + self.0.expect("the panel closes", |tree| !tree.has("folder-rename-input")); + } + + /// Opens the panel of a folder. + pub fn open_folder_panel(&mut self, name: &str) { + self.0 + .click_where("folder-edit", "the folder's « ⋯ »", |row| said(row).contains(name)); + } + + /// Deletes a folder, its notes handed to its parent. + pub fn delete_folder(&mut self, name: &str) { + self.open_folder_panel(name); + self.delete_folder_open(); + self.expect_no_folder(name, "the folder is gone"); + } + + /// Deletes a folder with the notes it holds. + pub fn delete_folder_with_its_notes(&mut self, name: &str) { + self.open_folder_panel(name); + self.0.click("folder-delete-held", "what becomes of its notes"); + self.0.click("folder-delete-held-1", "« Delete them too »"); + self.delete_folder_open(); + self.expect_no_folder(name, "the folder is gone"); + } + + /// The panel's *Delete*, twice. + fn delete_folder_open(&mut self) { + self.0.click("folder-delete", "« Delete »"); + self.0.click("folder-delete", "« Delete », again"); + } + + /// Opens a folder. + pub fn open_folder(&mut self, name: &str) { + self.0 + .click_where("folder-option", "the folder in the rail", |row| said(row) == name); + self.expect_folder_open(name, "the folder is open"); + } + + /// Drags a folder onto another. + pub fn drag_folder_onto(&mut self, name: &str, onto: &str) { + let (from, to) = (self.folder_row(name), self.folder_row(onto)); + self.0.drag(middle(from), middle(to)); + } + + /// Drags a folder onto a space. + pub fn drag_folder_onto_space(&mut self, name: &str, space: &str) { + let from = self.folder_row(name); + let to = self.0.place("the space in the rail", |tree| row(tree, "space-option", space)); + self.0.drag(middle(from), middle(to)); + } + + /// Takes the keyboard to a folder and moves it out of the one it is in, Alt+←. + pub fn move_folder_out(&mut self, name: &str) { + self.0.tab_to("folder-option", name, "the folder in the rail"); + self.0.press(Shortcut::MoveOut); + } + + /// The one other space than `name`, whatever the machine's language calls it. + pub fn other_space(&mut self, name: &str) -> String { + self.0.seen("another space is listed", |tree| { + tree.texts("space-option").into_iter().find(|space| space != name) + }) + } + + /// The first space of the rail. + pub fn expect_first_space(&mut self, name: &str, says: &str) { + self.0 + .expect(says, |tree| tree.texts("space-option").first().is_some_and(|first| first == name)); + } + + /// This space is the one shown. + pub fn expect_space_shown(&mut self, name: &str, says: &str) { + self.0.expect(says, |tree| is_shown(tree, name)); + } + + /// As many spaces are listed. + pub fn expect_spaces(&mut self, count: usize, says: &str) { + self.0.expect(says, |tree| tree.count("space-option") == count); + } + + /// The space whose panel is open cannot be deleted: it is the last one. + pub fn expect_no_deletion(&mut self, says: &str) { + self.0 + .expect(says, |tree| tree.has("space-delete-blocked") && !tree.has("space-delete")); + } + + /// The panel says where the space's notes would go. + pub fn expect_notes_destination(&mut self, says: &str) { + self.0 + .expect(says, |tree| tree.has("space-delete-consequence") && tree.has("space-delete-held")); + } + + /// A folder is drawn inside another. + pub fn expect_inside(&mut self, name: &str, parent: &str, says: &str) { + self.0.expect(says, |tree| { + let place = |folder| row(tree, "folder-option", folder); + place(name) + .zip(place(parent)) + .is_some_and(|(inner, outer)| inner.x0 > outer.x0 && inner.y0 > outer.y0) + }); + } + + /// Two folders are drawn side by side, neither inside the other. + pub fn expect_beside(&mut self, name: &str, other: &str, says: &str) { + self.0.expect(says, |tree| { + let left = |folder| row(tree, "folder-option", folder).map(|place| place.x0); + left(name).zip(left(other)).is_some_and(|(a, b)| (a - b).abs() < 1.0) + }); + } + + /// No folder goes by this name. + pub fn expect_no_folder(&mut self, name: &str, says: &str) { + self.0.expect(says, |tree| { + tree.has("space-option") && !tree.texts("folder-option").iter().any(|row| row == name) + }); + } + + /// A banner says why the folder was not made; it is then dismissed, and the field put away. + pub fn expect_folder_refused(&mut self, says: &str) { + self.0.expect(says, |tree| tree.has("error-banner")); + self.0.click("error-dismiss", "the banner's cross"); + self.0.press(Shortcut::Escape); + self.0.expect("the banner goes", |tree| !tree.has("error-banner")); + } + + /// As many folders go by this name. + pub fn expect_folders_named(&mut self, name: &str, count: usize, says: &str) { + self.0.expect(says, |tree| { + tree.texts("folder-option").iter().filter(|row| *row == name).count() == count + }); + } + + /// A folder is open, named by the breadcrumb. + pub fn expect_folder_open(&mut self, name: &str, says: &str) { + self.0 + .expect(says, |tree| tree.text("folder-breadcrumb-name").as_deref() == Some(name)); + } + + /// No folder is open. + pub fn expect_no_folder_open(&mut self, says: &str) { + self.0 + .expect(says, |tree| tree.has("area-notes") && !tree.has("folder-breadcrumb-name")); + } + + fn folder_row(&mut self, name: &str) -> Rect { + self.0.place("the folder in the rail", |tree| row(tree, "folder-option", name)) + } +} + +fn row(tree: &Tree, id: &str, name: &str) -> Option { + tree.all(id).into_iter().find(|row| said(row) == name).and_then(Node::bounds) +} + +fn is_shown(tree: &Tree, space: &str) -> bool { + tree.all("space-option").into_iter().any(|row| said(row) == space && is_on(row)) +} diff --git a/e2e/src/sdk/selection.rs b/e2e/src/sdk/selection.rs new file mode 100644 index 00000000..ddfb5d35 --- /dev/null +++ b/e2e/src/sdk/selection.rs @@ -0,0 +1,79 @@ +use super::{App, Modifiers, Shortcut}; + +/// The cards ticked together, and the bar that acts on them. +pub struct Selection<'a>(pub(super) &'a mut App); + +impl Selection<'_> { + /// Ticks or unticks a card by its box. + pub fn tick(&mut self, title: &str) { + self.0.notes().click_box(title); + } + + /// Ticks a card by a click with Ctrl held. + pub fn ctrl_click(&mut self, title: &str) { + self.0.notes().click_holding(Modifiers::COMMAND, title); + } + + /// Ticks the cards from the last one ticked to this one, by a click with Shift held. + pub fn shift_click(&mut self, title: &str) { + self.0.notes().click_holding(Modifiers::SHIFT, title); + } + + /// Moves the notes to a space or a folder, by the end of the place's name. + pub fn move_to(&mut self, place: &str) { + self.0.click("selection-move", "« Move to… »"); + let inside = format!(" › {place}"); + self.0.click_where("selection-move-place", "the place to move to", |entry| { + entry.label().is_some_and(|name| name == place || name.ends_with(&inside)) + }); + } + + /// Takes the notes out of every folder: the first place of the menu. + pub fn take_out_of_folders(&mut self) { + self.0.click("selection-move", "« Move to… »"); + self.0.click("selection-move-place", "« No folder »"); + } + + /// Adds a tag to the notes. + pub fn add_tag(&mut self, tag: &str) { + self.0.fill("selection-tag", "the field of a tag to add", tag); + self.0.press(Shortcut::Enter); + } + + /// Gives the notes the urgent priority, from the menu of what is left. + pub fn make_urgent(&mut self) { + self.0.click("selection-more", "the selection's « ⋯ »"); + self.0.click("selection-more-priority", "« Priority »"); + self.0.click("selection-more-priority-4", "« Urgent »"); + } + + /// Puts the notes on the clipboard as Markdown. + pub fn copy_as_markdown(&mut self) { + self.0.click("selection-more", "the selection's « ⋯ »"); + self.0.click("selection-more-copy", "« Copy as Markdown »"); + } + + /// Sends the notes to the trash: the second click does it. + pub fn delete(&mut self) { + self.0.click("selection-delete", "the selection's « Delete »"); + self.0.click("selection-delete", "« Delete » again"); + } + + /// Lets the cards go, by the bar's cross. + pub fn clear(&mut self) { + self.0.click("selection-clear", "the selection's cross"); + self.expect_none("the selection is let go"); + } + + /// As many cards are ticked, and counted. + pub fn expect(&mut self, count: usize, says: &str) { + let count = count.to_string(); + self.0 + .expect(says, |tree| tree.text("selection-count").is_some_and(|said| said.contains(&count))); + } + + /// No card is ticked. + pub fn expect_none(&mut self, says: &str) { + self.0.expect(says, |tree| !tree.has("selection-count")); + } +} diff --git a/e2e/src/sdk/shortcut.rs b/e2e/src/sdk/shortcut.rs index f30ebd7b..123e27fb 100644 --- a/e2e/src/sdk/shortcut.rs +++ b/e2e/src/sdk/shortcut.rs @@ -34,12 +34,16 @@ pub enum Shortcut { Italic, /// Alt+↑: moves what has the keyboard up. MoveUp, + /// Alt+←: moves what has the keyboard out of what it is in. + MoveOut, /// Del. Delete, /// Ctrl+Z. Undo, /// Ctrl+A. SelectAll, + /// Ctrl+K: the search. + Search, /// Ctrl+F. Find, /// Ctrl+Alt+G. @@ -76,9 +80,11 @@ impl Shortcut { Self::NewDrawing => (Key::D, Modifiers::COMMAND | Modifiers::SHIFT), Self::Italic => (Key::I, Modifiers::COMMAND), Self::MoveUp => (Key::ArrowUp, Modifiers::ALT), + Self::MoveOut => (Key::ArrowLeft, Modifiers::ALT), Self::Delete => (Key::Delete, Modifiers::NONE), Self::Undo => (Key::Z, Modifiers::COMMAND), Self::SelectAll => (Key::A, Modifiers::COMMAND), + Self::Search => (Key::K, Modifiers::COMMAND), Self::Find => (Key::F, Modifiers::COMMAND), Self::GoToLine => (Key::G, Modifiers::COMMAND | Modifiers::ALT), Self::Format => (Key::F, Modifiers::SHIFT | Modifiers::ALT), diff --git a/e2e/src/sdk/tags.rs b/e2e/src/sdk/tags.rs new file mode 100644 index 00000000..2d7e5635 --- /dev/null +++ b/e2e/src/sdk/tags.rs @@ -0,0 +1,75 @@ +use egui::accesskit::Node; + +use super::App; + +/// The manager of the library's tags. +pub struct Tags<'a>(pub(super) &'a mut App); + +impl Tags<'_> { + /// Ticks a tag of the list, its name filled in the field. + pub fn tick(&mut self, tag: &str) { + let row = format!("#{tag}"); + self.0 + .click_where("tag-item", "the tag in the list", |item| item.label() == Some(row.as_str())); + self.0.expect("its name fills the field", |tree| { + tree.find("tag-target").and_then(Node::value) == Some(tag) + }); + } + + /// Types another name over the ticked tag's, and asks for it: what it would touch is said. + pub fn ask_rename(&mut self, name: &str) { + self.0.replace("tag-target", "the tag's new name", name); + self.0.click("tag-apply", "« Rename »"); + self.expect_asked(); + } + + /// Asks to delete the ticked tag: what it would touch is said. + pub fn ask_delete(&mut self) { + self.0.click("tag-delete", "« Delete »"); + self.expect_asked(); + } + + /// Goes through with what was asked. + pub fn confirm(&mut self) { + self.0.click("tag-confirm-apply", "the button that goes through with it"); + self.0.expect("it is done", |tree| !tree.has("tag-confirm-apply")); + } + + /// Gives up what was asked. + pub fn give_up(&mut self) { + self.0.click("tag-confirm-cancel", "« Cancel »"); + self.0 + .expect("nothing is asked any more", |tree| !tree.has("tag-confirm-apply")); + } + + /// Closes the manager. + pub fn close(&mut self) { + self.0.click("tag-manager-close", "the manager's cross"); + self.0.expect("the manager closes", |tree| !tree.has("tag-manager-close")); + } + + /// What was asked says how many notes it would touch. + pub fn expect_touching(&mut self, notes: usize, says: &str) { + let notes = notes.to_string(); + self.0 + .expect(says, |tree| tree.text("tag-confirm-text").is_some_and(|said| said.contains(¬es))); + } + + /// The list holds this tag. + pub fn expect_listed(&mut self, tag: &str, says: &str) { + let row = format!("#{tag}"); + self.0.expect(says, |tree| tree.texts("tag-item").contains(&row)); + } + + /// The list does not hold this tag. + pub fn expect_gone(&mut self, tag: &str, says: &str) { + let row = format!("#{tag}"); + self.0 + .expect(says, |tree| tree.has("tag-manager-close") && !tree.texts("tag-item").contains(&row)); + } + + fn expect_asked(&mut self) { + self.0 + .expect("what it would touch is said", |tree| tree.has("tag-confirm-text")); + } +} diff --git a/e2e/tests/02_snippet_to_paste.rs b/e2e/tests/02_snippet_to_paste.rs index f7f4eb69..eda99942 100644 --- a/e2e/tests/02_snippet_to_paste.rs +++ b/e2e/tests/02_snippet_to_paste.rs @@ -263,8 +263,8 @@ fn from_the_keyboard(app: &mut App) { }); step("duplicated from its card's menu, the copy is sent to another space", || { - app.notes().new_space("Work"); - app.notes().show_all_spaces(); + app.rail().new_space("Work"); + app.rail().show_all_spaces(); app.notes().duplicate(JUMP); app.editor() .expect_code_holding("mosh {{host}}", "the copy is open, with the same code"); @@ -272,7 +272,7 @@ fn from_the_keyboard(app: &mut App) { app.editor().close(); app.notes().expect_card(JUMP, "the first one is still there"); app.notes().move_to_space("Jump from work", "Work"); - app.notes().show_space("Work"); + app.rail().show_space("Work"); app.notes().expect_card("Jump from work", "the copy is in the other space"); app.notes().expect_cards(1, "and it alone"); }); diff --git a/e2e/tests/05_finding.rs b/e2e/tests/05_finding.rs new file mode 100644 index 00000000..4c15c94b --- /dev/null +++ b/e2e/tests/05_finding.rs @@ -0,0 +1,289 @@ +//! Journey 5, « Finding things »: searched, filtered, sorted and grouped, by its tags, and several +//! notes at once. In a space of its own: the samples are in the machine's language. + +use e2e::{App, FilterMenu, GroupBy, Key, Kind, QuickFilter, Shortcut, SortBy, step}; + +const DEPLOY: &str = "Déploiement"; +const LIST: &str = "Before release"; +const QUERY: &str = "Alpha query"; +const PLAN: &str = "Zulu plan"; + +#[test] +fn finding() { + let mut app = App::open("05_finding"); + app.window().widen(); + four_notes(&mut app); + + searching(&mut app); + filtering(&mut app); + sorting(&mut app); + by_its_tags(&mut app); + several_at_once(&mut app); + + app.quit(); +} + +fn four_notes(app: &mut App) { + app.rail().new_space("Work"); + app.press(Shortcut::NewSnippet); + app.editor().type_title(DEPLOY); + app.editor().type_code("kubectl apply -f api.yaml"); + app.editor().type_context("runbooks/zanzibar.md"); + app.editor().add_tag("quokka"); + app.editor().close(); + app.press(Shortcut::NewTodoList); + app.editor().type_title(LIST); + app.todo().add("warn the walrus"); + app.editor().add_tag("quokka"); + app.editor().choose_due_tomorrow(); + app.editor().close(); + app.press(Shortcut::NewSnippet); + app.editor().type_title(QUERY); + app.editor().choose_language("sql"); + app.editor().type_code("select 1"); + app.editor().add_tag("narwhal"); + app.editor().close(); + app.notes().write_note(PLAN, "one thing after another"); + app.notes().go_to_card(PLAN); + app.press(Shortcut::CardKey(Key::P)); + app.notes().go_to_card(QUERY); + app.press(Shortcut::CardKey(Key::Num4)); + // Esc would take it back while the bar offers to. + app.notes().dismiss_undo(); + app.notes().clear_search(); + app.notes().expect_cards(4, "the four notes are cards"); +} + +fn searching(app: &mut App) { + step("Ctrl+K goes to the search, which reads words without their accents", || { + app.press(Shortcut::Search); + app.notes().expect_keyboard_in_search("the search has the keyboard"); + app.type_text("deploiement"); + app.notes().expect_cards(1, "one note answers"); + app.notes().expect_card(DEPLOY, "it is the one with the accents"); + }); + + step("a word of a list, of a context and of a tag is found, and quoted on the card", || { + for (word, note, quoted) in [ + ("walrus", LIST, "warn the walrus"), + ("zanzibar", DEPLOY, "zanzibar"), + ("quokk", DEPLOY, "quokka"), + ] { + app.notes().search(word); + app.notes().expect_quoting(note, quoted, "the card quotes the words found"); + } + }); + + step("nothing found says so", || { + app.notes().search("zz nothing is called this"); + app.notes().expect_nothing_found("the cards give way to a sentence"); + app.notes().clear_search(); + app.notes().expect_cards(4, "every note is back"); + }); +} + +fn filtering(app: &mut App) { + step("« All », « Pinned » and « Untriaged » keep what they say", || { + app.notes().filter(QuickFilter::Pinned); + app.notes().expect_order(&[PLAN], "the pinned note is alone"); + app.notes().filter(QuickFilter::Untriaged); + app.notes().expect_order(&[LIST], "the note with a due date is alone"); + app.notes().filter(QuickFilter::All); + app.notes().expect_cards(4, "every note is back"); + }); + + step("several values of one menu add up, and it says how many are ticked", || { + app.filters().flip_band(); + app.filters().open(FilterMenu::Type); + app.filters().tick_kind(Kind::Note); + app.notes().expect_cards(1, "the Note is alone"); + app.filters().tick_kind(Kind::TodoList); + app.notes().expect_cards(2, "the list joins it"); + app.filters().expect_menu_counting(FilterMenu::Type, 2, "the menu says two"); + app.capture("filters"); + app.filters().close_menu(); + app.filters().expect_ticked(2, "the band says two"); + app.filters().clear(); + app.notes().expect_cards(4, "every note is back"); + }); + + step("the other menus narrow too", || { + app.filters().open(FilterMenu::Priority); + app.filters().tick_urgent(); + app.notes().expect_order(&[QUERY], "the urgent note is alone"); + app.filters().close_menu(); + app.filters().clear(); + app.filters().open(FilterMenu::Tags); + app.filters().tick_tag("quokka"); + app.notes().expect_cards(2, "the two notes with the tag are left"); + app.filters().close_menu(); + app.filters().open(FilterMenu::Format); + app.filters().tick_format("SQL"); + app.notes().expect_nothing_found("none of the two is in that format"); + app.filters().close_menu(); + }); + + step("« Clear the filters » removes them with the search", || { + app.notes().search("alpha"); + app.filters().clear(); + app.notes().expect_search_empty("the search is empty"); + app.filters().expect_none("no value is ticked"); + app.notes().expect_cards(4, "every note is back"); + app.filters().flip_band(); + }); +} + +fn sorting(app: &mut App) { + step("sorted by title in one list, the pinned one first, or not", || { + app.filters().group_by(GroupBy::Nothing); + app.filters().sort_by(SortBy::Title); + app.notes() + .expect_order(&[PLAN, QUERY, LIST, DEPLOY], "the pinned one comes first"); + app.filters().expect_one_list("the cards are in one list"); + app.filters().flip_pinned_first(); + app.notes() + .expect_order(&[QUERY, LIST, DEPLOY, PLAN], "the titles alone decide"); + }); + + step("sorted by date, by priority and by format", || { + app.filters().sort_by(SortBy::Priority); + app.notes().expect_first(QUERY, "the urgent one comes first"); + app.filters().sort_by(SortBy::Format); + app.notes().expect_first(QUERY, "the snippets come first"); + app.filters().sort_by(SortBy::Modified); + app.notes().expect_first(PLAN, "the last one written comes first"); + }); + + step("grouped by date, priority and format", || { + for grouping in [GroupBy::Date, GroupBy::Priority, GroupBy::Format] { + app.filters().group_by(grouping); + app.filters().expect_several_groups("the cards are under headings"); + } + }); + + step("the choice comes back after a relaunch", || { + app.filters().group_by(GroupBy::Nothing); + app.filters().sort_by(SortBy::Title); + app.relaunch_and_unlock(); + app.notes() + .expect_order(&[QUERY, LIST, DEPLOY, PLAN], "the order is the one chosen"); + app.filters().expect_one_list("the cards are in one list"); + }); +} + +fn by_its_tags(app: &mut App) { + step("a tag is renamed on all its notes, once it has said which", || { + app.filters().flip_band(); + app.filters().open(FilterMenu::Tags); + app.filters().manage_tags(); + app.tags().tick("quokka"); + app.tags().ask_rename("wombat"); + app.tags().expect_touching(2, "two notes wear it"); + app.capture("tags"); + app.tags().give_up(); + app.tags().expect_listed("quokka", "given up, the tag is as it was"); + app.tags().ask_rename("wombat"); + app.tags().confirm(); + app.tags().expect_listed("wombat", "the tag has its new name"); + app.tags().expect_gone("quokka", "the former one is gone"); + }); + + step("it is corrected in case alone", || { + app.tags().tick("wombat"); + app.tags().ask_rename("Wombat"); + app.tags().confirm(); + app.tags().expect_listed("Wombat", "the tag is spelt as it was typed"); + }); + + step("onto an existing tag, it merges", || { + app.tags().tick("narwhal"); + app.tags().ask_rename("Wombat"); + app.tags().confirm(); + app.tags().expect_gone("narwhal", "one tag is left of the two"); + }); + + step("deleted, it leaves its notes", || { + app.tags().tick("Wombat"); + app.tags().ask_delete(); + app.tags().expect_touching(3, "three notes wear it"); + app.tags().confirm(); + app.tags().expect_gone("Wombat", "the tag is gone"); + app.tags().close(); + app.filters().flip_band(); + app.notes().expect_cards(4, "every note stays"); + }); +} + +fn several_at_once(app: &mut App) { + step("notes are ticked with X, a Ctrl-click and a Shift-click", || { + app.notes().go_to_first_card(); + app.press(Shortcut::CardKey(Key::X)); + app.selection().expect(1, "one note is ticked"); + app.selection().ctrl_click(DEPLOY); + app.selection().expect(2, "two are"); + app.selection().clear(); + app.notes().go_to_first_card(); + app.selection().shift_click(DEPLOY); + app.selection().expect(3, "the three from the one with the keyboard are"); + app.capture("selection"); + app.selection().clear(); + }); + + step("moved to another space, they are taken back", || { + app.rail().new_space("Archive"); + app.rail().show_space("Work"); + app.selection().tick(QUERY); + app.selection().tick(LIST); + app.selection().move_to("Archive"); + app.notes().expect_undo_offered("the bar says what was done"); + app.notes().expect_cards(2, "two are left here"); + app.notes().undo(); + app.notes().expect_cards(4, "both are back"); + app.selection().clear(); + }); + + step("given a priority, then a tag, they are taken back too", || { + tick_two(app); + app.selection().make_urgent(); + app.notes().expect_undo_offered("the bar says what was done"); + app.notes().expect_urgent(3, "two cards more wear the priority"); + app.notes().undo(); + app.notes().expect_urgent(1, "one does, as before"); + app.selection().clear(); + tick_two(app); + app.selection().add_tag("batch"); + app.notes().expect_undo_offered("the bar says what was done"); + app.notes().dismiss_undo(); + app.selection().clear(); + app.notes().search("batch"); + app.notes().expect_cards(2, "the two notes wear the tag, and they alone"); + app.notes().clear_search(); + }); + + step("sent to the trash, they are given back whole", || { + tick_two(app); + app.selection().delete(); + app.notes().expect_cards(2, "two are left"); + app.notes().undo(); + app.notes().expect_cards(4, "both are back"); + }); + + step("Esc steps back from the selection, then the filter", || { + app.filters().flip_band(); + app.filters().open(FilterMenu::Type); + app.filters().tick_kind(Kind::Note); + app.filters().close_menu(); + app.selection().tick(PLAN); + app.press(Shortcut::Escape); + app.selection().expect_none("the selection is let go"); + app.notes().expect_order(&[PLAN], "the filter is still there"); + app.press(Shortcut::Escape); + app.notes().expect_cards(4, "the filter is gone too"); + }); +} + +fn tick_two(app: &mut App) { + app.selection().tick(LIST); + app.selection().tick(DEPLOY); + app.selection().expect(2, "two notes are ticked"); +} diff --git a/e2e/tests/05_spaces.rs b/e2e/tests/05_spaces.rs deleted file mode 100644 index 57653c6e..00000000 --- a/e2e/tests/05_spaces.rs +++ /dev/null @@ -1,144 +0,0 @@ -//! Spaces from the library rail: made, renamed, pinned, chosen, remembered, and deleted with -//! their notes moved out first, or put in the trash. Only a real database proves the cascade -//! never fires. -//! -//! Nothing compares a seeded word: the samples are in the system's language. The space made -//! here is named by the scenario, and found by that name. - -use e2e::old::{App, step}; -use egui::accesskit::{Node, Toggled}; -use egui::{Key, Modifiers}; - -const CARDS: usize = 6; -const DOOMED: &str = "Brouillon à jeter"; - -fn named(name: &str) -> impl Fn(&Node) -> bool + '_ { - move |node| node.label() == Some(name) -} - -/// A row's ⋯, by the name its label carries in any language. -fn options_of(name: &str) -> impl Fn(&Node) -> bool + '_ { - move |node| node.label().is_some_and(|label| label.contains(name)) -} - -fn is_shown(tree: &e2e::old::Tree, name: &str) -> bool { - tree.all("space-option") - .into_iter() - .any(|node| node.label() == Some(name) && node.toggled() == Some(Toggled::True)) -} - -fn deleted_with_its_notes(app: &mut App) { - step("a space deleted with its notes puts them in the trash", || { - app.click("space-create-open"); - app.fill("space-create-input", "Brouillons"); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the new space is shown", |tree| { - is_shown(tree, "Brouillons") && tree.count("note-card") == 0 - }); - app.click("new-note"); - app.fill("editor-title", DOOMED); - app.fill("editor-body", "à jeter"); - app.click("editor-close"); - app.eventually("its note is a card", |tree| tree.count("note-card") == 1); - app.click_where("space-edit", options_of("Brouillons")); - app.click("space-delete-held"); - app.click("space-delete-held-1"); - app.click("space-delete"); - app.click("space-delete"); - app.eventually("the space is gone, its note not in the refuge", |tree| { - tree.count("space-option") == 1 && tree.count("note-card") == CARDS - }); - app.click("trash-open"); - app.eventually("the note waits in the trash", |tree| { - tree.texts("trash-row-title").contains(&DOOMED.to_owned()) - }); - app.press(Key::Escape, Modifiers::NONE); - }); -} - -#[test] -fn spaces() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("05_spaces", profile.path()); - app.create_library(); - - step("a new library has one space, and it cannot be deleted", || { - app.eventually("the samples are drawn", |tree| tree.count("note-card") == CARDS); - assert_eq!(app.tree().count("space-option"), 1); - app.click("space-edit"); - app.wait_for("space-delete-blocked"); - assert!(!app.has("space-delete")); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the panel is closed", |tree| !tree.has("space-delete-blocked")); - }); - - step("a space made from the rail is the one shown", || { - app.click("space-create-open"); - app.fill("space-create-input", "Veille"); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the new space is listed and shown", |tree| { - is_shown(tree, "Veille") && tree.count("note-card") == 0 - }); - app.capture("rail-new-space"); - }); - - step("a space renamed in its panel", || { - app.click_where("space-edit", options_of("Veille")); - app.wait_for("space-rename-input"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text("Lectures"); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the space comes back under its new name", |tree| { - let names = tree.texts("space-option"); - names.contains(&"Lectures".to_owned()) && !names.contains(&"Veille".to_owned()) - }); - }); - - step("pinned, it heads the list whatever its name, and falls back", || { - app.click_where("space-edit", options_of("Lectures")); - app.click("space-pin"); - app.eventually("the pinned space is first", |tree| { - tree.texts("space-option").first().map(String::as_str) == Some("Lectures") - }); - app.click("space-pin"); - app.eventually("the unpinned space is back in its name's order", |tree| { - let names = tree.texts("space-option"); - names.len() == 2 && names.contains(&"Lectures".to_owned()) - }); - app.click_where("space-edit", options_of("Lectures")); - app.eventually("the panel is closed", |tree| !tree.has("space-pin")); - }); - - step("« all spaces » shows every note, a space its own", || { - app.click("space-option-all"); - app.eventually("every card is back", |tree| tree.count("note-card") == CARDS); - app.click_where("space-option", named("Lectures")); - app.eventually("the canvas narrowed to the space", |tree| tree.count("note-card") == 0); - }); - - let mut app = app.relaunch(); - - step("a relaunch opens on the space it was left on", || { - app.fill("vault-passphrase", e2e::old::PASSPHRASE); - app.click("vault-submit"); - app.wait_for("area-notes"); - app.eventually("the space chosen before is shown", |tree| { - is_shown(tree, "Lectures") && tree.count("note-card") == 0 - }); - }); - - step("deleting a space says where its notes go, then moves them", || { - app.click_where("space-edit", options_of("Lectures")); - app.wait_for("space-delete-consequence"); - app.capture("rail-space-panel"); - app.click("space-delete"); - app.click("space-delete"); - app.eventually("the space is gone, its refuge shown", |tree| { - tree.count("space-option") == 1 && tree.count("note-card") == CARDS - }); - }); - - deleted_with_its_notes(&mut app); - - app.quit(); -} diff --git a/e2e/tests/06_search_and_filters.rs b/e2e/tests/06_search_and_filters.rs deleted file mode 100644 index d9626d1a..00000000 --- a/e2e/tests/06_search_and_filters.rs +++ /dev/null @@ -1,270 +0,0 @@ -//! The search, the quick filter and the order, over the first launch's samples. Filtering, -//! grouping and folding run in Rust; what is proved here is the query the window sends. -//! -//! Nothing compares a seeded word: the samples are in the system's language. What is searched -//! is in their code, which no translation touches. - -use e2e::old::{App, step}; -use egui::{Key, Modifiers}; - -const CARDS: usize = 6; -/// Groupings in the menu's order: date, priority, format, none. -const NO_GROUPING: usize = 3; -/// Quick filters in the switch's order. -const ALL: &str = "quick-filter-0"; -const PINNED: &str = "quick-filter-1"; -const UNTRIAGED: &str = "quick-filter-2"; - -/// The header's controls, left to right as they are drawn. -const HEADER: [&str; 13] = [ - "library-rail-toggle", - "trash-open", - "space-switcher", - "view-list", - "folder-switcher", - "search-input", - "quick-filter-0", - "quick-filter-2", - "sort-trigger", - "facets-toggle", - "new-note", - "new-note-kind", - "area-notes", -]; - -/// How many rows the header's controls sit on, each one's row, and whether any runs past the -/// notes area. Rows are told apart by their middles, as the controls differ in height. -struct Layout { - rows: usize, - row_of: Vec<(&'static str, usize)>, - overflowing: bool, -} - -fn layout(tree: &e2e::old::Tree) -> Layout { - let area = tree.find("area-notes").and_then(egui::accesskit::Node::bounds); - let boxes: Vec<(&'static str, egui::accesskit::Rect)> = HEADER[..HEADER.len() - 1] - .iter() - .filter_map(|id| Some((*id, tree.find(id)?.bounds()?))) - .collect(); - let mut middles: Vec = boxes.iter().map(|(_, b)| f64::midpoint(b.y0, b.y1)).collect(); - middles.sort_by(f64::total_cmp); - let starts: Vec = middles - .iter() - .enumerate() - .filter(|(at, middle)| *at == 0 || **middle - middles[at - 1] > 12.0) - .map(|(_, middle)| *middle) - .collect(); - let row_of = boxes - .iter() - .map(|(id, b)| { - let middle = f64::midpoint(b.y0, b.y1); - (*id, starts.iter().filter(|start| **start <= middle + 12.0).count()) - }) - .collect(); - let overflowing = - area.is_none_or(|area| boxes.iter().any(|(_, b)| b.x0 < area.x0 - 1.0 || b.x1 > area.x1 + 1.0)); - Layout { rows: starts.len(), row_of, overflowing } -} - -fn row(layout: &Layout, id: &str) -> usize { - layout.row_of.iter().find(|(each, _)| *each == id).map_or(0, |(_, row)| *row) -} - -fn search(app: &mut App, words: &str) { - app.click("search-input"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(words); -} - -#[test] -fn search_and_filters() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("06_search_and_filters", profile.path()); - app.create_library(); - app.eventually("the samples are drawn", |tree| tree.count("note-card") == CARDS); - - step("a search finds a note by its body, past the debounce", || { - search(&mut app, "withRetry"); - app.eventually("one card, and its count", |tree| { - tree.count("note-card") == 1 && tree.has("search-matched") - }); - }); - - step("down from the field to the card it found", || { - app.press(Key::ArrowDown, Modifiers::NONE); - app.eventually("the card has the focus", |tree| tree.focused().starts_with("note-card-open")); - }); - - step("it folds case the way Rust does", || { - search(&mut app, "WITHRETRY"); - app.eventually("the same card", |tree| tree.count("note-card") == 1); - }); - - step("nothing found says so, and still counts", || { - search(&mut app, "nothing matches this"); - app.eventually("the canvas says nothing matches", |tree| { - tree.has("canvas-no-results") && tree.text("search-matched").is_some_and(|said| !said.is_empty()) - }); - app.capture("search-nothing"); - }); - - step("the cross empties the field, and the count goes", || { - app.click("search-clear"); - app.eventually("every card is back", |tree| { - tree.count("note-card") == CARDS && !tree.has("search-matched") - }); - }); - - step("the quick filter keeps one pinned note, then one with a deadline", || { - app.click(PINNED); - app.eventually("the pinned welcome", |tree| tree.count("note-card") == 1); - app.click(UNTRIAGED); - app.eventually("the list with a deadline", |tree| tree.count("note-card") == 1); - app.click(ALL); - app.eventually("every card is back", |tree| tree.count("note-card") == CARDS); - }); - - step("Ctrl+K puts the caret in the search", || { - app.press(Key::K, Modifiers::COMMAND); - app.eventually("the search has the focus", |tree| tree.focused().starts_with("search-input")); - }); - - step("no grouping lays the cards out as one list", || { - app.click("sort-trigger"); - app.click_nth("sort-grouping", NO_GROUPING); - app.eventually("the date sections are gone", |tree| { - tree.count("note-section") <= 1 && tree.count("note-card") == CARDS - }); - app.capture("sort-no-grouping"); - app.press(Key::Escape, Modifiers::NONE); - }); - - rails_and_header(&mut app); - - let mut app = app.relaunch(); - - step("the arrangement is the library's, found again", || { - app.fill("vault-passphrase", e2e::old::PASSPHRASE); - app.click("vault-submit"); - app.wait_for("area-notes"); - app.eventually("still one list", |tree| { - tree.count("note-card") == CARDS && tree.count("note-section") <= 1 - }); - }); - - step("the board waits for its own phase", || { - assert!(app.tree().find("view-board").is_some_and(egui::accesskit::Node::is_disabled)); - }); - - read_text(&mut app); - app.quit(); -} - -fn read_text(app: &mut App) { - step("a Note is found by the words it shows, across its bold", || { - app.click("new-note-kind"); - app.click("new-note-note"); - app.click("editor-rich"); - app.type_text("ask about the "); - app.click("rich-bold"); - app.type_text("rollout"); - app.click("rich-bold"); - app.type_text(" window"); - app.click("editor-close"); - app.eventually("the editor is closed", |tree| !tree.has("editor-title")); - search(app, "rollout window"); - app.eventually("the Note alone", |tree| tree.count("note-card") == 1 && tree.has("search-matched")); - }); -} - -/// The filters' menus and their way out, side by side. -fn band_on_one_line(tree: &e2e::old::Tree) -> bool { - let middles: Vec = ["facet-menu-kind", "facet-menu-tag", "clear-filters"] - .iter() - .filter_map(|id| tree.find(id)?.bounds()) - .map(|b| f64::midpoint(b.y0, b.y1)) - .collect(); - middles.len() == 3 && middles.windows(2).all(|pair| (pair[0] - pair[1]).abs() < 2.0) -} - -/// The filters' menus over the samples, then the header at three widths. -fn rails_and_header(app: &mut App) { - step("a kind from its menu narrows the cards, and « All » gives them back", || { - app.click("facets-toggle"); - app.click("facet-menu-kind"); - app.click("kind-chip-note"); - app.eventually("the Notes alone, and the toggle counts one value", |tree| { - let cards = tree.count("note-card"); - cards > 0 && cards < CARDS && tree.text("facets-count").as_deref() == Some("1") - }); - assert!( - app.tree().find("facets-toggle").is_some_and(egui::accesskit::Node::is_disabled), - "it refuses to fold while a value is ticked" - ); - assert!(app.tree().has("kind-chip-all"), "the menu stays open"); - app.capture("facets-kind"); - app.click("kind-chip-all"); - app.eventually("every card is back", |tree| tree.count("note-card") == CARDS); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the menu closed", |tree| !tree.has("kind-chip-all")); - }); - - step("a tag and a format narrow too, and one click clears them", || { - app.click("facet-menu-tag"); - app.click("tag-pill"); - app.eventually("fewer cards", |tree| tree.count("note-card") < CARDS); - app.click("facet-menu-language"); - app.click_nth("language-chip", 0); - app.eventually("two values ticked", |tree| tree.text("facets-count").as_deref() == Some("2")); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the band on one line", band_on_one_line); - app.click("clear-filters"); - app.eventually("every card is back, and the way out goes", |tree| { - tree.count("note-card") == CARDS && !tree.has("clear-filters") && !tree.has("facets-count") - }); - }); - - step("Escape closes the menu, then lets the value go", || { - app.click("facet-menu-kind"); - app.click("kind-chip-note"); - app.eventually("fewer cards", |tree| tree.count("note-card") < CARDS); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the menu closed, the value still ticked", |tree| { - !tree.has("kind-chip-all") && tree.count("note-card") < CARDS - }); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("every card is back", |tree| tree.count("note-card") == CARDS); - app.click("facets-toggle"); - app.eventually("the band folds", |tree| !tree.has("facet-menu-kind")); - }); - - step("the header holds one row at 1,100 with the rail open", || { - app.resize(1_100, 720); - let shown = layout(&app.tree()); - assert!(!shown.overflowing); - assert_eq!(shown.rows, 1); - }); - - step("the rail put away, one row at 1,330, two at 640", || { - app.click("library-rail-toggle"); - app.wait_for("space-switcher"); - app.resize(1_330, 720); - app.eventually("one row, inside the window", |tree| { - let shown = layout(tree); - shown.rows == 1 && !shown.overflowing - }); - app.resize(1_100, 720); - app.eventually("nothing overflows", |tree| !layout(tree).overflowing); - app.resize(640, 720); - app.eventually("two rows, « New note » ending the first", |tree| { - let shown = layout(tree); - shown.rows == 2 - && !shown.overflowing - && row(&shown, "new-note") == row(&shown, "library-rail-toggle") - && row(&shown, "search-input") == 2 - }); - app.capture("header-two-rows"); - app.resize(1_100, 720); - app.click("library-rail-toggle"); - }); -} diff --git a/e2e/tests/06_spaces_and_board.rs b/e2e/tests/06_spaces_and_board.rs new file mode 100644 index 00000000..2c7645cc --- /dev/null +++ b/e2e/tests/06_spaces_and_board.rs @@ -0,0 +1,264 @@ +//! Journey 6, « Spaces, folders and the board »: a space made and chosen, its folders filed into, +//! dragged and deleted, its board arranged by hand, a folder opened. + +use e2e::{App, Sample, Shortcut, step}; + +const SPACE: &str = "Workshop"; +const QUERY: &str = "Slow query"; +const DUMP: &str = "Nightly export"; +const INDEX: &str = "Partial index"; +const CACHE: &str = "Cache ratio"; +const SAMPLES: usize = 6; + +#[test] +fn spaces_and_board() { + let mut app = App::open("06_spaces_and_board"); + app.window().widen(); + + spaces(&mut app); + folders(&mut app); + folders_moved(&mut app); + the_board(&mut app); + a_folder_opened(&mut app); + a_space_deleted(&mut app); + + app.quit(); +} + +fn spaces(app: &mut App) { + step("the last space cannot be deleted", || { + let only = app.rail().other_space(""); + app.rail().open_space_panel(&only); + app.rail().expect_no_deletion("the panel says why"); + app.rail().close_space_panel(&only); + }); + + step("a space is made, renamed, and pinned above the others", || { + app.rail().new_space("Zebra"); + app.rail().rename_space("Zebra", SPACE); + app.rail().pin_space(SPACE); + app.rail().expect_first_space(SPACE, "the pinned one heads the list"); + }); + + step("« All spaces » shows every note, a space its own", || { + app.rail().show_all_spaces(); + app.notes().expect_cards(SAMPLES, "every note is listed"); + app.rail().show_space(SPACE); + app.notes().write_snippet(QUERY, "SELECT 1;"); + app.notes().write_snippet(DUMP, "pg_dump prod"); + app.notes().expect_cards(2, "the space has its own two"); + }); + + step("the one chosen is remembered", || { + app.relaunch_and_unlock(); + app.rail().expect_space_shown(SPACE, "the space left is shown"); + app.notes().expect_cards(2, "its two notes are listed"); + }); +} + +fn folders(app: &mut App) { + step("a folder is made, and a second one of the same name refused", || { + app.rail().new_folder("Bases"); + app.rail().ask_folder("Bases"); + app.rail().expect_folder_refused("a banner says it is taken"); + app.rail().expect_folders_named("Bases", 1, "one folder has the name"); + }); + + step("a sub-folder is made, renamed, and given a colour", || { + app.rail().new_sub_folder("Bases", "Indices"); + app.rail().rename_folder("Indices", "Indexes"); + app.rail().recolour_folder("Indexes"); + app.rail().new_folder("Reports"); + }); + + step("a selection is filed into it, and taken back out", || { + app.selection().tick(QUERY); + app.selection().tick(DUMP); + app.selection().move_to("Indexes"); + app.notes().expect_chip(QUERY, "Bases › Indexes", "the card says its folder"); + app.notes().expect_chips(2, "both cards wear the chip"); + app.notes().dismiss_undo(); + app.selection().take_out_of_folders(); + app.notes().expect_chips(0, "no card wears a chip any more"); + app.notes().dismiss_undo(); + app.selection().clear(); + }); + + step("a note filed from its card wears the folder's chip", || { + app.notes().file_into(QUERY, "reports"); + app.notes().expect_chip(QUERY, "Reports", "the card says its folder"); + app.notes().dismiss_undo(); + }); + + step("deleting a folder leaves its notes in its parent", || { + app.notes().file_into(DUMP, "indexes"); + app.notes() + .expect_chip(DUMP, "Bases › Indexes", "the note is in the sub-folder"); + app.notes().dismiss_undo(); + app.rail().delete_folder("Indexes"); + app.notes().expect_chip(DUMP, "Bases", "the note is in the folder that held it"); + app.notes().expect_cards(2, "both notes stay"); + }); +} + +fn folders_moved(app: &mut App) { + step("a folder dragged onto another goes inside it, and Alt+← takes it out", || { + app.rail().drag_folder_onto("Reports", "Bases"); + app.rail().expect_inside("Reports", "Bases", "it is drawn inside"); + app.capture("rail"); + app.notes().dismiss_undo(); + app.rail().move_folder_out("Reports"); + app.rail().expect_beside("Reports", "Bases", "it is beside it again"); + app.rail().show_space(SPACE); + }); + + step("dragged onto another space, it goes there with its notes, and comes back", || { + let samples = app.rail().other_space(SPACE); + app.rail().drag_folder_onto_space("Reports", &samples); + app.notes().expect_undo_offered("the bar says where it went"); + app.rail().show_space(&samples); + app.notes().expect_card(QUERY, "its note came with it"); + app.notes().undo(); + app.rail().show_space(SPACE); + app.notes().expect_card(QUERY, "its note is back"); + }); + + step("deleted with its notes, they wait in the trash", || { + app.rail().new_folder("Drafts"); + app.rail().open_folder("Drafts"); + app.notes().write_snippet("To throw", "echo throw"); + app.rail().delete_folder_with_its_notes("Drafts"); + app.trash().open(); + app.trash().expect(&["To throw"], "the note is in the trash"); + app.trash().empty(); + app.trash().close(); + }); +} + +fn the_board(app: &mut App) { + step("on the board, the folders are zones holding their notes", || { + app.rail().show_space(SPACE); + app.board().show(); + app.board().expect_zones(&["Bases", "Reports"], "each folder is a zone"); + app.board().expect_in_zone("Bases", &[DUMP], "its note is in it"); + app.board().expect_in_zone("Reports", &[QUERY], "its note is in it"); + app.capture("board"); + }); + + step("a card is dragged out of its zone, into another, and onto a folder of the rail", || { + app.board().drag_card_out(DUMP); + app.board().expect_loose(&[DUMP], "it stands loose on the ground"); + app.board().drag_card_into(DUMP, "Reports"); + app.board().expect_in_zone("Bases", &[], "its first zone is empty"); + app.board().expect_holding("Reports", DUMP, "the other one holds it"); + app.board().drag_card_out(DUMP); + app.board().expect_loose(&[DUMP], "it is loose again"); + app.board().drag_card_onto_folder(DUMP, "Bases"); + app.board().expect_in_zone("Bases", &[DUMP], "it is filed again"); + }); + + step("« File into » is the keyboard's twin", || { + app.selection().tick(DUMP); + app.selection().move_to("Reports"); + app.board().expect_holding("Reports", DUMP, "the note is in the other zone"); + app.notes().undo(); + app.board().expect_in_zone("Bases", &[DUMP], "and back"); + app.selection().clear(); + }); + + step("a zone's cards are ticked together", || { + app.board().tick_zone("Bases"); + app.selection().expect(1, "its card is ticked"); + app.selection().clear(); + }); + + step("a zone is moved, then widened, and keeps its notes", || { + let before = app.board().place_of("Bases"); + app.board().move_zone("Bases"); + app.board() + .expect_moved("Bases", before, "the zone is elsewhere, of the same size"); + let moved = app.board().place_of("Bases"); + app.board().widen_zone("Bases"); + app.board().expect_wider("Bases", moved, "the zone is wider, where it was"); + app.board().expect_in_zone("Bases", &[DUMP], "its note is in it"); + }); + + step("a folder is drawn on the ground", || { + app.board().draw_folder("Sketches"); + app.board() + .expect_zones(&["Bases", "Reports", "Sketches"], "it is a zone of the board"); + }); + + step("« Align » and the other arrangements are taken back", || { + app.board().align(); + let aligned = app.board().place_of("Bases"); + app.board().reorganise(); + app.board() + .expect_moved_anywhere("Bases", aligned, "everything is put back in order"); + app.notes().expect_undo_offered("the bar offers it back"); + app.notes().undo(); + app.board().expect_place("Bases", aligned, "the hand's own is back"); + }); + + step("a search dims what it leaves out", || { + app.notes().search("pg_dump"); + app.board().expect_dimmed(QUERY, "the other note is dimmed"); + app.notes().clear_search(); + }); + + step("a relaunch finds the layout, and the view of each space", || { + let left = app.board().place_of("Bases"); + app.relaunch_and_unlock(); + app.board().expect("the board is back"); + app.board().expect_place("Bases", left, "its zones are as they were"); + let samples = app.rail().other_space(SPACE); + app.rail().show_space(&samples); + app.board().expect_list("the other space is a list"); + app.rail().show_space(SPACE); + app.board().expect("this one is a board again"); + }); +} + +fn a_folder_opened(app: &mut App) { + step("empty, a folder offers the card a note is made from", || { + app.board().open_zone("Sketches"); + app.rail().expect_folder_open("Sketches", "the breadcrumb names it"); + app.notes().expect_ghost("the card offers a note"); + app.notes().write_from_the_ghost(INDEX, "CREATE INDEX;"); + app.notes().leave_folder(); + app.board() + .expect_in_zone("Sketches", &[INDEX], "the note made inside is filed there"); + }); + + step("a folder that holds folders is a board one level down", || { + app.rail().new_sub_folder("Bases", "Indexes"); + app.board().open_zone("Bases"); + app.rail().expect_folder_open("Bases", "the breadcrumb names it"); + app.board().expect_zones(&["Indexes"], "its sub-folder is the one zone"); + app.notes().write_snippet(CACHE, "SELECT ratio;"); + app.board().expect_loose(&[CACHE, DUMP], "its notes are beside it"); + }); + + step("Esc gives the search back, then leaves the folder", || { + app.notes().search("ratio"); + app.press(Shortcut::Escape); + app.notes().expect_search_empty("the search is given back"); + app.rail().expect_folder_open("Bases", "the folder is still open"); + app.press(Shortcut::Escape); + app.rail().expect_no_folder_open("the space's board is back"); + app.board().expect_zone("Bases", "its zones are there"); + }); +} + +fn a_space_deleted(app: &mut App) { + step("deleting a space asks where its notes go, and moves them", || { + app.rail().open_space_panel(SPACE); + app.rail().expect_notes_destination("the panel says where they would go"); + app.capture("space-panel"); + app.rail().delete_space(); + app.rail().expect_spaces(1, "one space is left"); + app.rail().show_all_spaces(); + app.notes().expect_card(QUERY, "its notes are in the other one"); + app.notes().expect_card(Sample::Welcome, "with those it already had"); + }); +} diff --git a/e2e/tests/13_making_it_mine.rs b/e2e/tests/13_making_it_mine.rs index 30fda893..30a14e92 100644 --- a/e2e/tests/13_making_it_mine.rs +++ b/e2e/tests/13_making_it_mine.rs @@ -171,7 +171,7 @@ fn the_keys(app: &mut App) { app.prefs().close(); app.notes().go_to_first_card(); app.press(Shortcut::CardKey(Key::J)); - app.notes().expect_selected(1, "the first card is selected"); + app.selection().expect(1, "the first card is selected"); app.press(Shortcut::Escape); }); diff --git a/e2e/tests/13_multiple_selection.rs b/e2e/tests/13_multiple_selection.rs deleted file mode 100644 index 5bc8297c..00000000 --- a/e2e/tests/13_multiple_selection.rs +++ /dev/null @@ -1,82 +0,0 @@ -//! Several notes at once: ticked from the keyboard, tagged and deleted together, and only them. -//! What is searched is a tag the scenario gives, which no translation touches. - -use e2e::old::{App, Tree, step}; -use egui::{Key, Modifiers}; - -const CARDS: usize = 6; - -fn tick_two(app: &mut App) { - for key in [Key::X, Key::ArrowRight, Key::X] { - app.press(key, Modifiers::NONE); - } - app.eventually("two cards are ticked", |tree| { - tree.text("selection-count").is_some_and(|said| said.contains('2')) - }); -} - -/// Where each card's box is: one per card, in the tree's order. -fn boxes(tree: &Tree) -> Vec<(f64, f64)> { - tree.all("note-card-check") - .iter() - .filter_map(|node| node.bounds()) - .map(|bounds| (bounds.x0, bounds.y0)) - .collect() -} - -/// A box ticked by the pointer, and every card's box where it was before. -fn ticked_by_its_box(app: &mut App) { - let before = boxes(&app.tree()); - assert_eq!(before.len(), CARDS, "every card shows its box"); - app.click_nth("note-card-check", 1); - app.wait_for("selection-count"); - assert_eq!(boxes(&app.tree()), before, "no box moved"); - app.click_nth("note-card-check", 1); - app.eventually("the bar is gone", |tree| !tree.has("selection-count")); -} - -#[test] -fn multiple_selection() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("13_multiple_selection", profile.path()); - app.create_library(); - app.eventually("the samples are drawn", |tree| tree.count("note-card") == CARDS); - - step("a card is ticked by its box, which stays put", || { - ticked_by_its_box(&mut app); - }); - - step("no bar until a card is ticked, then it counts them", || { - assert!(!app.has("selection-count")); - app.press(Key::ArrowDown, Modifiers::NONE); - tick_two(&mut app); - app.capture("selection-bar"); - }); - - step("a tag reaches every ticked note, and only those", || { - app.fill("selection-tag", "batchtag"); - app.press(Key::Enter, Modifiers::NONE); - // While the bar offers the tagging back, Escape would take it back. - app.click("undo-dismiss"); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the selection is let go", |tree| !tree.has("selection-count")); - app.click("search-input"); - app.type_text("batchtag"); - app.eventually("the two tagged notes are found", |tree| tree.count("note-card") == 2); - }); - - step("deleting the selection takes two clicks", || { - app.press(Key::ArrowDown, Modifiers::NONE); - tick_two(&mut app); - app.click("selection-delete"); - assert_eq!(app.tree().count("note-card"), 2); - app.click("selection-delete"); - app.eventually("both are in the trash, and the bar is gone", |tree| { - tree.has("canvas-no-results") && !tree.has("selection-count") - }); - app.click("search-clear"); - app.eventually("the others are untouched", |tree| tree.count("note-card") == CARDS - 2); - }); - - app.quit(); -} diff --git a/e2e/tests/14_tag_manager.rs b/e2e/tests/14_tag_manager.rs deleted file mode 100644 index 00923e70..00000000 --- a/e2e/tests/14_tag_manager.rs +++ /dev/null @@ -1,130 +0,0 @@ -//! The library's tags managed from the tag rail: a ticked tag's name filled in the field, renamed, -//! merged onto an existing tag, corrected in case alone, deleted — each said before it runs. The tags are the scenario's own, given -//! from the selection bar: the samples' are in the system's language. - -use e2e::old::{App, step}; -use egui::{Key, Modifiers}; - -const CARDS: usize = 6; - -/// The cards at `positions` ticked from their boxes, then given `tag` from the selection bar. -fn tag(app: &mut App, positions: &[usize], tag: &str) { - for at in positions { - app.click_nth("note-card-check", *at); - } - app.eventually("the cards are ticked", |tree| { - tree.text("selection-count") - .is_some_and(|said| said.contains(&positions.len().to_string())) - }); - app.fill("selection-tag", tag); - app.press(Key::Enter, Modifiers::NONE); - app.click("undo-dismiss"); - app.click("selection-clear"); - app.eventually("the selection is let go", |tree| !tree.has("selection-count")); -} - -fn listed(tree: &e2e::old::Tree, tag: &str) -> bool { - let name = format!("#{tag}"); - tree.texts("tag-item").contains(&name) -} - -fn tick(app: &mut App, tag: &str) { - let name = format!("#{tag}"); - app.click_where("tag-item", |node| node.label() == Some(name.as_str())); -} - -fn target(tree: &e2e::old::Tree) -> String { - let field = tree.find("tag-target"); - field.and_then(|node| node.value()).unwrap_or_default().to_owned() -} - -/// The ticked tags under `into`, typed over what the field holds, proposed then confirmed. -fn rename(app: &mut App, into: &str) { - app.fill("tag-target", ""); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(into); - app.click("tag-apply"); - app.click("tag-confirm-apply"); -} - -#[test] -fn tag_manager() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("14_tag_manager", profile.path()); - app.create_library(); - app.eventually("the samples are drawn", |tree| tree.count("note-card") == CARDS); - tag(&mut app, &[0, 1], "staging"); - tag(&mut app, &[0], "urgent"); - tag(&mut app, &[2], "preprod"); - - step("the tags' menu opens the manager, which lists every tag", || { - app.click("facets-toggle"); - app.click("facet-menu-tag"); - app.click("tag-manage"); - app.eventually("the scenario's tags are listed", |tree| { - ["staging", "urgent", "preprod"].iter().all(|tag| listed(tree, tag)) - }); - assert!( - app.tree().find("tag-apply").is_some_and(egui::accesskit::Node::is_disabled), - "nothing ticked, nothing to apply" - ); - }); - - step("a rename says what it touches, and cancelling writes nothing", || { - tick(&mut app, "staging"); - app.eventually("its name fills the field, which has the focus", |tree| { - target(tree) == "staging" && tree.focused().starts_with("tag-target") - }); - assert!( - app.tree().find("tag-apply").is_some_and(egui::accesskit::Node::is_disabled), - "its own name changes nothing" - ); - assert!(app.tree().has("tag-target-reason")); - // Selected: what is typed replaces it. - app.type_text("recette"); - app.eventually("edited in place", |tree| target(tree) == "recette"); - app.click("tag-apply"); - app.eventually("two notes carry it, and the sentence says so", |tree| { - tree.text("tag-confirm-text").is_some_and(|said| said.contains('2')) - }); - app.capture("tag-confirm"); - app.click("tag-confirm-cancel"); - assert!(listed(&app.tree(), "staging")); - }); - - step("confirmed, the rename reaches every note", || { - app.click("tag-apply"); - app.click("tag-confirm-apply"); - app.eventually("recette replaces staging", |tree| { - listed(tree, "recette") && !listed(tree, "staging") - }); - }); - - step("onto an existing tag it merges", || { - tick(&mut app, "preprod"); - rename(&mut app, "recette"); - app.eventually("preprod is gone into recette", |tree| { - listed(tree, "recette") && !listed(tree, "preprod") - }); - }); - - step("a change of case alone is written", || { - tick(&mut app, "recette"); - rename(&mut app, "Recette"); - app.eventually("the new spelling", |tree| listed(tree, "Recette")); - }); - - step("a deleted tag leaves its notes", || { - tick(&mut app, "urgent"); - app.click("tag-delete"); - app.click("tag-confirm-apply"); - app.eventually("urgent is gone", |tree| !listed(tree, "urgent")); - app.click("tag-manager-close"); - app.eventually("the manager is closed", |tree| !tree.has("tag-manager-close")); - // The band takes room from the cards: how many are drawn under it depends on the window. - app.click("facets-toggle"); - app.eventually("every note stays", |tree| tree.count("note-card") == CARDS); - }); - - app.quit(); -} diff --git a/e2e/tests/17_folders.rs b/e2e/tests/17_folders.rs deleted file mode 100644 index 06120cf1..00000000 --- a/e2e/tests/17_folders.rs +++ /dev/null @@ -1,305 +0,0 @@ -//! Folders: made from the rail, refused twice under one name, a selection filed and taken back -//! out, the chip a card wears, a note filed from its card, the notes left standing when the -//! folder goes — then folders inside folders: dragged onto another in the rail and offered back, -//! the list of an opened folder gathering its sub-tree, its own board one level down, a -//! sub-folder made from its panel, the folder dragged onto another space with its notes, and one -//! deleted with its notes, which wait in the trash. -//! -//! A space of its own, made here: the samples are in the system's language. - -use e2e::old::{App, Tree, step}; -use egui::accesskit::Node; -use egui::{Key, Modifiers, PointerButton, Pos2}; - -const SPACE: &str = "Dossiers"; -const FIRST: &str = "Requête lente"; -const SECOND: &str = "Plan d'exécution"; -const NESTED: &str = "Index partiel sur jobs"; -const DOOMED: &str = "Brouillon à jeter"; - -fn named(name: &str) -> impl Fn(&Node) -> bool + '_ { - move |node| node.label() == Some(name) -} - -fn titles(tree: &Tree) -> Vec { - tree.all("note-card-title") - .into_iter() - .map(|node| node.label().or(node.value()).unwrap_or_default().to_owned()) - .collect() -} - -/// How many rows of the rail are named `name`: the samples' folders are listed too. -fn rows_named(tree: &Tree, name: &str) -> usize { - tree.texts("folder-option").iter().filter(|row| *row == name).count() -} - -fn crumb(tree: &Tree) -> Option { - tree.text("folder-breadcrumb-name") -} - -fn centre(node: &Node) -> Pos2 { - let rect = node.bounds().expect("a place on screen"); - #[expect(clippy::cast_possible_truncation, reason = "points on a screen")] - Pos2::new(f64::midpoint(rect.x0, rect.x1) as f32, f64::midpoint(rect.y0, rect.y1) as f32) -} - -fn write(app: &mut App, title: &str) { - app.click("new-note"); - app.fill("editor-title", title); - app.fill("editor-body", "SELECT 1;"); - app.click("editor-close"); - app.eventually("the note is a card", |tree| { - !tree.has("editor-title") && titles(tree).contains(&title.to_owned()) - }); -} - -fn make_folder(app: &mut App, name: &str) { - app.click("folder-create-open"); - app.fill("folder-create-input", name); - app.press(Key::Enter, Modifiers::NONE); -} - -fn file_into(app: &mut App, name: &str) { - app.click("selection-move"); - app.click_where("selection-move-place", ends_with(name)); -} - -/// The first place offered, whatever the language calls it: out of every folder. -fn unfile(app: &mut App) { - app.click("selection-move"); - app.wait_for("selection-move-place"); - app.click("selection-move-place"); -} - -/// A folder's place: its path ends with its name. -fn ends_with(name: &str) -> impl Fn(&Node) -> bool { - let end = format!(" › {name}"); - move |node| node.label().is_some_and(|label| label.ends_with(&end)) -} - -fn tick_all(app: &mut App) { - app.click("search-input"); - app.press(Key::ArrowDown, Modifiers::NONE); - for key in [Key::X, Key::ArrowRight, Key::X] { - app.press(key, Modifiers::NONE); - } - app.eventually("two cards are ticked", |tree| { - tree.text("selection-count").is_some_and(|said| said.contains('2')) - }); -} - -fn space_of_its_own(app: &mut App) { - step("a space of its own, two notes, a folder made from the rail", || { - app.click("space-create-open"); - app.fill("space-create-input", SPACE); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the new space is shown", |tree| { - tree.texts("space-option").contains(&SPACE.to_owned()) && !tree.has("note-card") - }); - write(app, FIRST); - write(app, SECOND); - make_folder(app, "Perf"); - app.eventually("the folder is listed", |tree| rows_named(tree, "Perf") == 1); - }); - - step("a second folder of the same name is refused", || { - make_folder(app, "Perf"); - app.eventually("the refusal is said", |tree| tree.has("error-banner")); - assert_eq!(rows_named(&app.tree(), "Perf"), 1); - app.click("error-dismiss"); - app.press(Key::Escape, Modifiers::NONE); - }); -} - -fn filing(app: &mut App) { - step("a whole selection is filed in one gesture, and says where", || { - tick_all(app); - file_into(app, "Perf"); - app.eventually("both cards wear the folder's chip", |tree| tree.count("note-card-folder") == 2); - // While the bar offers the filing back, Escape would take it back. - app.click("undo-dismiss"); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the selection is let go", |tree| !tree.has("selection-count")); - }); - - step("the folder narrows the canvas, and the space opens it back", || { - app.click_where("folder-option", named("Perf")); - app.eventually("its notes alone, no chip naming it", |tree| { - crumb(tree).as_deref() == Some("Perf") && titles(tree).len() == 2 && !tree.has("note-card-folder") - }); - app.click_where("space-option", named(SPACE)); - app.eventually("the whole space", |tree| crumb(tree).is_none()); - }); - - step("a selection taken back out wears no chip at all", || { - tick_all(app); - unfile(app); - app.eventually("no card wears a chip", |tree| !tree.has("note-card-folder")); - // While the bar offers the filing back, Escape would take it back. - app.click("undo-dismiss"); - app.press(Key::Escape, Modifiers::NONE); - }); - - step("a note is filed from its card's menu", || { - app.hover("note-card"); - app.click("note-card-menu"); - app.click("note-card-move"); - app.fill("note-card-move-filter", "perf"); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("one card wears the chip", |tree| tree.count("note-card-folder") == 1); - }); - - step("deleting the folder leaves every note standing", || { - app.click_where("folder-edit", |node| node.label().is_some_and(|label| label.contains("Perf"))); - app.click("folder-delete"); - app.click("folder-delete"); - app.eventually("the folder is gone, both notes kept", |tree| { - rows_named(tree, "Perf") == 0 && titles(tree).len() == 2 && !tree.has("note-card-folder") - }); - }); -} - -fn nested(app: &mut App) { - step("a folder dragged onto another goes inside it, offered back", || { - make_folder(app, "Bases"); - app.eventually("listed", |tree| rows_named(tree, "Bases") == 1); - make_folder(app, "Index"); - app.eventually("listed", |tree| rows_named(tree, "Index") == 1); - app.click_where("folder-option", named("Index")); - app.wait_for("folder-breadcrumb-name"); - write(app, NESTED); - app.click_where("space-option", named(SPACE)); - app.eventually("the space", |tree| crumb(tree).is_none()); - let tree = app.tree(); - let index = tree - .all("folder-option") - .into_iter() - .find(|node| node.label() == Some("Index")) - .map(centre) - .unwrap(); - let bases = tree - .all("folder-option") - .into_iter() - .find(|node| node.label() == Some("Bases")) - .map(centre) - .unwrap(); - app.drag(index, bases, PointerButton::Primary); - app.eventually("« Index » is drawn inside « Bases », and offered back", |tree| { - let rows = tree.all("folder-option"); - let left = |name: &str| { - rows.iter() - .find(|node| node.label() == Some(name)) - .and_then(|node| node.bounds()) - .map(|bounds| bounds.x0) - }; - left("Index") > left("Bases") && tree.has("undo-restore") - }); - app.capture("rail-nested"); - app.click("undo-dismiss"); - app.eventually("the bar is gone", |tree| !tree.has("undo-bar")); - }); - - step("an opened folder lists its whole sub-tree, each card naming its own", || { - app.click_where("folder-option", named("Bases")); - app.eventually("the note of « Index » is listed", |tree| { - crumb(tree).as_deref() == Some("Bases") && titles(tree).contains(&NESTED.to_owned()) - }); - // The chip shows the deepest folder and says its path from the top. - assert_eq!(app.tree().text("note-card-folder").as_deref(), Some("Bases › Index")); - }); - - step("on the board, a folder that holds folders is a board one level down", || { - app.click("folder-breadcrumb-back"); - app.eventually("the space", |tree| crumb(tree).is_none()); - app.click("view-board"); - app.click_where("board-zone-open", named("Bases")); - app.eventually("« Index » is its one zone, holding its note", |tree| { - crumb(tree).as_deref() == Some("Bases") && tree.texts("board-zone-open") == ["Index"] - }); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the space's board, « Index » inside « Bases »'s zone", |tree| { - crumb(tree).is_none() - && tree.texts("board-zone-open").contains(&"Bases".to_owned()) - && tree.texts("board-zone-child").contains(&"Index".to_owned()) - }); - app.click("view-list"); - }); - - step("a folder made inside another from its panel", || { - app.click_where("folder-edit", |node| node.label().is_some_and(|label| label.contains("Index"))); - app.click("folder-subfolder-open"); - app.fill("folder-subfolder-input", "Partiels"); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("listed under « Index », the field gone", |tree| { - tree.texts("folder-option").contains(&"Partiels".to_owned()) - && !tree.has("folder-subfolder-input") - }); - }); -} - -/// « Bases », holding « Index » and its note, dropped onto the samples' space: the note is found -/// there, and the undo bar brings everything back. -fn to_another_space(app: &mut App) { - step("a folder dragged onto another space goes there with its notes, offered back", || { - let tree = app.tree(); - let samples = tree - .texts("space-option") - .into_iter() - .find(|name| name != SPACE) - .expect("the samples' space"); - let at = |author_id: &str, name: &str| { - tree.all(author_id) - .into_iter() - .find(|node| node.label() == Some(name)) - .map_or_else(|| panic!("no row {name}"), centre) - }; - let (bases, other) = (at("folder-option", "Bases"), at("space-option", &samples)); - app.drag(bases, other, PointerButton::Primary); - app.wait_for("undo-restore"); - app.click_where("space-option", named(&samples)); - app.eventually("the note of « Index » is in the samples' space", |tree| { - titles(tree).contains(&NESTED.to_owned()) - }); - app.click("undo-restore"); - app.click_where("space-option", named(SPACE)); - app.eventually("back in its space, with its note", |tree| titles(tree).contains(&NESTED.to_owned())); - }); -} - -fn deleted_with_its_notes(app: &mut App) { - step("a folder deleted with its notes puts them in the trash", || { - make_folder(app, "Jetable"); - app.eventually("the folder is listed", |tree| rows_named(tree, "Jetable") == 1); - app.click_where("folder-option", named("Jetable")); - app.wait_for("folder-breadcrumb-name"); - write(app, DOOMED); - app.click_where("folder-edit", |node| node.label().is_some_and(|label| label.contains("Jetable"))); - app.click("folder-delete-held"); - app.click("folder-delete-held-1"); - app.click("folder-delete"); - app.click("folder-delete"); - app.eventually("the folder is gone, its note with it", |tree| { - rows_named(tree, "Jetable") == 0 && !titles(tree).contains(&DOOMED.to_owned()) - }); - app.click("trash-open"); - app.eventually("the note waits in the trash", |tree| { - tree.texts("trash-row-title").contains(&DOOMED.to_owned()) - }); - app.press(Key::Escape, Modifiers::NONE); - }); -} - -#[test] -fn folders() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("17_folders", profile.path()); - app.create_library(); - app.wait_for("note-card"); - - space_of_its_own(&mut app); - filing(&mut app); - nested(&mut app); - to_another_space(&mut app); - deleted_with_its_notes(&mut app); - app.quit(); -} diff --git a/e2e/tests/18_board.rs b/e2e/tests/18_board.rs deleted file mode 100644 index 82eb5f4a..00000000 --- a/e2e/tests/18_board.rs +++ /dev/null @@ -1,280 +0,0 @@ -//! The board: a space's folders drawn as zones holding their notes, the loose ones beside, the -//! same card the list draws, a first layout that comes back unchanged after a relaunch, and the -//! view remembered space by space. Only a real database proves the first layout is written. -//! -//! A space of its own, made here: the samples are in the system's language. - -use e2e::old::{App, Tree, step}; -use egui::accesskit::{Node, Rect, Toggled}; -use egui::{Key, Modifiers}; - -const SPACE: &str = "Tableau"; -const FILED: &str = "EXPLAIN lent sur join"; -const LOOSE: &str = "Dump nocturne"; -const LIST: &str = "Avant la release"; - -fn named(name: &str) -> impl Fn(&Node) -> bool + '_ { - move |node| node.label() == Some(name) -} - -fn is_on(tree: &Tree, author_id: &str) -> bool { - tree.find(author_id).is_some_and(|node| node.toggled() == Some(Toggled::True)) -} - -fn frame_of(tree: &Tree, zone: &str) -> Option { - tree.all("board-zone") - .into_iter() - .find(|node| node.label() == Some(zone)) - .and_then(Node::bounds) -} - -/// The titles drawn inside `zone`, in reading order. -fn titles_in(tree: &Tree, zone: &str) -> Vec { - let Some(frame) = frame_of(tree, zone) else { - return Vec::new(); - }; - tree.all("note-card-title") - .into_iter() - .filter(|node| { - node.bounds().is_some_and(|card| { - card.x0 >= frame.x0 && card.x1 <= frame.x1 && card.y0 >= frame.y0 && card.y1 <= frame.y1 - }) - }) - .map(|node| node.label().or(node.value()).unwrap_or_default().to_owned()) - .collect() -} - -fn frames(tree: &Tree) -> Vec { - tree.all("board-zone").into_iter().filter_map(Node::bounds).collect() -} - -/// A note written from the editor in whatever space or folder is shown. -fn write(app: &mut App, title: &str) { - app.click("new-note"); - app.fill("editor-title", title); - app.fill("editor-body", "SELECT 1;"); - app.click("editor-close"); - app.eventually("the note is a card", |tree| { - !tree.has("editor-title") && tree.texts("note-card").contains(&title.to_owned()) - }); -} - -fn choose_space(app: &mut App, name: &str) { - app.click_where("space-option", named(name)); - app.eventually("the space is shown", |tree| { - tree.all("space-option") - .into_iter() - .any(|node| node.label() == Some(name) && node.toggled() == Some(Toggled::True)) - }); -} - -/// A space of its own: two folders, a note filed in the first, one loose. -fn seed(app: &mut App) { - step("a space of its own: two folders, a note filed, one loose", || { - app.click("space-create-open"); - app.fill("space-create-input", SPACE); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the new space is shown, empty", |tree| { - tree.texts("space-option").contains(&SPACE.to_owned()) && !tree.has("note-card") - }); - for name in ["Perf", "Migrations"] { - app.click("folder-create-open"); - app.fill("folder-create-input", name); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the folder is listed", |tree| { - tree.texts("folder-option").contains(&name.to_owned()) - }); - } - app.click_where("folder-option", named("Perf")); - app.wait_for("folder-breadcrumb-name"); - write(app, FILED); - choose_space(app, SPACE); - write(app, LOOSE); - }); -} - -/// What a card on the board still does: tick its items, take the selection, take the arrows. -fn on_the_board(app: &mut App) { - step("a todo list is ticked on the board, and shown ticked", || { - app.click("new-note-kind"); - app.click("new-note-checklist"); - app.fill("editor-title", LIST); - app.click("checklist-add"); - app.eventually("the new row has the focus", |tree| tree.focused().starts_with("checklist-text")); - app.type_text("Tag"); - app.click("editor-close"); - app.eventually("the list is a loose card", |tree| { - tree.texts("board-loose-card").contains(&LIST.to_owned()) - }); - app.click_nth("note-card-item", 0); - app.eventually("the item is ticked", |tree| { - tree.find("note-card-item") - .is_some_and(|node| node.toggled() == Some(Toggled::True)) - }); - }); - - step("the corner is the selection tick's", || { - let title = app.tree().texts("board-loose-card")[0].clone(); - let its_tick = |node: &Node| node.label().is_some_and(|label| label.contains(&title)); - app.hover("board-loose-card"); - app.click_where("note-card-check", its_tick); - app.wait_for("selection-count"); - app.click_where("note-card-check", its_tick); - app.eventually("the bar is gone", |tree| !tree.has("selection-count")); - }); - - step("from one open note to the next, the panel stays", || { - panel_kept(app); - }); - - step("the arrows walk the cards as the board lays them out", || { - app.click("search-input"); - app.press(Key::ArrowDown, Modifiers::NONE); - for _ in 0..3 { - app.press(Key::ArrowLeft, Modifiers::NONE); - } - app.eventually("the first card of the board has the focus", |tree| tree.focused().contains(FILED)); - app.press(Key::ArrowRight, Modifiers::NONE); - app.eventually("then the next", |tree| !tree.focused().contains(FILED)); - app.press(Key::Escape, Modifiers::NONE); - }); -} - -fn open_title(tree: &Tree) -> Option<&str> { - tree.find("editor-title").and_then(Node::value) -} - -/// One note open, then the next one by J: the zones never move while the second is read. J -/// rather than a click: the panel may cover the next card. -fn panel_kept(app: &mut App) { - app.click_where("note-card-open", named(FILED)); - app.eventually("the first note is open, no field focused", |tree| { - open_title(tree) == Some(FILED) && !tree.focused().starts_with("editor-title") - }); - let beside = frames(&app.tree()); - app.press(Key::J, Modifiers::NONE); - app.eventually("the next is open, the zones where they were", |tree| { - assert_eq!(frames(tree), beside, "the board moved"); - open_title(tree).is_some_and(|title| title != FILED) - }); - app.click("editor-close"); - app.eventually("the editor closed", |tree| !tree.has("editor-title")); -} - -/// Whether the card titled `title` is drawn lit: a dimmed one keeps its seat, disabled. -fn lit(tree: &Tree, title: &str) -> Option { - tree.all("board-loose-card") - .into_iter() - .chain(tree.all("board-zone-card")) - .find(|node| node.label() == Some(title)) - .map(|node| !node.is_disabled()) -} - -/// A search dims on the board, and the tidy names what it would touch. -fn dimmed(app: &mut App) { - step("a search dims what it does not match, and drops nothing", || { - app.click("search-input"); - app.type_text("EXPLAIN"); - app.eventually("the loose card is dimmed", |tree| lit(tree, LOOSE) == Some(false)); - let tree = app.tree(); - assert_eq!(lit(&tree, FILED), Some(true)); - assert_eq!(titles_in(&tree, "Perf"), [FILED]); - app.capture("board-dimmed"); - app.click("search-clear"); - app.eventually("the card is lit again", |tree| lit(tree, LOOSE) == Some(true)); - }); - - step("reorganising says how many folders and cards it moves", || { - app.click("board-tidy-more"); - app.eventually("the entry counts two of each", |tree| { - tree.text("board-tidy-everything") - .is_some_and(|said| said.matches('2').count() == 2) - }); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the menu is closed", |tree| !tree.has("board-tidy-everything")); - }); -} - -#[test] -fn board() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("18_board", profile.path()); - app.create_library(); - app.wait_for("note-card"); - let samples = app.tree().texts("space-option")[0].clone(); - - seed(&mut app); - - step("the list is the default, and there is no board across every space", || { - assert!(is_on(&app.tree(), "view-list")); - assert!(!app.has("board")); - app.click("space-option-all"); - app.eventually("the board is offered disabled", |tree| { - tree.find("view-board").is_some_and(Node::is_disabled) - }); - choose_space(&mut app, SPACE); - }); - - step("each folder is a zone holding its notes, the loose ones beside", || { - app.click("view-board"); - app.eventually("the zones are drawn", |tree| tree.count("board-zone") == 2); - let tree = app.tree(); - let mut zones = tree.texts("board-zone-open"); - zones.sort(); - assert_eq!(zones, ["Migrations", "Perf"]); - assert_eq!(titles_in(&tree, "Perf"), [FILED]); - assert!(titles_in(&tree, "Migrations").is_empty()); - assert_eq!(tree.texts("board-loose-card"), [LOOSE]); - // The same card as the list's: its title, and the layer that opens it. - assert_eq!(tree.count("note-card-open"), 2); - let [first, second] = frames(&tree)[..] else { - panic!("two zones"); - }; - assert!(first.x1 <= second.x0 || second.x1 <= first.x0, "side by side"); - app.capture("board"); - }); - - on_the_board(&mut app); - dimmed(&mut app); - - let before = frames(&app.tree()); - let mut app = app.relaunch(); - - step("a relaunch comes back on the board, its layout unchanged", || { - app.fill("vault-passphrase", e2e::old::PASSPHRASE); - app.click("vault-submit"); - app.eventually("the board is back", |tree| tree.count("board-zone") == 2); - assert_eq!(frames(&app.tree()), before); - }); - - step("the view is remembered space by space", || { - choose_space(&mut app, &samples); - app.eventually("the samples are listed", |tree| !tree.has("board") && tree.has("note-card")); - choose_space(&mut app, SPACE); - app.eventually("the board is back", |tree| tree.has("board")); - }); - - step("the list is left exactly as it was", || { - app.click("view-list"); - app.eventually("the three notes are listed", |tree| { - !tree.has("board") && tree.count("note-card") == 3 - }); - app.click("view-board"); - app.wait_for("board"); - }); - - step("a window larger than the board is pointer ground all over", || { - app.resize(1600, 1000); - app.eventually("the surface covers the ground", |tree| { - let (Some(ground), Some(surface)) = ( - tree.find("board").and_then(Node::bounds), - tree.find("board-surface").and_then(Node::bounds), - ) else { - return false; - }; - surface.x1 >= ground.x1 && surface.y1 >= ground.y1 - }); - }); - - app.quit(); -} diff --git a/e2e/tests/19_board_gesture.rs b/e2e/tests/19_board_gesture.rs deleted file mode 100644 index 4012eb22..00000000 --- a/e2e/tests/19_board_gesture.rs +++ /dev/null @@ -1,306 +0,0 @@ -//! Arranging the board by hand: a card dragged into a zone and back out, a zone moved and -//! resized, a folder drawn on the ground, a right-button sweep, a whole zone ticked, and the -//! tidy — each checked against what a relaunch reads back from the database. The keyboard twin -//! of a drop is the selection bar's « File into ». -//! -//! A space of its own, made here: the samples are in the system's language. - -use e2e::old::{App, Tree, step}; -use egui::accesskit::{Node, Rect}; -use egui::{Key, Modifiers, PointerButton, Pos2}; - -const SPACE: &str = "Gestes"; -const FILED: &str = "EXPLAIN lent sur join"; -const LOOSE: &str = "Dump nocturne"; -/// `folders::board::ZONE_HEADER`: every control of a zone's header holds in it. -const ZONE_HEADER: f64 = 38.0; - -fn named(name: &str) -> impl Fn(&Node) -> bool + '_ { - move |node| node.label() == Some(name) -} - -fn bounds_of(tree: &Tree, author_id: &str, name: &str) -> Option { - tree.all(author_id) - .into_iter() - .find(|node| node.label() == Some(name)) - .and_then(Node::bounds) -} - -/// Points on the window, from the tree's `f64`. -fn point(x: f64, y: f64) -> Pos2 { - #[expect(clippy::cast_possible_truncation, reason = "points on a screen")] - Pos2::new(x as f32, y as f32) -} - -fn centre(rect: Rect) -> Pos2 { - point(f64::midpoint(rect.x0, rect.x1), f64::midpoint(rect.y0, rect.y1)) -} - -/// The titles drawn inside `zone`. -fn titles_in(tree: &Tree, zone: &str) -> Vec { - let Some(frame) = bounds_of(tree, "board-zone", zone) else { - return Vec::new(); - }; - tree.all("board-zone-card") - .into_iter() - .filter(|node| { - node.bounds() - .is_some_and(|card| card.x0 >= frame.x0 && card.x1 <= frame.x1 && card.y0 >= frame.y0) - }) - .map(|node| node.label().unwrap_or_default().to_owned()) - .collect() -} - -/// A zone's control, the one in that zone's header. -fn control_of(tree: &Tree, author_id: &str, zone: &str) -> Option { - let frame = bounds_of(tree, "board-zone", zone)?; - tree.all(author_id).into_iter().filter_map(Node::bounds).find(|control| { - control.x0 >= frame.x0 - 1.0 - && control.x1 <= frame.x1 + 1.0 - && control.y0 >= frame.y0 - 1.0 - && control.y1 <= frame.y1 + 1.0 - }) -} - -fn write(app: &mut App, title: &str) { - app.click("new-note"); - app.fill("editor-title", title); - app.fill("editor-body", "SELECT 1;"); - app.click("editor-close"); - app.eventually("the note is a card", |tree| { - !tree.has("editor-title") && tree.texts("note-card").contains(&title.to_owned()) - }); -} - -/// The selection bar's « File into », on the entry named `name`. -/// The box of the card the steps file and take back. -fn filed(node: &Node) -> bool { - node.label().is_some_and(|label| label.contains(FILED)) -} - -fn file_into(app: &mut App, name: &str) { - app.click("selection-move"); - let end = format!(" › {name}"); - app.click_where("selection-move-place", |node| node.label().is_some_and(|label| label.ends_with(&end))); -} - -fn reopen(app: App) -> App { - let mut app = app.relaunch(); - app.fill("vault-passphrase", e2e::old::PASSPHRASE); - app.click("vault-submit"); - app.eventually("the board is back", |tree| tree.has("board-zone")); - app -} - -fn seed(app: &mut App) { - step("a space of its own: two folders, a note filed, one loose", || { - app.click("space-create-open"); - app.fill("space-create-input", SPACE); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the new space is shown", |tree| { - tree.texts("space-option").contains(&SPACE.to_owned()) && !tree.has("note-card") - }); - for name in ["Perf", "Migrations"] { - app.click("folder-create-open"); - app.fill("folder-create-input", name); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the folder is listed", |tree| { - tree.texts("folder-option").contains(&name.to_owned()) - }); - } - app.click_where("folder-option", named("Perf")); - app.wait_for("folder-breadcrumb-name"); - write(app, FILED); - app.click_where("space-option", named(SPACE)); - app.eventually("the space is shown", |tree| !tree.has("folder-breadcrumb-name")); - write(app, LOOSE); - app.click("view-board"); - app.eventually("the board is drawn", |tree| tree.count("board-zone") == 2); - }); -} - -fn cards(app: &mut App) { - step("a card dragged into a zone is filed there, and its place forgotten", || { - let tree = app.tree(); - let card = bounds_of(&tree, "board-loose-card", LOOSE).unwrap(); - let zone = bounds_of(&tree, "board-zone", "Migrations").unwrap(); - // The card lands where its corner does: the grab, at its centre, keeps the offset. - let into = point(zone.x0 + 150.0, zone.y0 + 120.0); - app.drag(centre(card), into, PointerButton::Primary); - app.eventually("the card flows in the zone", |tree| { - titles_in(tree, "Migrations") == [LOOSE] - && !tree.texts("board-loose-card").contains(&LOOSE.to_owned()) - }); - app.capture("board-filed"); - }); - - step("dropped on the ground, it comes back out", || { - let card = bounds_of(&app.tree(), "board-zone-card", LOOSE).unwrap(); - let ground = Pos2::new(centre(card).x, centre(card).y + 360.0); - app.drag(centre(card), ground, PointerButton::Primary); - app.eventually("the card is loose again", |tree| { - tree.texts("board-loose-card").contains(&LOOSE.to_owned()) - && titles_in(tree, "Migrations").is_empty() - }); - }); - - step("dropped on the rail, it is filed in that folder", || { - let tree = app.tree(); - let card = bounds_of(&tree, "board-loose-card", LOOSE).unwrap(); - let row = bounds_of(&tree, "folder-option", "Migrations").unwrap(); - app.drag(centre(card), centre(row), PointerButton::Primary); - app.eventually("the card flows in the zone", |tree| titles_in(tree, "Migrations") == [LOOSE]); - let card = bounds_of(&app.tree(), "board-zone-card", LOOSE).unwrap(); - let ground = Pos2::new(centre(card).x, centre(card).y + 360.0); - app.drag(centre(card), ground, PointerButton::Primary); - app.eventually("the card is loose again", |tree| titles_in(tree, "Migrations").is_empty()); - }); - - step("the keyboard files with no pointer, from the selection bar", || { - app.click_where("note-card-check", filed); - app.wait_for("selection-count"); - file_into(app, "Migrations"); - app.eventually("the note is in the other zone", |tree| titles_in(tree, "Migrations") == [FILED]); - // While the bar offers the filing back, Escape would take it back. - app.click("undo-dismiss"); - app.press(Key::Escape, Modifiers::NONE); - app.click_where("note-card-check", filed); - file_into(app, "Perf"); - app.eventually("and back", |tree| titles_in(tree, "Perf") == [FILED]); - // While the bar offers the filing back, Escape would take it back. - app.click("undo-dismiss"); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the selection is let go", |tree| !tree.has("selection-count")); - }); - - step("a zone's menu ticks every card it holds", || { - app.click_where("board-zone-menu", |node| node.label().is_some_and(|label| label.contains("Perf"))); - app.click("folder-select-notes"); - app.eventually("its card is ticked", |tree| { - tree.text("selection-count").is_some_and(|said| said.contains('1')) - }); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the selection is let go", |tree| !tree.has("selection-count")); - }); -} - -fn zones(app: &mut App) { - step("a zone's header holds in ZONE_HEADER", || { - let tree = app.tree(); - let frame = bounds_of(&tree, "board-zone", "Perf").unwrap(); - for control in ["board-zone-grip", "board-zone-open", "board-zone-menu"] { - let drawn = control_of(&tree, control, "Perf").unwrap(); - assert!(drawn.y1 <= frame.y0 + ZONE_HEADER, "{control} overflows the header"); - } - }); - - step("a zone moved by its grip lands on the grid and keeps its notes", || { - let tree = app.tree(); - let before = bounds_of(&tree, "board-zone", "Perf").unwrap(); - let grip = control_of(&tree, "board-zone-grip", "Perf").unwrap(); - let to = centre(grip) + egui::vec2(93.0, 141.0); - app.drag(centre(grip), to, PointerButton::Primary); - app.eventually("the zone moved, its size kept", |tree| { - bounds_of(tree, "board-zone", "Perf").is_some_and(|moved| { - (moved.x0 - before.x0).abs() > 0.5 && (moved.width() - before.width()).abs() < 0.5 - }) - }); - assert_eq!(titles_in(&app.tree(), "Perf"), [FILED]); - }); - - step("resized by its corner, it captures and releases nothing", || { - let tree = app.tree(); - let before = bounds_of(&tree, "board-zone", "Perf").unwrap(); - let corner = control_of(&tree, "board-zone-resize", "Perf").unwrap(); - let to = centre(corner) + egui::vec2(260.0, 120.0); - app.drag(centre(corner), to, PointerButton::Primary); - app.eventually("the zone is wider, where it was", |tree| { - bounds_of(tree, "board-zone", "Perf").is_some_and(|resized| { - resized.width() > before.width() + 100.0 && (resized.x0 - before.x0).abs() < 0.5 - }) - }); - let tree = app.tree(); - assert_eq!(titles_in(&tree, "Perf"), [FILED]); - assert!(tree.texts("board-loose-card").contains(&LOOSE.to_owned())); - }); - - step("a band drawn on the ground becomes the folder named there", || { - let ground = app.tree().find("board").and_then(Node::bounds).unwrap(); - let from = point(ground.x0 + 40.0, ground.y1 - 260.0); - app.drag(from, from + egui::vec2(300.0, 220.0), PointerButton::Primary); - app.fill("folder-name-input", "Reporting"); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the zone is drawn where it was drawn", |tree| { - tree.texts("board-zone-open").contains(&"Reporting".to_owned()) - }); - app.capture("board-drawn-zone"); - }); -} - -fn selecting(app: &mut App) { - step("a right-button sweep ticks the cards it crosses, zones included", || { - let ground = app.tree().find("board").and_then(Node::bounds).unwrap(); - let from = point(ground.x0 + 4.0, ground.y0 + 4.0); - let to = point(ground.x1 - 40.0, ground.y1 - 60.0); - app.drag(from, to, PointerButton::Secondary); - app.eventually("both cards are ticked", |tree| { - tree.text("selection-count").is_some_and(|said| said.contains('2')) - }); - assert!(!app.has("folder-name-input"), "the right button draws no folder"); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the selection is let go", |tree| !tree.has("selection-count")); - }); -} - -/// One step: the core writes in order, so the undo of the reorganisation puts back the layout -/// aligning left — the hand's, if aligning moved no zone. -fn tidying(app: &mut App) { - step("aligning leaves the zones; reorganising moves them, and its undo puts the hand's back", || { - let by_hand = bounds_of(&app.tree(), "board-zone", "Perf").unwrap(); - app.click("board-tidy"); - app.click("board-tidy-more"); - app.click("board-tidy-everything"); - app.eventually("the zone is back at its seat", |tree| { - bounds_of(tree, "board-zone", "Perf").is_some_and(|seat| (seat.x0 - by_hand.x0).abs() > 0.5) - && tree.has("undo-restore") - }); - app.capture("board-reorganised"); - app.click("undo-restore"); - app.eventually("the hand's layout is back", |tree| { - bounds_of(tree, "board-zone", "Perf") - .is_some_and(|back| (back.x0 - by_hand.x0).abs() < 0.5 && (back.y0 - by_hand.y0).abs() < 0.5) - }); - }); -} - -#[test] -fn board_gesture() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("19_board_gesture", profile.path()); - app.create_library(); - app.wait_for("note-card"); - - seed(&mut app); - cards(&mut app); - zones(&mut app); - let before = ( - bounds_of(&app.tree(), "board-zone", "Perf"), - bounds_of(&app.tree(), "board-loose-card", LOOSE), - bounds_of(&app.tree(), "board-zone", "Reporting"), - ); - let mut app = reopen(app); - - step("a relaunch reads back every place the hand chose", || { - let tree = app.tree(); - let after = ( - bounds_of(&tree, "board-zone", "Perf"), - bounds_of(&tree, "board-loose-card", LOOSE), - bounds_of(&tree, "board-zone", "Reporting"), - ); - assert_eq!(after, before); - }); - - selecting(&mut app); - tidying(&mut app); - app.quit(); -} diff --git a/e2e/tests/20_folder_descent.rs b/e2e/tests/20_folder_descent.rs deleted file mode 100644 index 6e4e9d76..00000000 --- a/e2e/tests/20_folder_descent.rs +++ /dev/null @@ -1,184 +0,0 @@ -//! Opening a folder: empty, it offers the card a note is made from, not « nothing matches »; from -//! a zone's title on the board, a flat grid of its notes named after it, -//! the switchers put away for its breadcrumb, a note made inside it filed there, renamed from -//! beside the breadcrumb, and left again — Escape giving the search back first, then the folder -//! — down to the board it was opened from, or through the breadcrumb, or by deleting it. -//! -//! A space of its own, made here: the samples are in the system's language. - -use e2e::old::{App, Tree, step}; -use egui::accesskit::{Node, Toggled}; -use egui::{Key, Modifiers}; - -const SPACE: &str = "Descente"; -const INSIDE: &str = "EXPLAIN lent sur join"; -const LOOSE: &str = "Dump nocturne"; -const MADE: &str = "Cache hit ratio"; - -fn named(name: &str) -> impl Fn(&Node) -> bool + '_ { - move |node| node.label() == Some(name) -} - -fn crumb(tree: &Tree) -> Option { - tree.text("folder-breadcrumb-name") -} - -fn titles(tree: &Tree) -> Vec { - tree.all("note-card-title") - .into_iter() - .map(|node| node.label().or(node.value()).unwrap_or_default().to_owned()) - .collect() -} - -fn heading(tree: &Tree) -> String { - tree.texts("note-section").join(" ") -} - -/// A note made from `from`: « + New note », or the card that offers it. -fn write(app: &mut App, from: &str, title: &str) { - app.click(from); - app.fill("editor-title", title); - app.fill("editor-body", "SELECT 1;"); - app.click("editor-close"); - app.eventually("the note is a card", |tree| { - !tree.has("editor-title") && titles(tree).contains(&title.to_owned()) - }); -} - -fn search(app: &mut App, words: &str) { - app.click("search-input"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(words); -} - -fn clear(app: &mut App) { - app.click("search-clear"); - app.eventually("the search is empty", |tree| !tree.has("search-clear")); -} - -fn seed(app: &mut App) { - step("a space of its own, a folder holding one note, one loose", || { - app.click("space-create-open"); - app.fill("space-create-input", SPACE); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the new space is shown", |tree| { - tree.texts("space-option").contains(&SPACE.to_owned()) && !tree.has("note-card") - }); - app.click("folder-create-open"); - app.fill("folder-create-input", "Perf"); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the folder is listed", |tree| tree.has("folder-option")); - app.click_where("folder-option", named("Perf")); - app.eventually("empty, it offers the card to create from, not a search", |tree| { - tree.has("create-ghost") - && !tree.has("canvas-no-results") - && heading(tree).to_uppercase().starts_with("PERF") - }); - write(app, "create-ghost", INSIDE); - app.click_where("space-option", named(SPACE)); - app.eventually("the space is shown", |tree| crumb(tree).is_none()); - write(app, "new-note", LOOSE); - app.click("view-board"); - app.wait_for("board-zone"); - }); -} - -fn inside(app: &mut App) { - step("a zone's title opens its folder, a flat grid of its notes", || { - app.click_where("board-zone-open", named("Perf")); - app.eventually("the breadcrumb names it, the grid shows its note", |tree| { - crumb(tree).as_deref() == Some("Perf") && !tree.has("board") && titles(tree) == [INSIDE] - }); - let tree = app.tree(); - assert!(heading(&tree).to_uppercase().starts_with("PERF"), "{}", heading(&tree)); - for gone in ["space-switcher", "view-board", "folder-switcher"] { - assert!(!tree.has(gone), "{gone} is put away"); - } - assert!(tree.has("create-ghost"), "a note is made from here"); - app.capture("folder-open"); - }); - - step("a search stays inside the folder, and drops the ghost", || { - search(app, "EXPLAIN"); - // The heading follows the field at once, the ghost the view once the search rests. - app.eventually("found inside, the list no longer named after it", |tree| { - titles(tree) == [INSIDE] - && !heading(tree).to_uppercase().starts_with("PERF") - && !tree.has("create-ghost") - }); - search(app, "Dump"); - app.eventually("a note of the space outside it stays out of reach", |tree| { - tree.has("canvas-no-results") && crumb(tree).is_some() - }); - clear(app); - }); - - step("a note made here arrives filed", || { - write(app, "new-note", MADE); - app.eventually("both notes are in it", |tree| titles(tree).len() == 2); - }); - - step("renamed from beside the breadcrumb", || { - app.click("folder-breadcrumb-menu"); - app.click("folder-rename-input"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text("Performance"); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the breadcrumb carries the new name", |tree| { - crumb(tree).as_deref() == Some("Performance") - }); - }); -} - -fn leaving(app: &mut App) { - step("Escape gives the search back before the folder", || { - search(app, "EXPLAIN"); - app.eventually("searched", |tree| tree.has("search-clear")); - // egui lets go of the field before the canvas reads the key: one press is one rung. - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the search is cleared, the folder kept", |tree| { - !tree.has("search-clear") && crumb(tree).is_some() - }); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("back on the board it was opened from", |tree| { - crumb(tree).is_none() && tree.has("board") - }); - }); - - step("the breadcrumb leads back too", || { - app.click_where("board-zone-open", named("Performance")); - app.wait_for("folder-breadcrumb-name"); - app.click("folder-breadcrumb-back"); - app.eventually("back on the board", |tree| crumb(tree).is_none() && tree.has("board")); - assert!( - app.tree() - .all("space-option") - .into_iter() - .any(|node| node.label() == Some(SPACE) && node.toggled() == Some(Toggled::True)) - ); - }); - - step("deleted from inside it, its notes stay on the board", || { - app.click_where("board-zone-open", named("Performance")); - app.wait_for("folder-breadcrumb-name"); - app.click("folder-breadcrumb-menu"); - app.click("folder-delete"); - app.click("folder-delete"); - app.eventually("the folder is gone, its notes loose", |tree| { - crumb(tree).is_none() && !tree.has("board-zone") && tree.count("board-loose-card") == 3 - }); - }); -} - -#[test] -fn folder_descent() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("20_folder_descent", profile.path()); - app.create_library(); - app.wait_for("note-card"); - - seed(&mut app); - inside(&mut app); - leaving(&mut app); - app.quit(); -} diff --git a/e2e/tests/38_recette_notes.rs b/e2e/tests/38_recette_notes.rs deleted file mode 100644 index 0677988b..00000000 --- a/e2e/tests/38_recette_notes.rs +++ /dev/null @@ -1,558 +0,0 @@ -//! The acceptance sheet's main paths through the notes that no other scenario walks whole. A step -//! opens on the case it runs, so that a run can be read back into the sheet. - -use e2e::old::{App, Tree, step}; -use egui::accesskit::Node; -use egui::{Key, Modifiers}; - -const SHIFT_COMMAND: Modifiers = Modifiers::COMMAND.plus(Modifiers::SHIFT); - -const SHEET: &str = "# Hébergement -prix = 0,045 €/h -serveurs = 3 -coût = prix × 730 h × serveurs -20 % de 340 -30 sur 120 en % -de 80 à 100 -250 + 20 % -300 hors 20 % -2,5 kg en g -3 h 20 min en min -1 Go en Mo - -# Courses -10 € -20 € -30 € -total -moyenne - -# Erreurs -distance = 5 km -distance + 3 Go -distance en m"; - -const RUST: &str = "editor-language-6"; -const TYPESCRIPT: &str = "editor-language-3"; - -const LITERAL: &str = "{{db_host}}\na -> b\n2 * 3 * 4\nsnake_case_name"; -const SLIDES: &str = "# Un\n\ntexte\n\n## Deux\n\n### Reste ici\n\n---\n\nTrois"; - -fn close_editor(app: &mut App) { - app.click("editor-close"); - app.eventually("the editor closed", |tree| !tree.has("editor-title")); -} - -fn open_card(app: &mut App, title: &str) { - app.click_where("note-card-open", |node| node.label().is_some_and(|label| label.contains(title))); - app.wait_for("editor-title"); -} - -fn card_titles(tree: &Tree) -> Vec { - tree.texts("note-card-title") -} - -fn has_card(tree: &Tree, title: &str) -> bool { - card_titles(tree).iter().any(|it| it == title) -} - -fn a_snippet(app: &mut App, title: &str, body: &str) { - app.click("new-note"); - app.fill("editor-title", title); - app.click("editor-body"); - app.paste(body); - close_editor(app); -} - -fn code(tree: &Tree) -> String { - tree.find("editor-body").and_then(Node::value).unwrap_or_default().to_owned() -} - -/// A snippet holding Markdown, made a Note: what a file of Markdown comes in as. -fn a_note_of(app: &mut App, title: &str, markdown: &str) { - a_snippet(app, title, markdown); - open_card(app, title); - app.click("editor-kind"); - app.click_nth("editor-kind-0", 0); - app.wait_for("editor-rich"); -} - -/// The language menu's filter takes the focus a frame after it opens; a click in it keeps the -/// menu open. -fn choose_language(app: &mut App, typed: &str, option: &str) { - app.click("editor-language"); - app.wait_for("editor-language-filter"); - app.click("editor-language-filter"); - app.eventually("the filter has the focus", |tree| tree.focused().starts_with("editor-language-filter")); - app.type_text(typed); - app.click(option); -} - -fn digits(text: &str) -> String { - text.chars().filter(char::is_ascii_digit).collect() -} - -fn calc_results(tree: &Tree) -> Vec { - tree.all("calc-result") - .into_iter() - .map(|node| digits(node.value().unwrap_or_default())) - .collect() -} - -fn a_new_library(scenario: &'static str, profile: &std::path::Path) -> App { - let mut app = App::launch(scenario, profile); - app.create_library(); - app.eventually("the samples are drawn", |tree| tree.has("note-card")); - app -} - -#[test] -fn recette_creating() { - let profile = tempfile::tempdir().unwrap(); - let mut app = a_new_library("38_recette_creating", profile.path()); - - step("NOT-02 a title alone, left by Escape, is a note", || { - app.click("new-note"); - app.fill("editor-title", "Recette première note"); - app.press(Key::Escape, Modifiers::NONE); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the card is there", |tree| { - !tree.has("editor-title") && has_card(tree, "Recette première note") - }); - }); - - step("NOT-06 a fast close writes one note, with its body", || { - app.click("new-note"); - app.fill("editor-title", "Course"); - app.fill("editor-body", "corps"); - app.press(Key::Escape, Modifiers::NONE); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the card is there", |tree| has_card(tree, "Course")); - let titles = app.tree().texts("note-card-title"); - assert_eq!(titles.iter().filter(|it| *it == "Course").count(), 1); - }); - - a_snippet(&mut app, "Psql", "psql -h localhost"); - - step("NOT-07 a title changed, another card clicked", || { - open_card(&mut app, "Course"); - app.click("editor-title"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text("Titre modifié au clic"); - app.capture("not-07-before"); - let psql = |node: &egui::accesskit::Node| node.label().is_some_and(|it| it.contains("Psql")); - // In a window too narrow to keep the cards beside the editor, none is there to click. - let beside = app.tree().all("note-card-open").into_iter().any(psql); - if beside { - app.click_where("note-card-open", psql); - } else { - close_editor(&mut app); - } - app.eventually("the editor closed or moved", |tree| { - !tree.has("editor-title") || has_card(tree, "Titre modifié au clic") - }); - app.capture("not-07-after"); - if app.has("editor-title") { - close_editor(&mut app); - } - app.eventually("the first note wears its new title", |tree| has_card(tree, "Titre modifié au clic")); - }); - - step("NOT-10 a snippet made a Note, and taken back", || { - open_card(&mut app, "Psql"); - app.click("editor-kind"); - app.click_nth("editor-kind-0", 0); - app.wait_for("editor-rich"); - app.capture("not-10-converted"); - app.click("undo-restore"); - app.wait_for("editor-body"); - close_editor(&mut app); - }); - - app.quit(); -} - -#[test] -fn recette_a_snippet_and_a_list() { - let profile = tempfile::tempdir().unwrap(); - let mut app = a_new_library("38_recette_snippet", profile.path()); - - step("COD-01 the language menu filters, and the card says it", || { - app.click("new-note"); - app.fill("editor-title", "Rouille"); - app.fill("editor-body", "fn main() { println!(\"bonjour\"); }"); - choose_language(&mut app, "rus", RUST); - app.eventually("the language is chosen", |tree| { - tree.text("editor-stats").is_some_and(|said| said.starts_with("RS")) - }); - app.capture("cod-01-coloured"); - close_editor(&mut app); - }); - - step("COD-09 a formatted snippet keeps its fields", || { - app.click("new-note"); - app.fill("editor-title", "Champs formatés"); - app.click("editor-body"); - app.paste("const url=\"{{host}}/api/{{version=v2}}\";fetch(url)"); - choose_language(&mut app, "typescript", TYPESCRIPT); - app.click("editor-format"); - app.wait_for("editor-format-notice"); - let body = code(&app.tree()); - assert!(body.contains("{{host}}/api/{{version=v2}}"), "{body}"); - assert!(body.contains(";\n"), "{body}"); - close_editor(&mut app); - }); - - step("COD-12 a word found three times, stepped through", || { - app.click("new-note"); - app.fill("editor-title", "Trois foo"); - app.fill("editor-body", "foo(); foo(); foo();"); - app.press(Key::F, Modifiers::COMMAND); - app.wait_for("search-field"); - app.type_text("foo"); - app.eventually("three are counted", |tree| { - tree.text("search-count").is_some_and(|said| said.ends_with("/ 3")) - }); - let count = app.tree().text("search-count").unwrap_or_default(); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the next one", |tree| tree.text("search-count").is_some_and(|said| said != count)); - app.click("search-previous"); - app.eventually("back to the first", |tree| { - tree.text("search-count").is_some_and(|said| said == count) - }); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the bar closed", |tree| !tree.has("search-field")); - assert!(app.has("editor-title"), "the editor stays"); - close_editor(&mut app); - }); - - step("TCH-01 Enter adds a row, the caret in it", || { - app.press(Key::L, SHIFT_COMMAND); - app.fill("editor-title", "Tâches"); - app.click("checklist-add"); - app.eventually("the row takes the caret", |tree| tree.focused().starts_with("checklist-text")); - app.type_text("Préparer"); - app.press(Key::Enter, Modifiers::NONE); - app.type_text("Déployer"); - app.eventually("two rows", |tree| { - tree.all("checklist-text") - .iter() - .filter_map(|row| row.value()) - .eq(["Préparer", "Déployer"]) - }); - close_editor(&mut app); - }); - - step("TCH-06 ticked from its card, the progress follows", || { - app.click_nth("note-card-item", 0); - app.eventually("the progress moved", |tree| { - tree.texts("note-card-progress").iter().any(|it| it.contains("1/2")) - }); - }); - - app.quit(); -} - -#[test] -fn recette_a_formatted_note() { - let profile = tempfile::tempdir().unwrap(); - let mut app = a_new_library("38_recette_rich", profile.path()); - - step("RIC-01 every button of the bar formats", || { - app.press(Key::N, SHIFT_COMMAND); - app.fill("editor-title", "Barre"); - for button in [ - "rich-h1", - "rich-h2", - "rich-h3", - "rich-bold", - "rich-italic", - "rich-strike", - "rich-code", - "rich-bullet", - "rich-ordered", - "rich-tasks", - "rich-quote", - ] { - assert!(app.has(button), "{button}"); - } - app.click("editor-rich"); - app.type_text("gras"); - app.press(Key::A, Modifiers::COMMAND); - app.click("rich-bold"); - app.capture("ric-01"); - close_editor(&mut app); - }); - - step("RIC-08 a final code block is left by the down arrow", || { - app.press(Key::N, SHIFT_COMMAND); - app.fill("editor-title", "Bloc final"); - app.click("editor-rich"); - app.click("rich-codeBlock"); - app.type_text("let x = 1;"); - app.press(Key::ArrowDown, Modifiers::NONE); - app.type_text("Suite"); - app.eventually("the text is under the block", |tree| { - tree.find("editor-rich") - .and_then(Node::value) - .is_some_and(|text| text.contains("let x = 1;") && text.contains("\nSuite")) - }); - close_editor(&mut app); - }); - - step("RIC-09 what looks like Markdown comes back as typed", || { - app.press(Key::N, SHIFT_COMMAND); - app.fill("editor-title", "Littéral"); - app.click("editor-rich"); - for line in LITERAL.lines() { - app.type_text(line); - app.press(Key::Enter, Modifiers::NONE); - } - close_editor(&mut app); - open_card(&mut app, "Littéral"); - app.capture("ric-09"); - close_editor(&mut app); - }); - - step("RIC-19 a Note presented: cover, then a slide per heading", || { - a_note_of(&mut app, "Lancement", SLIDES); - app.click("editor-present"); - app.wait_for("presentation"); - app.wait_for("presentation-cover"); - app.capture("ric-19-cover"); - let count = app.tree().text("presentation-count").unwrap_or_default(); - assert!(count.contains('1') && count.contains('4'), "{count}"); - app.press(Key::ArrowRight, Modifiers::NONE); - app.eventually("the next slide", |tree| { - tree.text("presentation-count").is_some_and(|now| now != count) - }); - app.capture("ric-19-slide"); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("it left", |tree| !tree.has("presentation")); - close_editor(&mut app); - }); - - app.quit(); -} - -#[test] -fn recette_a_sheet_and_a_drawing() { - let profile = tempfile::tempdir().unwrap(); - let mut app = a_new_library("38_recette_calc", profile.path()); - // Every result in view under the notes header, which stays above an expanded note. - app.resize(1_100, 900); - - step("CAL-45 a sheet pasted answers line by line", || { - app.press(Key::M, SHIFT_COMMAND); - // Every result in view: the sheet expanded over the cards. - app.click("editor-fullscreen"); - app.fill("editor-title", "Feuille"); - app.click("editor-body"); - app.paste(SHEET); - app.eventually("the figures are there", |tree| { - let results = calc_results(tree); - ["9855", "68", "25", "300", "250", "2500", "200", "1000", "6000", "2000", "5000"] - .iter() - .all(|it| results.contains(&(*it).to_owned())) - }); - app.eventually("one line refused, the next carries on", |tree| tree.count("calc-failure") == 1); - app.capture("cal-45"); - }); - - step("CAL-37 results picked: a range, then a stranger", || { - app.click_where("calc-result", |node| node.value().is_some_and(|it| digits(it) == "1000")); - app.eventually("the footer sums it", |tree| { - tree.text("calc-summary").is_some_and(|said| digits(&said).contains("1000")) - }); - close_editor(&mut app); - }); - - step("DES-01 an empty drawing says what to do", || { - app.press(Key::D, SHIFT_COMMAND); - app.fill("editor-title", "Plan"); - app.wait_for("drawing-stage"); - app.capture("des-01"); - }); - - step("DES-02 three shapes from their letters", || { - app.click("drawing-stage"); - for (key, from, to) in [ - (Key::R, (40.0, 40.0), (140.0, 100.0)), - (Key::O, (180.0, 40.0), (280.0, 100.0)), - (Key::D, (320.0, 40.0), (420.0, 100.0)), - ] { - app.press(key, Modifiers::NONE); - app.drag_in("drawing-stage", from, to); - } - app.eventually("the footer counts three", |tree| { - tree.text("editor-stats").is_some_and(|said| said.contains('3')) - }); - app.capture("des-02"); - }); - - step("DES-09 the drawing is kept, its card shows it", || { - close_editor(&mut app); - app.wait_for("note-card-drawing"); - app.click("note-card-drawing"); - app.wait_for("drawing-stage"); - app.eventually("the footer still counts three", |tree| { - tree.text("editor-stats").is_some_and(|said| said.contains('3')) - }); - close_editor(&mut app); - }); - - step("DES-13 a drawing inserted into a Note shows its picture", || { - app.press(Key::N, SHIFT_COMMAND); - app.fill("editor-title", "Avec dessin"); - app.click("rich-embed-drawing"); - app.click("rich-embed-drawing-0"); - app.wait_for("rich-embed"); - app.capture("des-13"); - }); - - step("a drawing in a Note is resized, and stays so", || { - let width = |tree: &Tree| { - let drawn = tree.find("rich-embed").and_then(Node::bounds); - drawn.map_or(0.0, |bounds| bounds.width()) - }; - app.click("rich-embed"); - app.click("rich-embed-size-4"); - app.wait_for("rich-embed-resize"); - let whole = width(&app.tree()); - app.click("rich-embed-size-1"); - app.eventually("a quarter of the width", |tree| (width(tree) - whole / 4.0).abs() < 2.0); - app.drag_in("rich-embed-resize", (12.0, 12.0), (1_200.0, 12.0)); - app.eventually("the whole width again", |tree| (width(tree) - whole).abs() < 2.0); - app.capture("des-13-sized"); - close_editor(&mut app); - open_card(&mut app, "Avec dessin"); - app.eventually("kept", |tree| (width(tree) - whole).abs() < 2.0); - close_editor(&mut app); - }); - - app.quit(); -} - -#[test] -fn recette_on_the_canvas() { - let profile = tempfile::tempdir().unwrap(); - let mut app = a_new_library("38_recette_canvas", profile.path()); - - step("MET-01 three spellings are one tag", || { - a_snippet(&mut app, "Avec tags", "echo tags"); - open_card(&mut app, "Avec tags"); - for tag in ["devops", "#DevOps", " DEVOPS "] { - app.fill("editor-tag-add", tag); - app.press(Key::Enter, Modifiers::NONE); - } - app.eventually("one tag", |tree| tree.count("editor-tag") == 1); - close_editor(&mut app); - }); - - step("CLV-01 the arrows walk the cards, Enter opens", || { - app.press(Key::ArrowDown, Modifiers::NONE); - app.press(Key::ArrowRight, Modifiers::NONE); - app.press(Key::Enter, Modifiers::NONE); - app.wait_for("editor-title"); - close_editor(&mut app); - }); - - step("MET-04 P pins and unpins, no date moves", || { - let sorted = |mut dates: Vec| { - dates.sort(); - dates - }; - let when = sorted(app.tree().texts("note-card-when")); - let pinned = app.tree().count("note-card-pin"); - app.press(Key::ArrowDown, Modifiers::NONE); - app.press(Key::P, Modifiers::NONE); - app.eventually("the pin moved", |tree| tree.count("note-card-pin") != pinned); - assert_eq!(sorted(app.tree().texts("note-card-when")), when); - app.click("undo-restore"); - app.eventually("the pin is back", |tree| tree.count("note-card-pin") == pinned); - }); - - step("CLV-02 C copies a plain card and says so", || { - app.press(Key::ArrowDown, Modifiers::NONE); - app.press(Key::C, Modifiers::NONE); - app.wait_for("status-toast"); - app.capture("clv-02"); - }); - - step("SEL-02 a selection moved to a space, and taken back", || { - app.click("space-create-open"); - app.fill("space-create-input", "Perso"); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the new space is shown, empty", |tree| !tree.has("note-card")); - app.click("space-option-all"); - app.eventually("the cards are back", |tree| tree.has("note-card")); - app.press(Key::ArrowDown, Modifiers::NONE); - for key in [Key::X, Key::ArrowRight, Key::X] { - app.press(key, Modifiers::NONE); - } - app.click("selection-move"); - app.click_where("selection-move-place", |node| node.label() == Some("Perso")); - app.wait_for("undo-text"); - app.capture("sel-02"); - app.click("undo-restore"); - app.eventually("the bar went", |tree| !tree.has("undo-text")); - }); - - step("SEL-09 a selection trashed, then given back whole", || { - let cards = app.tree().count("note-card"); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the selection let go", |tree| !tree.has("selection-count")); - app.press(Key::ArrowDown, Modifiers::NONE); - for key in [Key::X, Key::ArrowRight, Key::X] { - app.press(key, Modifiers::NONE); - } - app.click("selection-delete"); - app.click("selection-delete"); - app.eventually("two left", |tree| tree.count("note-card") == cards - 2); - app.click("undo-restore"); - app.eventually("both back", |tree| tree.count("note-card") == cards); - }); - - app.quit(); -} - -#[test] -fn recette_a_line_gone_to() { - let profile = tempfile::tempdir().unwrap(); - let mut app = a_new_library("38_recette_go_to_line", profile.path()); - - step("COD-15 Ctrl+Alt+G goes to a line, the keys back in the code", || { - app.click("new-note"); - app.fill("editor-title", "Lignes"); - app.click("editor-body"); - app.paste("un\ndeux\ntrois"); - app.press(Key::G, Modifiers::COMMAND | Modifiers::ALT); - app.eventually("the field has the focus", |tree| tree.focused().starts_with("go-to-line-input")); - app.type_text("2"); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the code has the focus", |tree| { - !tree.has("go-to-line-input") && tree.focused().starts_with("editor-body") - }); - app.type_text("X"); - app.eventually("typed on line 2", |tree| code(tree) == "un\nXdeux\ntrois"); - close_editor(&mut app); - }); - - app.quit(); -} - -/// The focus follows the card: the second P reaches the note the first one moved. -#[test] -fn recette_a_second_p_gives_the_card_back() { - let profile = tempfile::tempdir().unwrap(); - let mut app = a_new_library("38_ko_met_04", profile.path()); - app.eventually("the six samples", |tree| tree.count("note-card") == 6); - app.press(Key::ArrowDown, Modifiers::NONE); - app.press(Key::ArrowDown, Modifiers::NONE); - app.press(Key::ArrowRight, Modifiers::NONE); - app.press(Key::P, Modifiers::NONE); - app.eventually("a second pin", |tree| tree.count("note-card-pin") == 2); - app.press(Key::P, Modifiers::NONE); - app.eventually("back to one pin", |tree| tree.count("note-card-pin") == 1); - app.quit(); -} From df41ff9d486e137f9b54c1f2d839b82e9fd05c8b Mon Sep 17 00:00:00 2001 From: Valentin Millet Date: Fri, 4 Dec 2026 04:09:22 +0100 Subject: [PATCH 2/4] Clicks and the rail wait for the screen to answer --- e2e/src/sdk/act.rs | 13 +++++++++++++ e2e/src/sdk/gate.rs | 15 +++------------ e2e/src/sdk/rail.rs | 10 ++++++++++ e2e/src/sdk/rich.rs | 5 ++++- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/e2e/src/sdk/act.rs b/e2e/src/sdk/act.rs index b6c7b223..81bec5a2 100644 --- a/e2e/src/sdk/act.rs +++ b/e2e/src/sdk/act.rs @@ -89,6 +89,19 @@ 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, id: &str, name: &str, answered: impl Fn(&Tree) -> bool) { + let until = Instant::now() + PATIENCE; + loop { + self.click(id, name); + 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(); diff --git a/e2e/src/sdk/gate.rs b/e2e/src/sdk/gate.rs index 8bb7ccc0..08eec7e9 100644 --- a/e2e/src/sdk/gate.rs +++ b/e2e/src/sdk/gate.rs @@ -1,7 +1,5 @@ -use std::time::Instant; - use super::App; -use crate::driver::{PATIENCE, Tree}; +use crate::driver::Tree; /// The gate: a phrase makes the library, then opens it. pub struct Gate<'a>(pub(super) &'a mut App); @@ -39,16 +37,9 @@ impl Gate<'_> { self.0.fill("vault-confirmation", "the confirmation's field", phrase); } - /// Clicks the button that makes or opens the library. ⚠️ On a machine whose own pointer moves, a - /// click can be dropped: clicked again until the gate answers. + /// Clicks the button that makes or opens the library. pub fn submit(&mut self) { - let until = Instant::now() + PATIENCE; - while Instant::now() < until { - self.0.click("vault-submit", "the gate's button"); - if (0..20).any(|_| answered(&self.0.tree())) { - return; - } - } + self.0.click_until("vault-submit", "the gate's button", answered); } /// The gate asks for a phrase twice: this profile has no library yet. diff --git a/e2e/src/sdk/rail.rs b/e2e/src/sdk/rail.rs index 5d341447..a6be59fa 100644 --- a/e2e/src/sdk/rail.rs +++ b/e2e/src/sdk/rail.rs @@ -158,6 +158,9 @@ impl Rail<'_> { let from = self.folder_row(name); let to = self.0.place("the space in the rail", |tree| row(tree, "space-option", space)); self.0.drag(middle(from), middle(to)); + self.0.expect("the folder is listed under the space", |tree| { + space_of(tree, name) == Some(space.to_owned()) + }); } /// Takes the keyboard to a folder and moves it out of the one it is in, Alt+←. @@ -262,6 +265,13 @@ fn row(tree: &Tree, id: &str, name: &str) -> Option { tree.all(id).into_iter().find(|row| said(row) == name).and_then(Node::bounds) } +/// The space a folder is listed under: the last row of a space above its own. +fn space_of(tree: &Tree, folder: &str) -> Option { + let folder = row(tree, "folder-option", folder)?; + let above = |space: &&Node| space.bounds().is_some_and(|bounds| bounds.y0 < folder.y0); + tree.all("space-option").into_iter().rfind(above).map(said) +} + fn is_shown(tree: &Tree, space: &str) -> bool { tree.all("space-option").into_iter().any(|row| said(row) == space && is_on(row)) } diff --git a/e2e/src/sdk/rich.rs b/e2e/src/sdk/rich.rs index d6d91d1a..5c04d24e 100644 --- a/e2e/src/sdk/rich.rs +++ b/e2e/src/sdk/rich.rs @@ -148,7 +148,10 @@ impl Rich<'_> { /// Selects the drawing shown in the Note and gives it a part of the Note's width. pub fn size_drawing(&mut self, size: DrawingSize) { - self.0.click("rich-embed", "the drawing in the Note"); + if !self.0.tree().has("rich-embed-resize") { + self.0 + .click_until("rich-embed", "the drawing in the Note", |tree| tree.has("rich-embed-resize")); + } let id = match size { DrawingSize::Quarter => "rich-embed-size-1", DrawingSize::Whole => "rich-embed-size-4", From 9f5fbe6da7770d8d0f32670f715eda4419377c95 Mon Sep 17 00:00:00 2001 From: Valentin Millet Date: Fri, 4 Dec 2026 04:52:50 +0100 Subject: [PATCH 3/4] A drawing in a Note is picked by its top --- e2e/src/sdk/act.rs | 16 +++++++++++----- e2e/src/sdk/gate.rs | 6 +++++- e2e/src/sdk/notes.rs | 4 ++-- e2e/src/sdk/rich.rs | 7 ++++++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/e2e/src/sdk/act.rs b/e2e/src/sdk/act.rs index 81bec5a2..31b402ea 100644 --- a/e2e/src/sdk/act.rs +++ b/e2e/src/sdk/act.rs @@ -91,10 +91,15 @@ impl App { /// 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, id: &str, name: &str, answered: impl Fn(&Tree) -> bool) { + 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 { - self.click(id, name); + click(self); if (0..20).any(|_| answered(&self.tree())) { return; } @@ -116,10 +121,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); } diff --git a/e2e/src/sdk/gate.rs b/e2e/src/sdk/gate.rs index 08eec7e9..10eec5c9 100644 --- a/e2e/src/sdk/gate.rs +++ b/e2e/src/sdk/gate.rs @@ -39,7 +39,11 @@ impl Gate<'_> { /// Clicks the button that makes or opens the library. pub fn submit(&mut self) { - self.0.click_until("vault-submit", "the gate's button", answered); + self.0.click_until( + "the gate's button", + |app| app.click("vault-submit", "the gate's button"), + answered, + ); } /// The gate asks for a phrase twice: this profile has no library yet. diff --git a/e2e/src/sdk/notes.rs b/e2e/src/sdk/notes.rs index b22e8fed..e3d7577d 100644 --- a/e2e/src/sdk/notes.rs +++ b/e2e/src/sdk/notes.rs @@ -147,7 +147,7 @@ impl Notes<'_> { /// Opens a note by its card. pub fn open(&mut self, note: impl Named) { let card = self.card(note); - self.0.click_card(card); + self.0.click_top(card); self.0.expect("the note opens", |tree| tree.has("editor-title")); } @@ -239,7 +239,7 @@ impl Notes<'_> { pub(super) fn click_holding(&mut self, held: Modifiers, note: impl Named) { let card = self.card(note); self.0.hold(held); - self.0.click_card(card); + self.0.click_top(card); self.0.hold(Modifiers::NONE); } diff --git a/e2e/src/sdk/rich.rs b/e2e/src/sdk/rich.rs index 5c04d24e..dde0dbbc 100644 --- a/e2e/src/sdk/rich.rs +++ b/e2e/src/sdk/rich.rs @@ -149,8 +149,13 @@ impl Rich<'_> { /// Selects the drawing shown in the Note and gives it a part of the Note's width. pub fn size_drawing(&mut self, size: DrawingSize) { if !self.0.tree().has("rich-embed-resize") { + let drawing = |tree: &Tree| tree.find("rich-embed").and_then(Node::bounds); + let click = |app: &mut App| { + let place = app.place("the drawing in the Note", drawing); + app.click_top(place); + }; self.0 - .click_until("rich-embed", "the drawing in the Note", |tree| tree.has("rich-embed-resize")); + .click_until("the drawing in the Note", click, |tree| tree.has("rich-embed-resize")); } let id = match size { DrawingSize::Quarter => "rich-embed-size-1", From 25d40e04ab6190b3c5a83576e66e3d9beb222500 Mon Sep 17 00:00:00 2001 From: Valentin Millet Date: Fri, 4 Dec 2026 09:49:45 +0100 Subject: [PATCH 4/4] A journey fails instead of waiting for ever --- e2e/src/driver.rs | 7 ++++++- e2e/src/sdk/act.rs | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/e2e/src/driver.rs b/e2e/src/driver.rs index 65a779fe..c0c2ffc7 100644 --- a/e2e/src/driver.rs +++ b/e2e/src/driver.rs @@ -273,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}") + } } } } @@ -326,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; diff --git a/e2e/src/sdk/act.rs b/e2e/src/sdk/act.rs index 31b402ea..6cb5d5e8 100644 --- a/e2e/src/sdk/act.rs +++ b/e2e/src/sdk/act.rs @@ -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 { 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()); } }