diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 179f24486..95980c8ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -322,7 +322,7 @@ jobs: save-if: 'true' # The capture needs a rendered window, which xvfb gives; maximising one is a window - # manager's answer (`44_window_controls`), which openbox gives. + # manager's answer (journey 13), which openbox gives. - name: X server if: runner.os == 'Linux' run: sudo apt-get install -y --no-install-recommends xvfb openbox diff --git a/crates/app/src/desktop.rs b/crates/app/src/desktop.rs index 4d31588c1..6d06f0f4f 100644 --- a/crates/app/src/desktop.rs +++ b/crates/app/src/desktop.rs @@ -8,7 +8,7 @@ use platform::autostart::Autostart; use platform::dialog::FileDialog; use platform::shortcuts::Shortcuts; use platform::tray::{NoTray, Picture, Tray}; -use platform::updater::Source; +use platform::updater::{Source, Updater}; use ui::{Inbox, Input, Preferences, Settings}; /// Who sends a toast on Windows. @@ -30,12 +30,23 @@ pub(crate) fn start(preferences: &Preferences, inbox: &Inbox) -> ui::Desktop { autostart: autostart(), notifier: platform::notify::system(METADATA.name, IDENTIFIER), dialog: dialog(inbox.clone()), - updater: platform::updater::system(&UPDATES), + updater: updater(), clipboard: platform::clipboard::system(), opener: platform::desktop::system(), } } +#[cfg(not(feature = "e2e"))] +fn updater() -> Arc { + platform::updater::system(&UPDATES) +} + +/// A scenario is asked by nobody but the server it serves itself. +#[cfg(feature = "e2e")] +fn updater() -> Arc { + platform::updater::from_scenario(&UPDATES) +} + fn dialog(inbox: Inbox) -> Arc { platform::dialog::system(move || inbox.post(Input::NoFileDialog)) } diff --git a/crates/platform/src/updater.rs b/crates/platform/src/updater.rs index 82506bb43..682cdfaad 100644 --- a/crates/platform/src/updater.rs +++ b/crates/platform/src/updater.rs @@ -2,12 +2,19 @@ //! then installed once the application has finished leaving (D26). Nothing installs //! without an explicit gesture, and deb and rpm packages do not update themselves. +#[cfg(feature = "e2e")] +mod scenario; mod system; #[cfg(test)] mod tests; +#[cfg(feature = "e2e")] +pub use scenario::system as from_scenario; pub use system::{Source, system}; +/// Where a scenario serves the `latest.json` the `e2e` flavour asks for. +pub const E2E_UPDATES: &str = "DEVNOTES_E2E_UPDATES"; + /// A version the updater found. #[derive(Debug, Clone, PartialEq, Eq)] pub struct AvailableUpdate { diff --git a/crates/platform/src/updater/scenario.rs b/crates/platform/src/updater/scenario.rs new file mode 100644 index 000000000..9cae41c5c --- /dev/null +++ b/crates/platform/src/updater/scenario.rs @@ -0,0 +1,15 @@ +//! The `e2e` flavour's updater: the real one, on the server a scenario serves. ⚠️ Without one it +//! asks nobody: a published version would be offered in the middle of a scenario. + +use std::sync::Arc; + +use super::system::{Source, built}; +use super::{E2E_UPDATES, NoUpdater, Updater}; + +pub fn system(source: &Source<'_>) -> Arc { + let Ok(endpoint) = std::env::var(E2E_UPDATES) else { + return Arc::new(NoUpdater); + }; + let served = Source { endpoint: &endpoint, ..*source }; + built(&served, true).map_or_else(|| Arc::new(NoUpdater) as _, |updater| Arc::new(updater) as _) +} diff --git a/crates/platform/src/updater/system.rs b/crates/platform/src/updater/system.rs index 3026b2995..e2ee51180 100644 --- a/crates/platform/src/updater/system.rs +++ b/crates/platform/src/updater/system.rs @@ -12,6 +12,7 @@ use cargo_packager_updater::{Config, Error, Update, UpdaterBuilder}; use super::{AvailableUpdate, DownloadError, NoUpdater, Updater}; /// Where the releases are, and who signs them. +#[derive(Clone, Copy)] pub struct Source<'a> { /// The running version. pub version: &'a str, diff --git a/e2e/src/driver.rs b/e2e/src/driver.rs index 0444edc40..f38bdc841 100644 --- a/e2e/src/driver.rs +++ b/e2e/src/driver.rs @@ -67,6 +67,17 @@ impl Tree { found } + /// The ids on the screen that begin so: a list's rows, each wearing its own. + pub(crate) fn all_starting(&self, start: &str) -> Vec<&str> { + let ids = self.nodes.iter().filter_map(|(_, node)| node.author_id()); + ids.filter(|id| id.starts_with(start)).collect() + } + + /// What each node wearing `id` says, in reading order. + pub(crate) fn texts(&self, id: &str) -> Vec { + self.all(id).into_iter().map(said).collect() + } + pub(crate) fn count(&self, id: &str) -> usize { self.all(id).len() } @@ -101,6 +112,16 @@ pub(crate) fn said(node: &Node) -> String { node.label().or(node.value()).unwrap_or_default().to_owned() } +/// Whether a node stands inside a place: a control of a card, a card of a zone. +pub(crate) fn within(node: &Node, place: Rect) -> bool { + node.bounds().is_some_and(|bounds| { + bounds.x0 >= place.x0 - 1.0 + && bounds.x1 <= place.x1 + 1.0 + && bounds.y0 >= place.y0 - 1.0 + && bounds.y1 <= place.y1 + 1.0 + }) +} + pub(crate) fn top(node: &Node) -> f64 { node.bounds().map_or(f64::INFINITY, |bounds| bounds.y0) } @@ -171,10 +192,20 @@ impl Driver { } } + /// Until egui has nothing left to draw: not until the core has answered. + pub(crate) fn settle(&mut self) { + self.ask(&Request::Settle { max_steps: 10 }); + } + pub(crate) fn apply(&mut self, events: Vec) { self.ask(&Request::ApplyEvents { events }); } + /// The directory of the profile the application runs on. + pub(crate) fn profile(&self) -> &Path { + &self.profile + } + /// The window as it stands, as `//.png`. pub(crate) fn capture(&mut self, name: &str) { match self.ask(&Request::GetScreenshot { pixels_per_point: Some(1.0) }) { diff --git a/e2e/src/sdk/act.rs b/e2e/src/sdk/act.rs new file mode 100644 index 000000000..59c8702ad --- /dev/null +++ b/e2e/src/sdk/act.rs @@ -0,0 +1,221 @@ +//! What the areas are made of: a control found by its id, waited for, acted on. A failure says, in +//! the step it stops, what the person would have seen: each act takes the control's name for it. + +use std::time::{Duration, Instant}; + +use egui::accesskit::{Node, Rect}; +use egui::{Event, Key, Modifiers, PointerButton, Pos2}; + +use super::{App, Shortcut}; +use crate::current_step; +use crate::driver::{PATIENCE, Tree, middle}; + +/// 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. +const DOUBLE_CLICK: Duration = Duration::from_millis(300); + +impl App { + pub(super) fn tree(&mut self) -> Tree { + self.driver.tree() + } + + /// Reads the screen until `holds` is true of it: answers arrive from the core frames later. + pub(super) fn expect(&mut self, says: &str, holds: impl Fn(&Tree) -> bool) { + self.seen(says, |tree| holds(tree).then_some(())); + } + + /// What the screen shows once egui has nothing left to draw: for what must not be there. + pub(super) fn expect_at_rest(&mut self, says: &str, holds: impl Fn(&Tree) -> bool) { + self.driver.settle(); + assert!(holds(&self.tree()), "« {} »: {says}", current_step()); + } + + /// What `find` finds on the screen, once it does. No pause between reads: each one renders a + /// frame. + pub(super) fn seen(&mut self, says: &str, find: impl Fn(&Tree) -> Option) -> T { + let until = Instant::now() + PATIENCE; + loop { + let tree = self.tree(); + if let Some(found) = find(&tree) { + return found; + } + assert!( + Instant::now() < until, + "« {} »: {says} — still not so after {PATIENCE:?}; the keyboard is {}", + current_step(), + tree.keyboard() + ); + } + } + + /// Where a control stands, once it holds still: a node joins the tree a frame before it has a + /// place, and one still moving would be clicked where it no longer is. + pub(super) fn place(&mut self, name: &str, find: impl Fn(&Tree) -> Option) -> Rect { + let says = format!("{name} is on the screen"); + loop { + let first = self.seen(&says, &find); + if find(&self.tree()) == Some(first) { + return first; + } + } + } + + pub(super) fn click(&mut self, id: &str, name: &str) { + self.click_where(id, name, |_| true); + } + + /// The first `id` that `which` picks, in reading order. + pub(super) fn click_where(&mut self, id: &str, name: &str, which: impl Fn(&Node) -> bool) { + self.click_nth_where(id, 0, name, which); + } + + /// The `n`th `id` in reading order, counting from 0. + pub(super) fn click_nth(&mut self, id: &str, n: usize, name: &str) { + self.click_nth_where(id, n, name, |_| true); + } + + /// The `n`th `id` that `which` picks, in reading order, counting from 0. + pub(super) fn click_nth_where(&mut self, id: &str, n: usize, name: &str, which: impl Fn(&Node) -> bool) { + let bounds = self.place(name, |tree| { + let picked = tree.all(id).into_iter().filter(|node| which(node)).nth(n); + picked.and_then(Node::bounds) + }); + self.click_at(middle(bounds), PointerButton::Primary); + } + + /// 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")] + let band = Pos2::new(middle(card).x, card.y0 as f32 + CARD_BAND); + self.click_at(band, PointerButton::Primary); + } + + fn click_at(&mut self, pos: Pos2, button: PointerButton) { + self.driver.apply(vec![Event::PointerMoved(pos)]); + self.driver.apply(vec![press(pos, button, true)]); + self.driver.apply(vec![press(pos, button, false)]); + self.clicked = Some(Instant::now()); + } + + /// Two clicks, sent together so that they are one double click however slowly the window draws. + /// ⚠️ A click just before makes egui count three, wherever it was: they wait their turn. + pub(super) fn double_click(&mut self, pos: Pos2) { + while self.clicked.is_some_and(|at| at.elapsed() < DOUBLE_CLICK) { + self.tree(); + } + let click = || [true, false].map(|down| press(pos, PointerButton::Primary, down)); + self.driver.apply(vec![Event::PointerMoved(pos)]); + self.driver.apply([click(), click()].concat()); + self.clicked = Some(Instant::now()); + } + + /// 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))]); + } + + /// Clicks a field, then types at the end of what it holds. + pub(super) fn fill(&mut self, id: &str, name: &str, text: &str) { + self.take_keyboard(id, name); + self.type_text(text); + } + + /// Types over what a field holds. ⚠️ Not by a second click, which selects a word only within + /// the double click's delay: the machine's speed. + pub(super) fn replace(&mut self, id: &str, name: &str, text: &str) { + self.take_keyboard(id, name); + self.press(Shortcut::SelectAll); + self.type_text(text); + } + + /// Clicks a field until it holds the keyboard: what is typed a frame early goes nowhere. ⚠️ A + /// click can land in a frame that drops it; the next comes a few frames later — two at once + /// would be a double click. + pub(super) fn take_keyboard(&mut self, id: &str, name: &str) { + let until = Instant::now() + PATIENCE; + loop { + self.click(id, name); + if (0..5).any(|_| self.tree().has_focus(id)) { + return; + } + assert!(Instant::now() < until, "« {} »: {name} never took the keyboard", current_step()); + } + } + + /// A key pressed and released at its place on the keyboard. + pub(super) fn key(&mut self, key: Key, modifiers: Modifiers) { + self.key_printed(key, key, modifiers); + } + + /// As `key`, `printed` being what the layout prints on the key that stands at `place`. + pub(super) fn key_printed(&mut self, printed: Key, place: Key, modifiers: Modifiers) { + let physical_key = Some(place); + let event = |pressed| Event::Key { key: printed, physical_key, pressed, repeat: false, modifiers }; + self.driver.apply(vec![event(true)]); + self.driver.apply(vec![event(false)]); + } + + /// Scrolls `within` down until `find` finds its place, back from the top past its end: a list + /// draws only what is in view. + pub(super) fn scroll_to( + &mut self, + within: &str, + name: &str, + find: impl Fn(&Tree) -> Option, + ) -> Rect { + for notch in 0..60 { + let tree = self.tree(); + let room = tree.find(within).and_then(Node::bounds); + let in_view = + |place: Rect| room.is_none_or(|room| place.y0 >= room.y0 && place.y1 <= room.y1 + 1.0); + if find(&tree).is_some_and(in_view) { + break; + } + // The first reads are the core's to answer. + match notch { + 0..5 => {} + _ if notch % 20 == 19 => self.wheel(within, 100_000.0), + _ => self.wheel(within, -120.0), + } + } + self.place(name, find) + } + + /// Scrolls `within` until a control stands above `foot`: a panel draws what lies past its edge + /// too, where no click reaches it. + pub(super) fn reach(&mut self, within: &str, (id, name): (&str, &str), foot: &str) { + self.expect(&format!("{name} is on the screen"), |tree| tree.has(id)); + for _ in 0..60 { + let tree = self.tree(); + let place = |id| tree.find(id).and_then(Node::bounds); + let above = place(id).zip(place(foot)).is_some_and(|(target, foot)| target.y1 < foot.y0); + if above { + return; + } + self.wheel(within, -120.0); + } + } + + /// The wheel over `within`, in points: down is negative. + fn wheel(&mut self, within: &str, points: f32) { + let Some(bounds) = self.tree().find(within).and_then(Node::bounds) else { + return; + }; + self.driver.apply(vec![ + Event::PointerMoved(middle(bounds)), + Event::MouseWheel { + unit: egui::MouseWheelUnit::Point, + delta: egui::vec2(0.0, points), + phase: egui::TouchPhase::Move, + source: egui::MouseWheelSource::Wheel, + modifiers: Modifiers::NONE, + }, + ]); + self.driver.settle(); + } +} + +fn press(pos: Pos2, button: PointerButton, pressed: bool) -> Event { + Event::PointerButton { pos, button, pressed, modifiers: Modifiers::NONE } +} diff --git a/e2e/src/sdk/clipboard.rs b/e2e/src/sdk/clipboard.rs new file mode 100644 index 000000000..9052880fa --- /dev/null +++ b/e2e/src/sdk/clipboard.rs @@ -0,0 +1,39 @@ +use std::time::Instant; + +use platform::clipboard::Clipboard as _; + +use super::App; +use crate::current_step; +use crate::driver::PATIENCE; + +/// The system's clipboard. +pub struct Clipboard<'a>(pub(super) &'a mut App); + +impl Clipboard<'_> { + /// The clipboard holds this text, line endings aside. + pub fn expect(&mut self, text: &str, says: &str) { + self.expect_that(says, |held| held.replace("\r\n", "\n") == text); + } + + /// The clipboard holds a text that says this, among other things. + pub fn expect_saying(&mut self, words: &str, says: &str) { + self.expect_that(says, |held| held.contains(words)); + } + + fn expect_that(&mut self, says: &str, holds: impl Fn(&str) -> bool) { + let until = Instant::now() + PATIENCE; + loop { + let held = platform::clipboard::System.text().unwrap_or_default(); + if holds(&held) { + return; + } + assert!( + Instant::now() < until, + "« {} »: {says} — the clipboard still holds {held:?} after {PATIENCE:?}", + current_step() + ); + // A frame between two reads. + let _ = self.0.tree(); + } + } +} diff --git a/e2e/src/sdk/editor.rs b/e2e/src/sdk/editor.rs new file mode 100644 index 000000000..c081e1831 --- /dev/null +++ b/e2e/src/sdk/editor.rs @@ -0,0 +1,139 @@ +use egui::accesskit::Node; + +use super::{App, Shortcut}; +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) { + self.0.fill("editor-title", "the note's title", title); + } + + /// Types in the code, or the text of a calculation. + pub fn type_code(&mut self, code: &str) { + self.0.fill("editor-body", "the note's text", code); + let typed = code.to_owned(); + self.0 + .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"), + } + } + + /// Opens the find bar from the note's text and types a word in it. + pub fn find(&mut self, word: &str) { + let written = if self.0.tree().has("editor-rich") { "editor-rich" } else { "editor-body" }; + self.0.take_keyboard(written, "the note's text"); + self.0.press(Shortcut::Find); + self.0 + .expect("the find bar opens, the keyboard in it", |tree| tree.has_focus("search-field")); + self.0.type_text(word); + } + + /// Closes the find bar. + pub fn close_find(&mut self) { + self.0.press(Shortcut::Escape); + self.0.expect("the find bar closes", |tree| !tree.has("search-field")); + } + + /// 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"); + self.expect_closed("the note closes"); + } + + /// A snippet or a calculation is open, its text under the hand. + pub fn expect_code_open(&mut self, says: &str) { + self.0.expect(says, |tree| tree.has("editor-body")); + } + + /// A Note is open, written formatted. + pub fn expect_note_open(&mut self, says: &str) { + self.0.expect(says, |tree| tree.has("editor-rich") && !tree.has("editor-body")); + } + + /// The code is laid out over several lines. + pub fn expect_several_lines(&mut self, says: &str) { + self.0.expect(says, |tree| held(tree).lines().count() > 5); + } + + /// 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); + } + + /// The find bar counts its matches, as « 1 / 3 ». + pub fn expect_matches(&mut self, counted: &str, says: &str) { + self.0 + .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| { + let first = tree.all("calc-result").first().and_then(|result| result.value()); + first.is_some_and(|result| digits(result) == figures) + }); + } + + /// The first line of the code goes on past the edge: the next row is another line's. + pub fn expect_line_unwrapped(&mut self, says: &str) { + self.mark_the_next_row(); + self.0.expect(says, |tree| held(tree).trim_end().ends_with('|')); + } + + /// The first line of the code is laid out over several rows: the next one is still its own. + pub fn expect_line_wrapped(&mut self, says: &str) { + self.mark_the_next_row(); + self.0 + .expect(says, |tree| held(tree).contains('|') && !held(tree).trim_end().ends_with('|')); + } + + /// A mark typed one row down from the start. + fn mark_the_next_row(&mut self) { + self.0.press(Shortcut::Down); + self.0.type_text("|"); + } + + /// 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. + pub fn go_to_start(&mut self) { + self.0.take_keyboard("editor-body", "the note's text"); + self.0.press(Shortcut::TextStart); + } +} + +/// The text the code holds. +fn held(tree: &Tree) -> String { + tree.find("editor-body").and_then(Node::value).unwrap_or_default().to_owned() +} + +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 new file mode 100644 index 000000000..53f4a2c43 --- /dev/null +++ b/e2e/src/sdk/fields.rs @@ -0,0 +1,28 @@ +use super::{App, Shortcut}; + +/// The form that asks for a snippet's `{{fields}}` before it is copied. +pub struct Fields<'a>(pub(super) &'a mut App); + +impl Fields<'_> { + /// Types a field's value, over what it holds; the fields counted from 0, in the text's order. + pub fn type_value(&mut self, field: usize, value: &str) { + self.0.click_nth("placeholder-input", field, "the field of a value to fill"); + self.0.press(Shortcut::SelectAll); + self.0.type_text(value); + } + + /// Copies the snippet, filled. + pub fn copy(&mut self) { + self.0.press(Shortcut::Enter); + self.expect_closed("the form closes once the snippet is copied"); + } + + /// The form is open, the keyboard in its first field. + pub fn expect_open(&mut self, says: &str) { + self.0.expect(says, |tree| tree.has_focus("placeholder-input")); + } + + fn expect_closed(&mut self, says: &str) { + self.0.expect(says, |tree| !tree.has("placeholder-form-hint")); + } +} diff --git a/e2e/src/sdk/gate.rs b/e2e/src/sdk/gate.rs index e2e512cd5..8bb7ccc06 100644 --- a/e2e/src/sdk/gate.rs +++ b/e2e/src/sdk/gate.rs @@ -1,4 +1,7 @@ +use std::time::Instant; + use super::App; +use crate::driver::{PATIENCE, Tree}; /// The gate: a phrase makes the library, then opens it. pub struct Gate<'a>(pub(super) &'a mut App); @@ -36,9 +39,16 @@ impl Gate<'_> { self.0.fill("vault-confirmation", "the confirmation's field", phrase); } - /// Clicks the button that makes or opens the library. + /// Clicks the button that makes or opens the library. ⚠️ On a machine whose own pointer moves, a + /// click can be dropped: clicked again until the gate answers. pub fn submit(&mut self) { - self.0.click("vault-submit", "the gate's button"); + let until = Instant::now() + PATIENCE; + while Instant::now() < until { + self.0.click("vault-submit", "the gate's button"); + if (0..20).any(|_| answered(&self.0.tree())) { + return; + } + } } /// The gate asks for a phrase twice: this profile has no library yet. @@ -58,6 +68,14 @@ impl Gate<'_> { self.0.expect(says, |tree| tree.is_disabled("vault-submit")); } + /// The gate says the two phrases differ: the button is out of reach. + pub fn expect_phrases_differ(&mut self, says: &str) { + self.0.expect(says, |tree| { + tree.text("vault-problem").is_some_and(|said| !said.is_empty()) + && tree.is_disabled("vault-submit") + }); + } + /// The gate says the phrase is not the library's, which stays shut. pub fn expect_wrong_phrase(&mut self, says: &str) { self.0.expect(says, |tree| { @@ -65,7 +83,20 @@ impl Gate<'_> { }); } + /// The check for a new version answered, and the gate offers none. + pub fn expect_no_update(&mut self, says: &str) { + self.0.expect(says, |tree| tree.has("update-dot")); + self.0.expect_at_rest(says, |tree| !tree.has("gate-update")); + } + fn expect_open(&mut self, says: &str) { self.0.expect(says, |tree| tree.has("area-switch")); } } + +/// The gate is opening the library, or says why it does not. +fn answered(tree: &Tree) -> bool { + !tree.has("vault-submit") + || tree.is_disabled("vault-submit") + || tree.text("vault-problem").is_some_and(|said| !said.is_empty()) +} diff --git a/e2e/src/sdk/help.rs b/e2e/src/sdk/help.rs new file mode 100644 index 000000000..015c6aab8 --- /dev/null +++ b/e2e/src/sdk/help.rs @@ -0,0 +1,126 @@ +use super::{App, Shortcut}; + +/// The *About* menu and what it opens. +pub struct Help<'a>(pub(super) &'a mut App); + +/// The documentation's pages, under their four headings. +const DOCUMENTATION: [&str; 11] = [ + "overview", + "start", + "writing", + "organising", + "paste", + "tools", + "api", + "safety", + "transfer", + "settings", + "faq", +]; + +impl Help<'_> { + /// *About → Documentation*. + pub fn open_documentation(&mut self) { + self.choose("about-documentation", "« Documentation »"); + } + + /// *About → Keyboard shortcuts*. + pub fn open_shortcuts(&mut self) { + self.choose("about-shortcuts", "« Keyboard shortcuts »"); + } + + /// *About → What's new*. + pub fn open_whats_new(&mut self) { + self.choose("about-whats-new", "« What's new »"); + } + + /// *About → About DevNotes*. + pub fn open_about(&mut self) { + self.choose("about-about", "« About DevNotes »"); + } + + /// *About → Check for updates*, or the version already found. + pub fn check_for_updates(&mut self) { + self.choose("about-check-updates", "« Check for updates »"); + } + + /// *Later*, in the offer of a new version. + pub fn update_later(&mut self) { + self.0.click("update-later", "« Later »"); + self.0.expect("the offer closes", |tree| !tree.has("update-prompt")); + } + + /// Ticks *Do not offer version … again*, then *Later*. + pub fn skip_update(&mut self) { + self.0.click("update-skip", "« Do not offer this version again »"); + self.update_later(); + } + + /// Closes the panel that is open. + pub fn close(&mut self) { + self.0.press(Shortcut::Escape); + self.0 + .expect("the panel closes", |tree| PANELS.iter().all(|panel| !tree.has(panel))); + } + + /// The documentation lists its pages, and reads one. + pub fn expect_documentation(&mut self, says: &str) { + self.0.expect(says, |tree| { + let pages = tree.all_starting("docs-page-"); + let mut listed: Vec<&str> = pages.iter().map(|id| &id["docs-page-".len()..]).collect(); + listed.sort_unstable(); + let mut known = DOCUMENTATION; + known.sort_unstable(); + listed == known && tree.text("docs-title").is_some_and(|title| !title.is_empty()) + }); + } + + /// Each page of the documentation is one of reading: a title, and sections under it. The + /// overview alone is of cards, one per page. From the last to the first: a page's sections + /// unfold under it, and push the pages below out of view. + pub fn expect_every_page_read(&mut self, says: &str) { + for page in DOCUMENTATION.into_iter().rev() { + self.0.click(&format!("docs-page-{page}"), "a page of the documentation"); + self.0.expect(says, |tree| { + let sections = tree.all_starting("docs-section-").len(); + let cards = tree.all_starting("docs-card-").len(); + if page == "overview" { cards == DOCUMENTATION.len() - 1 } else { sections > 1 && cards == 0 } + }); + } + } + + /// The version of the application is said. + pub fn expect_version(&mut self, says: &str) { + let version = format!("v{}", env!("CARGO_PKG_VERSION")); + self.0 + .expect(says, |tree| tree.text("about-version").as_deref() == Some(version.as_str())); + } + + /// The shortcuts are listed, group by group. + pub fn expect_shortcuts(&mut self, says: &str) { + self.0.expect(says, |tree| tree.count("shortcut-group") > 1); + } + + /// The changelog is read, release by release. + pub fn expect_changelog(&mut self, says: &str) { + self.0.expect(says, |tree| tree.count("news-version") > 1); + } + + /// A new version is offered, its notes with it. + pub fn expect_update_offered(&mut self, says: &str) { + self.0 + .expect(says, |tree| tree.has("update-prompt") && tree.has("update-notes")); + } + + /// The menu wears its dot: a new version is known. + pub fn expect_update_known(&mut self, says: &str) { + self.0.expect(says, |tree| tree.has("update-dot") && !tree.has("update-prompt")); + } + + fn choose(&mut self, id: &str, name: &str) { + self.0.click("about-open", "the « About » menu"); + self.0.click(id, name); + } +} + +const PANELS: [&str; 4] = ["docs-dialog", "about-dialog", "shortcut-group", "news-version"]; diff --git a/e2e/src/sdk/http.rs b/e2e/src/sdk/http.rs new file mode 100644 index 000000000..d46d06365 --- /dev/null +++ b/e2e/src/sdk/http.rs @@ -0,0 +1,25 @@ +use super::App; + +/// The HTTP area: its rail, its tabs and the request that is open. +pub struct Http<'a>(pub(super) &'a mut App); + +impl Http<'_> { + /// Opens a draft in a tab of its own. + pub fn new_draft(&mut self) { + self.0.click("http-tab-new", "the button of a new request"); + self.0.expect("a draft opens in its tab", |tree| tree.has("http-url")); + } + + /// Closes the only tab, its changes not kept. + pub fn close_tab_discarding(&mut self) { + self.0.click("http-tab-close", "the tab's cross"); + self.0.click("http-close-discard", "« Do not save »"); + self.0.expect("the tab closes", |tree| !tree.has("http-tab-open")); + } + + /// As many tabs are open. + pub fn expect_tabs(&mut self, count: usize, says: &str) { + self.0 + .expect(says, |tree| tree.has("http-rail-title") && tree.count("http-tab-open") == count); + } +} diff --git a/e2e/src/sdk/mod.rs b/e2e/src/sdk/mod.rs index 480c75f11..77ffbe9b4 100644 --- a/e2e/src/sdk/mod.rs +++ b/e2e/src/sdk/mod.rs @@ -1,37 +1,80 @@ //! What a person does with the application, area by area. Each method waits until the window can //! take its act and until it has taken it: a journey never waits on its own. +mod act; +mod clipboard; +mod editor; +mod fields; mod gate; +mod help; +mod http; mod notes; - +mod prefs; +mod shortcut; +mod tools; +mod window; + +pub use clipboard::Clipboard; +pub use editor::{Editor, JsonView}; +pub use egui::Key; +pub use fields::Fields; pub use gate::Gate; -pub use notes::Notes; - -use std::path::Path; +pub use help::Help; +pub use http::Http; +pub use notes::{Named, Notes, Sample}; +pub use prefs::{CardKey, DefaultKind, Density, Indent, Language, Page, Prefs, Switch, Theme}; +pub use shortcut::Shortcut; +pub use tools::Tools; +pub use window::{Area, Window}; + +use std::ffi::OsString; +use std::path::{Path, PathBuf}; use std::time::Instant; -use egui::accesskit::{Node, Rect}; -use egui::{Event, Modifiers, PointerButton, Pos2}; +use egui::Event; use tempfile::TempDir; -use crate::current_step; -use crate::driver::{Driver, PATIENCE, Tree, middle}; +use crate::driver::Driver; +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. room: TempDir, + /// When the last click was. + clicked: Option, } impl App { /// DevNotes launched for the first time: nothing on the disk, the gate on the screen. pub fn first_launch(journey: &'static str) -> Self { + Self::launch(journey, Vec::new()) + } + + /// DevNotes with its library made and open on its sample notes: where a journey starts. + pub fn open(journey: &'static str) -> Self { + Self::launch(journey, Vec::new()).with_a_library() + } + + /// As `open`, a new version published on a server of the journey's own. + pub fn open_before_an_update(journey: &'static str) -> Self { + let served = server::publish_update(); + Self::launch(journey, vec![(platform::updater::E2E_UPDATES, served.into())]).with_a_library() + } + + fn launch(journey: &'static str, 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"); - let driver = Driver::launch(journey, profile, terminal(room.path()), Vec::new()); - App { driver, room } + let driver = Driver::launch(journey, profile, terminal(room.path()), set); + App { driver, room, clicked: None } + } + + fn with_a_library(mut self) -> Self { + self.gate().create_library(PASSPHRASE); + self.notes().expect_samples("the sample notes are on the screen"); + self } /// The gate, where a library is made or opened. @@ -44,6 +87,64 @@ impl App { Notes(self) } + /// The note open. + pub fn editor(&mut self) -> Editor<'_> { + Editor(self) + } + + /// The form that asks for a snippet's fields. + pub fn fields(&mut self) -> Fields<'_> { + Fields(self) + } + + /// The tools area. + pub fn tools(&mut self) -> Tools<'_> { + Tools(self) + } + + /// The HTTP area. + pub fn http(&mut self) -> Http<'_> { + Http(self) + } + + /// The preferences. + pub fn prefs(&mut self) -> Prefs<'_> { + Prefs(self) + } + + /// The *About* menu and what it opens. + pub fn help(&mut self) -> Help<'_> { + Help(self) + } + + /// The window itself. + pub fn window(&mut self) -> Window<'_> { + Window(self) + } + + /// The system's clipboard. + pub fn clipboard(&mut self) -> Clipboard<'_> { + Clipboard(self) + } + + /// Presses a shortcut. + pub fn press(&mut self, shortcut: Shortcut) { + let (key, modifiers) = shortcut.keys(); + self.key(key, modifiers); + } + + /// Presses a shortcut on a keyboard of another layout: its keys stand where they do on QWERTY, + /// another character printed on them. + pub fn press_on_another_layout(&mut self, shortcut: Shortcut) { + let (place, modifiers) = shortcut.keys(); + self.key_printed(Key::Semicolon, place, modifiers); + } + + /// Types a text where the keyboard is. + pub fn type_text(&mut self, text: &str) { + self.driver.apply(vec![Event::Text(text.to_owned())]); + } + /// 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")); @@ -51,6 +152,24 @@ impl App { self.driver.start_again(); } + /// As `relaunch`, through the gate with the journey's phrase. + pub fn relaunch_and_unlock(&mut self) { + self.relaunch(); + self.gate().unlock(PASSPHRASE); + } + + /// *File → Quit*, clicked again as it asks, and DevNotes ends. + pub fn quit_from_the_menu(mut self) { + self.click("file-menu", "the « File » menu"); + let quit = self.tree().text("file-quit").unwrap_or_default(); + self.click("file-quit", "« Quit »"); + self.expect("« Quit » asks for a second click", |tree| { + tree.text("file-quit").is_some_and(|said| said != quit) + }); + self.click("file-quit", "« Quit » again"); + self.ended(); + } + /// Quits DevNotes, once the journey is over. pub fn quit(mut self) { self.driver.hand_over(Some("quit")); @@ -70,93 +189,29 @@ impl App { let fault = wrote .lines() .any(|line| !(line.starts_with("libEGL warning:") && line.contains("DRI3"))); - assert!(!cfg!(target_os = "linux") || !fault, "{}: {says}\n{wrote}", current_step()); - } - - // What the areas are made of. Each failure says, in the step it stops, what the person would - // have seen. - - pub(crate) fn tree(&mut self) -> Tree { - self.driver.tree() + assert!(!cfg!(target_os = "linux") || !fault, "« {} »: {says}\n{wrote}", current_step()); } - /// Reads the screen until `holds` is true of it: answers arrive from the core frames later. - pub(crate) fn expect(&mut self, says: &str, holds: impl Fn(&Tree) -> bool) { - self.seen(says, |tree| holds(tree).then_some(())); + /// DevNotes started a second time while it runs: the window comes back on the screen. + fn launch_again(&mut self) { + self.driver.hand_over(None); + self.driver.settle(); } - /// What `find` finds on the screen, once it does. No pause between reads: each one renders a - /// frame. - fn seen(&mut self, says: &str, find: impl Fn(&Tree) -> Option) -> T { - let until = Instant::now() + PATIENCE; - loop { - let tree = self.tree(); - if let Some(found) = find(&tree) { - return found; - } - assert!( - Instant::now() < until, - "« {} »: {says} — still not so after {PATIENCE:?}; the keyboard is {}", - current_step(), - tree.keyboard() - ); - } - } - - /// Where a control stands, once it holds still: a node joins the tree a frame before it has a - /// place, and one still moving would be clicked where it no longer is. - fn place(&mut self, name: &str, find: impl Fn(&Tree) -> Option) -> Rect { - let says = format!("{name} is on the screen"); - loop { - let first = self.seen(&says, &find); - if find(&self.tree()) == Some(first) { - return first; - } - } - } - - pub(crate) fn click(&mut self, id: &str, name: &str) { - self.click_where(id, name, |_| true); - } - - /// The first `id` that `which` picks, in reading order. - pub(crate) fn click_where(&mut self, id: &str, name: &str, which: impl Fn(&Node) -> bool) { - let bounds = self - .place(name, |tree| tree.all(id).into_iter().filter(|node| which(node)).find_map(Node::bounds)); - self.click_at(middle(bounds), PointerButton::Primary); - } - - fn click_at(&mut self, pos: Pos2, button: PointerButton) { - let press = |pressed| Event::PointerButton { pos, button, pressed, modifiers: Modifiers::NONE }; - self.driver.apply(vec![Event::PointerMoved(pos)]); - self.driver.apply(vec![press(true)]); - self.driver.apply(vec![press(false)]); - } - - /// Clicks a field, then types into it once it holds the keyboard. ⚠️ A click can land in a - /// frame that drops it: clicked again until the focus moves, a few frames apart — two at once - /// would be a double click. - pub(crate) fn fill(&mut self, id: &str, name: &str, text: &str) { - self.take_keyboard(id, name); - self.type_text(text); + /// Waits for DevNotes to end by itself, everything written. + fn ended(&mut self) { + self.driver.ended(); } - pub(crate) fn take_keyboard(&mut self, id: &str, name: &str) { - let until = Instant::now() + PATIENCE; - loop { - self.click(id, name); - if (0..5).any(|_| self.tree().has_focus(id)) { - return; - } - assert!(Instant::now() < until, "« {} »: {name} never took the keyboard", current_step()); - } + fn start_again(&mut self) { + self.driver.start_again(); } - pub(crate) fn type_text(&mut self, text: &str) { - self.driver.apply(vec![Event::Text(text.to_owned())]); + fn profile(&self) -> &Path { + self.driver.profile() } } -fn terminal(room: &Path) -> std::path::PathBuf { +fn terminal(room: &Path) -> PathBuf { room.join("terminal.txt") } diff --git a/e2e/src/sdk/notes.rs b/e2e/src/sdk/notes.rs index a32469657..fd06a8124 100644 --- a/e2e/src/sdk/notes.rs +++ b/e2e/src/sdk/notes.rs @@ -1,23 +1,242 @@ +use egui::accesskit::{Node, Rect}; +use egui::{Key, Modifiers}; + use super::App; -use crate::driver::Tree; +use crate::driver::{Tree, said, within}; /// The notes area: its rail, its header and its cards. pub struct Notes<'a>(pub(super) &'a mut App); +/// A sample note of the first launch, in whichever language the machine speaks. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Sample { + Welcome, + PsqlConnection, + ApiResponse, + ReleaseDay, + SnippetToFormat, + ThingsToTry, +} + +impl Sample { + /// Its title, in English and in French. + fn titles(self) -> [&'static str; 2] { + match self { + Self::Welcome => ["Welcome to DevNotes", "Bienvenue dans DevNotes"], + Self::PsqlConnection => ["psql connection", "Connexion psql"], + Self::ApiResponse => ["API response — open it as a graph", "Réponse d’API — à ouvrir en graphe"], + Self::ReleaseDay => ["Release day", "Mise en production"], + Self::SnippetToFormat => ["Code to format (Shift+Alt+F)", "Code à formater (Maj+Alt+F)"], + Self::ThingsToTry => ["Things to try", "À essayer"], + } + } +} + +/// A note as a journey names it: by its title, or a sample. +pub trait Named: Copy { + /// Whether `title` is this note's. + fn is(self, title: &str) -> bool; +} + +impl Named for &str { + fn is(self, title: &str) -> bool { + self == title + } +} + +impl Named for Sample { + fn is(self, title: &str) -> bool { + self.titles().contains(&title) + } +} + +const SAMPLES: usize = 6; +/// The samples' space, in English and in French. +const FIRST_SPACE: [&str; 2] = ["Getting started", "Découverte"]; + impl Notes<'_> { - /// The library holds the first launch's sample notes, and nothing went wrong: one stands - /// outside every folder. + /// *New note*, of the kind the preferences say. + pub fn new_note(&mut self) { + self.0.click("new-note", "« New note »"); + self.0.expect("a new note opens", |tree| tree.has("editor-title")); + } + + /// 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 »"); + self.0.click("new-note-calc", "« Calculation »"); + self.0.expect("a new calculation opens", |tree| tree.has("calc-counts")); + } + + /// A snippet written and closed: its title and its code. + pub fn write_snippet(&mut self, title: &str, code: &str) { + self.new_note(); + self.0.editor().type_title(title); + self.0.editor().type_code(code); + self.0.editor().close(); + self.expect_card(title, "the snippet is a card"); + } + + /// Opens a note by its card. + pub fn open(&mut self, note: impl Named) { + let card = self.card(note); + self.0.click_card(card); + self.0.expect("the note opens", |tree| tree.has("editor-title")); + } + + /// Copies a note by the button of its card. + pub fn copy(&mut self, note: impl Named) { + self.click_on_card(note, "note-card-copy", "the card's « Copy »"); + } + + /// Copies a note that has fields, by the button of its card: the form asks for them. + pub fn copy_filled(&mut self, note: impl Named) { + self.click_on_card(note, "note-card-fill", "the card's « Fill and copy »"); + self.0.fields().expect_open("the form asks for the fields"); + } + + /// Ticks an item of a todo list from its card, the items counted from 0. + pub fn tick_on_card(&mut self, note: impl Named, item: usize) { + let card = self.card(note); + self.0 + .click_nth_where("note-card-item", item, "an item on the card", |node| within(node, card)); + } + + /// Types in the search, over what it holds. + pub fn search(&mut self, words: &str) { + self.0.replace("search-input", "the search", words); + } + + /// Empties the search by its cross. + pub fn clear_search(&mut self) { + self.0.click("search-clear", "the search's cross"); + 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) { + self.0.take_keyboard("search-input", "the search"); + self.0.key(Key::ArrowDown, Modifiers::NONE); + 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. + pub fn card_height(&mut self) -> f64 { + let tree = self.0.tree(); + tree.find("note-card").and_then(Node::bounds).map_or(0.0, |card| card.height()) + } + + /// How far apart two cards of a row stand, in points: what the density sets. + pub fn cards_apart(&mut self) -> f64 { + apart(&self.0.tree()).unwrap_or_default() + } + + /// The cards stand closer than `before`. + pub fn expect_cards_closer(&mut self, before: f64, says: &str) { + self.0.expect(says, |tree| apart(tree).is_some_and(|now| now < before - 1.0)); + } + + /// The cards stand as far apart as `before`. + pub fn expect_cards_apart(&mut self, before: f64, says: &str) { + self.0 + .expect(says, |tree| apart(tree).is_some_and(|now| (now - before).abs() < 1.0)); + } + + /// The cards grew by a line since they were `four` points high, for four lines each. + pub fn expect_one_line_taller(&mut self, four: f64, says: &str) { + // 160 points for five lines against 140 for four, the window's scale aside. + self.0.expect(says, |tree| { + let card = tree.find("note-card").and_then(Node::bounds); + card.is_some_and(|card| (card.height() / four - 160.0 / 140.0).abs() < 0.02) + }); + } + + /// The library holds the first launch's sample notes, in the one space there is, and nothing went wrong: + /// one stands outside every folder. pub fn expect_samples(&mut self, says: &str) { self.0.expect(says, |tree| { + let spaces = tree.texts("space-option"); tree.count("note-card") == SAMPLES && tree.count("note-card-folder") == SAMPLES - 1 - && no_error(tree) + && !tree.has("error-banner") + && spaces.len() == 1 + && FIRST_SPACE.contains(&spaces[0].as_str()) + }); + } + + /// This note has a card, and no note is open. + pub fn expect_card(&mut self, note: impl Named, says: &str) { + self.0.expect(says, |tree| { + tree.texts("note-card-title").iter().any(|title| note.is(title)) && !tree.has("editor-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| { + let Some(card) = card_of(tree, note) else { + return false; + }; + let mut progress = tree.all("note-card-progress").into_iter(); + progress.any(|node| within(node, card) && said(node) == done) }); } + + /// Nothing answers the search. + pub fn expect_nothing_found(&mut self, says: &str) { + self.0.expect(says, |tree| tree.has("canvas-no-results")); + } + + /// As many cards are selected, and counted. + pub fn expect_selected(&mut self, count: usize, says: &str) { + let count = count.to_string(); + self.0 + .expect(says, |tree| tree.text("selection-count").is_some_and(|said| said.contains(&count))); + } + + /// A toast says what was done; its cross takes it off the screen. + pub fn expect_acknowledged(&mut self, says: &str) { + self.0.expect(says, |tree| tree.has("status-toast")); + self.0.click("status-dismiss", "the toast's cross"); + self.0.expect("the toast goes", |tree| !tree.has("status-toast")); + } + + /// 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")); + } + + /// A button a card shows under the pointer. + fn click_on_card(&mut self, note: impl Named, id: &str, name: &str) { + let card = self.card(note); + self.0.move_over(card); + self.0.click_where(id, name, |node| on_card(node, card)); + } + + /// Where a note's card stands, the cards scrolled to it. + fn card(&mut self, note: impl Named) -> Rect { + self.0.scroll_to("canvas", "the note's card", |tree| card_of(tree, note)) + } } -const SAMPLES: usize = 6; +/// Whether a button is one of the card's under the pointer: they hang over its foot. +fn on_card(node: &Node, card: Rect) -> bool { + let hanging = Rect { y1: card.y1 + 24.0, ..card }; + within(node, hanging) +} + +/// Between two cards of one row. +fn apart(tree: &Tree) -> Option { + let cards: Vec = tree.all("note-card").into_iter().filter_map(Node::bounds).collect(); + let mut pairs = cards.windows(2); + let row = pairs.find(|pair| (pair[0].y0 - pair[1].y0).abs() < 1.0)?; + Some(row[1].x0 - row[0].x1) +} -fn no_error(tree: &Tree) -> bool { - !tree.has("error-banner") +/// Where the card of `note` stands. +fn card_of(tree: &Tree, note: impl Named) -> Option { + let mut cards = tree.all("note-card").into_iter(); + cards.find(|card| note.is(&said(card)))?.bounds() } diff --git a/e2e/src/sdk/prefs.rs b/e2e/src/sdk/prefs.rs new file mode 100644 index 000000000..0215a379e --- /dev/null +++ b/e2e/src/sdk/prefs.rs @@ -0,0 +1,243 @@ +use std::collections::BTreeMap; +use std::path::Path; + +use egui::accesskit::Node; +use egui::{Key, Modifiers}; +use serde_json::Value; + +use super::App; + +/// The preferences: *File → Preferences…*, and the file they are kept in. +pub struct Prefs<'a>(pub(super) &'a mut App); + +/// A page of the panel. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Page { + General, + Variables, + Shortcuts, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Theme { + Dark, + Light, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Density { + Comfortable, + Compact, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Language { + French, + English, +} + +/// What *New note* makes. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum DefaultKind { + Note, + Snippet, +} + +/// What Tab writes in the code. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Indent { + FourSpaces, +} + +/// A switch of the panel. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Switch { + WrapLines, + CloseToTray, + CopyAcknowledged, +} + +/// An action a key of the cards is for. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum CardKey { + Pin, + Check, +} + +impl Prefs<'_> { + /// *File → Preferences…*, on its first page. + pub fn open(&mut self) { + self.0.click("file-menu", "the « File » menu"); + self.0.click("file-preferences", "« Preferences… »"); + self.0.expect("the preferences open", |tree| tree.has("settings-dialog")); + } + + /// Opens the panel, changes what `change` does, and closes it with its button. + pub fn change(&mut self, change: impl FnOnce(&mut Self)) { + self.open(); + change(self); + self.close(); + } + + /// Goes to a page of the panel. + pub fn go_to(&mut self, page: Page) { + match page { + Page::General => self.0.click("settings-page-general", "the « General » page"), + Page::Variables => self.0.click("settings-page-variables", "the « Variables » page"), + Page::Shortcuts => self.0.click("settings-page-shortcuts", "the « Shortcuts » page"), + } + } + + /// *Apply*: the panel stays. + pub fn apply(&mut self) { + self.0.click("settings-apply", "« Apply »"); + self.0 + .expect("what was chosen is applied", |tree| tree.is_disabled("settings-apply")); + } + + /// The button that applies and closes. + pub fn close(&mut self) { + self.0.click("settings-close", "the button that applies and closes"); + self.expect_closed(); + } + + /// *Cancel*: what was shown goes back. + pub fn cancel(&mut self) { + self.0.click("settings-cancel", "« Cancel »"); + self.expect_closed(); + } + + /// Chooses dark or light. + pub fn choose_theme(&mut self, theme: Theme) { + match theme { + Theme::Dark => self.choose("setting-theme-1", "« Dark »"), + Theme::Light => self.choose("setting-theme-2", "« Light »"), + } + } + + /// Chooses how close the cards stand. + pub fn choose_density(&mut self, density: Density) { + match density { + Density::Comfortable => self.choose("setting-density-0", "« Comfortable »"), + Density::Compact => self.choose("setting-density-1", "« Compact »"), + } + } + + /// Chooses the language of the window. + pub fn choose_language(&mut self, language: Language) { + self.choose("setting-locale", "the language's menu"); + match language { + Language::French => self.0.click("setting-locale-1", "« Français »"), + Language::English => self.0.click("setting-locale-2", "« English »"), + } + } + + /// Chooses what *New note* makes. + pub fn choose_default_kind(&mut self, kind: DefaultKind) { + match kind { + DefaultKind::Note => self.choose("setting-note-kind-0", "« Note » as the default"), + DefaultKind::Snippet => self.choose("setting-note-kind-1", "« Snippet » as the default"), + } + } + + /// Chooses how many lines a card previews: 3, 4 or 5. + pub fn choose_preview_lines(&mut self, lines: usize) { + self.choose(&format!("setting-preview-lines-{}", lines - 3), "a number of lines"); + } + + /// Chooses what Tab writes in the code. + pub fn choose_indent(&mut self, indent: Indent) { + self.choose("setting-indent", "the indentation's menu"); + match indent { + Indent::FourSpaces => self.0.click("setting-indent-2", "« 4 spaces »"), + } + } + + /// Chooses how many decimals a calculation's results have. + pub fn choose_decimals(&mut self, places: usize) { + self.choose("setting-calc-decimals", "the decimals' menu"); + self.0 + .click(&format!("setting-calc-decimals-{}", places + 1), "a number of decimals"); + } + + /// Turns a switch over. + pub fn flip(&mut self, switch: Switch) { + match switch { + Switch::WrapLines => self.choose("setting-code-wrap", "the switch of the wrapped lines"), + Switch::CloseToTray => self.choose("setting-close-to-tray", "« Close to tray »"), + Switch::CopyAcknowledged => { + self.choose("setting-copy-confirmation", "the switch of the copy's acknowledgement"); + } + } + } + + /// Adds a global variable, on its page. + pub fn add_variable(&mut self, name: &str, value: &str) { + self.0.click("variable-add", "« Add a variable »"); + self.0.fill("variable-name", "the variable's name", name); + self.0.fill("variable-value", "the variable's value", value); + } + + /// Presses a letter as the key of an action, on the « Shortcuts » page. + pub fn take_key(&mut self, action: CardKey, letter: Key) { + self.choose(&field(action), "the action's key"); + self.0.key(letter, Modifiers::NONE); + } + + /// Puts an action's key back. + pub fn reset_key(&mut self, action: CardKey) { + self.choose(&field(action).replace("field", "reset"), "the key's « Reset »"); + } + + /// The panel says another action holds the key asked for. + pub fn expect_key_flagged(&mut self, action: CardKey, says: &str) { + let at = field(action).replace("field", "error"); + self.0.expect(says, |tree| tree.has(&at)); + } + + /// An action's key, as the panel shows it. + pub fn expect_key(&mut self, action: CardKey, shown: &str, says: &str) { + let at = field(action); + self.0.expect(says, |tree| tree.find(&at).and_then(Node::value) == Some(shown)); + } + + /// The file on the disk holds this value for a setting, named as the file names it. + pub fn expect_stored(&mut self, setting: &str, value: &str, says: &str) { + let file = self.0.profile().join("preferences.json"); + let key = format!("devnotes.{setting}"); + self.0 + .expect(says, |_| stored(&file).get(&key).and_then(Value::as_str) == Some(value)); + } + + /// The file on the disk holds one key per setting, each a text. + pub fn expect_stored_as_texts(&mut self, says: &str) { + let file = self.0.profile().join("preferences.json"); + self.0.expect(says, |_| { + let settings = stored(&file); + !settings.is_empty() && settings.values().all(Value::is_string) + }); + } + + fn expect_closed(&mut self) { + self.0.expect("the preferences close", |tree| !tree.has("settings-dialog")); + } + + /// Scrolled to, above the panel's foot. + fn choose(&mut self, id: &str, name: &str) { + self.0.reach("settings-content", (id, name), "settings-cancel"); + self.0.click(id, name); + } +} + +fn field(action: CardKey) -> String { + let action = match action { + CardKey::Pin => "pin", + CardKey::Check => "check", + }; + format!("shortcut-field-canvas.{action}") +} + +fn stored(file: &Path) -> BTreeMap { + let text = std::fs::read_to_string(file).unwrap_or_default(); + serde_json::from_str(&text).unwrap_or_default() +} diff --git a/e2e/src/sdk/shortcut.rs b/e2e/src/sdk/shortcut.rs new file mode 100644 index 000000000..6179b335b --- /dev/null +++ b/e2e/src/sdk/shortcut.rs @@ -0,0 +1,53 @@ +use egui::{Key, Modifiers}; + +/// A shortcut as a person knows it: what it does, whatever key of their keyboard says it. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Shortcut { + /// Esc. + Escape, + /// Enter. + Enter, + /// Tab. + Tab, + /// The arrows. + Up, + Down, + Right, + /// The start of the line, of the text. + Home, + TextStart, + /// Ctrl+A. + SelectAll, + /// Ctrl+F. + Find, + /// Shift+Alt+F. + Format, + /// Ctrl+1, Ctrl+2 and Ctrl+3. + NotesArea, + ToolsArea, + HttpArea, + /// Ctrl+B: the side rail. + SideRail, +} + +impl Shortcut { + pub(crate) fn keys(self) -> (Key, Modifiers) { + match self { + Self::Escape => (Key::Escape, Modifiers::NONE), + Self::Enter => (Key::Enter, Modifiers::NONE), + Self::Tab => (Key::Tab, Modifiers::NONE), + Self::Up => (Key::ArrowUp, Modifiers::NONE), + Self::Down => (Key::ArrowDown, Modifiers::NONE), + Self::Right => (Key::ArrowRight, Modifiers::NONE), + Self::Home => (Key::Home, Modifiers::NONE), + Self::TextStart => (Key::Home, Modifiers::COMMAND), + Self::SelectAll => (Key::A, Modifiers::COMMAND), + Self::Find => (Key::F, Modifiers::COMMAND), + 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::SideRail => (Key::B, Modifiers::COMMAND), + } + } +} diff --git a/e2e/src/sdk/tools.rs b/e2e/src/sdk/tools.rs new file mode 100644 index 000000000..26b4b49f0 --- /dev/null +++ b/e2e/src/sdk/tools.rs @@ -0,0 +1,17 @@ +use super::App; + +/// The tools area: its home and the tool that is open. +pub struct Tools<'a>(pub(super) &'a mut App); + +impl Tools<'_> { + /// Opens a tool from the home, by the name it goes by in the catalogue. + pub fn open(&mut self, tool: &str) { + self.0.click(&format!("tools-entry-{tool}"), "the tool on the home"); + self.expect_tool_open("the tool opens"); + } + + /// A tool is open. + pub fn expect_tool_open(&mut self, says: &str) { + self.0.expect(says, |tree| tree.has("area-tools") && tree.has("tool-title")); + } +} diff --git a/e2e/src/sdk/window.rs b/e2e/src/sdk/window.rs new file mode 100644 index 000000000..d5f998bd4 --- /dev/null +++ b/e2e/src/sdk/window.rs @@ -0,0 +1,147 @@ +use egui::accesskit::Node; + +use super::App; +use crate::driver::{Tree, middle}; + +/// The window itself: its title bar and what the system does with it. +pub struct Window<'a>(pub(super) &'a mut App); + +/// An area of the application. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Area { + Notes, + Tools, + Http, +} + +impl Window<'_> { + /// Goes to an area by the switch of the areas. + pub fn go_to(&mut self, area: Area) { + match area { + Area::Notes => self.0.click("area-option-notes", "« Notes » among the areas"), + Area::Tools => self.0.click("area-option-tools", "« Tools » among the areas"), + Area::Http => self.0.click("area-option-http", "« HTTP » among the areas"), + } + } + + /// Switches between dark and light from the title bar. + pub fn switch_theme(&mut self) { + self.0.click("theme-toggle", "the theme's button"); + } + + /// Maximises the window, or restores it, by its control. + pub fn maximize_or_restore(&mut self) { + self.0.click("window-maximize", "the window's « Maximise »"); + } + + /// Double-clicks the empty part of the title bar. + pub fn double_click_title_bar(&mut self) { + let toggle = self + .0 + .place("the theme's button", |tree| tree.find("theme-toggle").and_then(Node::bounds)); + self.0.double_click(middle(toggle) - egui::vec2(100.0, 0.0)); + } + + /// Minimises the window by its control, then starts DevNotes again, which brings it back. + pub fn minimize_and_come_back(&mut self) { + let before = self.put_away(); + self.0.click("window-minimize", "the window's « Minimise »"); + self.0.launch_again(); + self.expect_back_after(before, "the window went out of sight and is back"); + } + + /// Closes the window by its control, DevNotes ending with it, then starts it again. + pub fn close_and_start_again(&mut self) { + self.0.click("window-close", "the window's « Close »"); + self.0.ended(); + self.0.start_again(); + } + + /// The word the title bar has for the theme it would switch to, which says the theme on. + pub fn theme_offered(&mut self) -> String { + self.0.tree().text("theme-toggle").unwrap_or_default() + } + + /// The window wears another theme than the one that offered `word`. + pub fn expect_theme_changed(&mut self, word: &str, says: &str) { + self.0 + .expect(says, |tree| tree.text("theme-toggle").is_some_and(|now| now != word)); + } + + /// The window wears the theme that offers `word`. + pub fn expect_theme(&mut self, word: &str, says: &str) { + self.0.expect(says, |tree| tree.text("theme-toggle").as_deref() == Some(word)); + } + + /// The name of the window's control that maximises, which is another once it would restore. + pub fn maximize_offered(&mut self) -> String { + self.0 + .expect("the window's controls are drawn", |tree| tree.has("window-maximize")); + self.0.tree().text("window-maximize").unwrap_or_default() + } + + /// The window is maximised: its control no longer offers `word`. + pub fn expect_maximized(&mut self, word: &str, says: &str) { + self.0 + .expect(says, |tree| tree.text("window-maximize").is_some_and(|now| now != word)); + } + + /// The window is restored: its control offers `word` again. + pub fn expect_restored(&mut self, word: &str, says: &str) { + self.0 + .expect(says, |tree| tree.text("window-maximize").as_deref() == Some(word)); + } + + /// The window has no control of DevNotes' own: the system draws its three buttons. + pub fn expect_system_buttons(&mut self, says: &str) { + self.0 + .expect(says, |tree| !tree.has("window-maximize") && !tree.has("window-close")); + } + + /// This area is on the screen. + pub fn expect_area(&mut self, area: Area, says: &str) { + let id = match area { + Area::Notes => "area-notes", + Area::Tools => "area-tools", + Area::Http => "area-http", + }; + self.0.expect(says, |tree| tree.has(id)); + } + + /// The side rail is put away: the areas' switch stands in the title bar. + pub fn expect_rail_away(&mut self, says: &str) { + self.0.expect(says, switch_in_the_bar); + } + + /// The side rail is there, the areas' switch in it. + pub fn expect_rail(&mut self, says: &str) { + self.0 + .expect(says, |tree| tree.has("area-option-notes") && !switch_in_the_bar(tree)); + } + + /// The window speaks the language that names the « File » menu so. + pub fn expect_file_menu(&mut self, word: &str, says: &str) { + self.0.expect(says, |tree| tree.text("file-menu").as_deref() == Some(word)); + } + + /// How many times the window went out of sight. + fn put_away(&mut self) -> u32 { + let count = self.0.tree().text("window-put-away").and_then(|count| count.parse().ok()); + count.expect("the e2e flavour counts the window put away") + } + + fn expect_back_after(&mut self, before: u32, says: &str) { + let once_more = (before + 1).to_string(); + self.0.expect(says, |tree| { + tree.has("window-shown") && tree.text("window-put-away").as_deref() == Some(once_more.as_str()) + }); + } +} + +/// The areas' switch beside the theme's button, above the notes' header. +fn switch_in_the_bar(tree: &Tree) -> bool { + let top = |id| tree.find(id).and_then(Node::bounds).map(|bounds| bounds.y0); + top("area-option-notes") + .zip(top("theme-toggle")) + .is_some_and(|(switch, bar)| switch < bar + 20.0) +} diff --git a/e2e/src/server.rs b/e2e/src/server.rs index 33bef7d18..1060f1855 100644 --- a/e2e/src/server.rs +++ b/e2e/src/server.rs @@ -19,6 +19,45 @@ pub fn serve() -> u16 { port } +/// A server publishing a version far ahead of this one, with its notes; the address of its +/// `latest.json`. Nothing is downloaded from it. +pub(crate) fn publish_update() -> String { + let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, 0)).expect("a local port is free"); + let origin = format!("http://{}", listener.local_addr().expect("the address is known")); + let entry = + serde_json::json!({ "signature": "", "url": format!("{origin}/installer"), "format": "nsis" }); + let manifest = serde_json::json!({ + "version": "99.0.0", + "notes": "### Added + +- Everything", + "pub_date": "2026-12-03T00:00:00Z", + "platforms": { + "windows-x86_64": entry, + "linux-x86_64": entry, + "macos-aarch64": entry, + "macos-x86_64": entry, + }, + }) + .to_string(); + std::thread::spawn(move || { + for mut stream in listener.incoming().flatten() { + let _ = stream.read(&mut [0; 1024]); + let length = manifest.len(); + let head = format!( + "HTTP/1.1 200 OK +Content-Length: {length} +Connection: close + +" + ); + let _ = stream.write_all(head.as_bytes()); + let _ = stream.write_all(manifest.as_bytes()); + } + }); + format!("{origin}/latest.json") +} + /// A socket server echoing each text, for the scenarios' connections; its port. pub fn serve_socket() -> u16 { let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, 0)).expect("a local port is free"); diff --git a/e2e/tests/01_first_day.rs b/e2e/tests/01_first_day.rs new file mode 100644 index 000000000..8765879a0 --- /dev/null +++ b/e2e/tests/01_first_day.rs @@ -0,0 +1,121 @@ +//! Journey 1, « First day »: a machine where DevNotes never ran. The gate makes the library, a real +//! relaunch opens it, and the samples are walked as their own list proposes. + +use e2e::{App, JsonView, PASSPHRASE, Sample, Shortcut, step}; + +#[test] +fn first_day() { + let mut app = App::first_launch("01_first_day"); + + making_the_library(&mut app); + coming_back(&mut app); + first_tour(&mut app); + the_documentation(&mut app); + + app.quit(); +} + +fn making_the_library(app: &mut App) { + // Typed in two goes: the start alone is under the floor of twelve characters. + let (start, rest) = PASSPHRASE.split_at(7); + + step("the first launch asks to protect the library, and says nothing in the terminal", || { + app.gate().expect_new_phrase_asked("the phrase is asked twice"); + app.expect_silent_terminal("the launch wrote nothing in the terminal"); + app.capture("gate"); + }); + + step("a phrase under twelve characters is refused", || { + app.gate().type_phrase(start); + app.gate().confirm_phrase(start); + app.gate().expect_phrase_refused("the button stays out of reach"); + }); + + step("two phrases that differ are refused", || { + app.gate().type_phrase(rest); + app.gate().expect_phrases_differ("the gate says the two phrases differ"); + }); + + step("a good phrase, twice, opens the notes on their samples", || { + app.gate().confirm_phrase(rest); + app.gate().submit(); + app.notes().expect_samples("the sample notes are on the screen"); + app.capture("samples"); + }); +} + +fn coming_back(app: &mut App) { + step("quit and started again, DevNotes asks for the phrase, once", || { + app.relaunch(); + app.gate().expect_phrase_asked("the phrase is asked once"); + }); + + step("a wrong phrase is refused, and nothing opens", || { + app.gate().try_phrase("not the phrase"); + app.gate().expect_wrong_phrase("the gate says the phrase is wrong"); + }); + + step("the right one opens the library, its samples seeded once", || { + app.gate().unlock(PASSPHRASE); + app.notes().expect_samples("the sample notes are on the screen"); + }); +} + +fn first_tour(app: &mut App) { + step("a sample opens from its card", || { + app.notes().open(Sample::Welcome); + app.editor().expect_note_open("the welcome is read formatted"); + app.editor().close(); + }); + + step("« psql connection » is copied with its fields filled", || { + app.notes().copy_filled(Sample::PsqlConnection); + app.fields().type_value(0, "db.internal"); + app.fields().copy(); + app.clipboard() + .expect_saying("psql -h db.internal -p 5432", "the connection is copied, filled"); + }); + + 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.editor().close(); + }); + + step("a word is found in « Release day »", || { + app.notes().open(Sample::ReleaseDay); + app.editor().find("kubectl"); + app.editor().expect_matches("1 / 1", "the word is found once"); + app.editor().close_find(); + app.editor().close(); + }); + + step("the snippet to format is formatted", || { + app.notes().open(Sample::SnippetToFormat); + app.press(Shortcut::Format); + app.editor().expect_several_lines("the code is laid out"); + app.editor().close(); + }); + + step("an item of « Things to try » is ticked from its card", || { + app.notes().tick_on_card(Sample::ThingsToTry, 0); + app.notes() + .expect_progress(Sample::ThingsToTry, "1/9", "the card counts one thing tried"); + }); +} + +fn the_documentation(app: &mut App) { + step("the documentation opens without the network, each page of its kind", || { + app.help().open_documentation(); + app.help().expect_documentation("its eleven pages are listed"); + app.capture("documentation"); + app.help() + .expect_every_page_read("each page has its sections, the overview its cards"); + }); + + step("Esc goes back to the notes", || { + app.press(Shortcut::Escape); + app.notes().expect_card(Sample::Welcome, "the notes are where they were left"); + }); +} diff --git a/e2e/tests/01_first_launch.rs b/e2e/tests/01_first_launch.rs deleted file mode 100644 index 142e4d446..000000000 --- a/e2e/tests/01_first_launch.rs +++ /dev/null @@ -1,49 +0,0 @@ -//! A blank profile: the gate creates the library, then a real relaunch unlocks it. - -use e2e::{App, PASSPHRASE, step}; - -#[test] -fn first_launch() { - let mut app = App::first_launch("01_first_launch"); - - step("a blank profile opens on the gate, asking the phrase twice", || { - app.gate().expect_new_phrase_asked("the phrase is asked twice"); - app.expect_silent_terminal("the launch wrote nothing in the terminal"); - app.capture("gate-create"); - }); - - // Typed in two goes: the start alone is under the floor of twelve characters. - let (start, rest) = PASSPHRASE.split_at(7); - - step("a phrase under twelve characters cannot be chosen", || { - app.gate().type_phrase(start); - app.gate().confirm_phrase(start); - app.gate().expect_phrase_refused("the button stays out of reach"); - }); - - step("a long enough phrase, twice, creates the library and opens it on its samples", || { - app.gate().type_phrase(rest); - app.gate().confirm_phrase(rest); - app.gate().submit(); - app.notes().expect_samples("the sample notes are on the screen"); - app.capture("first-launch-samples"); - }); - - step("a relaunch asks for the phrase once", || { - app.relaunch(); - app.gate().expect_phrase_asked("the phrase is asked once"); - }); - - step("a wrong phrase is refused and says so", || { - app.gate().try_phrase("not the phrase"); - app.gate().expect_wrong_phrase("the gate says the phrase is wrong"); - app.capture("gate-wrong"); - }); - - step("the phrase chosen opens the library, its samples seeded once", || { - app.gate().unlock(PASSPHRASE); - app.notes().expect_samples("the sample notes are on the screen"); - }); - - app.quit(); -} diff --git a/e2e/tests/12_preferences.rs b/e2e/tests/12_preferences.rs deleted file mode 100644 index c9da20a5b..000000000 --- a/e2e/tests/12_preferences.rs +++ /dev/null @@ -1,177 +0,0 @@ -//! A preference applies on a button; only the theme and the density show while chosen. The -//! language is established here, never assumed: `system` is the machine's. - -use e2e::old::{App, step}; -use egui::accesskit::{Node, Rect}; -use egui::{Key, Modifiers}; - -const THEME_LIGHT: &str = "setting-theme-2"; -const THEME_DARK: &str = "setting-theme-1"; -const COMPACT: &str = "setting-density-1"; -const COMFORTABLE: &str = "setting-density-0"; -const FRENCH: &str = "setting-locale-1"; -const ENGLISH: &str = "setting-locale-2"; -const NOTE_KIND_NOTE: &str = "setting-note-kind-0"; -const NOTE_KIND_SNIPPET: &str = "setting-note-kind-1"; -const FIVE_LINES: &str = "setting-preview-lines-2"; - -fn open(app: &mut App) { - app.click("file-menu"); - app.click("file-preferences"); - app.wait_for("settings-dialog"); -} - -fn closed(app: &mut App) { - app.eventually("the panel is closed", |tree| !tree.has("settings-dialog")); -} - -fn locale(app: &mut App, choice: &str) { - app.click("setting-locale"); - app.click(choice); -} - -/// What the theme control offers, which names the theme it would switch to: it reads the window's. -fn theme_word(app: &mut App) -> String { - app.tree().text("theme-toggle").unwrap_or_default() -} - -/// A card's height, in the window's own units. -fn card_height(app: &mut App) -> f64 { - let tree = app.tree(); - tree.find("note-card") - .and_then(Node::bounds) - .map_or(0.0, |card| card.y1 - card.y0) -} - -/// Taller by the ratio of a 160 px card to a 140 px one: the window's scale aside. -fn one_line_taller(card: f64, four: f64) -> bool { - (card / four - 160.0 / 140.0).abs() < 0.02 -} - -fn still_five_lines(app: &mut App, four: f64) { - app.wait_for("note-card"); - let five = card_height(app); - assert!(one_line_taller(five, four), "{five} for {four}"); -} - -fn five_lines(app: &mut App, four: f64) { - open(app); - app.click(FIVE_LINES); - app.click("settings-apply"); - app.click("settings-close"); - closed(app); - app.eventually("the cards grew by a line", |tree| { - tree.find("note-card") - .and_then(Node::bounds) - .is_some_and(|card: Rect| one_line_taller(card.y1 - card.y0, four)) - }); -} - -fn file_word(app: &mut App) -> String { - app.tree().text("file-menu").unwrap_or_default() -} - -#[test] -fn preferences() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("12_preferences", profile.path()); - app.create_library(); - - step("the theme shows as it is chosen, and Cancel takes it back", || { - open(&mut app); - app.capture("preferences"); - app.click(THEME_DARK); - app.click("settings-apply"); - let dark = theme_word(&mut app); - - app.click(THEME_LIGHT); - app.eventually("the window previews the light theme", |tree| { - tree.text("theme-toggle").is_some_and(|word| word != dark) - }); - app.click("settings-cancel"); - closed(&mut app); - app.eventually("the theme is back", |tree| { - tree.text("theme-toggle").as_deref() == Some(dark.as_str()) - }); - }); - - step("the language waits for the button", || { - open(&mut app); - locale(&mut app, FRENCH); - app.click("settings-apply"); - app.eventually("the window speaks French", |tree| { - tree.text("file-menu").as_deref() == Some("Fichier") - }); - - locale(&mut app, ENGLISH); - assert_eq!(file_word(&mut app), "Fichier", "nothing before the button"); - app.click("settings-apply"); - app.eventually("the window speaks English", |tree| tree.text("file-menu").as_deref() == Some("File")); - app.click("settings-close"); - closed(&mut app); - }); - - step("Escape says what is waiting instead of closing", || { - open(&mut app); - app.click(COMPACT); - app.press(Key::Escape, Modifiers::NONE); - app.wait_for("settings-unapplied"); - assert!(app.has("settings-dialog")); - app.click("settings-discard"); - closed(&mut app); - - open(&mut app); - app.click(COMPACT); - app.press(Key::Escape, Modifiers::NONE); - app.click("settings-apply-close"); - closed(&mut app); - }); - - step("Escape with nothing waiting just closes", || { - open(&mut app); - app.press(Key::Escape, Modifiers::NONE); - closed(&mut app); - }); - - step("« New note » opens the kind the preference says", || { - open(&mut app); - app.click(NOTE_KIND_NOTE); - app.click("settings-close"); - closed(&mut app); - app.click("new-note"); - app.wait_for("editor-rich"); - assert!(!app.has("editor-body")); - app.click("editor-close"); - app.eventually("the editor closed", |tree| !tree.has("editor-rich")); - - open(&mut app); - app.click(NOTE_KIND_SNIPPET); - app.click("settings-close"); - closed(&mut app); - app.click("new-note"); - app.wait_for("editor-body"); - app.click("editor-close"); - app.eventually("the editor closed", |tree| !tree.has("editor-body")); - }); - - let four = card_height(&mut app); - step("five preview lines make every card 160 px rather than 140", || five_lines(&mut app, four)); - - let theme = theme_word(&mut app); - let mut app = app.relaunch(); - app.fill("vault-passphrase", e2e::old::PASSPHRASE); - app.click("vault-submit"); - app.wait_for("area-notes"); - - step("what was applied is what the next launch opens with", || { - assert_eq!(file_word(&mut app), "File"); - assert_eq!(theme_word(&mut app), theme); - still_five_lines(&mut app, four); - open(&mut app); - app.click(COMFORTABLE); - app.click("settings-cancel"); - closed(&mut app); - }); - - app.quit(); -} diff --git a/e2e/tests/13_making_it_mine.rs b/e2e/tests/13_making_it_mine.rs new file mode 100644 index 000000000..9471e530e --- /dev/null +++ b/e2e/tests/13_making_it_mine.rs @@ -0,0 +1,310 @@ +//! Journey 13, « Making it mine »: what is chosen in the preferences and seen where it acts, the +//! keys, the areas, the window, and a new version offered. + +use e2e::{ + App, Area, CardKey, DefaultKind, Density, Indent, Key, Language, Page, Sample, Shortcut, Switch, Theme, + step, +}; + +#[test] +fn making_it_mine() { + let mut app = App::open_before_an_update("13_making_it_mine"); + + the_look(&mut app); + where_they_act(&mut app); + a_global_variable(&mut app); + the_keys(&mut app); + the_areas(&mut app); + the_window(&mut app); + what_the_about_menu_says(&mut app); + + step("*File → Quit* asks for a second click, and ends DevNotes", || { + app.quit_from_the_menu(); + }); +} + +fn the_look(app: &mut App) { + let apart = app.notes().cards_apart(); + + step("the theme and the density show while chosen, and Cancel takes them back", || { + app.prefs().open(); + app.prefs().choose_theme(Theme::Dark); + app.prefs().apply(); + app.prefs().expect_stored("theme", "dark", "what was applied is on the disk"); + let dark = app.window().theme_offered(); + app.prefs().choose_theme(Theme::Light); + app.prefs().choose_density(Density::Compact); + app.window().expect_theme_changed(&dark, "the window previews the light theme"); + app.notes().expect_cards_closer(apart, "the cards preview the density"); + app.prefs() + .expect_stored("theme", "dark", "nothing is written before « Apply »"); + app.prefs().cancel(); + app.window().expect_theme(&dark, "the dark theme is back"); + app.notes().expect_cards_apart(apart, "the cards are as far apart as before"); + }); + + step("« Apply » keeps them, one text a setting on the disk", || { + app.prefs().open(); + app.prefs().choose_density(Density::Compact); + app.prefs().apply(); + app.prefs().expect_stored("density", "compact", "the density is on the disk"); + app.prefs().expect_stored_as_texts("the file holds one text per setting"); + app.capture("preferences"); + app.prefs().close(); + app.notes().expect_cards_closer(apart, "the cards stand closer"); + }); + + step("the language is switched by « Apply »", || { + app.prefs().open(); + app.prefs().choose_language(Language::French); + app.prefs().apply(); + app.window().expect_file_menu("Fichier", "the window speaks French"); + app.prefs().choose_language(Language::English); + app.prefs().apply(); + app.window().expect_file_menu("File", "the window speaks English"); + app.prefs().expect_stored("locale", "en", "the language is on the disk"); + app.prefs().close(); + }); + + step("the title bar switches the theme in one click", || { + let dark = app.window().theme_offered(); + app.window().switch_theme(); + app.window().expect_theme_changed(&dark, "the light theme is on"); + app.prefs().expect_stored("theme", "light", "it is kept"); + }); +} + +fn where_they_act(app: &mut App) { + step("« New note » makes the kind chosen", || { + app.prefs().change(|prefs| prefs.choose_default_kind(DefaultKind::Note)); + app.notes().new_note(); + app.editor().expect_note_open("a Note is open"); + app.editor().close(); + app.prefs().change(|prefs| prefs.choose_default_kind(DefaultKind::Snippet)); + app.notes().new_note(); + app.editor().expect_code_open("a snippet is open"); + app.editor().close(); + }); + + step("a card previews as many lines as chosen", || { + let four = app.notes().card_height(); + app.prefs().change(|prefs| prefs.choose_preview_lines(5)); + app.notes().expect_one_line_taller(four, "the cards grew by a line"); + }); + + step("Tab writes what was chosen", || { + app.prefs().change(|prefs| prefs.choose_indent(Indent::FourSpaces)); + app.notes().new_note(); + app.editor().type_code("indented"); + app.editor().go_to_start(); + app.press(Shortcut::Tab); + app.editor().expect_code(" indented", "four spaces stand before the code"); + app.editor().close(); + }); + + step("a long line is wrapped, or goes on, as chosen", || { + let line = "echo ".repeat(60); + app.notes().new_note(); + app.editor().type_code(&line); + app.editor().go_to_start(); + app.editor().expect_line_unwrapped("the line goes on past the edge"); + app.editor().close(); + app.prefs().change(|prefs| prefs.flip(Switch::WrapLines)); + app.notes().new_note(); + app.editor().type_code(&line); + app.editor().go_to_start(); + app.editor().expect_line_wrapped("the line is laid out over several rows"); + app.editor().close(); + }); + + step("a calculation has the decimals chosen", || { + app.prefs().change(|prefs| prefs.choose_decimals(2)); + app.notes().new_calculation(); + app.editor().type_code("10 / 3"); + app.editor().expect_first_result("333", "the result has two decimals"); + app.editor().close(); + }); + + step("a copy is acknowledged, or not, as chosen", || { + app.notes().copy(Sample::SnippetToFormat); + app.notes().expect_acknowledged("a toast says the copy was done"); + app.prefs().change(|prefs| prefs.flip(Switch::CopyAcknowledged)); + app.notes().copy(Sample::ApiResponse); + app.clipboard().expect_saying("billing", "the second one is copied"); + app.notes().expect_no_acknowledgement("no toast this time"); + }); +} + +fn a_global_variable(app: &mut App) { + step("a global variable is offered to the fields of its name", || { + app.prefs().open(); + app.prefs().go_to(Page::Variables); + app.prefs().add_variable("host", "db.global"); + app.prefs().close(); + app.notes().write_snippet("Ping", "ping {{host}}"); + app.notes().copy_filled("Ping"); + app.fields().copy(); + app.clipboard() + .expect("ping db.global", "the variable fills the field left as it was"); + }); + + step("what is typed on the note comes first", || { + app.notes().copy_filled("Ping"); + app.fields().type_value(0, "db.mine"); + app.fields().copy(); + app.clipboard().expect("ping db.mine", "the value typed is the one copied"); + }); +} + +fn the_keys(app: &mut App) { + step("a key another action holds is flagged", || { + app.prefs().open(); + app.prefs().go_to(Page::Shortcuts); + app.prefs().take_key(CardKey::Check, Key::P); + app.prefs() + .expect_key_flagged(CardKey::Check, "the panel says the key is taken"); + }); + + step("a free key is taken, and the cards answer to it", || { + 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().expect_selected(1, "the first card is selected"); + app.press(Shortcut::Escape); + }); + + step("« Reset » goes back to the first key", || { + app.prefs().open(); + app.prefs().go_to(Page::Shortcuts); + app.prefs().reset_key(CardKey::Check); + app.prefs() + .expect_key(CardKey::Check, "X", "the panel shows the first key again"); + app.prefs().close(); + }); + + step("the areas' keys are read by their place, whatever is printed on them", || { + app.press_on_another_layout(Shortcut::ToolsArea); + app.window().expect_area(Area::Tools, "the tools are on the screen"); + app.press_on_another_layout(Shortcut::NotesArea); + app.window().expect_area(Area::Notes, "the notes are on the screen"); + }); +} + +fn the_areas(app: &mut App) { + step("each area is left as it is and found again, by its key", || { + app.notes().search("zz nothing is called this"); + app.notes().expect_nothing_found("nothing answers the search"); + app.press(Shortcut::ToolsArea); + app.tools().open("case"); + app.press(Shortcut::HttpArea); + app.http().new_draft(); + app.press(Shortcut::NotesArea); + app.notes().expect_nothing_found("the search is as it was"); + app.press(Shortcut::ToolsArea); + app.tools().expect_tool_open("the tool is as it was"); + app.press(Shortcut::HttpArea); + app.http().expect_tabs(1, "the draft is as it was"); + app.http().close_tab_discarding(); + }); + + step("the switch of the areas leads there too", || { + app.window().go_to(Area::Notes); + app.window().expect_area(Area::Notes, "the notes are on the screen"); + app.notes().clear_search(); + app.window().go_to(Area::Http); + app.window().expect_area(Area::Http, "the HTTP area is on the screen"); + app.window().go_to(Area::Tools); + app.window().expect_area(Area::Tools, "the tools are on the screen"); + }); + + step("the side rail is put away in every area at once, and taken back", || { + app.press(Shortcut::SideRail); + app.window().expect_rail_away("the areas' switch went up to the title bar"); + app.press(Shortcut::NotesArea); + app.window().expect_rail_away("the rail is away in the notes too"); + app.press(Shortcut::SideRail); + app.window().expect_rail("the rail is back"); + app.press(Shortcut::ToolsArea); + app.window().expect_rail("it is back in the tools too"); + }); + + step("the window reopens on the area it was left in, as it was set", || { + app.relaunch_and_unlock(); + app.window().expect_area(Area::Tools, "the tools are on the screen"); + app.window().expect_file_menu("File", "the window still speaks English"); + app.window().go_to(Area::Notes); + }); +} + +/// macOS keeps its own three buttons: the steps that press DevNotes' own say what it shows instead. +fn the_window(app: &mut App) { + if cfg!(target_os = "macos") { + step("the window wears the system's own buttons", || { + app.window().expect_system_buttons("DevNotes draws none of its own"); + }); + return; + } + let maximize = app.window().maximize_offered(); + + step("maximised by its control, the window is found so at the next launch", || { + app.window().maximize_or_restore(); + app.window().expect_maximized(&maximize, "the window is maximised"); + app.relaunch_and_unlock(); + app.window().expect_maximized(&maximize, "the window is still maximised"); + }); + + step("a double click on the title bar restores it, and it is found so", || { + app.window().double_click_title_bar(); + app.window().expect_restored(&maximize, "the window is restored"); + app.relaunch_and_unlock(); + app.window().expect_restored(&maximize, "the window is still restored"); + }); + + step("minimised, it goes out of sight, and a new launch brings it back", || { + app.window().minimize_and_come_back(); + }); + + step("closed, with « Close to tray » off, it ends DevNotes", || { + app.prefs().change(|prefs| prefs.flip(Switch::CloseToTray)); + app.window().close_and_start_again(); + app.gate().unlock(e2e::PASSPHRASE); + }); +} + +fn what_the_about_menu_says(app: &mut App) { + step("the version, the shortcuts and the changelog are read from the menu", || { + app.help().open_about(); + app.help().expect_version("the version is said"); + app.help().close(); + app.help().open_shortcuts(); + app.help().expect_shortcuts("the shortcuts are listed, group by group"); + app.help().close(); + app.help().open_whats_new(); + app.help().expect_changelog("the changelog is read, release by release"); + app.help().close(); + }); + + step("a new version is offered, and « Later » closes the offer", || { + app.help().expect_update_known("the menu says a version waits"); + app.help().check_for_updates(); + app.help().expect_update_offered("the version is offered with its notes"); + app.capture("update"); + app.help().update_later(); + }); + + step("« Do not offer this version again » silences it over a relaunch", || { + app.help().check_for_updates(); + app.help().skip_update(); + app.relaunch(); + app.gate() + .expect_no_update("the gate says nothing of it, once the check has answered"); + app.gate().unlock(e2e::PASSPHRASE); + }); + + step("asked from the menu, it is found again", || { + app.help().check_for_updates(); + app.help().expect_update_offered("the version is offered again"); + app.help().update_later(); + }); +} diff --git a/e2e/tests/15_preferences_on_disk.rs b/e2e/tests/15_preferences_on_disk.rs deleted file mode 100644 index 30785e3fd..000000000 --- a/e2e/tests/15_preferences_on_disk.rs +++ /dev/null @@ -1,77 +0,0 @@ -//! The file itself, read from outside the application: one key per setting, each a string, and -//! nothing written before the draft is applied. - -use std::path::Path; - -use e2e::old::{App, step}; -use serde_json::Value; - -const THEME_DARK: &str = "setting-theme-1"; -const THEME_LIGHT: &str = "setting-theme-2"; - -fn stored(profile: &Path) -> serde_json::Map { - let Ok(text) = std::fs::read_to_string(profile.join("preferences.json")) else { - return serde_json::Map::new(); - }; - serde_json::from_str(&text).unwrap_or_default() -} - -fn says(profile: &Path, key: &str) -> Option { - stored(profile).get(key).and_then(Value::as_str).map(str::to_owned) -} - -/// Read again through the window: a write answers frames later, on the core's queue. -fn settled(app: &mut App, profile: &Path, key: &str, want: &str) { - app.eventually(&format!("{key} reaches the file"), |_| says(profile, key).as_deref() == Some(want)); -} - -fn open(app: &mut App) { - app.click("file-menu"); - app.click("file-preferences"); - app.wait_for("settings-dialog"); -} - -#[test] -fn preferences_on_disk() { - let directory = tempfile::tempdir().unwrap(); - let profile = directory.path(); - let mut app = App::launch("15_preferences_on_disk", profile); - app.create_library(); - - step("the file is written, one key per setting", || { - open(&mut app); - app.click(THEME_DARK); - app.click("settings-close"); - settled(&mut app, profile, "devnotes.theme", "dark"); - }); - - step("the file waits for the draft to be applied", || { - open(&mut app); - app.click(THEME_LIGHT); - // The window has drawn the choice, and with it any write it would have asked for. - app.wait_for("settings-apply"); - assert_eq!(says(profile, "devnotes.theme").as_deref(), Some("dark"), "a preview is not a write"); - app.click("settings-close"); - settled(&mut app, profile, "devnotes.theme", "light"); - }); - - step("the locale the panel applied is stored", || { - open(&mut app); - app.click("setting-locale"); - app.click("setting-locale-2"); - app.click("settings-close"); - settled(&mut app, profile, "devnotes.locale", "en"); - }); - - step("every value is a string", || { - let file = stored(profile); - let others: Vec<&String> = file - .iter() - .filter(|(_, value)| !value.is_string()) - .map(|(key, _)| key) - .collect(); - assert!(others.is_empty(), "{others:?}"); - }); - - app.quit(); -} diff --git a/e2e/tests/28_areas.rs b/e2e/tests/28_areas.rs deleted file mode 100644 index d5c5fc0ed..000000000 --- a/e2e/tests/28_areas.rs +++ /dev/null @@ -1,181 +0,0 @@ -//! The three areas: reached from the bar and by `Ctrl+1/2/3` read by position, each keeping its -//! state, the window reopening on the last one, and a key moved in the preferences. - -use e2e::old::{App, PASSPHRASE, step}; -use egui::{Key, Modifiers}; - -fn tools(app: &mut App) { - app.press(Key::Num2, Modifiers::COMMAND); - app.wait_for("area-tools"); -} - -fn notes(app: &mut App) { - app.press(Key::Num1, Modifiers::COMMAND); - app.wait_for("area-notes"); -} - -fn shortcuts(app: &mut App) { - app.click("file-menu"); - app.click("file-preferences"); - app.click("settings-page-shortcuts"); - app.wait_for("shortcut-field-palette"); -} - -fn close_preferences(app: &mut App) { - app.click("settings-close"); - app.eventually("the panel closed", |tree| !tree.has("settings-dialog")); -} - -fn reach(app: &mut App, author_id: &str) { - app.scroll_above("settings-content", author_id, "settings-cancel"); -} - -fn value_of(app: &mut App, author_id: &str) -> String { - let tree = app.tree(); - let node = tree.find(author_id); - node.and_then(egui::accesskit::Node::value).unwrap_or_default().to_owned() -} - -fn palette_key_shows(app: &mut App, said: &str) { - app.eventually(&format!("the palette's field shows {said}"), |tree| { - tree.find("shortcut-field-palette").and_then(egui::accesskit::Node::value) == Some(said) - }); -} - -/// AZERTY's Q, where QWERTY's A stands: macOS hears the place, the others the letter. -fn another_layout(app: &mut App) { - step("a key of another layout is kept as the system will hear it", || { - app.click("shortcut-field-palette"); - app.press_laid_out(Key::Q, Key::A, Modifiers::COMMAND | Modifiers::ALT); - let heard = if cfg!(target_os = "macos") { "Ctrl+Alt+A" } else { "Ctrl+Alt+Q" }; - palette_key_shows(app, heard); - app.click("shortcut-reset-palette"); - palette_key_shows(app, "Ctrl+Alt+P"); - }); -} - -/// The sidebar toggle's box in the area shown, once it holds still. -fn toggle_box(app: &mut App, author_id: &str) -> (f64, f64, f64, f64) { - app.at_rest(author_id); - let tree = app.tree(); - let bounds = tree - .find(author_id) - .and_then(egui::accesskit::Node::bounds) - .expect("the toggle is drawn"); - (bounds.x0, bounds.y0, bounds.x1, bounds.y1) -} - -/// The toggle stands at one place in the three areas. -fn one_toggle_place(app: &mut App) { - let same = |a: (f64, f64, f64, f64), b: (f64, f64, f64, f64)| { - [a.0 - b.0, a.1 - b.1, a.2 - b.2, a.3 - b.3].iter().all(|gap| gap.abs() < 0.5) - }; - step("the sidebar toggle stands at one place in every area", || { - let notes = toggle_box(app, "library-rail-toggle"); - app.click("area-option-tools"); - let tools = toggle_box(app, "tools-rail-toggle"); - assert!(same(tools, notes), "{tools:?} in the tools, {notes:?} in the notes"); - app.click("area-option-http"); - let http = toggle_box(app, "http-rail-toggle"); - assert!(same(http, notes), "{http:?} in HTTP, {notes:?} in the notes"); - app.click("area-option-notes"); - app.wait_for("area-notes"); - }); -} - -#[test] -fn areas() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("28_areas", profile.path()); - app.create_library(); - app.eventually("the samples are drawn", |tree| tree.has("note-card")); - - step("the bar goes to the tools, and back", || { - app.click("area-option-tools"); - app.wait_for("area-tools"); - assert!(!app.has("canvas")); - app.click("area-option-notes"); - app.wait_for("area-notes"); - }); - - one_toggle_place(&mut app); - - step("the keys go there too, and the notes keep their search", || { - app.click("search-input"); - app.type_text("zzz-nothing-matches"); - app.eventually("nothing matches", |tree| !tree.has("note-card")); - tools(&mut app); - notes(&mut app); - app.eventually("the search is as it was", |tree| !tree.has("note-card")); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the search is off", |tree| tree.has("note-card")); - }); - - step("what the native side asks comes back to the notes", || { - tools(&mut app); - app.act("new-note"); - app.wait_for("editor-title"); - app.click("editor-close"); - app.eventually("the editor closed", |tree| !tree.has("editor-title")); - assert!(app.has("area-notes")); - }); - - step("a global key is refused without a modifier", || { - shortcuts(&mut app); - let before = value_of(&mut app, "shortcut-field-palette"); - app.click("shortcut-field-palette"); - app.press(Key::P, Modifiers::NONE); - app.wait_for("shortcut-error-palette"); - assert_eq!(value_of(&mut app, "shortcut-field-palette"), before); - }); - - step("a key another action holds is refused by its name", || { - app.press(Key::N, Modifiers::COMMAND | Modifiers::ALT); - app.eventually("the refusal names the key", |tree| { - tree.text("shortcut-error-palette") - .is_some_and(|said| said.contains("Ctrl+Alt+N")) - }); - }); - - step("a free one is taken, and put back", || { - app.press(Key::J, Modifiers::COMMAND | Modifiers::ALT); - palette_key_shows(&mut app, "Ctrl+Alt+J"); - app.click("shortcut-reset-palette"); - palette_key_shows(&mut app, "Ctrl+Alt+P"); - }); - - another_layout(&mut app); - - step("Escape ends the listening, not the panel", || { - reach(&mut app, "shortcut-field-canvas.pin"); - app.click("shortcut-field-canvas.pin"); - // The field keeps Escape from the frame after it took the focus: `has` settles. - assert!(app.has("settings-dialog")); - app.press(Key::Escape, Modifiers::NONE); - assert!(app.has("settings-dialog")); - }); - - step("a canvas key takes a bare letter, and the canvas answers", || { - reach(&mut app, "shortcut-field-canvas.check"); - app.click("shortcut-field-canvas.check"); - app.press(Key::J, Modifiers::NONE); - app.eventually("the field shows it", |tree| { - tree.find("shortcut-field-canvas.check").and_then(egui::accesskit::Node::value) == Some("J") - }); - close_preferences(&mut app); - app.press(Key::ArrowDown, Modifiers::NONE); - app.press(Key::J, Modifiers::NONE); - app.wait_for("selection-count"); - }); - - tools(&mut app); - let mut app = app.relaunch(); - app.fill("vault-passphrase", PASSPHRASE); - app.click("vault-submit"); - - step("the window reopens on the area it was left in", || { - app.wait_for("area-tools"); - }); - - app.quit(); -} diff --git a/e2e/tests/42_documentation.rs b/e2e/tests/42_documentation.rs deleted file mode 100644 index e52f6fe8b..000000000 --- a/e2e/tests/42_documentation.rs +++ /dev/null @@ -1,47 +0,0 @@ -//! About › Documentation: its pages, read without the network, a search that leads to a section, -//! a link from one page to another, and the way out. Addressed by the pages' names, the same in -//! both languages; what is searched is a word of both. - -use e2e::old::{App, Tree, step}; -use egui::{Key, Modifiers}; - -fn title(tree: &Tree) -> String { - tree.text("docs-title").unwrap_or_default() -} - -#[test] -fn documentation() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("42_documentation", profile.path()); - app.create_library(); - - step("the About menu opens it on the overview", || { - app.click("about-open"); - app.click("about-documentation"); - app.wait_for("docs-dialog"); - app.wait_for("docs-card-start"); - }); - - step("a card leads to its page, and the page to the next", || { - let overview = title(&app.tree()); - app.click("docs-card-start"); - app.eventually("another page is read", |tree| title(tree) != overview); - let start = title(&app.tree()); - app.click("docs-page-writing"); - app.eventually("a page is chosen in the list", |tree| title(tree) != start); - }); - - step("a search answers sections, and one of them is read", || { - app.fill("docs-search", "Argon2id"); - app.eventually("the list gave way to the answers", |tree| { - tree.has("docs-result") && !tree.has("docs-page-start") - }); - app.click("docs-result"); - app.eventually("the list is back", |tree| tree.has("docs-page-start")); - }); - - step("Escape closes it", || { - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the window is closed", |tree| !tree.has("docs-dialog")); - }); -} diff --git a/e2e/tests/44_window_controls.rs b/e2e/tests/44_window_controls.rs deleted file mode 100644 index 80afcce4d..000000000 --- a/e2e/tests/44_window_controls.rs +++ /dev/null @@ -1,87 +0,0 @@ -//! The window's own controls at the end of the title bar, the system's frame gone: maximise then -//! restore, remembered by the next launch; minimise; close, which ends the application with -//! « Close to tray » off (`43_close_to_tray` holds the close with it on). Maximised is the -//! system's answer — under Linux the window manager's — read from the control's name. macOS -//! keeps its own three buttons: nothing here runs there. -#![cfg(not(target_os = "macos"))] - -use std::path::Path; - -use e2e::old::{App, step}; - -fn maximized_on_disk(profile: &Path) -> bool { - platform::window::read(&profile.join("window.json")) - .expect("the geometry is kept") - .maximized -} - -fn name_of(app: &mut App, author_id: &str) -> String { - app.tree().text(author_id).unwrap_or_else(|| panic!("{author_id} is named")) -} - -#[test] -fn maximised_then_restored_and_the_next_launch_remembers() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("44_window_controls", profile.path()); - app.wait_for("window-maximize"); - let maximize = name_of(&mut app, "window-maximize"); - - step("maximised, the control names the restore", || { - app.click("window-maximize"); - app.eventually("the window is maximised", |tree| { - tree.text("window-maximize").is_some_and(|name| name != maximize) - }); - app.capture("maximised"); - }); - - let mut app = app.relaunch(); - step("the next launch opens maximised", || { - assert!(maximized_on_disk(profile.path())); - app.eventually("the window comes back maximised", |tree| { - tree.text("window-maximize").is_some_and(|name| name != maximize) - }); - }); - - step("restored, the control names the maximise again", || { - app.click("window-maximize"); - app.eventually("the window is restored", |tree| { - tree.text("window-maximize").as_deref() == Some(maximize.as_str()) - }); - }); - - app.quit(); - assert!(!maximized_on_disk(profile.path())); -} - -#[test] -fn minimised_it_goes_out_of_sight_and_a_launch_brings_it_back() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("44_window_controls", profile.path()); - app.wait_for("window-minimize"); - let before: u32 = app - .tree() - .text("window-put-away") - .and_then(|count| count.parse().ok()) - .expect("the e2e flavour counts the window put away"); - - app.click("window-minimize"); - app.launch_again(); - - let once_more = (before + 1).to_string(); - app.eventually("the window went out of sight once, and is back", |tree| { - tree.has("window-shown") && tree.text("window-put-away").as_deref() == Some(&once_more) - }); - app.quit(); -} - -#[test] -fn with_the_preference_off_close_ends_the_application() { - let profile = tempfile::tempdir().unwrap(); - std::fs::write(profile.path().join("preferences.json"), r#"{ "devnotes.closeToTray": "false" }"#) - .unwrap(); - let mut app = App::launch("44_window_controls", profile.path()); - app.wait_for("window-close"); - - app.click("window-close"); - app.ended(); -}