diff --git a/crates/platform/src/dialog.rs b/crates/platform/src/dialog.rs index 59c78354..70206f86 100644 --- a/crates/platform/src/dialog.rs +++ b/crates/platform/src/dialog.rs @@ -1,5 +1,5 @@ //! Choosing a file to read, or where to write one. An end-to-end scenario cannot reach the -//! system's dialog, so the `e2e` flavour answers the path the scenario fixed instead. +//! system's dialog, so the `e2e` flavour answers the path the scenario wrote down instead. mod system; @@ -21,8 +21,8 @@ pub trait FileDialog { /// `on_missing` hears a desktop with no dialog to show, which otherwise reads as a cancel. pub fn system(on_missing: impl Fn() + Send + Sync + 'static) -> Arc { #[cfg(feature = "e2e")] - if let Some(fixed) = from_scenario() { - return Arc::new(fixed); + if let Some(written) = from_scenario() { + return Arc::new(written); } system::system(on_missing) } @@ -49,7 +49,7 @@ impl FileDialog for NoDialog { } } -/// Answers one path to whatever is asked: a scenario's file, or a test's. +/// Answers one path to whatever is asked: a test's file. pub struct Fixed(pub PathBuf); impl FileDialog for Fixed { @@ -62,13 +62,30 @@ impl FileDialog for Fixed { } } -/// Where a scenario names the file every dialog answers. +/// Where a scenario names the file it writes a dialog's answer in: a path, and a cancel when it +/// holds none. pub const E2E_DIALOG: &str = "DEVNOTES_E2E_DIALOG"; -/// The `e2e` flavour's dialog, when the scenario fixed a path. +/// Answers the path written in a file, read again at each question. #[cfg(feature = "e2e")] -pub fn from_scenario() -> Option { - std::env::var_os(E2E_DIALOG).map(|path| Fixed(PathBuf::from(path))) +pub struct Written(PathBuf); + +#[cfg(feature = "e2e")] +impl FileDialog for Written { + fn open(&self) -> Option { + let path = std::fs::read_to_string(&self.0).ok()?; + (!path.is_empty()).then(|| PathBuf::from(path)) + } + + fn save(&self, _name: &str) -> Option { + self.open() + } +} + +/// The `e2e` flavour's dialog, when the scenario answers it. +#[cfg(feature = "e2e")] +pub fn from_scenario() -> Option { + std::env::var_os(E2E_DIALOG).map(|file| Written(PathBuf::from(file))) } #[cfg(test)] diff --git a/e2e/src/driver.rs b/e2e/src/driver.rs index f38bdc84..5e323727 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, TreeUpdate}; +use egui::accesskit::{Node, NodeId, Rect, Toggled, TreeUpdate}; use egui::{Event, Pos2}; use egui_inspection::protocol::{self, Request, Response}; @@ -82,6 +82,12 @@ impl Tree { self.all(id).len() } + /// Whether anything on the screen says `words`. + pub(crate) fn mentions(&self, words: &str) -> bool { + let said = self.nodes.iter().flat_map(|(_, node)| [node.label(), node.value()]); + said.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) @@ -95,6 +101,11 @@ impl Tree { self.focused().is_some_and(|node| node.author_id() == Some(id)) } + /// What the control that has the keyboard says. + pub(crate) fn focused_says(&self) -> String { + self.focused().map(said).unwrap_or_default() + } + /// Where the keyboard is, as a failure says it. pub(crate) fn keyboard(&self) -> String { match self.focused() { @@ -122,6 +133,10 @@ pub(crate) fn within(node: &Node, place: Rect) -> bool { }) } +pub(crate) fn is_on(node: &Node) -> bool { + node.toggled() == Some(Toggled::True) +} + pub(crate) fn top(node: &Node) -> f64 { node.bounds().map_or(f64::INFINITY, |bounds| bounds.y0) } @@ -201,6 +216,12 @@ impl Driver { self.ask(&Request::ApplyEvents { events }); } + /// The window's inside, in points. + pub(crate) fn resize(&mut self, width: u32, height: u32) { + self.ask(&Request::Resize { width, height }); + self.settle(); + } + /// The directory of the profile the application runs on. pub(crate) fn profile(&self) -> &Path { &self.profile diff --git a/e2e/src/old.rs b/e2e/src/old.rs index adf0a785..dfbf6a1b 100644 --- a/e2e/src/old.rs +++ b/e2e/src/old.rs @@ -112,7 +112,9 @@ impl App { /// As `launch`, every file dialog answering `dialog`: no driver reaches the system's. pub fn launch_answering(scenario: &'static str, profile: &Path, dialog: &Path) -> Self { let mut command = Command::new(binary()); - command.env(platform::dialog::E2E_DIALOG, dialog); + let answer = profile.join("dialog-answer.txt"); + std::fs::write(&answer, dialog.display().to_string()).expect("the dialog's answer is written"); + command.env(platform::dialog::E2E_DIALOG, answer); Self::start(scenario, profile, command) } diff --git a/e2e/src/sdk/act.rs b/e2e/src/sdk/act.rs index 59c8702a..1197f352 100644 --- a/e2e/src/sdk/act.rs +++ b/e2e/src/sdk/act.rs @@ -10,6 +10,8 @@ use super::{App, Shortcut}; use crate::current_step; use crate::driver::{PATIENCE, Tree, middle}; +/// A toast's cross. +const DISMISS: &str = "status-dismiss"; /// How far down a card the middle of its title's band is, in points. const CARD_BAND: f32 = 14.0; /// Clicks closer than this are one gesture to egui. @@ -81,9 +83,26 @@ impl App { let picked = tree.all(id).into_iter().filter(|node| which(node)).nth(n); picked.and_then(Node::bounds) }); + if id != DISMISS && self.uncover(bounds) { + return self.click_nth_where(id, n, name, which); + } self.click_at(middle(bounds), PointerButton::Primary); } + /// Takes a toast standing over a place off the screen: whether one was. + fn uncover(&mut self, place: Rect) -> bool { + let tree = self.tree(); + let bounds = |id| tree.all(id).into_iter().filter_map(Node::bounds); + let mut toasts = bounds("status-toast").zip(bounds(DISMISS)); + let Some(at) = toasts.position(|(words, cross)| covers(words, cross, middle(place))) else { + return false; + }; + let shown = tree.count(DISMISS); + self.click_nth(DISMISS, at, "the toast's cross"); + self.expect("the toast goes", |tree| tree.count(DISMISS) < shown); + 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) { #[expect(clippy::cast_possible_truncation, reason = "points on a screen")] @@ -110,6 +129,12 @@ impl App { self.clicked = Some(Instant::now()); } + /// The pointer over a control, once it is shown. + pub(super) fn hover(&mut self, id: &str, name: &str) { + let bounds = self.place(name, |tree| tree.find(id).and_then(Node::bounds)); + self.move_over(bounds); + } + /// The pointer over a place: what a card shows on hover. pub(super) fn move_over(&mut self, bounds: Rect) { self.driver.apply(vec![Event::PointerMoved(middle(bounds))]); @@ -216,6 +241,14 @@ impl App { } } +/// Whether a toast, from its words to its cross and the margin around them, stands over a point. +fn covers(words: Rect, cross: Rect, at: Pos2) -> bool { + const MARGIN: f64 = 40.0; + let (x, y) = (f64::from(at.x), f64::from(at.y)); + let high = words.y0.min(cross.y0) - MARGIN / 2.0..words.y1.max(cross.y1) + MARGIN / 2.0; + (words.x0 - MARGIN..cross.x1 + MARGIN).contains(&x) && high.contains(&y) +} + fn press(pos: Pos2, button: PointerButton, pressed: bool) -> Event { Event::PointerButton { pos, button, pressed, modifiers: Modifiers::NONE } } diff --git a/e2e/src/sdk/attachments.rs b/e2e/src/sdk/attachments.rs new file mode 100644 index 00000000..c9e6c324 --- /dev/null +++ b/e2e/src/sdk/attachments.rs @@ -0,0 +1,74 @@ +use std::sync::Arc; + +use egui::accesskit::Node; +use egui::{Color32, ColorImage, Event}; + +use super::{App, Shortcut}; + +/// The files attached to the note open. +pub struct Attachments<'a>(pub(super) &'a mut App); + +impl Attachments<'_> { + /// *Attach*, the dialog answering one of the person's files. + pub fn add(&mut self, file: &str) { + self.0.files().answer(file); + self.0.click("attachment-add", "the button that attaches a file"); + } + + /// Pastes a picture in the note. + pub fn paste_picture(&mut self) { + let picture = Arc::new(ColorImage::filled([8, 8], Color32::RED)); + self.0.driver.apply(vec![Event::PasteImage(picture)]); + } + + /// Looks at the first picture, then grows it over the window. + pub fn grow(&mut self) { + self.0.click("attachment-preview", "the picture's eye"); + self.0.click("attachment-zoom", "the picture"); + self.0 + .expect("the picture grows over the window", |tree| tree.has("lightbox-image")); + } + + /// Takes the grown picture away. + pub fn shrink(&mut self) { + self.0.press(Shortcut::Escape); + self.0.expect("the picture goes, the note stays", |tree| { + !tree.has("lightbox-image") && tree.has("editor-title") + }); + } + + /// Saves a file elsewhere, the dialog answering where. + pub fn save(&mut self, n: usize, file: &str) { + self.0.files().answer(file); + self.0.click_nth("attachment-save", n, "the file's « Save »"); + } + + /// Clicks a file's cross: the first time asks, the second removes. + pub fn remove(&mut self, n: usize) { + self.0.click_nth("attachment-remove", n, "the file's cross"); + } + + /// As many files are attached. + pub fn expect(&mut self, count: usize, says: &str) { + self.0.expect(says, |tree| tree.count("attachment-open") == count); + } + + /// As many files go by this name. + pub fn expect_named(&mut self, name: &str, count: usize, says: &str) { + self.0.expect(says, |tree| { + let files = tree.all("attachment-open"); + files.into_iter().filter(|file| called(file, name)).count() == count + }); + } + + /// The file asked for is refused: a banner says it, which is then dismissed. + pub fn expect_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.expect("the banner goes", |tree| !tree.has("error-banner")); + } +} + +fn called(file: &Node, name: &str) -> bool { + file.label().is_some_and(|label| label.contains(name)) +} diff --git a/e2e/src/sdk/editor.rs b/e2e/src/sdk/editor.rs index c081e183..83b78d20 100644 --- a/e2e/src/sdk/editor.rs +++ b/e2e/src/sdk/editor.rs @@ -6,14 +6,6 @@ use crate::driver::Tree; /// The note open: its title, its text and what stands around them. pub struct Editor<'a>(pub(super) &'a mut App); -/// How a JSON snippet is looked at. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum JsonView { - Code, - Graph, - Tree, -} - impl Editor<'_> { /// Types in the title, at the end of what it holds. pub fn type_title(&mut self, title: &str) { @@ -28,13 +20,127 @@ impl Editor<'_> { .expect("the note's text is typed", move |tree| held(tree).contains(&typed)); } - /// Shows a JSON snippet as its code, its graph or its tree. - pub fn show_json_as(&mut self, view: JsonView) { - match view { - JsonView::Code => self.0.click("editor-view-code", "the « Code » view"), - JsonView::Graph => self.0.click("editor-view-graph", "the « Graph » view"), - JsonView::Tree => self.0.click("editor-view-tree", "the « Tree » view"), - } + /// Types over the title. + pub fn retype_title(&mut self, title: &str) { + self.0.replace("editor-title", "the note's title", title); + } + + /// Types over the code. + pub fn retype_code(&mut self, code: &str) { + self.0.take_keyboard("editor-body", "the note's text"); + self.0.press(Shortcut::SelectAll); + self.0.paste(code); + let typed = code.to_owned(); + self.0.expect("the note's text is typed over", move |tree| held(tree) == typed); + } + + /// Types at the end of the code. + pub fn add_to_code(&mut self, code: &str) { + self.0.take_keyboard("editor-body", "the note's text"); + self.0.press(Shortcut::TextEnd); + self.0.type_text(code); + } + + /// Types where the snippet is for. + pub fn type_context(&mut self, context: &str) { + self.0.fill("editor-source", "the note's context", context); + } + + /// Adds a tag. + pub fn add_tag(&mut self, tag: &str) { + self.0.fill("editor-tag-add", "the field of a new tag", tag); + self.0.press(Shortcut::Enter); + self.0.expect("the tag is added", |tree| { + tree.texts("editor-tag").iter().any(|worn| worn.contains(tag)) + }); + } + + /// Chooses the language from the keyboard, in its menu's filter. + pub fn choose_language(&mut self, typed: &str) { + self.0.click("editor-language", "the language's menu"); + self.0.take_keyboard("editor-language-filter", "the filter of the languages"); + self.0.type_text(typed); + self.0.press(Shortcut::Enter); + self.0 + .expect("the language's menu closes", |tree| !tree.has("editor-language-filter")); + } + + /// Gives the note a due date: tomorrow, from the calendar's keys. + pub fn choose_due_tomorrow(&mut self) { + self.0.click("editor-deadline", "the due date's field"); + self.0.expect("the calendar opens on this month", |tree| tree.has("date-day")); + self.0.press(Shortcut::Right); + self.0.press(Shortcut::Enter); + 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"); + self.0.type_text(text); + } + + /// *Format*, by its button. + pub fn format(&mut self) { + self.0.click("editor-format", "« Format »"); + } + + /// Takes the format back, from its notice. + pub fn undo_format(&mut self) { + self.0.click("editor-format-undo", "the notice's « Undo »"); + } + + /// Finds a word and puts another in its place, everywhere. + pub fn replace_everywhere(&mut self, word: &str, with: &str) { + self.find(word); + self.0.click("search-replace-toggle", "the arrow that shows the replacement"); + self.0.fill("search-replace-field", "the replacement", with); + self.0.click("search-replace-all", "« Replace all »"); + } + + /// Expands the note over the cards, or puts it back beside them. + pub fn flip_expanded(&mut self) { + self.0.click("editor-fullscreen", "the button that expands the note"); + } + + /// Folds the note's header into a line. + pub fn fold_header(&mut self) { + self.click_button_or_entry("editor-fold-header", "the button that folds the header"); + self.0.expect("the header is a line", |tree| tree.has("editor-header-summary")); + } + + /// Unfolds the note's header, from its line. + pub fn unfold_header(&mut self) { + self.0.click("editor-header-summary", "the header's line"); + self.0.expect("the header is back", |tree| !tree.has("editor-header-summary")); + } + + /// Goes to a line by its number, Ctrl+Alt+G. + pub fn go_to_line(&mut self, line: usize) { + self.0.press(Shortcut::GoToLine); + self.0 + .expect("the field of the line has the keyboard", |tree| tree.has_focus("go-to-line-input")); + self.0.type_text(&line.to_string()); + self.0.press(Shortcut::Enter); + self.0.expect("the code has the keyboard again", |tree| { + !tree.has("go-to-line-input") && tree.has_focus("editor-body") + }); + } + + /// Shows the text filled with its fields, or gives the code back. + pub fn flip_filled(&mut self) { + self.0 + .click("placeholder-panel-preview", "the button that shows the text filled"); } /// Opens the find bar from the note's text and types a word in it. @@ -53,6 +159,15 @@ impl Editor<'_> { self.0.expect("the find bar closes", |tree| !tree.has("search-field")); } + /// Leaves the note by Esc: the field first, then the note. + pub fn leave_by_escape(&mut self) { + self.0.press(Shortcut::Escape); + if self.0.tree().has("editor-title") { + self.0.press(Shortcut::Escape); + } + self.expect_closed("the note closes"); + } + /// Closes the note, which is written on the way out. pub fn close(&mut self) { self.0.click("editor-close", "the note's closing cross"); @@ -74,6 +189,11 @@ impl Editor<'_> { self.0.expect(says, |tree| held(tree).lines().count() > 5); } + /// The code is on one line. + pub fn expect_one_line(&mut self, says: &str) { + self.0.expect(says, |tree| held(tree).lines().count() == 1); + } + /// The text of the note, as it stands. pub fn expect_code(&mut self, code: &str, says: &str) { self.0.expect(says, |tree| held(tree) == code); @@ -85,11 +205,6 @@ impl Editor<'_> { .expect(says, |tree| tree.text("search-count").as_deref() == Some(counted)); } - /// The graph of a JSON snippet is drawn. - pub fn expect_graph(&mut self, says: &str) { - self.0.expect(says, |tree| tree.has("json-node-head")); - } - /// 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| { @@ -117,12 +232,91 @@ impl Editor<'_> { self.0.type_text("|"); } + /// The footer says this of what the code holds. + pub fn expect_footer(&mut self, words: &str, says: &str) { + self.0 + .expect(says, |tree| tree.text("editor-stats").is_some_and(|said| said.contains(words))); + } + + /// The code gives way to the text read with its values. + pub fn expect_filled(&mut self, says: &str) { + self.0.expect(says, |tree| !tree.has("editor-body") && tree.has("editor-title")); + } + + /// The code was formatted, and the notice says how many lines changed. + pub fn expect_formatted(&mut self, says: &str) { + self.0.expect(says, |tree| { + let told = notice(tree) == Some("formatted"); + let counted = tree.text("editor-format-notice"); + told && counted.is_some_and(|said| said.contains(|it: char| it.is_ascii_digit())) + }); + } + + /// The notice says where the code's syntax breaks. + pub fn expect_syntax_error(&mut self, says: &str) { + self.0.expect(says, |tree| notice(tree) == Some("syntax")); + } + + /// *Format* is out of reach, and says why under the pointer. + pub fn expect_no_format(&mut self, says: &str) { + self.0.expect(says, |tree| tree.is_disabled("editor-format")); + self.0.hover("editor-format", "« Format »"); + self.0.expect(says, |tree| tree.mentions("Prettier")); + } + + /// The code holds this, among other things. + pub fn expect_code_holding(&mut self, code: &str, says: &str) { + self.0.expect(says, |tree| held(tree).contains(code)); + } + + /// The note's title. + pub fn expect_title(&mut self, title: &str, says: &str) { + self.0 + .expect(says, |tree| tree.find("editor-title").and_then(Node::value) == Some(title)); + } + + /// Another note than this one is open. + pub fn expect_another_note(&mut self, title: &str, says: &str) { + self.0.expect(says, |tree| { + tree.find("editor-title") + .and_then(Node::value) + .is_some_and(|open| open != title) + }); + } + + /// The note's context. + pub fn expect_context(&mut self, context: &str, says: &str) { + self.0 + .expect(says, |tree| tree.find("editor-source").and_then(Node::value) == Some(context)); + } + + /// The note takes the whole area, the cards put away. + pub fn expect_expanded(&mut self, says: &str) { + self.0.expect(says, |tree| !tree.has("note-card") && tree.has("editor-title")); + } + + /// 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) { + if !self.0.tree().has(id) { + self.0.click("editor-more", "the note's « ⋯ »"); + } + self.0.click(id, name); + } + /// No note is open. pub fn expect_closed(&mut self, says: &str) { self.0.expect(says, |tree| !tree.has("editor-title")); } - /// Goes to the start of the code, its keyboard. + /// Moves the caret to the end of the next line, inside its value. + pub fn go_to_line_end_below(&mut self) { + self.0.press(Shortcut::Down); + self.0.press(Shortcut::LineEnd); + self.0.press(Shortcut::Left); + self.0.press(Shortcut::Left); + } + + /// Puts the caret at the start of the code. pub fn go_to_start(&mut self) { self.0.take_keyboard("editor-body", "the note's text"); self.0.press(Shortcut::TextStart); @@ -134,6 +328,11 @@ fn held(tree: &Tree) -> String { tree.find("editor-body").and_then(Node::value).unwrap_or_default().to_owned() } +/// What the format's notice is about. +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/fields.rs b/e2e/src/sdk/fields.rs index 53f4a2c4..83c46868 100644 --- a/e2e/src/sdk/fields.rs +++ b/e2e/src/sdk/fields.rs @@ -11,6 +11,18 @@ impl Fields<'_> { self.0.type_text(value); } + /// *Copy as is*: the braces stay. + pub fn copy_as_is(&mut self) { + self.0.click("placeholder-copy-raw", "« Copy as is »"); + self.expect_closed("the form closes once the snippet is copied"); + } + + /// *Cancel*: nothing is kept. + pub fn cancel(&mut self) { + self.0.click("placeholder-cancel", "« Cancel »"); + self.expect_closed("the form closes"); + } + /// Copies the snippet, filled. pub fn copy(&mut self) { self.0.press(Shortcut::Enter); @@ -22,6 +34,14 @@ impl Fields<'_> { self.0.expect(says, |tree| tree.has_focus("placeholder-input")); } + /// A field holds this value. + pub fn expect_value(&mut self, field: usize, value: &str, says: &str) { + self.0.expect(says, |tree| { + let inputs = tree.all("placeholder-input"); + inputs.get(field).and_then(|input| input.value()) == Some(value) + }); + } + fn expect_closed(&mut self, says: &str) { self.0.expect(says, |tree| !tree.has("placeholder-form-hint")); } diff --git a/e2e/src/sdk/files.rs b/e2e/src/sdk/files.rs new file mode 100644 index 00000000..7b10fd49 --- /dev/null +++ b/e2e/src/sdk/files.rs @@ -0,0 +1,36 @@ +use std::path::{Path, PathBuf}; + +use super::App; + +/// The person's own files, and what they answer to the system's file dialogs: no driver reaches the +/// dialog itself. +pub struct Files<'a>(pub(super) &'a mut App); + +impl Files<'_> { + /// Puts a file among the person's own. + pub fn put(&mut self, name: &str, bytes: &[u8]) { + std::fs::write(self.path(name), bytes).expect("the person's file is written"); + } + + /// Answers this file to the dialogs from now on: the one to read, or the one to write. + pub fn answer(&mut self, name: &str) { + let path = self.path(name).display().to_string(); + std::fs::write(answer(self.0.room.path()), path).expect("the dialog's answer is written"); + } + + /// A file was written, and its bytes are what `holds` accepts. + pub fn expect(&mut self, name: &str, says: &str, holds: impl Fn(&[u8]) -> bool) { + let path = self.path(name); + self.0.expect(says, |_| std::fs::read(&path).is_ok_and(|bytes| holds(&bytes))); + } + + /// Where a file of the person's own is. + fn path(&self, name: &str) -> PathBuf { + self.0.room.path().join("files").join(name) + } +} + +/// Where the dialogs read their answer. +pub(super) fn answer(room: &Path) -> PathBuf { + room.join("dialog-answer.txt") +} diff --git a/e2e/src/sdk/history.rs b/e2e/src/sdk/history.rs new file mode 100644 index 00000000..bd486c56 --- /dev/null +++ b/e2e/src/sdk/history.rs @@ -0,0 +1,42 @@ +use super::App; + +/// The versions of the note open. +pub struct History<'a>(pub(super) &'a mut App); + +impl History<'_> { + /// Opens the list of versions. + pub fn open(&mut self) { + self.0.click("revisions-toggle", "« History »"); + self.0.expect("the versions are listed", |tree| tree.has("revision-open")); + } + + /// Looks at what going back to a version would change, the newest counted 0. + pub fn look_at(&mut self, version: usize) { + self.0.click_nth("revision-open", version, "the version"); + self.0.expect("what would change is shown", |tree| tree.has("revision-diff")); + } + + /// Goes back to the version looked at. + pub fn go_back(&mut self) { + self.0.click("revision-restore", "« Go back to this version »"); + } + + /// As many versions are kept. + pub fn expect_versions(&mut self, count: usize, says: &str) { + self.0.expect(says, |tree| tree.count("revision-open") == count); + } + + /// Going back would bring a line back, and drop another. + pub fn expect_change(&mut self, back: &str, dropped: &str, says: &str) { + self.0.expect(says, |tree| { + let holds = |id: &str, line: &str| tree.texts(id).iter().any(|shown| shown.contains(line)); + holds("diff-restored", back) && holds("diff-dropped", dropped) + }); + } + + /// The note has no version but its own. + pub fn expect_none(&mut self, says: &str) { + self.0 + .expect(says, |tree| tree.has("editor-title") && !tree.has("revisions-toggle")); + } +} diff --git a/e2e/src/sdk/json.rs b/e2e/src/sdk/json.rs new file mode 100644 index 00000000..c6865602 --- /dev/null +++ b/e2e/src/sdk/json.rs @@ -0,0 +1,107 @@ +use egui::accesskit::Node; + +use super::App; + +/// A JSON snippet explored: its graph, its tree, and what is selected in them. An entry is named by +/// its path, as `$.owner.team`. +pub struct Json<'a>(pub(super) &'a mut App); + +/// How a JSON snippet is looked at. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum JsonView { + Code, + Graph, + Tree, +} + +impl Json<'_> { + /// Shows the snippet as its code, its graph or its tree. + pub fn show_as(&mut self, view: JsonView) { + match view { + JsonView::Code => self.0.click("editor-view-code", "the « Code » view"), + JsonView::Graph => self.0.click("editor-view-graph", "the « Graph » view"), + JsonView::Tree => self.0.click("editor-view-tree", "the « Tree » view"), + } + } + + /// Puts the code and the graph side by side, or one at a time again. + pub fn flip_side_by_side(&mut self) { + self.0.click("editor-side-by-side", "« Side by side »"); + } + + /// Brings the whole graph in view. + pub fn fit(&mut self) { + self.0.click("json-fit", "the button that shows the whole graph"); + } + + /// Selects a node of the graph. + pub fn select(&mut self, path: &str) { + self.0 + .click_where("json-node-head", "the node of the graph", |node| at(node, path)); + } + + /// Folds or opens a container of the tree. + pub fn flip_in_the_tree(&mut self, path: &str) { + self.0.click_where("json-line", "the line of the tree", |node| at(node, path)); + } + + /// Opens every node. + pub fn open_all(&mut self) { + self.0.click("json-open-all", "« Open all »"); + } + + /// Folds every node. + pub fn collapse_all(&mut self) { + self.0.click("json-collapse-all", "« Collapse all »"); + } + + /// Searches a word in the document. + pub fn search(&mut self, word: &str) { + self.0.replace("json-search", "the document's search", word); + } + + /// Goes to the next match. + pub fn next_match(&mut self) { + self.0.click("json-match-next", "the next match's arrow"); + } + + /// Shows what is selected in the code. + pub fn show_in_code(&mut self) { + self.0.click("json-show-in-code", "« Show in the code »"); + } + + /// The graph draws this many nodes. + pub fn expect_nodes(&mut self, count: usize, says: &str) { + self.0.expect(says, |tree| tree.count("json-node-head") == count); + } + + /// This entry is selected, its path said. + pub fn expect_selected(&mut self, path: &str, says: &str) { + self.0 + .expect(says, |tree| tree.text("json-selected-path").as_deref() == Some(path)); + } + + /// The search counts its matches. + pub fn expect_matches(&mut self, count: usize, says: &str) { + let count = count.to_string(); + self.0 + .expect(says, |tree| tree.text("json-match-count").as_deref() == Some(count.as_str())); + } + + /// A container of the tree is folded. + pub fn expect_folded_in_the_tree(&mut self, path: &str, says: &str) { + self.0.expect(says, |tree| { + let mut lines = tree.all("json-line").into_iter(); + lines.any(|line| at(line, path) && line.is_expanded() == Some(false)) + }); + } + + /// The code stands beside the graph, or not. + pub fn expect_side_by_side(&mut self, beside: bool, says: &str) { + self.0.expect(says, |tree| tree.has("side-by-side") == beside); + } +} + +fn at(node: &Node, path: &str) -> bool { + node.description() == Some(path) +} diff --git a/e2e/src/sdk/mod.rs b/e2e/src/sdk/mod.rs index 77ffbe9b..3b753f8f 100644 --- a/e2e/src/sdk/mod.rs +++ b/e2e/src/sdk/mod.rs @@ -2,29 +2,39 @@ //! take its act and until it has taken it: a journey never waits on its own. mod act; +mod attachments; mod clipboard; mod editor; mod fields; +mod files; mod gate; mod help; +mod history; mod http; +mod json; mod notes; mod prefs; mod shortcut; mod tools; +mod trash; mod window; +pub use attachments::Attachments; pub use clipboard::Clipboard; -pub use editor::{Editor, JsonView}; +pub use editor::Editor; pub use egui::Key; pub use fields::Fields; +pub use files::Files; pub use gate::Gate; pub use help::Help; +pub use history::History; pub use http::Http; -pub use notes::{Named, Notes, Sample}; +pub use json::{Json, JsonView}; +pub use notes::{Named, Notes, QuickFilter, Sample}; pub use prefs::{CardKey, DefaultKind, Density, Indent, Language, Page, Prefs, Switch, Theme}; pub use shortcut::Shortcut; pub use tools::Tools; +pub use trash::Trash; pub use window::{Area, Window}; use std::ffi::OsString; @@ -40,7 +50,7 @@ use crate::{PASSPHRASE, current_step, server}; /// DevNotes as a person has it in front of them, on a profile of the journey's own. pub struct App { driver: Driver, - /// The profile and the terminal's lines: gone once the application is. + /// The profile, the person's files and the terminal's lines: gone once the application is. room: TempDir, /// When the last click was. clicked: Option, @@ -63,10 +73,13 @@ impl App { Self::launch(journey, vec![(platform::updater::E2E_UPDATES, served.into())]).with_a_library() } - fn launch(journey: &'static str, set: Vec<(&'static str, OsString)>) -> Self { + fn launch(journey: &'static str, mut set: Vec<(&'static str, OsString)>) -> Self { let room = TempDir::new().expect("a directory of the journey's own"); let profile = room.path().join("profile"); - std::fs::create_dir(&profile).expect("the profile's directory is made"); + for directory in [&profile, &room.path().join("files")] { + std::fs::create_dir(directory).expect("the journey's directories are made"); + } + set.push((platform::dialog::E2E_DIALOG, files::answer(room.path()).into())); let driver = Driver::launch(journey, profile, terminal(room.path()), set); App { driver, room, clicked: None } } @@ -92,6 +105,26 @@ impl App { Editor(self) } + /// The files attached to the note open. + pub fn attachments(&mut self) -> Attachments<'_> { + Attachments(self) + } + + /// The versions of the note open. + pub fn history(&mut self) -> History<'_> { + History(self) + } + + /// The trash's panel. + pub fn trash(&mut self) -> Trash<'_> { + Trash(self) + } + + /// The JSON snippet open, explored. + pub fn json(&mut self) -> Json<'_> { + Json(self) + } + /// The form that asks for a snippet's fields. pub fn fields(&mut self) -> Fields<'_> { Fields(self) @@ -127,6 +160,11 @@ impl App { Clipboard(self) } + /// The person's own files, and what they answer to the file dialogs. + pub fn files(&mut self) -> Files<'_> { + Files(self) + } + /// Presses a shortcut. pub fn press(&mut self, shortcut: Shortcut) { let (key, modifiers) = shortcut.keys(); @@ -145,6 +183,16 @@ impl App { self.driver.apply(vec![Event::Text(text.to_owned())]); } + /// Pastes a text where the keyboard is, as the window delivers it. + pub fn paste(&mut self, text: &str) { + self.driver.apply(vec![Event::Paste(text.to_owned())]); + } + + /// Copies what is selected, as the window delivers Ctrl+C. + pub fn copy(&mut self) { + self.driver.apply(vec![Event::Copy]); + } + /// Quits and starts DevNotes again, as a person closing it and coming back: the gate asks. pub fn relaunch(&mut self) { self.driver.hand_over(Some("quit")); diff --git a/e2e/src/sdk/notes.rs b/e2e/src/sdk/notes.rs index fd06a812..44e0c7ac 100644 --- a/e2e/src/sdk/notes.rs +++ b/e2e/src/sdk/notes.rs @@ -1,8 +1,7 @@ use egui::accesskit::{Node, Rect}; -use egui::{Key, Modifiers}; -use super::App; -use crate::driver::{Tree, said, within}; +use super::{App, Shortcut}; +use crate::driver::{Tree, is_on, said, within}; /// The notes area: its rail, its header and its cards. pub struct Notes<'a>(pub(super) &'a mut App); @@ -50,6 +49,14 @@ impl Named for Sample { } } +/// The quick filter of the header. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum QuickFilter { + All, + Pinned, + Untriaged, +} + const SAMPLES: usize = 6; /// The samples' space, in English and in French. const FIRST_SPACE: [&str; 2] = ["Getting started", "Découverte"]; @@ -61,6 +68,53 @@ 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); + self.0.click("note-card-duplicate", "« Duplicate »"); + self.0.expect("the copy opens", |tree| tree.has("editor-title")); + } + + /// Sends a note to a space, from its card's menu. + pub fn move_to_space(&mut self, note: impl Named, space: &str) { + self.open_card_menu(note); + self.0.click("note-card-move", "« Move to… »"); + self.0 + .click_where("note-card-move-place", "the place to move to", |place| said(place) == space); + } + + /// 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 « ⋯ »"); + } + /// A calculation, from the menu beside *New note*. pub fn new_calculation(&mut self) { self.0.click("new-note-kind", "the menu beside « New note »"); @@ -102,6 +156,64 @@ impl Notes<'_> { .click_nth_where("note-card-item", item, "an item on the card", |node| within(node, card)); } + /// Takes the keyboard to a note's card: the search finds it alone, and the arrow goes down to it. + pub fn go_to_card(&mut self, title: &str) { + self.search(title); + self.0.expect("the note is alone", |tree| tree.texts("note-card") == [title]); + self.0.press(Shortcut::Down); + self.0 + .expect("its card has the keyboard", |tree| tree.has_focus("note-card-open")); + } + + /// Deletes a note from the keyboard: the first press asks, the second sends it to the trash. + pub fn delete_from_the_keyboard(&mut self, title: &str) { + self.go_to_card(title); + self.0.press(Shortcut::Delete); + self.0 + .expect("the card asks for a second press", |tree| tree.has("note-card-arming")); + self.0.press(Shortcut::Delete); + self.0 + .expect("the note is in the trash", |tree| !tree.has("note-card") && tree.has("undo-bar")); + } + + /// The undo bar's *Undo*. + pub fn undo(&mut self) { + self.0.click("undo-restore", "the bar's « Undo »"); + } + + /// Takes the undo bar off the screen, its offer turned down. + pub fn dismiss_undo(&mut self) { + self.0.click("undo-dismiss", "the bar's cross"); + self.0.expect("the bar goes", |tree| !tree.has("undo-bar")); + } + + /// The quick filter of the header. + pub fn filter(&mut self, filter: QuickFilter) { + match filter { + QuickFilter::All => self.0.click("quick-filter-0", "« All »"), + QuickFilter::Pinned => self.0.click("quick-filter-1", "« Pinned »"), + QuickFilter::Untriaged => self.0.click("quick-filter-2", "« Untriaged »"), + } + } + + /// A todo list with one task, written and closed. + 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.editor().close(); + self.expect_card(title, "the list is a card"); + } + + /// A Note with one line, written and closed. + pub fn write_note(&mut self, title: &str, text: &str) { + self.0.press(Shortcut::NewNote); + self.0.editor().type_title(title); + self.0.editor().type_note(text); + self.0.editor().close(); + self.expect_card(title, "the Note is a card"); + } + /// Types in the search, over what it holds. pub fn search(&mut self, words: &str) { self.0.replace("search-input", "the search", words); @@ -113,13 +225,12 @@ impl Notes<'_> { self.0.expect("the search is empty", |tree| !tree.has("search-clear")); } - /// Takes the keyboard to the first card, then presses a letter on it. - pub fn press_on_first_card(&mut self, letter: Key) { + /// Takes the keyboard to the first card. + pub fn go_to_first_card(&mut self) { self.0.take_keyboard("search-input", "the search"); - self.0.key(Key::ArrowDown, Modifiers::NONE); + self.0.press(Shortcut::Down); self.0 .expect("the first card has the keyboard", |tree| tree.has_focus("note-card-open")); - self.0.key(letter, Modifiers::NONE); } /// The height of the cards, in points. @@ -173,6 +284,68 @@ impl Notes<'_> { }); } + /// As many cards are on the screen. + pub fn expect_cards(&mut self, count: usize, says: &str) { + self.0 + .expect(says, |tree| tree.count("note-card") == count && !tree.has("editor-title")); + } + + /// This card has the keyboard. + pub fn expect_keyboard_on(&mut self, note: impl Named, says: &str) { + self.0 + .expect(says, |tree| tree.has_focus("note-card-open") && note.is(&tree.focused_says())); + } + + /// A card wears its language and how many fields it has. + pub fn expect_card_wearing(&mut self, note: impl Named, language: &str, fields: &str, says: &str) { + self.0.expect(says, |tree| { + let Some(card) = card_of(tree, note) else { + return false; + }; + let worn = |id: &str, words: &str| { + tree.all(id) + .into_iter() + .any(|node| within(node, card) && said(node).contains(words)) + }; + worn("note-format", language) && worn("note-card-fields", fields) + }); + } + + /// The first card is this note's, pinned and wearing its priority. + pub fn expect_first_pinned_with_priority(&mut self, note: impl Named, says: &str) { + self.0.expect(says, |tree| { + let Some(card) = card_of(tree, note) else { + return false; + }; + let worn = |id: &str| tree.all(id).into_iter().any(|node| within(node, card)); + let first = tree.texts("note-card").first().is_some_and(|title| note.is(title)); + first && worn("note-card-pin") && worn("priority-bars") + }); + } + + /// A card counts its files. + pub fn expect_files_counted(&mut self, note: impl Named, count: &str, says: &str) { + self.0.expect(says, |tree| { + let Some(card) = card_of(tree, note) else { + return false; + }; + let mut clips = tree.all("note-card-clip").into_iter(); + clips.any(|clip| within(clip, card) && said(clip).contains(count)) + }); + } + + /// 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")); + } + + /// Nothing is on the canvas under this title. + pub fn expect_no_card(&mut self, note: impl Named, says: &str) { + self.0.expect(says, |tree| { + tree.has("canvas-keyboard-hint") && !tree.texts("note-card").iter().any(|title| note.is(title)) + }); + } + /// A card counts this much of its list done, as « 1/9 ». pub fn expect_progress(&mut self, note: impl Named, done: &str, says: &str) { self.0.expect(says, |tree| { @@ -203,6 +376,14 @@ impl Notes<'_> { self.0.expect("the toast goes", |tree| !tree.has("status-toast")); } + /// Takes any toast off the screen. + pub fn clear_toasts(&mut self) { + while self.0.tree().has("status-dismiss") { + self.0.click("status-dismiss", "the toast's cross"); + self.0.driver.settle(); + } + } + /// No toast is on the screen, once what was done is done. pub fn expect_no_acknowledgement(&mut self, says: &str) { self.0.expect_at_rest(says, |tree| !tree.has("status-toast")); diff --git a/e2e/src/sdk/shortcut.rs b/e2e/src/sdk/shortcut.rs index 6179b335..95747860 100644 --- a/e2e/src/sdk/shortcut.rs +++ b/e2e/src/sdk/shortcut.rs @@ -12,14 +12,29 @@ pub enum Shortcut { /// The arrows. Up, Down, + Left, Right, - /// The start of the line, of the text. - Home, + /// The end of the line. + LineEnd, + /// The start of the text, its end. TextStart, + TextEnd, + /// Ctrl+N: a code snippet. + NewSnippet, + /// Ctrl+Shift+N: a Note. + NewNote, + /// Ctrl+Shift+L: a todo list. + NewTodoList, + /// Del. + Delete, + /// Ctrl+Z. + Undo, /// Ctrl+A. SelectAll, /// Ctrl+F. Find, + /// Ctrl+Alt+G. + GoToLine, /// Shift+Alt+F. Format, /// Ctrl+1, Ctrl+2 and Ctrl+3. @@ -28,6 +43,8 @@ pub enum Shortcut { HttpArea, /// Ctrl+B: the side rail. SideRail, + /// A letter or a digit on the card that has the keyboard. + CardKey(Key), } impl Shortcut { @@ -38,15 +55,24 @@ impl Shortcut { Self::Tab => (Key::Tab, Modifiers::NONE), Self::Up => (Key::ArrowUp, Modifiers::NONE), Self::Down => (Key::ArrowDown, Modifiers::NONE), + Self::Left => (Key::ArrowLeft, Modifiers::NONE), + Self::LineEnd => (Key::End, Modifiers::NONE), Self::Right => (Key::ArrowRight, Modifiers::NONE), - Self::Home => (Key::Home, Modifiers::NONE), Self::TextStart => (Key::Home, Modifiers::COMMAND), + Self::TextEnd => (Key::End, Modifiers::COMMAND), + Self::NewSnippet => (Key::N, Modifiers::COMMAND), + Self::NewNote => (Key::N, Modifiers::COMMAND | Modifiers::SHIFT), + Self::NewTodoList => (Key::L, Modifiers::COMMAND | Modifiers::SHIFT), + Self::Delete => (Key::Delete, Modifiers::NONE), + Self::Undo => (Key::Z, Modifiers::COMMAND), Self::SelectAll => (Key::A, Modifiers::COMMAND), Self::Find => (Key::F, Modifiers::COMMAND), + Self::GoToLine => (Key::G, Modifiers::COMMAND | Modifiers::ALT), Self::Format => (Key::F, Modifiers::SHIFT | Modifiers::ALT), Self::NotesArea => (Key::Num1, Modifiers::COMMAND), Self::ToolsArea => (Key::Num2, Modifiers::COMMAND), Self::HttpArea => (Key::Num3, Modifiers::COMMAND), + Self::CardKey(key) => (key, Modifiers::NONE), Self::SideRail => (Key::B, Modifiers::COMMAND), } } diff --git a/e2e/src/sdk/trash.rs b/e2e/src/sdk/trash.rs new file mode 100644 index 00000000..eb024a7b --- /dev/null +++ b/e2e/src/sdk/trash.rs @@ -0,0 +1,58 @@ +use super::{App, Shortcut}; + +/// The trash's panel. +pub struct Trash<'a>(pub(super) &'a mut App); + +impl Trash<'_> { + /// Opens the trash from the notes' header. + pub fn open(&mut self) { + self.0.click("trash-open", "the trash's button"); + self.0.expect("the trash opens", |tree| tree.has("trash-close")); + } + + /// Closes the panel. + pub fn close(&mut self) { + self.0.press(Shortcut::Escape); + self.0.expect("the trash closes", |tree| !tree.has("trash-close")); + } + + /// Restores a note, by its title. + pub fn restore(&mut self, title: &str) { + let row = self.row(title); + self.0.click_nth("trash-restore", row, "the note's « Restore »"); + } + + /// Deletes a note for good, by its title: the second click does it. + pub fn purge(&mut self, title: &str) { + let row = self.row(title); + self.0.click_nth("trash-purge", row, "the note's « Delete for good »"); + self.0 + .expect("the first click deletes nothing", |tree| tree.texts("trash-row-title").len() > row); + self.0.click_nth("trash-purge", row, "the note's « Delete for good », again"); + } + + /// Empties the trash, once it has said what it erases. + pub fn empty(&mut self) { + self.0.click("trash-empty", "« Empty the trash »"); + self.0 + .expect("the trash says what it erases", |tree| tree.has("trash-empty-warning")); + self.0.click("trash-empty-confirm", "« Empty »"); + } + + /// The trash holds these notes, in any order. + pub fn expect(&mut self, titles: &[&str], says: &str) { + self.0.expect(says, |tree| { + let mut held = tree.texts("trash-row-title"); + let mut wanted = titles.to_vec(); + held.sort(); + wanted.sort_unstable(); + held == wanted && (!titles.is_empty() || tree.has("trash-empty-state")) + }); + } + + fn row(&mut self, title: &str) -> usize { + self.0.seen(&format!("« {title} » is in the trash"), |tree| { + tree.texts("trash-row-title").iter().position(|row| row == title) + }) + } +} diff --git a/e2e/src/sdk/window.rs b/e2e/src/sdk/window.rs index d5f998bd..0668c3de 100644 --- a/e2e/src/sdk/window.rs +++ b/e2e/src/sdk/window.rs @@ -24,6 +24,11 @@ impl Window<'_> { } } + /// Makes the window wide enough for a note beside its cards, or over them with its details. + pub fn widen(&mut self) { + self.0.driver.resize(1_440, 900); + } + /// Switches between dark and light from the title bar. pub fn switch_theme(&mut self) { self.0.click("theme-toggle", "the theme's button"); diff --git a/e2e/tests/01_first_day.rs b/e2e/tests/01_first_day.rs index 8765879a..9a774582 100644 --- a/e2e/tests/01_first_day.rs +++ b/e2e/tests/01_first_day.rs @@ -78,8 +78,8 @@ fn first_tour(app: &mut App) { step("the API response opens as a graph", || { app.notes().open(Sample::ApiResponse); - app.editor().show_json_as(JsonView::Graph); - app.editor().expect_graph("the response is drawn as a graph"); + app.json().show_as(JsonView::Graph); + app.json().expect_nodes(3, "the response is drawn as a graph"); app.editor().close(); }); diff --git a/e2e/tests/02_note_lifecycle.rs b/e2e/tests/02_note_lifecycle.rs deleted file mode 100644 index 8d51a9f2..00000000 --- a/e2e/tests/02_note_lifecycle.rs +++ /dev/null @@ -1,105 +0,0 @@ -//! Creating a note writes nothing until it is worth saving, and the editor writes on the way -//! out: two rules about a row in the database, proved on the assembled window. - -use e2e::old::{App, step}; -use egui::{Key, Modifiers}; - -const CARDS: usize = 6; -const TITLE: &str = "Rotate the staging certificate"; -const BODY: &str = "openssl req -new -key staging.key -out staging.csr"; - -fn cards(app: &mut App, count: usize, what: &str) { - app.eventually(what, |tree| tree.count("note-card") == count); -} - -#[test] -fn note_lifecycle() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("02_note_lifecycle", profile.path()); - app.create_library(); - cards(&mut app, CARDS, "the samples are drawn"); - - step("a card names its kind by an icon, and only a snippet its format", || { - let tree = app.tree(); - assert_eq!(tree.count("kind-icon"), CARDS); - let formats = tree.count("note-format"); - assert!(formats > 0 && formats < CARDS, "{formats} formats"); - // Title bar over status line, on every card. - for (icon, when) in tree.all("kind-icon").iter().zip(tree.all("note-card-when")) { - let (icon, when) = (icon.bounds().unwrap(), when.bounds().unwrap()); - assert!(icon.y1 <= when.y0, "{icon:?} over {when:?}"); - } - }); - - step("a new note opens as a draft that is not yet a note", || { - app.click("new-note"); - app.wait_for("editor-title"); - // Beside the editor fewer cards fit on screen, none in a narrow window: none is added. - let drawn = app.tree().count("note-card"); - assert!(drawn <= CARDS, "{drawn} cards drawn"); - }); - - step("it is written once it carries something worth keeping", || { - app.fill("editor-title", TITLE); - app.fill("editor-body", BODY); - app.capture("editor-draft"); - app.click("editor-close"); - app.eventually("the editor is closed and the note is a card", |tree| { - !tree.has("editor-title") && tree.texts("note-card").contains(&TITLE.to_owned()) - }); - cards(&mut app, CARDS + 1, "one card more, and only one"); - }); - - step("the ghost opens a draft, and closed untouched it writes nothing", || { - app.scroll_to("canvas", "create-ghost"); - app.scroll_above("canvas", "create-ghost", "canvas-keyboard-hint"); - app.at_rest("create-ghost"); - app.click("create-ghost"); - app.wait_for("editor-title"); - app.click("editor-close"); - app.eventually("the editor is closed", |tree| !tree.has("editor-title")); - // Under a header of two rows the top ones went out of view, and were not counted. - app.scroll_top("canvas"); - cards(&mut app, CARDS + 1, "no card more"); - }); - - step("the kind menu opens the same draft as the button", || { - app.click("new-note-kind"); - app.click("new-note-snippet"); - app.wait_for("editor-title"); - app.click("editor-close"); - app.eventually("the editor is closed", |tree| !tree.has("editor-title")); - cards(&mut app, CARDS + 1, "no card more"); - }); - - step("each kind opens from its own key, and writes nothing untouched", || { - for (key, shift) in [(Key::N, false), (Key::N, true), (Key::L, true)] { - let modifiers = if shift { Modifiers::COMMAND | Modifiers::SHIFT } else { Modifiers::COMMAND }; - app.press(key, modifiers); - app.wait_for("editor-title"); - app.click("editor-close"); - app.eventually("the editor is closed", |tree| !tree.has("editor-title")); - } - cards(&mut app, CARDS + 1, "no card more"); - assert!(app.has("canvas-keyboard-hint")); - }); - - step("a note opened from its card shows what was written", || { - app.click_where("note-card-open", |node| node.label() == Some(TITLE)); - app.eventually("the note is read back whole", |tree| { - tree.find("editor-body").and_then(egui::accesskit::Node::value) == Some(BODY) - }); - app.click("editor-close"); - }); - - let mut app = app.relaunch(); - - step("the note is read back from the library on a relaunch", || { - app.fill("vault-passphrase", e2e::old::PASSPHRASE); - app.click("vault-submit"); - app.wait_for("area-notes"); - app.eventually("its card is there", |tree| tree.texts("note-card").contains(&TITLE.to_owned())); - }); - - app.quit(); -} diff --git a/e2e/tests/02_snippet_to_paste.rs b/e2e/tests/02_snippet_to_paste.rs new file mode 100644 index 00000000..f7f4eb69 --- /dev/null +++ b/e2e/tests/02_snippet_to_paste.rs @@ -0,0 +1,279 @@ +//! Journey 2, « A snippet, from writing to pasting »: written with its fields, copied filled, +//! formatted, explored when it is JSON, its draft kept whatever happens around it, and reached from +//! the keyboard. + +use e2e::{App, JsonView, Key, Sample, Shortcut, step}; + +const JUMP: &str = "Jump host"; +const SAMPLES: usize = 6; + +#[test] +fn snippet_to_paste() { + let mut app = App::open("02_snippet_to_paste"); + app.window().widen(); + + writing(&mut app); + copying(&mut app); + formatting(&mut app); + exploring(&mut app); + keeping_the_draft(&mut app); + from_the_keyboard(&mut app); + + app.quit(); +} + +fn writing(app: &mut App) { + step("an empty snippet left by Esc writes nothing", || { + app.press(Shortcut::NewSnippet); + app.editor().expect_code_open("a snippet is open"); + app.editor().leave_by_escape(); + app.notes().expect_cards(SAMPLES, "no note was written"); + }); + + step("a title, a language, code with fields, a context and tags make a note", || { + app.press(Shortcut::NewSnippet); + app.editor().type_title(JUMP); + app.editor().choose_language("rust"); + app.editor().type_code("ssh {{host}} -p {{port=22}}"); + app.editor().type_context("runbooks/ssh.md"); + app.editor().add_tag("remote"); + app.editor().add_tag("shell"); + app.editor().expect_footer("RS", "the footer says the language"); + app.editor().expect_footer("· 1 ", "the footer counts one line"); + app.capture("snippet"); + app.editor().leave_by_escape(); + }); + + step("its card shows them", || { + app.notes() + .expect_card_wearing(JUMP, "RS", "2", "the card wears its language and its fields"); + app.notes().expect_cards(SAMPLES + 1, "one note was written"); + app.notes().open(JUMP); + app.editor().expect_context("runbooks/ssh.md", "the context was written"); + app.editor().close(); + }); +} + +fn copying(app: &mut App) { + step("copied from its card, it asks for its fields and is copied filled", || { + app.notes().copy_filled(JUMP); + app.fields().type_value(0, "db.internal"); + app.capture("fields"); + app.fields().copy(); + app.clipboard() + .expect("ssh db.internal -p 22", "the field left empty takes the value the text suggests"); + }); + + step("what was typed comes back, and cancelling keeps nothing", || { + app.notes().copy_filled(JUMP); + app.fields().expect_value(0, "db.internal", "the value typed comes back"); + app.fields().type_value(0, "db.discarded"); + app.fields().cancel(); + app.notes().copy_filled(JUMP); + app.fields().expect_value(0, "db.internal", "what was cancelled is gone"); + }); + + step("« Copy as is » keeps the braces", || { + app.fields().copy_as_is(); + app.clipboard() + .expect("ssh {{host}} -p {{port=22}}", "the snippet is copied as it is written"); + }); + + step("the note open shows its text filled, and gives the code back", || { + app.notes().open(JUMP); + app.editor().flip_filled(); + app.editor().expect_filled("the text is read with its values"); + app.editor().flip_filled(); + app.editor().expect_code_open("the code is back"); + app.editor().close(); + }); + + step("a note with no field is copied at once, and the copy acknowledged", || { + app.notes().clear_toasts(); + app.notes().copy(Sample::ApiResponse); + app.clipboard().expect_saying("billing", "the response is copied"); + app.notes().expect_acknowledged("a toast says the copy was done"); + }); +} + +fn formatting(app: &mut App) { + step("the sample written on one line is formatted, and « Undo » goes back", || { + app.notes().open(Sample::SnippetToFormat); + app.editor().format(); + app.editor().expect_formatted("the notice says how many lines changed"); + app.editor().expect_several_lines("the code is laid out"); + app.editor().undo_format(); + app.editor().expect_one_line("the code is on one line again"); + }); + + step("a syntax error is said, and nothing changes", || { + app.editor().add_to_code(")"); + app.editor().format(); + app.editor().expect_syntax_error("the notice says where it breaks"); + app.editor().expect_one_line("the code is as typed"); + app.editor().close(); + }); + + step("a snippet keeps its fields when it is formatted", || { + app.press(Shortcut::NewSnippet); + app.editor().type_title("Call"); + app.editor().choose_language("typescript"); + app.editor().type_code(r#"const url="{{base}}/api/{{version=v2}}";fetch(url)"#); + app.editor().format(); + app.editor().expect_formatted("the code is formatted"); + app.editor() + .expect_code_holding("{{base}}/api/{{version=v2}}", "its fields are as written"); + app.editor().close(); + }); + + step("a language Prettier does not read says why it is not formatted", || { + app.notes().open(JUMP); + app.editor().expect_no_format("« Format » is out of reach, with its reason"); + app.editor().close(); + }); +} + +fn exploring(app: &mut App) { + step("a JSON snippet opens as a graph, a node selected with its path", || { + app.notes().open(Sample::ApiResponse); + app.editor().flip_expanded(); + app.json().show_as(JsonView::Graph); + app.json().fit(); + app.json().expect_nodes(6, "every node is drawn"); + app.json().select("$.owner"); + app.json().expect_selected("$.owner", "the node's path is said"); + app.capture("graph"); + }); + + step("everything folds, and opens", || { + app.json().collapse_all(); + app.json().expect_nodes(1, "the root is alone"); + app.json().open_all(); + app.json().expect_nodes(6, "every node is back"); + }); + + step("a search steps to its match, shown in the code", || { + app.json().search("ONCALL"); + app.json().expect_matches(1, "one match is counted"); + app.json().next_match(); + app.json().expect_selected("$.owner.onCall", "the match is selected"); + app.json().show_in_code(); + app.editor().expect_code_open("the code is back"); + app.copy(); + app.clipboard().expect("\"@oncall\"", "the match is selected in it"); + }); + + step("the tree folds a container", || { + app.json().show_as(JsonView::Tree); + app.json().flip_in_the_tree("$.owner"); + app.json().expect_folded_in_the_tree("$.owner", "the owner is folded"); + }); + + step("side by side, the code and the graph select in each other", || { + app.json().show_as(JsonView::Graph); + app.json().flip_side_by_side(); + app.json().expect_side_by_side(true, "the code stands beside the graph"); + app.editor().go_to_start(); + app.editor().go_to_line_end_below(); + app.json() + .expect_selected("$.service", "the caret in a value selects it in the graph"); + app.json().select("$.endpoints"); + app.json().show_in_code(); + app.copy(); + app.clipboard() + .expect_saying("invoices", "the node's lines are selected in the code"); + app.json().show_as(JsonView::Graph); + app.json().flip_side_by_side(); + app.json().expect_side_by_side(false, "one at a time again"); + app.editor().flip_expanded(); + app.editor().close(); + }); +} + +fn keeping_the_draft(app: &mut App) { + step("a word is found and replaced, and Tab stays in the code", || { + app.notes().open(JUMP); + app.editor().replace_everywhere("ssh", "mosh"); + app.editor().close_find(); + app.editor().expect_code("mosh {{host}} -p {{port=22}}", "the word is replaced"); + app.editor().go_to_start(); + app.press(Shortcut::Tab); + app.editor() + .expect_code_holding(" mosh {{host}}", "a level stands before the code"); + }); + + step("a line is gone to by its number", || { + app.editor().add_to_code(" "); + app.editor().go_to_line(1); + app.type_text("#"); + app.editor() + .expect_code_holding("# mosh {{host}}", "what is typed is at the line's start"); + }); + + step("the draft survives the note expanded and its header folded", || { + app.editor().add_to_code(" # mine"); + app.editor().flip_expanded(); + app.editor().expect_expanded("the note takes the whole area"); + app.editor().expect_code_holding("# mine", "the draft is there, expanded"); + app.editor().flip_expanded(); + app.editor().fold_header(); + app.editor() + .expect_code_holding("# mine", "the draft is there, the header folded"); + app.editor().unfold_header(); + app.editor().close(); + app.notes().open(JUMP); + app.editor().expect_code_holding("# mine", "the draft was written"); + }); + + step("a title being typed is kept when another card is clicked", || { + app.editor().retype_title("Jump by mosh"); + app.notes().open(Sample::PsqlConnection); + app.editor().close(); + app.notes().expect_card("Jump by mosh", "the card wears its new title"); + }); + + step("a title being typed is kept when DevNotes quits", || { + app.notes().open("Jump by mosh"); + app.editor().retype_title(JUMP); + app.relaunch_and_unlock(); + app.notes().expect_card(JUMP, "the card wears its new title"); + }); +} + +fn from_the_keyboard(app: &mut App) { + step("the arrows walk the cards, Enter opens one, and J the next one", || { + app.notes().go_to_first_card(); + app.press(Shortcut::Down); + app.notes().expect_keyboard_on(JUMP, "the arrow went down to the snippet"); + app.press(Shortcut::Enter); + app.editor().expect_title(JUMP, "the snippet is open"); + app.press(Shortcut::CardKey(Key::J)); + app.editor().expect_another_note(JUMP, "the next note is open"); + app.press(Shortcut::CardKey(Key::K)); + app.editor().expect_title(JUMP, "K goes back to the snippet"); + app.editor().close(); + }); + + step("C on a card copies it, asking for its fields", || { + app.notes().go_to_card(JUMP); + app.press(Shortcut::CardKey(Key::C)); + app.fields().expect_open("the form asks for the fields"); + app.fields().cancel(); + app.notes().clear_search(); + }); + + 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.notes().duplicate(JUMP); + app.editor() + .expect_code_holding("mosh {{host}}", "the copy is open, with the same code"); + app.editor().retype_title("Jump from work"); + 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.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/03_keeping_a_note.rs b/e2e/tests/03_keeping_a_note.rs new file mode 100644 index 00000000..fa7cddd8 --- /dev/null +++ b/e2e/tests/03_keeping_a_note.rs @@ -0,0 +1,195 @@ +//! Journey 3, « Keeping, correcting and losing a note »: pinned and dated, its files, its versions, +//! deleted and taken back. + +use e2e::{App, Key, QuickFilter, Sample, Shortcut, step}; + +const NOTE: &str = "Nightly dump"; +const SAMPLES: usize = 6; +const DIAGRAM: &[u8] = br##""##; +/// One byte past the 10 MB a file may weigh. +const TOO_HEAVY: usize = 10 * 1024 * 1024 + 1; + +#[test] +fn keeping_a_note() { + let mut app = App::open("03_keeping_a_note"); + app.window().widen(); + app.notes().write_snippet(NOTE, "pg_dump one"); + + on_top(&mut app); + with_its_files(&mut app); + and_its_versions(&mut app); + deleted_and_taken_back(&mut app); + in_the_trash(&mut app); + + app.quit(); +} + +fn on_top(app: &mut App) { + step("pinned, given a priority from its digit and a due date, it sorts on top", || { + app.notes().go_to_card(NOTE); + app.press(Shortcut::CardKey(Key::P)); + app.press(Shortcut::CardKey(Key::Num4)); + app.notes().clear_search(); + app.notes() + .expect_first_pinned_with_priority(NOTE, "it is the first card, pinned, with its priority"); + app.notes().open(NOTE); + app.editor().choose_due_tomorrow(); + app.editor().close(); + }); + + step("« Untriaged » finds it, and « Pinned » too", || { + app.notes().filter(QuickFilter::Untriaged); + app.notes().expect_cards(2, "the two notes with a due date are listed"); + app.notes().expect_card(NOTE, "this one is among them"); + app.notes().filter(QuickFilter::Pinned); + app.notes().expect_card(NOTE, "it is among the pinned ones"); + app.notes().filter(QuickFilter::All); + app.notes().expect_cards(SAMPLES + 1, "every note is back"); + }); +} + +fn with_its_files(app: &mut App) { + step("a file and a pasted picture are attached, and the card counts them", || { + app.files().put("diagram.svg", DIAGRAM); + app.notes().open(NOTE); + app.attachments().add("diagram.svg"); + app.attachments().expect(1, "the file is attached"); + app.attachments().paste_picture(); + app.attachments().expect(2, "the picture is attached"); + app.capture("attachments"); + app.editor().close(); + app.notes().expect_files_counted(NOTE, "2", "the card counts two files"); + }); + + step("the picture grows in the lightbox, and Esc takes it away", || { + app.notes().open(NOTE); + app.attachments().grow(); + app.attachments().shrink(); + }); + + step("two files of one name stay apart", || { + app.attachments().add("diagram.svg"); + app.attachments() + .expect_named("diagram.svg", 2, "both are listed under the name"); + }); + + step("a file over 10 MB is refused, and nothing is attached", || { + app.files().put("dump.sql", &vec![b' '; TOO_HEAVY]); + app.attachments().add("dump.sql"); + app.attachments().expect_refused("a banner says it is too heavy"); + app.attachments().expect(3, "the files are as they were"); + }); + + step("an attachment is saved elsewhere", || { + app.attachments().save(0, "elsewhere.svg"); + app.files() + .expect("elsewhere.svg", "its bytes are the file's", |bytes| bytes == DIAGRAM); + }); + + step("a removal needs a second click", || { + app.attachments().remove(0); + app.attachments().expect(3, "the first click asks"); + app.attachments().remove(0); + app.attachments().expect(2, "the second one removes"); + app.editor().close(); + }); +} + +fn and_its_versions(app: &mut App) { + step("each edit keeps the version before it, the newest first", || { + for code in ["pg_dump two", "pg_dump three"] { + app.notes().open(NOTE); + app.editor().retype_code(code); + app.editor().close(); + } + app.notes().open(NOTE); + app.history().open(); + app.history().expect_versions(2, "two versions are listed"); + app.history().look_at(1); + app.history() + .expect_change("pg_dump one", "pg_dump three", "going back shows what it would change"); + app.capture("history"); + }); + + step("going back drops the later ones", || { + app.history().go_back(); + app.editor().expect_code("pg_dump one", "the first version is back"); + app.history().expect_none("no version is left"); + app.editor().close(); + }); + + step("a Note keeps its versions too", || { + app.notes().write_note("Runbook", "call the team"); + app.notes().open("Runbook"); + app.editor().type_note(" first"); + app.editor().close(); + app.notes().open("Runbook"); + app.history().open(); + app.history().expect_versions(1, "one version is listed"); + app.editor().close(); + }); + + 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.editor().close(); + app.notes().open("Before the dump"); + app.history().expect_none("no version is offered"); + app.editor().close(); + }); +} + +fn deleted_and_taken_back(app: &mut App) { + step("deleted from the keyboard in two presses, the undo bar takes it back", || { + app.notes().delete_from_the_keyboard(NOTE); + app.capture("undo"); + app.notes().undo(); + app.notes().clear_search(); + app.notes().expect_card(NOTE, "the note is back"); + }); + + step("once the bar has gone, Ctrl+Z still does", || { + app.notes().delete_from_the_keyboard(NOTE); + app.notes().expect_undo_gone("the bar had its time"); + app.press(Shortcut::Undo); + app.notes().clear_search(); + app.notes().expect_card(NOTE, "the note is back"); + }); +} + +fn in_the_trash(app: &mut App) { + step("the trash restores one note", || { + for title in [NOTE, "Runbook", "Before the dump"] { + app.notes().delete_from_the_keyboard(title); + app.notes().dismiss_undo(); + } + app.notes().clear_search(); + app.trash().open(); + app.trash() + .expect(&[NOTE, "Runbook", "Before the dump"], "the three notes wait there"); + app.trash().restore(NOTE); + app.trash().expect(&["Runbook", "Before the dump"], "two are left"); + app.trash().close(); + app.notes().expect_card(NOTE, "the note restored has its card"); + }); + + step("it deletes one for good, and empties the rest", || { + app.trash().open(); + app.trash().purge("Runbook"); + app.trash().expect(&["Before the dump"], "one is left"); + app.trash().empty(); + app.trash().expect(&[], "the trash says it is empty"); + app.trash().close(); + }); + + step("a relaunch finds it as left", || { + app.relaunch_and_unlock(); + app.notes().expect_card(NOTE, "the note restored is there"); + app.notes().expect_no_card("Runbook", "the one deleted for good is not"); + app.notes().expect_card(Sample::Welcome, "the others were not touched"); + app.trash().open(); + app.trash().expect(&[], "the trash is still empty"); + app.trash().close(); + }); +} diff --git a/e2e/tests/04_trash_and_undo.rs b/e2e/tests/04_trash_and_undo.rs deleted file mode 100644 index 61a977c3..00000000 --- a/e2e/tests/04_trash_and_undo.rs +++ /dev/null @@ -1,173 +0,0 @@ -//! Deleting a note does not delete it: it goes to the trash, and the undo bar, `Escape` while it -//! offers, and `Ctrl+Z` after it has gone take it back; the trash panel restores, purges and -//! empties. The samples' titles are translated: rows are counted, never read. - -use e2e::old::{App, step}; -use egui::{Key, Modifiers}; - -const CARDS: usize = 6; - -fn cards(app: &mut App, count: usize, what: &str) { - app.eventually(what, |tree| tree.count("note-card") == count); -} - -/// The first card, sent to the trash from the keyboard: the second press is the one that writes. -fn delete_first(app: &mut App) { - let before = app.tree().count("note-card"); - app.press(Key::ArrowDown, Modifiers::NONE); - app.press(Key::Delete, Modifiers::NONE); - app.wait_for("note-card-arming"); - app.press(Key::Delete, Modifiers::NONE); - cards(app, before - 1, "the note is in the trash"); -} - -/// Deleted, and the offer to take it back turned down. -fn trash_first(app: &mut App) { - delete_first(app); - app.click("undo-dismiss"); -} - -fn rows(app: &mut App, count: usize, what: &str) { - app.eventually(what, |tree| tree.count("trash-row") == count); -} - -fn emptied(app: &mut App) { - app.eventually("the trash says it is empty", |tree| { - tree.has("trash-empty-state") && tree.count("trash-row") == 0 - }); -} - -#[test] -fn trash_and_undo() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("04_trash_and_undo", profile.path()); - app.create_library(); - cards(&mut app, CARDS, "the samples are drawn"); - - step("the card's menu needs the second click to delete anything", || { - app.hover("note-card-open"); - app.click("note-card-menu"); - app.click("note-card-delete"); - assert_eq!(app.tree().count("note-card"), CARDS); - app.press(Key::Escape, Modifiers::NONE); - }); - - step("the priorities of the menu come and go with the pointer, and one is picked", || { - let levels = "note-card-priority-level"; - app.hover("note-card-open"); - app.click("note-card-menu"); - app.hover("note-card-priority"); - app.eventually("the five levels", |tree| tree.count(levels) == 5); - app.hover("note-card-duplicate"); - app.eventually("closed with the pointer gone", |tree| !tree.has(levels)); - app.hover("note-card-priority"); - app.hover_nth(levels, 3); - app.eventually("open under the pointer", |tree| tree.count(levels) == 5); - app.click_nth(levels, 0); - app.eventually("a pick closes the menu", |tree| !tree.has("note-card-priority")); - }); - - step("Delete arms the card, and Escape calls it off", || { - app.press(Key::ArrowDown, Modifiers::NONE); - app.press(Key::Delete, Modifiers::NONE); - app.wait_for("note-card-arming"); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the card is disarmed", |tree| !tree.has("note-card-arming")); - // Back to zero, not to one: the next Delete arms again rather than trashing. - app.press(Key::Delete, Modifiers::NONE); - app.wait_for("note-card-arming"); - assert_eq!(app.tree().count("note-card"), CARDS); - app.press(Key::Escape, Modifiers::NONE); - }); - - step("Escape takes the note back while the bar offers", || { - delete_first(&mut app); - app.wait_for("undo-bar"); - app.capture("undo-bar"); - app.press(Key::Escape, Modifiers::NONE); - cards(&mut app, CARDS, "the note is back"); - }); - - step("the bar's Undo takes it back", || { - delete_first(&mut app); - app.click("undo-restore"); - cards(&mut app, CARDS, "the note is back"); - assert!(!app.has("undo-bar")); - }); - - step("Ctrl+Z still takes it back once the banner has gone", || { - delete_first(&mut app); - app.wait_for("undo-bar"); - app.eventually("the banner's timer runs out", |tree| !tree.has("undo-bar")); - app.press(Key::Z, Modifiers::COMMAND); - cards(&mut app, CARDS, "the note is back"); - }); - - step("a dismissed offer is given up for good", || { - trash_first(&mut app); - app.press(Key::Z, Modifiers::COMMAND); - assert!(!app.has("undo-bar")); - assert_eq!(app.tree().count("note-card"), CARDS - 1); - }); - - trash_panel(&mut app); - app.quit(); -} - -/// Starts with one note in the trash and the others on the canvas. -fn trash_panel(app: &mut App) { - step("the trash panel restores what was deleted", || { - app.click("trash-open"); - rows(app, 1, "the deleted note is listed"); - app.capture("trash-panel"); - app.click("trash-restore"); - emptied(app); - app.click("trash-close"); - cards(app, CARDS, "the note is back"); - }); - - step("a row is purged for good on the second click", || { - trash_first(app); - app.click("trash-open"); - rows(app, 1, "the deleted note is listed"); - app.click("trash-purge"); - assert_eq!(app.tree().count("trash-row"), 1); - app.click("trash-purge"); - emptied(app); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("Escape closes the panel", |tree| !tree.has("trash-close")); - assert_eq!(app.tree().count("note-card"), CARDS - 1); - }); - - step("a search narrows the trash, and restoring reaches what it found", || { - for _ in 0..3 { - trash_first(app); - } - app.click("trash-open"); - rows(app, 3, "the three deleted notes are listed"); - app.fill("trash-search", "zz-nothing-zz"); - app.eventually("the search finds nothing", |tree| { - tree.has("trash-empty-state") && !tree.has("trash-empty") - }); - app.press(Key::A, Modifiers::COMMAND); - app.press(Key::Backspace, Modifiers::NONE); - rows(app, 3, "the whole trash is back"); - app.click("trash-restore-all"); - emptied(app); - app.click("trash-close"); - cards(app, CARDS - 1, "the three notes are back"); - }); - - step("emptying says what it erases, then erases it", || { - trash_first(app); - trash_first(app); - app.click("trash-open"); - rows(app, 2, "the two deleted notes are listed"); - app.click("trash-empty"); - app.wait_for("trash-empty-warning"); - app.click("trash-empty-confirm"); - emptied(app); - app.click("trash-close"); - cards(app, CARDS - 3, "the erased notes stay gone"); - }); -} diff --git a/e2e/tests/08_placeholder_fields.rs b/e2e/tests/08_placeholder_fields.rs deleted file mode 100644 index 3a4e98b1..00000000 --- a/e2e/tests/08_placeholder_fields.rs +++ /dev/null @@ -1,128 +0,0 @@ -//! `{{fields}}` in a snippet: copied, the note asks for them first, from the card as from the -//! keyboard; what is typed is kept, what is cancelled is not. In the editor the panel counts them, -//! folds and shows the body filled. The sample used is found by its code, which no translation -//! touches. - -use e2e::old::{App, step}; -use egui::{Key, Modifiers}; - -/// What the first field holds: its value, not its name. -fn first_value(tree: &e2e::old::Tree) -> String { - tree.all("placeholder-input") - .first() - .and_then(|field| field.value()) - .unwrap_or_default() - .to_owned() -} - -/// The card's fill button, which a note with fields shows instead of a plain copy. -fn open_from_card(app: &mut App) { - app.hover("note-card-open"); - app.click("note-card-fill"); - app.wait_for("placeholder-form-hint"); -} - -fn open_editor(app: &mut App) { - app.click("note-card-open"); - app.wait_for("editor-title"); -} - -fn close_editor(app: &mut App) { - app.click("editor-close"); - app.eventually("the editor is closed", |tree| !tree.has("editor-title")); -} - -/// `1/4`: what the panel's head counts. -fn counted(tree: &e2e::old::Tree) -> String { - tree.all("placeholder-panel-toggle") - .first() - .and_then(|toggle| toggle.value()) - .unwrap_or_default() - .to_owned() -} - -fn closed(app: &mut App) { - app.eventually("the form is closed", |tree| !tree.has("placeholder-form-hint")); -} - -#[test] -fn placeholder_fields() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("08_placeholder_fields", profile.path()); - app.create_library(); - app.wait_for("note-card"); - app.fill("search-input", "5432"); - app.eventually("the snippet with fields, alone", |tree| tree.count("note-card") == 1); - - step("the keyboard asks for the fields too, in the first one", || { - app.press(Key::ArrowDown, Modifiers::NONE); - app.eventually("the card has the focus", |tree| tree.focused().starts_with("note-card-open")); - app.press(Key::C, Modifiers::NONE); - app.eventually("the form, typing in its first field", |tree| { - tree.focused().starts_with("placeholder-input") - }); - app.capture("placeholder-form"); - app.press(Key::Escape, Modifiers::NONE); - closed(&mut app); - }); - - step("the card offers the fields instead of a plain copy", || { - app.hover("note-card-open"); - app.wait_for("note-card-fill"); - assert!(!app.has("note-card-copy")); - }); - - step("what is typed is copied filled, and kept", || { - open_from_card(&mut app); - app.type_text("db.internal"); - app.press(Key::Enter, Modifiers::NONE); - closed(&mut app); - app.wait_for("status-toast"); - open_from_card(&mut app); - app.eventually("the value typed comes back", |tree| first_value(tree) == "db.internal"); - }); - - step("cancelled, the form writes nothing", || { - app.click_nth("placeholder-input", 0); - app.press(Key::A, Modifiers::COMMAND); - app.type_text("db.discarded"); - app.click("placeholder-cancel"); - closed(&mut app); - open_from_card(&mut app); - app.eventually("the value kept is still there", |tree| first_value(tree) == "db.internal"); - }); - - step("« copy as is » copies and closes", || { - app.click("placeholder-copy-raw"); - closed(&mut app); - app.wait_for("status-toast"); - }); - - step("the editor's panel counts what is kept, default aside", || { - open_editor(&mut app); - app.eventually("one field filled of four", |tree| counted(tree) == "1/4"); - app.capture("fields-panel"); - }); - - step("the body is shown filled, and given back", || { - app.click("placeholder-panel-preview"); - app.eventually("the code gives way", |tree| !tree.has("editor-body")); - app.capture("fields-preview"); - app.click("placeholder-panel-preview"); - app.wait_for("editor-body"); - }); - - step("folded, the panel stays so for the next note opened", || { - app.click("placeholder-panel-toggle"); - app.eventually("the fields gone", |tree| !tree.has("placeholder-input")); - close_editor(&mut app); - open_editor(&mut app); - app.wait_for("placeholder-panel-toggle"); - assert!(!app.has("placeholder-input")); - app.click("placeholder-panel-toggle"); - app.wait_for("placeholder-input"); - close_editor(&mut app); - }); - - app.quit(); -} diff --git a/e2e/tests/11_attachments.rs b/e2e/tests/11_attachments.rs deleted file mode 100644 index a8c5ffb8..00000000 --- a/e2e/tests/11_attachments.rs +++ /dev/null @@ -1,108 +0,0 @@ -//! Attachments: an empty strip that says so, a file chosen and kept under its name, an image shown -//! at once and grown in the lightbox, the card counting them, two files of one name, a removal -//! on the second click, a file over the limit refused, and the plain copies swept. The system's -//! dialog is the one step no driver reaches: the scenario answers it. - -use e2e::old::{App, Tree, step}; -use egui::{Key, Modifiers}; - -const TITLE: &str = "Note with a file"; -const IMAGE: &str = r##""##; - -fn files(tree: &Tree) -> usize { - tree.count("attachment-open") -} - -fn open(app: &mut App) { - app.click("search-input"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(TITLE); - app.eventually("the note alone", |tree| tree.count("note-card") == 1); - app.click("note-card-open"); - app.wait_for("editor-title"); -} - -fn close(app: &mut App) { - app.click("editor-close"); - app.eventually("the editor is closed", |tree| !tree.has("editor-title")); -} - -#[test] -fn attachments() { - let profile = tempfile::tempdir().unwrap(); - let folder = tempfile::tempdir().unwrap(); - let file = folder.path().join("diagram.svg"); - std::fs::write(&file, IMAGE).unwrap(); - let mut app = App::launch_answering("11_attachments", profile.path(), &file); - app.create_library(); - app.wait_for("note-card"); - - step("the strip says it is empty", || { - app.click("new-note"); - app.fill("editor-title", TITLE); - app.click("editor-body"); - app.type_text("step one"); - close(&mut app); - open(&mut app); - app.wait_for("attachment-empty"); - app.wait_for("attachment-add"); - }); - - step("a file is kept, and an image shown at once", || { - app.click("attachment-add"); - app.eventually("the file listed", |tree| files(tree) == 1); - app.wait_for("attachment-zoom"); - assert!(!app.has("attachment-empty")); - app.capture("attachment-strip"); - }); - - step("the lightbox grows it and Escape takes it away", || { - app.click("attachment-zoom"); - app.wait_for("lightbox-image"); - app.capture("lightbox"); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the lightbox gone", |tree| !tree.has("lightbox-image")); - assert!(app.has("editor-title"), "only the lightbox went"); - }); - - step("the card counts it and a reopen lists it", || { - close(&mut app); - app.wait_for("note-card-clip"); - open(&mut app); - app.eventually("the file listed again", |tree| files(tree) == 1); - }); - - step("two files of one name are two records", || { - app.click("attachment-add"); - app.eventually("both listed", |tree| files(tree) == 2); - }); - - step("a file goes on the second click, and only then", || { - app.click_nth("attachment-remove", 0); - assert_eq!(app.tree().count("attachment-open"), 2); - app.click_nth("attachment-remove", 0); - app.eventually("one left", |tree| files(tree) == 1); - }); - - step("a file over the limit is refused and says so", || { - std::fs::write(&file, vec![b' '; 10 * 1024 * 1024 + 1]).unwrap(); - app.click("attachment-add"); - app.wait_for("error-banner"); - assert_eq!(app.tree().count("attachment-open"), 1); - }); - - let copies = profile.path().join("open"); - let leave_a_copy = || { - std::fs::create_dir_all(&copies).unwrap(); - std::fs::write(copies.join("left.txt"), "plain").unwrap(); - }; - leave_a_copy(); - app.quit(); - assert!(!copies.exists(), "swept at the exit"); - - leave_a_copy(); - let mut app = App::launch("11_attachments", profile.path()); - app.wait_for("vault-passphrase"); - assert!(!copies.exists(), "swept at the launch, before the unlock"); - app.quit(); -} diff --git a/e2e/tests/13_making_it_mine.rs b/e2e/tests/13_making_it_mine.rs index 9471e530..8d969fea 100644 --- a/e2e/tests/13_making_it_mine.rs +++ b/e2e/tests/13_making_it_mine.rs @@ -169,7 +169,8 @@ fn the_keys(app: &mut App) { app.prefs().take_key(CardKey::Check, Key::J); app.prefs().expect_key(CardKey::Check, "J", "the panel shows the new key"); app.prefs().close(); - app.notes().press_on_first_card(Key::J); + app.notes().go_to_first_card(); + app.press(Shortcut::CardKey(Key::J)); app.notes().expect_selected(1, "the first card is selected"); app.press(Shortcut::Escape); }); diff --git a/e2e/tests/22_note_history.rs b/e2e/tests/22_note_history.rs deleted file mode 100644 index f2916ca9..00000000 --- a/e2e/tests/22_note_history.rs +++ /dev/null @@ -1,125 +0,0 @@ -//! A note's history: nothing on a note nobody has edited, one body kept per edit, newest first, -//! a preview of what going back would change, and going back, which takes that version and every -//! newer one out of the list. Nothing on a todo list. - -use e2e::old::{App, Tree, step}; -use egui::{Key, Modifiers}; - -const TITLE: &str = "History under test"; -const LIST: &str = "List without history"; - -fn code(tree: &Tree) -> String { - tree.find("editor-body") - .and_then(|body| body.value()) - .unwrap_or_default() - .to_owned() -} - -/// The note titled `title`, found and opened from the keyboard: a list's card is mostly its -/// ticks. -fn open(app: &mut App, title: &str) { - app.click("search-input"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(title); - // By its title: the search before this one left a card alone too, until the debounce ends. - app.eventually("the note alone", |tree| { - tree.count("note-card") == 1 && tree.texts("note-card").contains(&title.to_owned()) - }); - 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-title"); -} - -fn close(app: &mut App) { - app.click("editor-close"); - app.eventually("the editor is closed", |tree| !tree.has("editor-title")); -} - -/// The code replaced by `text`, written on close. -fn rewrite(app: &mut App, text: &str) { - open(app, TITLE); - app.click("editor-body"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(text); - close(app); -} - -/// A row added to the list open, and 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); -} - -fn todo_list_keeps_none(app: &mut App) { - app.click("new-note-kind"); - app.click("new-note-checklist"); - app.fill("editor-title", LIST); - add(app, "one"); - close(app); - open(app, LIST); - add(app, "two"); - close(app); - open(app, LIST); - assert!(!app.has("revisions-toggle")); - close(app); -} - -#[test] -fn note_history() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("22_note_history", profile.path()); - app.create_library(); - app.wait_for("note-card"); - - step("a note nobody has edited shows no history", || { - app.click("new-note"); - app.fill("editor-title", TITLE); - app.click("editor-body"); - app.type_text("select 1"); - close(&mut app); - open(&mut app, TITLE); - assert!(!app.has("revisions-toggle")); - close(&mut app); - }); - - step("each edit keeps the body before it, newest first", || { - rewrite(&mut app, "select 2"); - rewrite(&mut app, "select 3"); - open(&mut app, TITLE); - app.click("revisions-toggle"); - app.eventually("two versions kept", |tree| tree.count("revision-open") == 2); - }); - - step("a click previews what going back would change", || { - app.click_nth("revision-open", 1); - app.wait_for("revision-diff"); - app.eventually("« select 1 » comes back, « select 3 » goes", |tree| { - let restored = tree.texts("diff-restored"); - let dropped = tree.texts("diff-dropped"); - restored.iter().any(|line| line.contains("select 1")) - && dropped.iter().any(|line| line.contains("select 3")) - }); - app.capture("revision-preview"); - }); - - step("going back puts the body in the editor, nothing newer kept", || { - app.click("revision-restore"); - app.eventually("the oldest body back", |tree| code(tree) == "select 1"); - app.eventually("nothing newer kept", |tree| !tree.has("revisions-toggle")); - close(&mut app); - open(&mut app, TITLE); - app.eventually("still the oldest body", |tree| code(tree) == "select 1"); - close(&mut app); - }); - - step("a todo list keeps no history", || { - todo_list_keeps_none(&mut app); - }); - - app.quit(); -} diff --git a/e2e/tests/26_formatting.rs b/e2e/tests/26_formatting.rs deleted file mode 100644 index 145c0032..00000000 --- a/e2e/tests/26_formatting.rs +++ /dev/null @@ -1,124 +0,0 @@ -//! Formatting a snippet with Prettier: the button formats the sample written on one line and its -//! notice undoes it, Shift+Alt+F formats from the title and the result is kept, a syntax error -//! is said, the library's settings change the style, and a language Prettier does not read -//! leaves the button disabled. The samples are found by their code, which no translation touches. - -use e2e::old::{App, Tree, step}; -use egui::{Key, Modifiers}; - -fn code(tree: &Tree) -> String { - tree.find("editor-body") - .and_then(|body| body.value()) - .unwrap_or_default() - .to_owned() -} - -fn notice(tree: &Tree) -> Option { - tree.find("editor-format-notice") - .and_then(|notice| notice.description()) - .map(str::to_owned) -} - -fn open(app: &mut App, found_by: &str) { - app.click("search-input"); - app.press(Key::A, Modifiers::COMMAND); - app.press(Key::Backspace, Modifiers::NONE); - // Until the search's debounce, the previous search's one card passes for this one. - app.eventually("every note listed", |tree| tree.count("note-card") > 1); - app.type_text(found_by); - app.eventually("the sample alone", |tree| tree.count("note-card") == 1); - 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")); -} - -#[test] -fn formatting() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("26_formatting", profile.path()); - app.create_library(); - app.wait_for("note-card"); - open(&mut app, "withRetry"); - - step("the button formats, marks the lines and says so", || { - app.click("editor-format"); - app.eventually("the code on several lines", |tree| { - code(tree).lines().count() > 5 && notice(tree).as_deref() == Some("formatted") - }); - }); - - step("its notice takes the format back", || { - app.click("editor-format-undo"); - app.eventually("the code on one line again", |tree| code(tree).lines().count() == 1); - }); - - step("Shift+Alt+F formats from the title, and it is kept", || { - app.click("editor-title"); - app.press(Key::F, Modifiers::SHIFT | Modifiers::ALT); - app.eventually("formatted", |tree| code(tree).lines().count() > 5); - // Here and not before the undo: a slow capture outlasts the notice it would click. - app.capture("formatted"); - close(&mut app); - open(&mut app, "withRetry"); - assert!( - app.tree() - .find("editor-body") - .is_some_and(|body| { body.value().unwrap_or_default().lines().count() > 5 }) - ); - }); - - step("the library's indentation is the next format's", || { - app.click("editor-format-settings"); - app.click("prettier-indentation-2"); - app.press(Key::Escape, Modifiers::NONE); - app.click("editor-format"); - app.eventually("four spaces a level", |tree| { - code(tree) - .lines() - .any(|line| line.starts_with(" ") && !line.starts_with(" ")) - }); - }); - - step("format on save is named beside its switch, and turns", || { - let on = |tree: &Tree| { - tree.find("prettier-formatOnSave").and_then(egui::accesskit::Node::toggled) - == Some(egui::accesskit::Toggled::True) - }; - app.click("editor-format-settings"); - app.wait_for("prettier-formatOnSave"); - let tree = app.tree(); - assert!(!on(&tree)); - let label = tree.text("prettier-formatOnSave").unwrap_or_default(); - assert!(!label.is_empty() && tree.mentions(&label)); - app.capture("format-settings"); - app.click("prettier-formatOnSave"); - app.eventually("on", on); - app.click("prettier-formatOnSave"); - app.eventually("off again", |tree| !on(tree)); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("closed", |tree| !tree.has("prettier-formatOnSave")); - }); - - step("a syntax error is said, and nothing changes", || { - app.click("editor-body"); - app.press(Key::End, Modifiers::COMMAND); - app.type_text(")"); - let typed = code(&app.tree()); - app.click("editor-format"); - app.eventually("the error said", |tree| notice(tree).as_deref() == Some("syntax")); - assert_eq!(code(&app.tree()), typed); - close(&mut app); - }); - - step("a language Prettier does not read leaves the button disabled", || { - open(&mut app, "5432"); - assert!(app.tree().find("editor-format").is_some_and(egui::accesskit::Node::is_disabled)); - close(&mut app); - }); - - app.quit(); -} diff --git a/e2e/tests/27_json_explorer.rs b/e2e/tests/27_json_explorer.rs deleted file mode 100644 index 0a3bebd9..00000000 --- a/e2e/tests/27_json_explorer.rs +++ /dev/null @@ -1,147 +0,0 @@ -//! A JSON snippet explored: the band says it parses, the graph draws its nodes and selects one -//! with its path, a row closes and opens its container, the arrows walk, everything folds and -//! opens again, a match is stepped to and shown in the code, the tree folds, the code and the -//! graph side by side select in each other. The sample used is found by its code, and every -//! entry by its path, which no translation touches. - -use e2e::old::{App, Tree, step}; -use egui::{Key, Modifiers}; - -fn selected(tree: &Tree) -> String { - tree.text("json-selected-path").unwrap_or_default() -} - -fn nodes(tree: &Tree) -> usize { - tree.count("json-node-head") -} - -fn at(path: &'static str) -> impl Fn(&egui::accesskit::Node) -> bool { - move |node| node.description() == Some(path) -} - -fn invalid(tree: &Tree) -> bool { - tree.find("editor-json-validity").is_some_and(|node| node.invalid().is_some()) -} - -#[test] -fn json_explorer() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("27_json_explorer", profile.path()); - app.create_library(); - app.wait_for("note-card"); - // The notes header stays above an expanded note: the graph is given its height back. - app.resize(1_100, 900); - app.fill("search-input", "p95Ms"); - app.eventually("the JSON sample, alone", |tree| tree.count("note-card") == 1); - - step("the band says the draft parses, over its code", || { - app.click("note-card-open"); - app.wait_for("editor-json-validity"); - // The whole graph wants the whole area, not the panel beside the cards. - app.click("editor-fullscreen"); - app.eventually("the draft read as valid", |tree| !invalid(tree)); - }); - - step("the graph draws the document and selects a node", || { - app.click("editor-view-graph"); - app.wait_for("json-node-head"); - app.click("json-fit"); - app.eventually("every node", |tree| nodes(tree) == 6); - app.click_where("json-node-head", at("$.owner")); - app.eventually("its path said", |tree| selected(tree) == "$.owner"); - app.capture("graph"); - }); - - step("a row closes and opens its container", || { - app.click_where("json-row", at("$.endpoints")); - app.eventually("the endpoints closed", |tree| nodes(tree) == 2); - app.click_where("json-row", at("$.endpoints")); - app.eventually("one level open again", |tree| nodes(tree) == 3); - }); - - step("the arrows walk the rows", || { - app.click_where("json-node-head", at("$")); - app.press(Key::ArrowDown, Modifiers::NONE); - app.eventually("the first row", |tree| selected(tree) == "$.service"); - }); - - step("everything folds and opens, the selection falling back and coming back", || { - app.click("json-open-all"); - app.eventually("every node", |tree| nodes(tree) == 6); - app.click_where("json-row", at("$.owner.team")); - app.click("json-collapse-all"); - app.eventually("the root alone", |tree| nodes(tree) == 1); - app.eventually("the row still drawn", |tree| selected(tree) == "$.owner"); - app.click("json-open-all"); - app.eventually("back where it was", |tree| selected(tree) == "$.owner.team"); - }); - - step("a match is stepped to and shown in the code", || { - app.fill("json-search", "ONCALL"); - app.eventually("one match", |tree| tree.text("json-match-count").as_deref() == Some("1")); - app.click("json-match-next"); - app.eventually("the match selected", |tree| selected(tree) == "$.owner.onCall"); - app.click("json-show-in-code"); - app.eventually("back to the code", |tree| tree.has("editor-body") && !tree.has("json-node-head")); - }); - - step("the tree folds a container", || { - app.click("editor-view-tree"); - app.click_where("json-line", at("$.owner")); - app.eventually("the owner folded", |tree| { - tree.all("json-line") - .into_iter() - .any(|line| at("$.owner")(line) && line.is_expanded() == Some(false)) - }); - app.capture("tree"); - }); - - side_by_side(&mut app); - broken_draft(&mut app); - app.quit(); -} - -/// The code and the graph side by side, selecting in each other; the code hidden; too narrow. -fn side_by_side(app: &mut App) { - step("side by side the code and the graph select in each other", || { - app.click("editor-view-graph"); - app.click("editor-side-by-side"); - app.eventually("the graph beside the code", |tree| { - tree.has("side-by-side") && tree.has("side-by-side-code") - }); - app.click("editor-body"); - app.press(Key::Home, Modifiers::COMMAND); - app.press(Key::ArrowDown, Modifiers::NONE); - app.press(Key::End, Modifiers::NONE); - app.press(Key::ArrowLeft, Modifiers::NONE); - app.press(Key::ArrowLeft, Modifiers::NONE); - app.eventually("the value under the caret", |tree| selected(tree) == "$.service"); - app.capture("side-by-side"); - - app.click("editor-hide-code"); - app.eventually("the graph alone", |tree| !tree.has("side-by-side")); - app.click("editor-hide-code"); - app.wait_for("side-by-side"); - app.resize(720, 700); - app.wait_for("editor-side-by-side-narrow"); - assert!(!app.has("side-by-side"), "too narrow, it is not squeezed"); - app.resize(1_100, 900); - app.wait_for("side-by-side"); - app.click("editor-side-by-side"); - app.eventually("one at a time again", |tree| !tree.has("side-by-side")); - }); -} - -fn broken_draft(app: &mut App) { - step("a broken draft says where it breaks", || { - app.click("editor-view-code"); - app.click("editor-body"); - app.press(Key::End, Modifiers::COMMAND); - app.type_text(",,"); - app.eventually("the draft refused", invalid); - app.click("editor-view-graph"); - app.wait_for("json-invalid"); - app.click("editor-close"); - app.eventually("the editor is closed", |tree| !tree.has("editor-title")); - }); -} diff --git a/e2e/tests/41_note_fullscreen.rs b/e2e/tests/41_note_fullscreen.rs deleted file mode 100644 index 10f780e4..00000000 --- a/e2e/tests/41_note_fullscreen.rs +++ /dev/null @@ -1,116 +0,0 @@ -//! A note expanded over the cards, with the layout of its kind: a snippet's fields over its code -//! and its text filled under it, the details in a column beside the body and put away, a task -//! list narrowed to the tasks done, and a title typed before J: the draft is written when the -//! next note opens. The scenario writes its own notes: the samples' names are translated. - -use e2e::old::{App, Tree, step}; -use egui::{Key, Modifiers}; - -const SHIFT_COMMAND: Modifiers = Modifiers::COMMAND.plus(Modifiers::SHIFT); -const RENAMED: &str = "Renamed while expanded"; - -fn open_title(tree: &Tree) -> String { - tree.find("editor-title") - .and_then(|title| title.value()) - .unwrap_or_default() - .to_owned() -} - -fn close(app: &mut App) { - app.click("editor-close"); - app.eventually("the editor is closed", |tree| !tree.has("editor-title")); -} - -/// The left edge of the expanded note's title. -fn note_left(tree: &Tree) -> f64 { - tree.find("editor-title") - .and_then(egui::accesskit::Node::bounds) - .map_or(f64::NAN, |bounds| bounds.x0) -} - -/// The header stays over the expanded note: its toggle folds the sidebar and the note widens. -fn sidebar_folded_under_an_expanded_note(app: &mut App) { - let left = note_left(&app.tree()); - app.click("library-rail-toggle"); - app.eventually("the note took the sidebar's room", |tree| note_left(tree) < left - 100.0); - app.click("library-rail-toggle"); - app.eventually("and gave it back", |tree| (note_left(tree) - left).abs() < 1.0); -} - -#[test] -fn note_fullscreen() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("41_note_fullscreen", profile.path()); - app.create_library(); - app.wait_for("note-card"); - // Room for the details beside the body. - app.resize(1_440, 900); - - step("a snippet expanded: its fields over the code, filled under it, details beside", || { - app.click("new-note-kind"); - app.click("new-note-snippet"); - app.fill("editor-title", "Connexion"); - app.click("editor-body"); - app.paste("psql -h {{host}} -p {{port=5432}}"); - app.click("editor-title"); - app.wait_for("placeholder-input"); - app.click("editor-fullscreen"); - app.eventually("the column and the filled text", |tree| { - !tree.has("note-card") && tree.has("editor-space") && tree.has("editor-filled") - }); - app.click_nth("placeholder-input", 0); - app.type_text("db.internal"); - app.click("editor-title"); - app.eventually("one field of two filled", |tree| { - tree.find("placeholder-panel-toggle").and_then(|toggle| toggle.value()) == Some("1/2") - }); - app.capture("snippet"); - }); - - step("the details are put away, then shown again", || { - app.click("editor-details"); - app.eventually("the column gone", |tree| !tree.has("editor-space")); - app.click("editor-details"); - app.wait_for("editor-space"); - }); - - step("expanded, the sidebar is folded by its toggle", || { - sidebar_folded_under_an_expanded_note(&mut app); - close(&mut app); - }); - - step("a task list expanded narrows to the tasks done", || { - app.press(Key::L, SHIFT_COMMAND); - app.fill("editor-title", "Tâches"); - app.click("checklist-add"); - app.type_text("Préparer"); - app.press(Key::Enter, Modifiers::NONE); - app.type_text("Déployer"); - app.wait_for("checklist-shown-0"); - let all = app.tree().count("checklist-text"); - app.click_nth("checklist-check", 0); - app.click("checklist-shown-2"); - app.eventually("the task done, alone", |tree| tree.count("checklist-text") == 1); - app.capture("tasks"); - app.click("checklist-shown-0"); - app.eventually("every task again", |tree| tree.count("checklist-text") == all); - close(&mut app); - }); - - step("a title typed is written when J opens the next note", || { - app.click_nth("note-card-open", 0); - app.wait_for("editor-position"); - app.click("editor-title"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(RENAMED); - // The title takes the keys: Escape gives it up first. - app.press(Key::Escape, Modifiers::NONE); - app.press(Key::J, Modifiers::NONE); - app.eventually("the next note open", |tree| tree.has("editor-title") && open_title(tree) != RENAMED); - // Stepped to, the note leaves the keys to J and K. - app.press(Key::K, Modifiers::NONE); - app.eventually("the draft written", |tree| open_title(tree) == RENAMED); - }); - - app.quit(); -}