diff --git a/e2e/src/driver.rs b/e2e/src/driver.rs index 5e323727..9219d698 100644 --- a/e2e/src/driver.rs +++ b/e2e/src/driver.rs @@ -8,7 +8,7 @@ use std::path::{Path, PathBuf}; use std::process::{Child, Command, Stdio}; use std::time::{Duration, Instant}; -use egui::accesskit::{Node, NodeId, Rect, Toggled, TreeUpdate}; +use egui::accesskit::{Node, NodeId, Rect, Role, Toggled, TreeUpdate}; use egui::{Event, Pos2}; use egui_inspection::protocol::{self, Request, Response}; @@ -93,10 +93,25 @@ impl Tree { self.find(id).map(said) } + /// Whether the middle of a place is inside the window, where it can be clicked. + pub(crate) fn in_window(&self, place: Rect) -> bool { + let window = self.nodes.iter().find(|(_, node)| node.role() == Role::Window); + let Some(window) = window.and_then(|(_, node)| node.bounds()) else { + return true; + }; + let at = middle(place); + let inside = |x: f32, from: f64, to: f64| (from..to).contains(&f64::from(x)); + inside(at.x, window.x0, window.x1) && inside(at.y, window.y0, window.y1) + } + pub(crate) fn is_disabled(&self, id: &str) -> bool { self.find(id).is_some_and(Node::is_disabled) } + pub(crate) fn is_on(&self, id: &str) -> bool { + self.find(id).is_some_and(is_on) + } + pub(crate) fn has_focus(&self, id: &str) -> bool { self.focused().is_some_and(|node| node.author_id() == Some(id)) } diff --git a/e2e/src/sdk/act.rs b/e2e/src/sdk/act.rs index 1197f352..a52e8058 100644 --- a/e2e/src/sdk/act.rs +++ b/e2e/src/sdk/act.rs @@ -81,7 +81,7 @@ impl App { pub(super) fn click_nth_where(&mut self, id: &str, n: usize, name: &str, which: impl Fn(&Node) -> bool) { let bounds = self.place(name, |tree| { let picked = tree.all(id).into_iter().filter(|node| which(node)).nth(n); - picked.and_then(Node::bounds) + picked.and_then(Node::bounds).filter(|bounds| tree.in_window(*bounds)) }); if id != DISMISS && self.uncover(bounds) { return self.click_nth_where(id, n, name, which); @@ -117,6 +117,37 @@ impl App { self.clicked = Some(Instant::now()); } + /// 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.click_nth(id, n, name); + self.driver.apply(vec![Event::ModifiersChanged(Modifiers::NONE)]); + } + + /// The right button, on a control. + pub(super) fn right_click(&mut self, id: &str, name: &str) { + let bounds = self.place(name, |tree| tree.find(id).and_then(Node::bounds)); + self.click_at(middle(bounds), PointerButton::Secondary); + } + + /// A press and a release elsewhere, the pointer moved half way between: what a gesture needs to + /// tell a drag from a click. + pub(super) fn drag(&mut self, from: Pos2, to: Pos2) { + let button = PointerButton::Primary; + self.driver.apply(vec![Event::PointerMoved(from)]); + self.driver.apply(vec![press(from, button, true)]); + self.driver.apply(vec![Event::PointerMoved(from + (to - from) / 2.0)]); + self.driver.apply(vec![Event::PointerMoved(to)]); + self.driver.apply(vec![press(to, button, false)]); + self.clicked = Some(Instant::now()); + } + + /// A control dragged by so much. + pub(super) fn drag_by(&mut self, id: &str, name: &str, by: egui::Vec2) { + let from = middle(self.place(name, |tree| tree.find(id).and_then(Node::bounds))); + self.drag(from, from + by); + } + /// Two clicks, sent together so that they are one double click however slowly the window draws. /// ⚠️ A click just before makes egui count three, wherever it was: they wait their turn. pub(super) fn double_click(&mut self, pos: Pos2) { diff --git a/e2e/src/sdk/calc.rs b/e2e/src/sdk/calc.rs new file mode 100644 index 00000000..a7f5a00e --- /dev/null +++ b/e2e/src/sdk/calc.rs @@ -0,0 +1,52 @@ +use egui::accesskit::Node; + +use super::{App, Modifiers}; +use crate::driver::Tree; + +/// The calculation open. Its results are read by their figures: the language on the screen writes +/// the decimal mark and the units. +pub struct Calc<'a>(pub(super) &'a mut App); + +impl Calc<'_> { + /// Picks a result, counted from 0. + pub fn pick(&mut self, result: usize) { + self.0.click_nth("calc-result", result, "the result"); + } + + /// Picks a result beside those picked, Ctrl held. + pub fn pick_also(&mut self, result: usize) { + self.0.click_holding(Modifiers::COMMAND, "calc-result", result, "the result"); + } + + /// The results, top to bottom, by their figures. + pub fn expect_results(&mut self, figures: &[&str], says: &str) { + self.0.expect(says, |tree| results(tree) == figures); + } + + /// As many lines say why they have no result. + pub fn expect_errors(&mut self, count: usize, says: &str) { + self.0.expect(says, |tree| { + let errors = tree.all("calc-failure"); + errors.len() == count && errors.iter().all(|error| !said(error).is_empty()) + }); + } + + /// The footer sums what is picked, by its figures. + pub fn expect_sum(&mut self, figures: &str, says: &str) { + self.0.expect(says, |tree| { + tree.text("calc-summary").is_some_and(|said| digits(&said).contains(figures)) + }); + } +} + +fn results(tree: &Tree) -> Vec { + tree.all("calc-result").into_iter().map(|node| digits(said(node))).collect() +} + +fn said(node: &Node) -> &str { + node.value().unwrap_or_default() +} + +pub(super) fn digits(text: &str) -> String { + text.chars().filter(char::is_ascii_digit).collect() +} diff --git a/e2e/src/sdk/clipboard.rs b/e2e/src/sdk/clipboard.rs index 9052880f..89a6fac9 100644 --- a/e2e/src/sdk/clipboard.rs +++ b/e2e/src/sdk/clipboard.rs @@ -20,7 +20,7 @@ impl Clipboard<'_> { self.expect_that(says, |held| held.contains(words)); } - fn expect_that(&mut self, says: &str, holds: impl Fn(&str) -> bool) { + pub(super) fn expect_that(&mut self, says: &str, holds: impl Fn(&str) -> bool) { let until = Instant::now() + PATIENCE; loop { let held = platform::clipboard::System.text().unwrap_or_default(); diff --git a/e2e/src/sdk/drawing.rs b/e2e/src/sdk/drawing.rs new file mode 100644 index 00000000..4c7f9485 --- /dev/null +++ b/e2e/src/sdk/drawing.rs @@ -0,0 +1,169 @@ +use egui::accesskit::Node; +use egui::{Pos2, Vec2}; + +use super::{App, Key, Modifiers, Shortcut}; +use crate::current_step; + +/// The drawing open. Places on it are named by the journey and stand still, zoom aside. +pub struct Drawing<'a>(pub(super) &'a mut App); + +/// A tool in hand. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Tool { + Rectangle, + Ellipse, + Diamond, + Arrow, + Text, +} + +/// A place on the drawing: its left, its middle or its right, each wide enough for a shape. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Spot { + Left, + Middle, + Right, + Below, +} + +impl Spot { + /// Its corner, in points from the stage's. + fn corner(self) -> Vec2 { + match self { + Self::Left => Vec2::new(40.0, 40.0), + Self::Middle => Vec2::new(200.0, 40.0), + Self::Right => Vec2::new(360.0, 40.0), + Self::Below => Vec2::new(200.0, 220.0), + } + } + + fn middle(self) -> Vec2 { + self.corner() + SHAPE / 2.0 + } +} + +const SHAPE: Vec2 = Vec2::new(100.0, 70.0); + +impl Drawing<'_> { + /// Draws a shape at a place, its tool taken by its button. + pub fn draw(&mut self, tool: Tool, at: Spot) { + let shapes = self.shapes(); + self.take(tool); + self.drag(at.corner(), at.corner() + SHAPE); + self.expect_shapes(shapes + 1, "the shape is drawn"); + } + + /// Draws an arrow from the shape of one place to the shape of another. + pub fn draw_arrow(&mut self, from: Spot, to: Spot) { + let shapes = self.shapes(); + self.take(Tool::Arrow); + self.drag(from.middle(), to.middle()); + self.expect_shapes(shapes + 1, "the arrow is drawn"); + } + + /// Writes a text at a place. + pub fn write(&mut self, text: &str, at: Spot) { + let shapes = self.shapes(); + self.take(Tool::Text); + self.drag(at.corner(), at.corner()); + self.0.expect("a text waits to be typed", |tree| tree.has("drawing-text")); + self.0.type_text(text); + self.0.press(Shortcut::Escape); + self.expect_shapes(shapes + 1, "the text is on the drawing"); + } + + /// Drags the shape of one place to another. + pub fn move_shape(&mut self, from: Spot, to: Spot) { + self.take_selection(); + self.drag(from.middle(), to.middle()); + } + + /// Selects the shape of a place and removes it with Delete. + pub fn delete(&mut self, at: Spot) { + self.take_selection(); + self.drag(at.middle(), at.middle()); + self.0.press(Shortcut::Delete); + } + + /// Zooms in, by its button. + pub fn zoom_in(&mut self) { + self.0.click("drawing-zoom-in", "the button that zooms in"); + } + + /// Shows the whole drawing, by its key. + pub fn show_whole(&mut self) { + // The stage takes the keys from a click on its ground. + self.take_selection(); + self.drag(Vec2::new(8.0, 8.0), Vec2::new(8.0, 8.0)); + self.0.key(Key::F, Modifiers::NONE); + } + + /// Exports the drawing as a PNG, the dialog answering where. + pub fn export_png(&mut self, file: &str) { + self.0.files().answer(file); + self.0.click("drawing-export-png", "« PNG »"); + } + + /// Exports the drawing as an SVG, the dialog answering where. + pub fn export_svg(&mut self, file: &str) { + self.0.files().answer(file); + self.0.click("drawing-export-svg", "« SVG »"); + } + + /// As many shapes are on the drawing, arrows and texts among them. + pub fn expect_shapes(&mut self, count: usize, says: &str) { + let count = count.to_string(); + self.0 + .expect(says, |tree| tree.find("drawing-stage").and_then(Node::value) == Some(count.as_str())); + } + + /// Between two SVG exports, the arrow moved. + pub fn expect_arrow_moved(&mut self, before: &str, after: &str, says: &str) { + let arrow = |bytes: Vec| { + let picture = String::from_utf8_lossy(&bytes).into_owned(); + picture.split(" usize { + self.0.expect("the drawing is open", |tree| tree.has("drawing-stage")); + let tree = self.0.tree(); + let count = tree.find("drawing-stage").and_then(Node::value); + count.and_then(|count| count.parse().ok()).unwrap_or_default() + } + + /// A tool by its button. + fn take(&mut self, tool: Tool) { + let id = match tool { + Tool::Rectangle => "drawing-tool-rectangle", + Tool::Ellipse => "drawing-tool-ellipse", + Tool::Diamond => "drawing-tool-diamond", + Tool::Arrow => "drawing-tool-arrow", + Tool::Text => "drawing-tool-text", + }; + self.0.click(id, "the tool's button"); + self.0.expect("the tool is in hand", |tree| tree.is_on(id)); + } + + fn take_selection(&mut self) { + self.0.click("drawing-tool-select", "the pointer's tool"); + } + + fn drag(&mut self, from: Vec2, to: Vec2) { + let stage = self + .0 + .place("the drawing", |tree| tree.find("drawing-stage").and_then(Node::bounds)); + #[expect(clippy::cast_possible_truncation, reason = "points on a screen")] + let corner = Pos2::new(stage.x0 as f32, stage.y0 as f32); + self.0.drag(corner + from, corner + to); + } +} diff --git a/e2e/src/sdk/editor.rs b/e2e/src/sdk/editor.rs index 83b78d20..41475c46 100644 --- a/e2e/src/sdk/editor.rs +++ b/e2e/src/sdk/editor.rs @@ -74,16 +74,6 @@ impl Editor<'_> { self.0.expect("the calendar closes", |tree| !tree.has("date-day")); } - /// Adds a task to the todo list, typed. - pub fn add_task(&mut self, words: &str) { - let before = self.0.tree().count("checklist-text"); - self.0.click("checklist-add", "« Add a task »"); - self.0.expect("a new row takes the keyboard", |tree| { - tree.count("checklist-text") == before + 1 && tree.has_focus("checklist-text") - }); - self.0.type_text(words); - } - /// Types in a Note, where its caret is. pub fn type_note(&mut self, text: &str) { self.0.take_keyboard("editor-rich", "the Note's text"); @@ -137,6 +127,14 @@ impl Editor<'_> { }); } + /// Makes the note a Note, from its *Kind* menu. + pub fn convert_to_note(&mut self) { + // The menu offers the other kinds, the snippet first: a list's has it above « Note ». + let note = if self.0.tree().has("checklist-add") { "editor-kind-1" } else { "editor-kind-0" }; + self.0.click("editor-kind", "the « Kind » menu"); + self.0.click(note, "« Note » in the menu"); + } + /// Shows the text filled with its fields, or gives the code back. pub fn flip_filled(&mut self) { self.0 @@ -205,14 +203,6 @@ impl Editor<'_> { .expect(says, |tree| tree.text("search-count").as_deref() == Some(counted)); } - /// The result of a calculation's first line, its figures alone: the marks are the language's. - pub fn expect_first_result(&mut self, figures: &str, says: &str) { - self.0.expect(says, |tree| { - let first = tree.all("calc-result").first().and_then(|result| result.value()); - first.is_some_and(|result| digits(result) == figures) - }); - } - /// The first line of the code goes on past the edge: the next row is another line's. pub fn expect_line_unwrapped(&mut self, says: &str) { self.mark_the_next_row(); @@ -269,6 +259,13 @@ impl Editor<'_> { self.0.expect(says, |tree| held(tree).contains(code)); } + /// The note's kind is said, and cannot be changed. + pub fn expect_no_kind_to_choose(&mut self, says: &str) { + self.0.click("editor-kind", "the note's kind"); + self.0 + .expect_at_rest(says, |tree| tree.has("editor-kind") && !tree.has("editor-kind-0")); + } + /// The note's title. pub fn expect_title(&mut self, title: &str, says: &str) { self.0 @@ -296,7 +293,7 @@ impl Editor<'_> { } /// A button of the note's header, or its entry of the ⋯ menu where there is no room for it. - fn click_button_or_entry(&mut self, id: &str, name: &str) { + pub(super) fn click_button_or_entry(&mut self, id: &str, name: &str) { if !self.0.tree().has(id) { self.0.click("editor-more", "the note's « ⋯ »"); } @@ -332,7 +329,3 @@ fn held(tree: &Tree) -> String { fn notice(tree: &Tree) -> Option<&str> { tree.find("editor-format-notice").and_then(Node::description) } - -fn digits(text: &str) -> String { - text.chars().filter(char::is_ascii_digit).collect() -} diff --git a/e2e/src/sdk/files.rs b/e2e/src/sdk/files.rs index 7b10fd49..ceae082c 100644 --- a/e2e/src/sdk/files.rs +++ b/e2e/src/sdk/files.rs @@ -24,6 +24,13 @@ impl Files<'_> { self.0.expect(says, |_| std::fs::read(&path).is_ok_and(|bytes| holds(&bytes))); } + /// What a file holds, once it is written. + pub(super) fn read(&mut self, name: &str, says: &str) -> Vec { + let path = self.path(name); + self.0 + .seen(says, |_| std::fs::read(&path).ok().filter(|bytes| !bytes.is_empty())) + } + /// Where a file of the person's own is. fn path(&self, name: &str) -> PathBuf { self.0.room.path().join("files").join(name) diff --git a/e2e/src/sdk/mod.rs b/e2e/src/sdk/mod.rs index 3b753f8f..28f99cf2 100644 --- a/e2e/src/sdk/mod.rs +++ b/e2e/src/sdk/mod.rs @@ -3,7 +3,9 @@ mod act; mod attachments; +mod calc; mod clipboard; +mod drawing; mod editor; mod fields; mod files; @@ -14,13 +16,17 @@ mod http; mod json; mod notes; mod prefs; +mod rich; mod shortcut; +mod todo; mod tools; mod trash; mod window; pub use attachments::Attachments; +pub use calc::Calc; pub use clipboard::Clipboard; +pub use drawing::{Drawing, Spot, Tool}; pub use editor::Editor; pub use egui::Key; pub use fields::Fields; @@ -30,9 +36,11 @@ pub use help::Help; pub use history::History; pub use http::Http; pub use json::{Json, JsonView}; -pub use notes::{Named, Notes, QuickFilter, Sample}; +pub use notes::{Kind, Named, Notes, QuickFilter, Sample}; pub use prefs::{CardKey, DefaultKind, Density, Indent, Language, Page, Prefs, Switch, Theme}; +pub use rich::{DrawingSize, Presentation, Rich, RichTool}; pub use shortcut::Shortcut; +pub use todo::Todo; pub use tools::Tools; pub use trash::Trash; pub use window::{Area, Window}; @@ -41,7 +49,7 @@ use std::ffi::OsString; use std::path::{Path, PathBuf}; use std::time::Instant; -use egui::Event; +use egui::{Event, Modifiers}; use tempfile::TempDir; use crate::driver::Driver; @@ -105,6 +113,31 @@ impl App { Editor(self) } + /// The Note open, written formatted. + pub fn rich(&mut self) -> Rich<'_> { + Rich(self) + } + + /// The Note open, presented. + pub fn presentation(&mut self) -> Presentation<'_> { + Presentation(self) + } + + /// The todo list open. + pub fn todo(&mut self) -> Todo<'_> { + Todo(self) + } + + /// The calculation open. + pub fn calc(&mut self) -> Calc<'_> { + Calc(self) + } + + /// The drawing open. + pub fn drawing(&mut self) -> Drawing<'_> { + Drawing(self) + } + /// The files attached to the note open. pub fn attachments(&mut self) -> Attachments<'_> { Attachments(self) diff --git a/e2e/src/sdk/notes.rs b/e2e/src/sdk/notes.rs index 44e0c7ac..c6b4fed0 100644 --- a/e2e/src/sdk/notes.rs +++ b/e2e/src/sdk/notes.rs @@ -49,6 +49,16 @@ impl Named for Sample { } } +/// A kind of note. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Kind { + Note, + Snippet, + TodoList, + Calculation, + Drawing, +} + /// The quick filter of the header. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum QuickFilter { @@ -115,11 +125,18 @@ impl Notes<'_> { self.click_on_card(note, "note-card-menu", "the card's « ⋯ »"); } - /// A calculation, from the menu beside *New note*. - pub fn new_calculation(&mut self) { + /// A note of a kind, from the menu beside *New note*. + pub fn new_of_kind(&mut self, kind: Kind) { + let (id, name) = match kind { + Kind::Note => ("new-note-note", "« Note »"), + Kind::Snippet => ("new-note-snippet", "« Snippet »"), + Kind::TodoList => ("new-note-checklist", "« Todo list »"), + Kind::Calculation => ("new-note-calc", "« Calculation »"), + Kind::Drawing => ("new-note-drawing", "« Drawing »"), + }; self.0.click("new-note-kind", "the menu beside « New note »"); - self.0.click("new-note-calc", "« Calculation »"); - self.0.expect("a new calculation opens", |tree| tree.has("calc-counts")); + self.0.click(id, name); + self.0.expect("a new note opens", |tree| tree.has("editor-title")); } /// A snippet written and closed: its title and its code. @@ -200,7 +217,7 @@ impl Notes<'_> { pub fn write_todo_list(&mut self, title: &str, task: &str) { self.0.press(Shortcut::NewTodoList); self.0.editor().type_title(title); - self.0.editor().add_task(task); + self.0.todo().add(task); self.0.editor().close(); self.expect_card(title, "the list is a card"); } @@ -334,6 +351,26 @@ impl Notes<'_> { }); } + /// A calculation's card shows its lines and their results. + pub fn expect_calculation(&mut self, note: impl Named, says: &str) { + self.0.expect(says, |tree| { + let Some(card) = card_of(tree, note) else { + return false; + }; + tree.all("note-card-calc").into_iter().any(|lines| within(lines, card)) + }); + } + + /// A drawing's card shows its picture. + pub fn expect_picture(&mut self, note: impl Named, says: &str) { + self.0.expect(says, |tree| { + let Some(card) = card_of(tree, note) else { + return false; + }; + tree.all("note-card-drawing").into_iter().any(|picture| within(picture, card)) + }); + } + /// The undo bar is gone: its offer had its time. pub fn expect_undo_gone(&mut self, says: &str) { self.0.expect(says, |tree| !tree.has("undo-bar")); diff --git a/e2e/src/sdk/rich.rs b/e2e/src/sdk/rich.rs new file mode 100644 index 00000000..d6d91d1a --- /dev/null +++ b/e2e/src/sdk/rich.rs @@ -0,0 +1,250 @@ +use egui::accesskit::Node; + +use super::{App, Shortcut}; +use crate::driver::{Tree, is_on}; + +/// A Note's text, written formatted. +pub struct Rich<'a>(pub(super) &'a mut App); + +/// A button of the toolbar. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum RichTool { + Heading1, + Heading2, + Heading3, + Bold, + Italic, + Strikethrough, + InlineCode, + BulletList, + NumberedList, + TaskList, + Quote, + CodeBlock, + Table, + RowBelow, + ColumnAfter, +} + +impl RichTool { + fn id(self) -> &'static str { + match self { + Self::Heading1 => "rich-h1", + Self::Heading2 => "rich-h2", + Self::Heading3 => "rich-h3", + Self::Bold => "rich-bold", + Self::Italic => "rich-italic", + Self::Strikethrough => "rich-strike", + Self::InlineCode => "rich-code", + Self::BulletList => "rich-bullet", + Self::NumberedList => "rich-ordered", + Self::TaskList => "rich-tasks", + Self::Quote => "rich-quote", + Self::CodeBlock => "rich-codeBlock", + Self::Table => "rich-table", + Self::RowBelow => "rich-rowAfter", + Self::ColumnAfter => "rich-columnAfter", + } + } +} + +impl Rich<'_> { + /// Types where the caret is, a letter at a time: what starts a line may format it. + pub fn type_keys(&mut self, text: &str) { + for letter in text.chars() { + self.0.type_text(&letter.to_string()); + } + } + + /// Clicks a button of the toolbar. + pub fn click(&mut self, tool: RichTool) { + self.0.click(tool.id(), "a button of the Note's toolbar"); + } + + /// A line of its own, formatted by a button: an Enter more leaves a list or a quote, a click + /// more the words' own format. + pub fn write_line(&mut self, tool: RichTool, text: &str) { + self.click(tool); + self.0.type_text(text); + self.0.press(Shortcut::Enter); + if self.0.tree().is_on(tool.id()) { + match tool { + RichTool::BulletList | RichTool::NumberedList | RichTool::TaskList | RichTool::Quote => { + self.0.press(Shortcut::Enter); + } + _ => self.click(tool), + } + } + self.0.expect("the next line is not formatted", |tree| !tree.is_on(tool.id())); + } + + /// Writes a code block, its language chosen from the keyboard in its menu. + pub fn write_code(&mut self, language: &str, code: &str) { + self.click(RichTool::CodeBlock); + self.0.type_text(code); + self.0.click("rich-code-language", "the menu of the block's language"); + self.0.take_keyboard("rich-code-language-filter", "the filter of the languages"); + self.0.type_text(language); + self.0.press(Shortcut::Enter); + self.0.expect("the menu closes", |tree| !tree.has("rich-code-language-filter")); + self.0.take_keyboard("editor-rich", "the Note's text"); + self.0.press(Shortcut::TextEnd); + } + + /// Writes a link at the caret, from its form. + pub fn write_link(&mut self, text: &str, address: &str) { + self.0.click("rich-link", "the link's button"); + self.0.fill("rich-link-text", "the link's text", text); + self.0.fill("rich-link-address", "the link's address", address); + self.0.press(Shortcut::Enter); + self.0.expect("the link's form closes", |tree| !tree.has("rich-link-apply")); + } + + /// Goes to the end of the Note, its caret on a line of its own. + pub fn go_to_end(&mut self) { + self.0.take_keyboard("editor-rich", "the Note's text"); + self.0.press(Shortcut::TextEnd); + self.0.press(Shortcut::Enter); + } + + /// Goes to the start of the Note, its caret on a line of its own. + pub fn go_to_start(&mut self) { + self.0.take_keyboard("editor-rich", "the Note's text"); + self.0.press(Shortcut::TextStart); + self.0.press(Shortcut::Enter); + self.0.press(Shortcut::Up); + } + + /// Ticks or unticks a task of the Note, counted from 0. + pub fn tick(&mut self, task: usize) { + self.0.click_nth("rich-task", task, "the task's box"); + } + + /// Puts the whole Note on the clipboard as Markdown, from the menu under the right button. + pub fn copy_as_markdown(&mut self) { + self.0.take_keyboard("editor-rich", "the Note's text"); + self.0.press(Shortcut::SelectAll); + self.0.right_click("editor-rich", "the Note's text"); + self.0.click("rich-menu-copy-markdown", "« Copy as Markdown »"); + } + + /// Puts the whole Note on the clipboard, whose table has as many rows — the header's among + /// them — and columns. + pub fn copy_table_and_expect(&mut self, rows: usize, columns: usize, says: &str) { + self.copy_as_markdown(); + self.0.clipboard().expect_that(says, |held| { + let lines = held.lines().filter(|line| line.starts_with('|') && !line.contains("---")); + let cells: Vec = lines.map(|line| line.matches('|').count() - 1).collect(); + cells.len() == rows && cells.iter().all(|count| *count == columns) + }); + } + + /// Inserts a drawing of the library, the first of the menu. + pub fn insert_drawing(&mut self) { + self.0.click("rich-embed-drawing", "the menu of the drawings"); + self.0.click("rich-embed-drawing-0", "the drawing"); + self.0.expect("the drawing is shown in the Note", |tree| tree.has("rich-embed")); + } + + /// 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"); + let id = match size { + DrawingSize::Quarter => "rich-embed-size-1", + DrawingSize::Whole => "rich-embed-size-4", + }; + self.0.click(id, "a width of the drawing"); + } + + /// Drags the corner of the drawing out to the right. + pub fn drag_drawing_corner_out(&mut self) { + self.0 + .drag_by("rich-embed-resize", "the drawing's corner", egui::vec2(1_200.0, 0.0)); + } + + /// The width of the drawing shown in the Note, in points. + pub fn drawing_width(&mut self) -> f64 { + self.0 + .expect("the drawing's corner is shown", |tree| tree.has("rich-embed-resize")); + drawn_width(&self.0.tree()) + } + + /// The drawing takes this part of `whole` in width. + pub fn expect_drawing_width(&mut self, whole: f64, part: f64, says: &str) { + self.0.expect(says, |tree| (drawn_width(tree) - whole * part).abs() < 2.0); + } + + /// The Note's text, as it is read. + pub fn expect_text(&mut self, text: &str, says: &str) { + self.0 + .expect(says, |tree| tree.find("editor-rich").and_then(Node::value) == Some(text)); + } + + /// A task of the Note is ticked, or not. + pub fn expect_ticked(&mut self, task: usize, ticked: bool, says: &str) { + self.0 + .expect(says, |tree| tree.all("rich-task").get(task).is_some_and(|task| is_on(task) == ticked)); + } +} + +/// How much of a Note's width a drawing takes. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum DrawingSize { + Quarter, + Whole, +} + +fn drawn_width(tree: &Tree) -> f64 { + tree.find("rich-embed") + .and_then(Node::bounds) + .map_or(0.0, |bounds| bounds.width()) +} + +/// A Note presented over the whole window. +pub struct Presentation<'a>(pub(super) &'a mut App); + +impl Presentation<'_> { + /// Presents the Note open. + pub fn open(&mut self) { + self.0.editor().click_button_or_entry("editor-present", "« Present »"); + self.0.expect("the cover is shown", |tree| tree.has("presentation-cover")); + } + + /// Opens the map of the headings. + pub fn open_map(&mut self) { + self.0.click("presentation-map", "« Map »"); + } + + /// Goes to the next slide by the arrow, and the count follows. + pub fn next(&mut self) { + let before = self.0.tree().text("presentation-count"); + self.0.press(Shortcut::Right); + self.0.expect("the next slide is shown", |tree| { + tree.has("presentation") && tree.text("presentation-count") != before + }); + } + + /// Leaves by Esc. + pub fn leave(&mut self) { + self.0.press(Shortcut::Escape); + self.0 + .expect("the Note is back", |tree| !tree.has("presentation") && tree.has("editor-title")); + } + + /// The slides are counted, the one shown first: « 1 / 4 » in any language's words. + pub fn expect_count(&mut self, at: usize, of: usize, says: &str) { + self.0.expect(says, |tree| { + let figures = tree.text("presentation-count").unwrap_or_default(); + let figures: Vec<&str> = figures + .split(|it: char| !it.is_ascii_digit()) + .filter(|it| !it.is_empty()) + .collect(); + figures == [at.to_string().as_str(), of.to_string().as_str()] + }); + } + + /// The map draws this many headings. + pub fn expect_map(&mut self, headings: usize, says: &str) { + self.0.expect(says, |tree| tree.count("presentation-map-node") == headings); + } +} diff --git a/e2e/src/sdk/shortcut.rs b/e2e/src/sdk/shortcut.rs index 95747860..f30ebd7b 100644 --- a/e2e/src/sdk/shortcut.rs +++ b/e2e/src/sdk/shortcut.rs @@ -25,6 +25,15 @@ pub enum Shortcut { NewNote, /// Ctrl+Shift+L: a todo list. NewTodoList, + /// Ctrl+Shift+M: a calculation. + NewCalculation, + /// Ctrl+Shift+D: a drawing. + NewDrawing, + /// Ctrl+B and Ctrl+I, in a Note. + Bold, + Italic, + /// Alt+↑: moves what has the keyboard up. + MoveUp, /// Del. Delete, /// Ctrl+Z. @@ -63,6 +72,10 @@ impl Shortcut { Self::NewSnippet => (Key::N, Modifiers::COMMAND), Self::NewNote => (Key::N, Modifiers::COMMAND | Modifiers::SHIFT), Self::NewTodoList => (Key::L, Modifiers::COMMAND | Modifiers::SHIFT), + Self::NewCalculation => (Key::M, Modifiers::COMMAND | Modifiers::SHIFT), + Self::NewDrawing => (Key::D, Modifiers::COMMAND | Modifiers::SHIFT), + Self::Italic => (Key::I, Modifiers::COMMAND), + Self::MoveUp => (Key::ArrowUp, Modifiers::ALT), Self::Delete => (Key::Delete, Modifiers::NONE), Self::Undo => (Key::Z, Modifiers::COMMAND), Self::SelectAll => (Key::A, Modifiers::COMMAND), @@ -73,7 +86,8 @@ impl Shortcut { Self::ToolsArea => (Key::Num2, Modifiers::COMMAND), Self::HttpArea => (Key::Num3, Modifiers::COMMAND), Self::CardKey(key) => (key, Modifiers::NONE), - Self::SideRail => (Key::B, Modifiers::COMMAND), + // The same keys: in a Note they are the text's. + Self::SideRail | Self::Bold => (Key::B, Modifiers::COMMAND), } } } diff --git a/e2e/src/sdk/todo.rs b/e2e/src/sdk/todo.rs new file mode 100644 index 00000000..286fd48e --- /dev/null +++ b/e2e/src/sdk/todo.rs @@ -0,0 +1,74 @@ +use egui::accesskit::Node; + +use super::{App, Shortcut}; +use crate::driver::{Tree, is_on}; + +/// The todo list open. +pub struct Todo<'a>(pub(super) &'a mut App); + +impl Todo<'_> { + /// Adds a task, typed. + pub fn add(&mut self, words: &str) { + self.add_empty(); + self.0.type_text(words); + } + + /// Adds an empty task, the keyboard in it. + pub fn add_empty(&mut self) { + let before = self.0.tree().count("checklist-text"); + self.0.click("checklist-add", "« Add a task »"); + self.0.expect("a new row takes the keyboard", |tree| { + tree.count("checklist-text") == before + 1 && tree.has_focus("checklist-text") + }); + } + + /// Splits a task before its last word, by Enter. + pub fn split_before(&mut self, task: usize, last_word: &str) { + self.take(task); + self.0.press(Shortcut::LineEnd); + for _ in last_word.chars() { + self.0.press(Shortcut::Left); + } + self.0.press(Shortcut::Enter); + } + + /// Moves a task up, Alt+↑. + pub fn move_up(&mut self, task: usize) { + self.take(task); + self.0.press(Shortcut::MoveUp); + } + + /// Ticks or unticks a task. + pub fn tick(&mut self, task: usize) { + self.0.click_nth("checklist-check", task, "the task's box"); + } + + /// Removes a task by its cross. + pub fn remove(&mut self, task: usize) { + self.0.click_nth("checklist-remove", task, "the task's cross"); + } + + /// The tasks, top to bottom. + pub fn expect(&mut self, tasks: &[&str], says: &str) { + self.0.expect(says, |tree| words(tree) == tasks); + } + + /// Which tasks are ticked, top to bottom. + pub fn expect_ticked(&mut self, ticked: &[bool], says: &str) { + self.0.expect(says, |tree| { + let boxes: Vec = tree.all("checklist-check").into_iter().map(is_on).collect(); + boxes == ticked + }); + } + + fn take(&mut self, task: usize) { + self.0.click_nth("checklist-text", task, "the task"); + self.0 + .expect("the task has the keyboard", |tree| tree.has_focus("checklist-text")); + } +} + +fn words(tree: &Tree) -> Vec { + let rows = tree.all("checklist-text").into_iter(); + rows.map(|row| Node::value(row).unwrap_or_default().to_owned()).collect() +} diff --git a/e2e/tests/03_editing_a_note.rs b/e2e/tests/03_editing_a_note.rs deleted file mode 100644 index dd23903e..00000000 --- a/e2e/tests/03_editing_a_note.rs +++ /dev/null @@ -1,375 +0,0 @@ -//! Editing a snippet: title, code and context written on the way out, the footer counting what -//! the code holds, full screen and the folded header keeping the draft, Tab staying in the code -//! and the find bar finding in it. Then a drawing: drawn on its stage, shown on its card from the -//! picture kept beside it, written as a PNG, and Escape stepping back through it. Then Notes: -//! the sample opens formatted and a box ticked there is kept, one typed from the toolbar keeps -//! « 2 * 3 * 4 » as typed, a double click takes a word to type over, and a list copied keeps its -//! markers. The editor sits beside the cards: J steps to the next one, and Escape leaves full -//! screen before it closes. - -use e2e::old::{App, Tree, step}; -use egui::{Key, Modifiers}; - -const TITLE: &str = "Rollout under edit"; -const SKETCH: &str = "Archi"; - -/// The code as the editor holds it. -fn code(tree: &Tree) -> String { - tree.find("editor-body") - .and_then(|body| body.value()) - .unwrap_or_default() - .to_owned() -} - -fn open(app: &mut App) { - app.click("search-input"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(TITLE); - app.eventually("the snippet alone", |tree| { - tree.count("note-card") == 1 && tree.texts("note-card").contains(&TITLE.to_owned()) - }); - app.click("note-card-open"); - app.wait_for("editor-body"); -} - -fn close(app: &mut App) { - app.click("editor-close"); - app.eventually("the editor is closed", |tree| !tree.has("editor-title")); -} - -fn shapes(tree: &Tree) -> String { - tree.find("drawing-stage") - .and_then(|stage| stage.value()) - .unwrap_or_default() - .to_owned() -} - -fn pressed(tree: &Tree, tool: &str) -> bool { - tree.find(tool) - .is_some_and(|button| button.toggled() == Some(egui::accesskit::Toggled::True)) -} - -fn open_sketch(app: &mut App) { - app.click("search-input"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(SKETCH); - app.eventually("the drawing alone", |tree| { - tree.count("note-card") == 1 && tree.texts("note-card").contains(&SKETCH.to_owned()) - }); - app.click("note-card-open"); - app.wait_for("drawing-stage"); -} - -fn drawings(app: &mut App, exported: &std::path::Path) { - step("a drawing is drawn, and its card shows its picture", || { - app.click("new-note-kind"); - app.click("new-note-drawing"); - app.fill("editor-title", SKETCH); - app.click("drawing-tool-rectangle"); - app.drag_in("drawing-stage", (40.0, 40.0), (160.0, 110.0)); - app.eventually("a rectangle drawn", |tree| shapes(tree) == "1"); - app.capture("drawing-editor"); - close(app); - app.click("search-input"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(SKETCH); - app.wait_for("note-card-drawing"); - }); - - step("a drawing is written as a PNG where the dialog says", || { - open_sketch(app); - app.eventually("the scene read back", |tree| shapes(tree) == "1"); - app.click("drawing-export-png"); - app.eventually("the file written", |_| { - std::fs::read(exported).is_ok_and(|bytes| bytes.starts_with(b"\x89PNG")) - }); - }); - - step("the eraser takes shape after shape and stays in hand", || { - app.click("drawing-tool-ellipse"); - app.drag_in("drawing-stage", (200.0, 40.0), (280.0, 110.0)); - app.eventually("two shapes", |tree| shapes(tree) == "2"); - app.click("drawing-tool-eraser"); - app.drag_in("drawing-stage", (20.0, 75.0), (300.0, 75.0)); - app.eventually("both gone in one drag", |tree| shapes(tree) == "0"); - assert!(pressed(&app.tree(), "drawing-tool-eraser")); - app.click("drawing-undo"); - app.eventually("one step back", |tree| shapes(tree) == "2"); - app.drag_in("drawing-stage", (240.0, 75.0), (240.0, 75.0)); - app.eventually("one by a click", |tree| shapes(tree) == "1"); - }); - - arrow_and_look(app); - - step("Escape drops the tool, the selection, then the editor", || { - app.drag_in("drawing-stage", (100.0, 75.0), (100.0, 75.0)); - app.eventually("the stage has the keys", |tree| tree.focused().starts_with("drawing-stage")); - app.press(Key::O, Modifiers::NONE); - app.eventually("the ellipse taken", |tree| pressed(tree, "drawing-tool-ellipse")); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("back to the selection", |tree| pressed(tree, "drawing-tool-select")); - app.press(Key::Escape, Modifiers::NONE); - assert!(app.has("editor-title"), "the selection went, not the editor"); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the editor is closed", |tree| !tree.has("editor-title")); - }); -} - -/// The sketch open, a rectangle on it: an arrow bound and let go, then the look moved. -fn arrow_and_look(app: &mut App) { - step("an arrow drawn from a shape, its end let go elsewhere", || { - app.click("drawing-tool-arrow"); - app.drag_in("drawing-stage", (100.0, 75.0), (320.0, 75.0)); - app.eventually("the arrow", |tree| shapes(tree) == "2"); - app.drag_in("drawing-stage", (320.0, 75.0), (320.0, 150.0)); - app.capture("drawing-arrow-end"); - assert_eq!(shapes(&app.tree()), "2", "moved, not drawn"); - app.click("drawing-undo"); - app.click("drawing-undo"); - app.eventually("the rectangle alone", |tree| shapes(tree) == "1"); - }); - - step("the drawing is zoomed, moved and shown whole again", || { - let shown = |tree: &Tree| tree.text("drawing-zoom").unwrap_or_default(); - app.eventually("as drawn", |tree| shown(tree).starts_with("100")); - app.click("drawing-zoom-in"); - app.click("drawing-zoom-in"); - app.eventually("closer", |tree| shown(tree).starts_with("156")); - app.drag(egui::pos2(700.0, 400.0), egui::pos2(640.0, 380.0), egui::PointerButton::Middle); - app.capture("drawing-zoomed"); - app.click("drawing-fit"); - app.eventually("whole again", |tree| shown(tree).starts_with("100")); - app.click("drawing-zoom-out"); - app.eventually("further", |tree| shown(tree).starts_with("80")); - app.click("drawing-zoom"); - app.eventually("as drawn again", |tree| shown(tree).starts_with("100")); - assert_eq!(shapes(&app.tree()), "1", "nothing was drawn"); - app.click("editor-close"); - app.eventually("closed", |tree| !tree.has("editor-title")); - open_sketch(app); - }); -} - -/// The title of the note open, as its field holds it. -fn open_title(tree: &Tree) -> String { - tree.find("editor-title") - .and_then(|title| title.value()) - .unwrap_or_default() - .to_owned() -} - -/// Beside the cards, J and K step through them; expanded, the cards go; Escape steps back. -fn beside_the_cards(app: &mut App) { - step("a note opens beside the cards, and J steps to the next one", || { - app.click("search-input"); - app.press(Key::A, Modifiers::COMMAND); - app.press(Key::Delete, Modifiers::NONE); - app.eventually("every card back", |tree| tree.count("note-card") > 2); - app.click_nth("note-card-open", 0); - app.wait_for("editor-title"); - let first = open_title(&app.tree()); - app.press(Key::J, Modifiers::NONE); - app.eventually("the next card open", |tree| tree.has("editor-title") && open_title(tree) != first); - app.press(Key::F2, Modifiers::NONE); - app.eventually("F2 goes to the title", |tree| tree.focused().starts_with("editor-title")); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("Escape leaves it, the note still open", |tree| { - tree.has("editor-title") && !tree.focused().starts_with("editor-title") - }); - app.capture("editor-beside-the-cards"); - }); - - step("expanded, the note takes the area; Escape steps back", || { - app.click("editor-fullscreen"); - app.eventually("the cards gone", |tree| !tree.has("note-card") && tree.has("editor-position")); - app.press(Key::Escape, Modifiers::NONE); - // Beside the cards again, or over them in a window too narrow for both. - app.eventually("out of full screen", |tree| !tree.has("editor-position") && tree.has("editor-title")); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the editor is closed", |tree| !tree.has("editor-title")); - }); -} - -/// The rich text a Note's surface holds. -fn rich(tree: &Tree) -> String { - tree.find("editor-rich") - .and_then(|surface| surface.value()) - .unwrap_or_default() - .to_owned() -} - -/// The first task's box: ticked or not. -fn first_box(tree: &Tree) -> Option { - tree.all("rich-task").first().and_then(|task| task.toggled()) -} - -/// The one card `words` finds. ⚠️ The previous search showed one card too: the count is -/// true of it until the debounce ends, so the card itself has to change. -fn search_alone(app: &mut App, words: &str) { - let before = app.tree().texts("note-card"); - app.click("search-input"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(words); - app.eventually("the note searched, alone", |tree| { - tree.count("note-card") == 1 && tree.texts("note-card") != before - }); -} - -fn notes(app: &mut App) { - step("the sample Note opens formatted, and a box ticked or unticked is kept", || { - search_alone(app, "timeout=120s"); - app.click("note-card-open"); - app.eventually("its tasks drawn", |tree| tree.count("rich-task") == 3); - assert!(!app.tree().has("editor-body"), "no code field for a Note"); - // The sample's first task is done in one language and not in the other. - let before = first_box(&app.tree()); - app.click_nth("rich-task", 0); - app.eventually("the box changed", |tree| first_box(tree) != before); - let after = first_box(&app.tree()); - app.capture("note"); - close(app); - app.click("note-card-open"); - app.eventually("kept once opened again", |tree| first_box(tree) == after); - close(app); - }); - - step("a Note typed with the toolbar keeps its stars as typed", || { - app.click("new-note-kind"); - app.click("new-note-note"); - app.click("editor-rich"); - for glyph in ["2", " ", "*", " ", "3", " ", "*", " ", "4"] { - app.type_text(glyph); - } - app.press(Key::Enter, Modifiers::NONE); - app.click("rich-bold"); - app.type_text("fort"); - app.eventually("both lines typed", |tree| rich(tree) == "2 * 3 * 4\nfort"); - close(app); - search_alone(app, "fort"); - app.click("note-card-open"); - app.eventually("written back as typed", |tree| rich(tree) == "2 * 3 * 4\nfort"); - close(app); - }); - - step("a double click in a Note takes the word under it", || { - // A click less than 0.3 s before a double click makes it a triple, for egui: the last - // one is the field's, two searches each wait out its pause, the card opens by the keys. - app.click("search-input"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text("nothing matches this"); - app.eventually("nothing found", |tree| tree.has("canvas-no-results")); - app.press(Key::A, Modifiers::COMMAND); - app.type_text("fort"); - app.eventually("the Note alone", |tree| tree.count("note-card") == 1); - app.press(Key::ArrowDown, Modifiers::NONE); - app.eventually("the card has the focus", |tree| tree.focused().starts_with("note-card-open")); - app.press(Key::Enter, Modifiers::NONE); - app.wait_for("editor-rich"); - // The first word: the page's margin is 28 points, 20 above the first line. - app.double_click_in("editor-rich", (31.0, 31.0)); - app.type_text("deux"); - app.eventually("the word typed over", |tree| rich(tree) == "deux * 3 * 4\nfort"); - close(app); - }); - - step("a list copied keeps its markers, a long item whole", || { - let long = "un élément assez long pour passer à la ligne plus d’une fois ".repeat(4); - let long = long.trim_end(); - app.click("new-note-kind"); - app.click("new-note-note"); - app.click("editor-rich"); - for glyph in ["-", " "] { - app.type_text(glyph); - } - app.type_text(long); - app.press(Key::Enter, Modifiers::NONE); - app.type_text("court"); - app.eventually("both items typed", |tree| rich(tree).ends_with("court")); - app.press(Key::A, Modifiers::COMMAND); - app.copy(); - let expected = format!("- {long}\n- court"); - app.clipboard_holds("the list with its markers", |held| held == expected); - close(app); - }); -} - -#[test] -fn editing_a_note() { - let profile = tempfile::tempdir().unwrap(); - let exported = profile.path().join("export.png"); - let mut app = App::launch_answering("03_editing_a_note", profile.path(), &exported); - app.create_library(); - app.wait_for("note-card"); - - step("a snippet written from a new note", || { - app.click("new-note"); - app.fill("editor-title", TITLE); - app.click("editor-body"); - app.type_text("kubectl rollout status"); - close(&mut app); - }); - - step("title, code and context are written on the way out", || { - open(&mut app); - app.click("editor-body"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text("kubectl rollout restart deployment/api"); - app.fill("editor-source", "runbooks/api.md"); - close(&mut app); - open(&mut app); - app.eventually("the code as typed", |tree| code(tree) == "kubectl rollout restart deployment/api"); - app.eventually("the context as typed", |tree| { - tree.find("editor-source").and_then(|field| field.value()) == Some("runbooks/api.md") - }); - }); - - step("the footer counts one line in the singular", || { - app.eventually("« 1 line »", |tree| { - tree.text("editor-stats") - .is_some_and(|stats| stats.contains("· 1 ligne ·") || stats.contains("· 1 line ·")) - }); - app.capture("snippet-editor"); - }); - - step("Tab stays in the code, and the find bar finds in it", || { - app.click("editor-body"); - app.press(Key::Home, Modifiers::COMMAND); - app.press(Key::Tab, Modifiers::NONE); - app.eventually("a level before the code", |tree| code(tree).starts_with(" kubectl")); - app.press(Key::F, Modifiers::COMMAND); - app.wait_for("search-field"); - app.type_text("rollout"); - app.eventually("one match, selected", |tree| tree.text("search-count").as_deref() == Some("1 / 1")); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the bar is closed", |tree| !tree.has("search-field")); - }); - - step("full screen and back keep the draft", || { - app.click("editor-body"); - app.press(Key::End, Modifiers::COMMAND); - app.type_text(" --watch"); - app.click("editor-fullscreen"); - app.click("editor-fullscreen"); - close(&mut app); - open(&mut app); - app.eventually("the draft written", |tree| code(tree).ends_with("--watch")); - }); - - step("the header folds, and stays folded from note to note", || { - app.click("editor-fold-header"); - app.wait_for("editor-header-summary"); - close(&mut app); - open(&mut app); - app.wait_for("editor-header-summary"); - assert!(!app.has("editor-source")); - app.click("editor-header-summary"); - app.wait_for("editor-source"); - close(&mut app); - }); - - beside_the_cards(&mut app); - drawings(&mut app, &exported); - notes(&mut app); - - app.quit(); -} diff --git a/e2e/tests/03_keeping_a_note.rs b/e2e/tests/03_keeping_a_note.rs index fa7cddd8..3fdc7278 100644 --- a/e2e/tests/03_keeping_a_note.rs +++ b/e2e/tests/03_keeping_a_note.rs @@ -132,7 +132,7 @@ fn and_its_versions(app: &mut App) { step("a todo list has none", || { app.notes().write_todo_list("Before the dump", "stop the writes"); app.notes().open("Before the dump"); - app.editor().add_task("tell the team"); + app.todo().add("tell the team"); app.editor().close(); app.notes().open("Before the dump"); app.history().expect_none("no version is offered"); diff --git a/e2e/tests/04_other_kinds.rs b/e2e/tests/04_other_kinds.rs new file mode 100644 index 00000000..4996bb62 --- /dev/null +++ b/e2e/tests/04_other_kinds.rs @@ -0,0 +1,312 @@ +//! Journey 4, « The other kinds of note »: a Note written formatted and presented, a todo list, a +//! calculation, a drawing inserted into the Note, and the kinds changed into one another. + +use e2e::{App, DrawingSize, Kind, RichTool, Sample, Shortcut, Spot, Tool, step}; + +const NOTE: &str = "Release plan"; +const LIST: &str = "Release checklist"; +const SHEET: &str = "Hosting budget"; +const SKETCH: &str = "Architecture"; + +#[test] +fn other_kinds() { + let mut app = App::open("04_other_kinds"); + app.window().widen(); + + a_note(&mut app); + a_presentation(&mut app); + a_todo_list(&mut app); + a_calculation(&mut app); + a_drawing(&mut app); + one_kind_into_another(&mut app); + + app.quit(); +} + +fn a_note(app: &mut App) { + step("a Note is written formatted, from each button of its toolbar", || { + app.press(Shortcut::NewNote); + app.editor().type_title(NOTE); + app.editor().expect_note_open("a Note is open"); + app.rich().go_to_end(); + for (tool, text) in [ + (RichTool::Heading1, "Plan"), + (RichTool::Heading2, "Before"), + (RichTool::Heading3, "Details"), + (RichTool::Bold, "fat"), + (RichTool::Italic, "slanted"), + (RichTool::Strikethrough, "gone"), + (RichTool::InlineCode, "kubectl"), + (RichTool::Quote, "said once"), + (RichTool::BulletList, "first point"), + (RichTool::NumberedList, "first step"), + (RichTool::TaskList, "first task"), + ] { + app.rich().write_line(tool, text); + } + app.rich().write_link("the site", "https://devnotes.fr"); + app.capture("note"); + }); + + step("it is kept as Markdown", || { + app.rich().copy_as_markdown(); + for markdown in [ + "# Plan", + "## Before", + "### Details", + "**fat**", + "*slanted*", + "~~gone~~", + "`kubectl`", + "> said once", + "- first point", + "1. first step", + "- [ ] first task", + "[the site](https://devnotes.fr)", + ] { + app.clipboard().expect_saying(markdown, "the Markdown holds what was written"); + } + app.editor().close(); + }); + + step("its shortcuts format too, and what looks like Markdown stays as typed", || { + app.press(Shortcut::NewNote); + app.editor().type_title("Product"); + app.editor().type_note(""); + app.rich().type_keys("2 * 3 * 4"); + app.press(Shortcut::Enter); + app.press(Shortcut::Bold); + app.type_text("strong"); + app.press(Shortcut::Bold); + app.press(Shortcut::Italic); + app.type_text(" light"); + app.rich().expect_text("2 * 3 * 4\nstrong light", "the text is as typed"); + app.editor().close(); + app.notes().open("Product"); + app.rich().expect_text("2 * 3 * 4\nstrong light", "it is read back as typed"); + app.rich().copy_as_markdown(); + app.clipboard().expect_saying("**strong**", "the word is bold"); + app.editor().close(); + }); + + step("a code block keeps its language, and the down arrow leaves it", || { + app.notes().open("Product"); + app.editor().flip_expanded(); + app.rich().go_to_end(); + app.rich().write_code("rust", "let x = 1;"); + app.press(Shortcut::Down); + app.type_text("After the code"); + app.rich().copy_as_markdown(); + app.clipboard() + .expect_saying("```rs\nlet x = 1;\n```\n\nAfter the code", "the block is Rust's"); + app.editor().flip_expanded(); + app.editor().close(); + }); + + step("a table grows by a row and a column", || { + app.notes().open(NOTE); + app.editor().flip_expanded(); + app.rich().go_to_end(); + app.rich().click(RichTool::Table); + app.type_text("Environment"); + app.rich().click(RichTool::RowBelow); + app.rich().click(RichTool::ColumnAfter); + app.rich() + .copy_table_and_expect(4, 4, "three rows of three became four of four"); + app.editor().flip_expanded(); + app.editor().close(); + }); + + step("a box ticked is kept", || { + app.notes().open(Sample::ReleaseDay); + app.rich().tick(1); + app.rich().expect_ticked(1, true, "the second task is ticked"); + app.editor().close(); + app.notes().open(Sample::ReleaseDay); + app.rich().expect_ticked(1, true, "it is still ticked"); + app.editor().close(); + }); +} + +fn a_presentation(app: &mut App) { + step("« Present » steps through the sections, opens the map, and leaves on Esc", || { + app.notes().open(Sample::ReleaseDay); + app.presentation().open(); + app.presentation() + .expect_count(1, 5, "the cover comes before the text and its sections"); + app.capture("presentation"); + app.presentation().next(); + app.presentation().expect_count(2, 5, "the text is shown"); + app.presentation().open_map(); + app.presentation() + .expect_map(4, "the map draws the Note and its three headings"); + app.presentation().leave(); + app.editor().close(); + // The window the system gives back is no larger than the screen. + app.window().widen(); + }); +} + +fn a_todo_list(app: &mut App) { + step("a list is typed a task at a time, split by Enter and pasted line by line", || { + app.press(Shortcut::NewTodoList); + app.editor().type_title(LIST); + app.todo().add("Tag the release"); + app.todo().add("Write the notes publish"); + app.todo().split_before(1, "publish"); + app.todo() + .expect(&["Tag the release", "Write the notes ", "publish"], "Enter cut the task in two"); + app.todo().add_empty(); + app.paste("- Freeze the merges\n- [x] Back the database up"); + app.todo() + .expect_ticked(&[false, false, false, false, true], "each line pasted is a task, its box read"); + }); + + step("a task moves up, and one is removed", || { + app.todo().move_up(1); + app.todo().expect( + &["Write the notes ", "Tag the release", "publish", "Freeze the merges", "Back the database up"], + "the second task is the first", + ); + app.todo().remove(2); + app.capture("list"); + app.editor().close(); + app.notes().expect_progress(LIST, "1/4", "the card counts one task done"); + }); + + step("it is ticked from its card without opening it", || { + app.notes().tick_on_card(LIST, 0); + app.notes().expect_progress(LIST, "2/4", "the card counts two"); + app.editor().expect_closed("no note is open"); + app.notes().open(LIST); + app.todo() + .expect_ticked(&[true, false, false, true], "the first task is ticked"); + app.editor().close(); + }); +} + +fn a_calculation(app: &mut App) { + step("each line is computed as it is typed, a name usable below it", || { + app.press(Shortcut::NewCalculation); + app.editor().type_title(SHEET); + app.editor() + .type_code("server = 100\ndomain = 20\nserver + domain\n20 % of 340"); + app.calc() + .expect_results(&["100", "20", "120", "68"], "each line has its result"); + }); + + step("an error is said beside its line", || { + app.editor().add_to_code("\n100 + "); + app.calc().expect_errors(1, "the line says why it has no result"); + app.capture("calculation"); + }); + + step("results picked are summed in the footer", || { + app.calc().pick(0); + app.calc().expect_sum("100", "the footer says what is picked"); + app.calc().pick_also(2); + app.calc().expect_sum("220", "the two are summed"); + app.editor().close(); + }); + + step("the card shows the last lines, and a relaunch what was written alone", || { + app.notes().expect_calculation(SHEET, "the calculation's lines are on its card"); + app.relaunch_and_unlock(); + app.notes().open(SHEET); + app.editor().expect_code( + "server = 100\ndomain = 20\nserver + domain\n20 % of 340\n100 + ", + "the text is as it was typed", + ); + app.calc() + .expect_results(&["100", "20", "120", "68"], "the results are computed again"); + app.editor().close(); + }); +} + +fn a_drawing(app: &mut App) { + step("shapes, a text and an arrow are drawn", || { + app.press(Shortcut::NewDrawing); + app.editor().type_title(SKETCH); + app.drawing().draw(Tool::Rectangle, Spot::Left); + app.drawing().draw(Tool::Ellipse, Spot::Right); + app.drawing().draw(Tool::Diamond, Spot::Middle); + app.drawing().write("queue", Spot::Below); + app.drawing().draw_arrow(Spot::Left, Spot::Right); + app.drawing().expect_shapes(5, "the five are on the drawing"); + app.capture("drawing"); + }); + + step("the arrow follows the shape it starts from", || { + app.drawing().export_svg("before.svg"); + app.drawing().move_shape(Spot::Right, Spot::Below); + app.drawing().export_svg("after.svg"); + app.drawing() + .expect_arrow_moved("before.svg", "after.svg", "its arrow is elsewhere"); + }); + + step("a shape is removed with Delete", || { + app.drawing().delete(Spot::Middle); + app.drawing().expect_shapes(4, "four are left"); + }); + + step("it is zoomed, and shown whole by F", || { + app.drawing().zoom_in(); + app.drawing().expect_zoom("125", "it is closer"); + app.drawing().show_whole(); + app.drawing().expect_zoom("100", "it is whole again"); + app.drawing().export_png("sketch.png"); + app.files() + .expect("sketch.png", "the picture is written", |bytes| bytes.starts_with(b"\x89PNG")); + app.editor().close(); + app.notes().expect_picture(SKETCH, "its card shows its picture"); + }); + + step("inserted into the Note, it is shown there and resized by its corner", || { + app.notes().open(NOTE); + app.editor().flip_expanded(); + app.rich().go_to_start(); + app.rich().insert_drawing(); + app.rich().size_drawing(DrawingSize::Whole); + let whole = app.rich().drawing_width(); + app.rich().size_drawing(DrawingSize::Quarter); + app.rich().expect_drawing_width(whole, 0.25, "it takes a quarter of the width"); + app.rich().drag_drawing_corner_out(); + app.rich().expect_drawing_width(whole, 1.0, "dragged, it takes the whole width"); + app.capture("drawing-in-a-note"); + app.editor().close(); + app.notes().open(NOTE); + app.rich().expect_drawing_width(whole, 1.0, "it was kept so"); + app.editor().flip_expanded(); + app.editor().close(); + }); +} + +fn one_kind_into_another(app: &mut App) { + step("the list becomes a Note, and so does a snippet", || { + app.notes().open(LIST); + app.editor().convert_to_note(); + app.editor().expect_note_open("the list is a Note"); + app.editor().close(); + app.press(Shortcut::NewSnippet); + app.editor().type_title("Restart"); + app.editor().type_code("systemctl restart api"); + app.editor().convert_to_note(); + app.editor().expect_note_open("the snippet is a Note"); + app.editor().close(); + }); + + step("the conversion is taken back by the undo bar", || { + app.notes().open(Sample::PsqlConnection); + app.editor().convert_to_note(); + app.editor().expect_note_open("the snippet is a Note"); + app.notes().undo(); + app.editor().expect_code_open("it is a snippet again"); + app.editor().close(); + }); + + step("a drawing offers no change", || { + app.notes().new_of_kind(Kind::Drawing); + app.editor().expect_no_kind_to_choose("its kind is said, and is no menu"); + app.editor().close(); + }); +} diff --git a/e2e/tests/07_checklists.rs b/e2e/tests/07_checklists.rs deleted file mode 100644 index dd5c100a..00000000 --- a/e2e/tests/07_checklists.rs +++ /dev/null @@ -1,133 +0,0 @@ -//! Todo lists: made from the kind menu, typed a row at a time, split by Enter, pasted line by -//! line, ticked from the editor and from the card, reordered by Alt+arrows — the twin of the -//! grip's drag — and a row removed. A list's position is all the identity an item has. - -use e2e::old::{App, Tree, step}; -use egui::{Key, Modifiers}; - -const TITLE: &str = "Release checklist"; - -/// The rows' words, top to bottom: a row's value, not its name. -fn rows(tree: &Tree) -> Vec { - tree.all("checklist-text") - .into_iter() - .map(|row| row.value().unwrap_or_default().to_owned()) - .collect() -} - -fn ticks(tree: &Tree) -> Vec { - tree.all("checklist-check") - .into_iter() - .map(|tick| tick.toggled() == Some(egui::accesskit::Toggled::True)) - .collect() -} - -/// The list found by its title and opened from the keyboard: a list's card is mostly its ticks. -fn open(app: &mut App) { - app.click("search-input"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(TITLE); - app.eventually("the list alone", |tree| tree.count("note-card") == 1); - app.press(Key::ArrowDown, Modifiers::NONE); - app.eventually("the card has the focus", |tree| tree.focused().starts_with("note-card-open")); - app.press(Key::Enter, Modifiers::NONE); - app.wait_for("checklist-add"); -} - -fn close(app: &mut App) { - app.click("editor-close"); - app.eventually("the editor is closed", |tree| !tree.has("editor-title")); -} - -/// A new row, typed in. -fn add(app: &mut App, words: &str) { - let before = app.tree().count("checklist-text"); - app.click("checklist-add"); - app.eventually("a new row has the focus", |tree| { - tree.count("checklist-text") == before + 1 && tree.focused().starts_with("checklist-text") - }); - app.type_text(words); -} - -#[test] -fn checklists() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("07_checklists", profile.path()); - app.create_library(); - app.wait_for("note-card"); - - step("a list is made from the kind menu, its rows typed", || { - app.click("new-note-kind"); - app.click("new-note-checklist"); - app.fill("editor-title", TITLE); - add(&mut app, "Tag the release"); - add(&mut app, "Write the changelog"); - add(&mut app, "Publish the binaries"); - close(&mut app); - open(&mut app); - app.eventually("the rows in the order added", |tree| { - rows(tree) == ["Tag the release", "Write the changelog", "Publish the binaries"] - }); - app.capture("checklist-editor"); - }); - - step("Enter cuts a row at the caret, Backspace joins it back", || { - app.click_nth("checklist-text", 2); - app.press(Key::End, Modifiers::NONE); - for _ in 0.."binaries".len() { - app.press(Key::ArrowLeft, Modifiers::NONE); - } - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the row cut in two", |tree| { - rows(tree).get(2..) == Some(&["Publish the ".to_owned(), "binaries".to_owned()][..]) - }); - app.press(Key::Backspace, Modifiers::NONE); - app.eventually("joined back", |tree| rows(tree).len() == 3); - }); - - step("lines pasted into a row are as many items, their boxes read", || { - add(&mut app, ""); - app.paste("- Freeze the merges\n- [x] Back the database up"); - app.eventually("two rows from the paste", |tree| { - rows(tree).get(3..) - == Some(&["Freeze the merges".to_owned(), "Back the database up".to_owned()][..]) - }); - app.eventually("the box pasted ticked", |tree| ticks(tree) == [false, false, false, false, true]); - }); - - step("a row is ticked, moved up by Alt+↑ and removed", || { - app.click_nth("checklist-check", 0); - app.eventually("the first row ticked", |tree| ticks(tree).first() == Some(&true)); - app.click_nth("checklist-text", 1); - app.press(Key::ArrowUp, Modifiers::ALT); - app.eventually("the second row first", |tree| { - rows(tree).first().map(String::as_str) == Some("Write the changelog") - }); - app.click_nth("checklist-remove", 4); - app.eventually("the last row gone", |tree| rows(tree).len() == 4); - close(&mut app); - }); - - step("the order and the ticks are written", || { - open(&mut app); - app.eventually("as left", |tree| { - rows(tree) - == ["Write the changelog", "Tag the release", "Publish the binaries", "Freeze the merges"] - && ticks(tree) == [false, true, false, false] - }); - close(&mut app); - }); - - step("a row is ticked from the card without opening it", || { - app.click_nth("note-card-item", 0); - app.eventually("the editor stayed closed", |tree| !tree.has("editor-title")); - app.eventually("the card's progress counts it", |tree| { - tree.text("note-card-progress").as_deref() == Some("2/4") - }); - open(&mut app); - app.eventually("the first open row ticked", |tree| ticks(tree).first() == Some(&true)); - close(&mut app); - }); - - app.quit(); -} diff --git a/e2e/tests/13_making_it_mine.rs b/e2e/tests/13_making_it_mine.rs index 8d969fea..30fda893 100644 --- a/e2e/tests/13_making_it_mine.rs +++ b/e2e/tests/13_making_it_mine.rs @@ -2,8 +2,8 @@ //! keys, the areas, the window, and a new version offered. use e2e::{ - App, Area, CardKey, DefaultKind, Density, Indent, Key, Language, Page, Sample, Shortcut, Switch, Theme, - step, + App, Area, CardKey, DefaultKind, Density, Indent, Key, Kind, Language, Page, Sample, Shortcut, Switch, + Theme, step, }; #[test] @@ -119,9 +119,9 @@ fn where_they_act(app: &mut App) { step("a calculation has the decimals chosen", || { app.prefs().change(|prefs| prefs.choose_decimals(2)); - app.notes().new_calculation(); + app.notes().new_of_kind(Kind::Calculation); app.editor().type_code("10 / 3"); - app.editor().expect_first_result("333", "the result has two decimals"); + app.calc().expect_results(&["333"], "the result has two decimals"); app.editor().close(); }); diff --git a/e2e/tests/33_calc.rs b/e2e/tests/33_calc.rs deleted file mode 100644 index b6f0153e..00000000 --- a/e2e/tests/33_calc.rs +++ /dev/null @@ -1,83 +0,0 @@ -//! A Calcul note: made from the new-note menu, each line computed as it is typed, an error kept on -//! its line, a result picked and summed in the footer, and the last lines on its card. Results -//! are read by their figures: the language on screen writes the decimal mark and the units. - -use e2e::old::{App, Tree, step}; - -const TITLE: &str = "Budget sheet"; -const SHEET: &str = "# Budget -hébergement = 100,521 € -domaines = 4,99 € -mensuel = total -mensuel × 12 -3 h 20 min en min -20 % of 340 -100 € en $ -en = 5"; - -fn digits(text: &str) -> String { - text.chars().filter(char::is_ascii_digit).collect() -} - -fn results(tree: &Tree) -> Vec { - tree.all("calc-result") - .into_iter() - .map(|node| digits(node.value().unwrap_or_default())) - .collect() -} - -#[test] -fn calc() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("33_calc", profile.path()); - app.create_library(); - app.wait_for("note-card"); - - step("a sheet is made from the new-note menu", || { - app.click("new-note-kind"); - app.click("new-note-calc"); - app.fill("editor-title", TITLE); - app.wait_for("calc-counts"); - }); - - step("each line is computed, and an error stays on its line", || { - app.click("editor-body"); - app.paste(SHEET); - app.eventually("the results computed", |tree| { - let results = results(tree); - results.contains(&"10551".to_owned()) && results.contains(&"200".to_owned()) - }); - app.eventually("two lines refused, on their lines", |tree| tree.count("calc-failure") == 2); - app.capture("sheet"); - }); - - step("a result picked is summed in the footer", || { - app.click_nth("calc-result", 0); - app.eventually("the sum said", |tree| { - tree.text("calc-summary").is_some_and(|said| digits(&said).contains("10052")) - }); - app.capture("picked"); - }); - - step("the card shows the last lines that gave something", || { - app.click("editor-close"); - app.eventually("the editor is closed", |tree| !tree.has("editor-title")); - app.capture("card"); - }); - - step("a short date before an accent leaves the sheet listed", || { - app.click("new-note-kind"); - app.click("new-note-calc"); - app.fill("editor-title", "Agenda"); - app.click("editor-body"); - app.paste("RDV le 5/11/24 à 10h\n2 + 2"); - app.eventually("the line computed", |tree| results(tree).contains(&"4".to_owned())); - app.click("editor-close"); - app.eventually("the card listed", |tree| { - tree.texts("note-card-title").iter().any(|title| title == "Agenda") - }); - app.capture("short-date"); - }); - - app.quit(); -}