From 4cb28a5a2fb31109e0814e3d4efb929ad3281b10 Mon Sep 17 00:00:00 2001 From: Valentin Millet Date: Fri, 4 Dec 2026 05:17:19 +0100 Subject: [PATCH] E2E: library journeys, and the last scenarios and their driver removed --- .claude/skills/add-feature/SKILL.md | 2 +- .claude/skills/bug-investigation/SKILL.md | 2 +- .claude/skills/desktop-e2e-testing/SKILL.md | 21 +- .claude/skills/verify-change/SKILL.md | 2 +- CLAUDE.md | 8 +- docs/architecture.md | 123 ++-- e2e/examples/footprint.rs | 36 +- e2e/src/driver.rs | 19 +- e2e/src/lib.rs | 1 - e2e/src/old.rs | 671 -------------------- e2e/src/sdk/act.rs | 2 +- e2e/src/sdk/files.rs | 18 +- e2e/src/sdk/gate.rs | 56 ++ e2e/src/sdk/http.rs | 16 +- e2e/src/sdk/libraries.rs | 105 +++ e2e/src/sdk/mod.rs | 63 +- e2e/src/sdk/notes.rs | 26 + e2e/src/sdk/prefs.rs | 4 + e2e/src/sdk/rail.rs | 13 + e2e/src/sdk/security.rs | 87 +++ e2e/src/sdk/transfer.rs | 108 ++++ e2e/src/server.rs | 19 +- e2e/tests/10_library_transfer.rs | 213 ------- e2e/tests/10_scripts_and_runs.rs | 2 +- e2e/tests/11_libraries_and_transfer.rs | 210 ++++++ e2e/tests/12_looking_after_the_library.rs | 93 +++ e2e/tests/16_passphrase_change.rs | 92 --- e2e/tests/21_folders_travel.rs | 106 ---- e2e/tests/23_backups.rs | 101 --- e2e/tests/24_forgotten_passphrase.rs | 47 -- e2e/tests/25_libraries.rs | 153 ----- e2e/tests/36_recette_libraries.rs | 136 ---- e2e/tests/37_recette_socle.rs | 368 ----------- 33 files changed, 921 insertions(+), 2002 deletions(-) delete mode 100644 e2e/src/old.rs create mode 100644 e2e/src/sdk/libraries.rs create mode 100644 e2e/src/sdk/security.rs create mode 100644 e2e/src/sdk/transfer.rs delete mode 100644 e2e/tests/10_library_transfer.rs create mode 100644 e2e/tests/11_libraries_and_transfer.rs create mode 100644 e2e/tests/12_looking_after_the_library.rs delete mode 100644 e2e/tests/16_passphrase_change.rs delete mode 100644 e2e/tests/21_folders_travel.rs delete mode 100644 e2e/tests/23_backups.rs delete mode 100644 e2e/tests/24_forgotten_passphrase.rs delete mode 100644 e2e/tests/25_libraries.rs delete mode 100644 e2e/tests/36_recette_libraries.rs delete mode 100644 e2e/tests/37_recette_socle.rs diff --git a/.claude/skills/add-feature/SKILL.md b/.claude/skills/add-feature/SKILL.md index d8fa9f96c..56158e060 100644 --- a/.claude/skills/add-feature/SKILL.md +++ b/.claude/skills/add-feature/SKILL.md @@ -12,6 +12,6 @@ description: Use when adding or changing a DevNotes feature end to end (core ser 5. The screen: run `egui-ui`. State in `AppState`, actions applied in `apply`, keys through `keys::dispatch`, widgets from `widgets/`, colours and gaps from `theme::tokens`, every string a key in both locales. 6. Something asked of the OS (a dialog, the clipboard, the tray)? Run `platform-integration`. 7. Sealed data (titles, bodies, names, attachments) touched? Run `devnotes-security-review`. -8. Tests with the code: Rust inline or `crates/engine/tests/`; kittest over a real core (`testing::backend`/`unlocked`); an e2e scenario if a user journey changes (`desktop-e2e-testing`). +8. Tests with the code: Rust inline or `crates/engine/tests/`; kittest over a real core (`testing::backend`/`unlocked`); a step of an e2e journey if a nominal path changes (`desktop-e2e-testing`). 9. Update `docs/architecture.md` and, only if a new trap exists, one line of `CLAUDE.md`. What the user sees: `docs/content/fr` and `docs/content/en` (`docs/content/README.md` says how), and, when they show the screen that changed, the README's GIFs (`docs/gifs/`, by `app::screens` then `--example tours`) and the site's scenes (`website/`, skill `marketing-site`). Publishing them is automatic. 10. Finish with `verify-change`, including a look at the window. Report what ran and what did not. diff --git a/.claude/skills/bug-investigation/SKILL.md b/.claude/skills/bug-investigation/SKILL.md index bdb7e1136..824d90647 100644 --- a/.claude/skills/bug-investigation/SKILL.md +++ b/.claude/skills/bug-investigation/SKILL.md @@ -5,7 +5,7 @@ description: Use when a DevNotes bug, crash, wrong result or flaky test must be # Bug investigation -1. Reproduce first, with the smallest input: a failing Rust test, a kittest test or an e2e scenario. No repro → say so and list what is missing. +1. Reproduce first, with the smallest input: a failing Rust test, a kittest test or a step of an e2e journey. No repro → say so and list what is missing. 2. Locate the owner: rules and data are the core (`crates/engine`), display is `crates/ui`. Check `CLAUDE.md` "Things that will bite you" for the matching trap before theorising (the db queue and the lock, `updated_at`, previews vs full body, `Engine::write` and the index, state vs view, the keyboard order, `LibraryCaches`, e2e waits). 3. State the root cause with evidence (file:line, log, failing assertion). Do not fix symptoms or add retries/sleeps. 4. Smallest fix at the owning layer; no unrelated refactors or dependency bumps. diff --git a/.claude/skills/desktop-e2e-testing/SKILL.md b/.claude/skills/desktop-e2e-testing/SKILL.md index 76ad7e433..980c3f78e 100644 --- a/.claude/skills/desktop-e2e-testing/SKILL.md +++ b/.claude/skills/desktop-e2e-testing/SKILL.md @@ -1,18 +1,19 @@ --- name: desktop-e2e-testing -description: Use when writing, running or debugging an end-to-end scenario of the assembled egui app (e2e/, driven through egui_inspection). Not for screen or widget tests (kittest, egui-ui), nor the website. +description: Use when writing, running or debugging an end-to-end journey of the assembled egui app (e2e/, driven through egui_inspection). Not for screen or widget tests (kittest, egui-ui), nor the website. --- # Desktop e2e -- The suite is being rewritten as journeys on an SDK (`e2e/src/sdk/`, milestone v1.3.2): `CONTRIBUTING.md` → "The end-to-end journeys" says how to run, watch, mend and extend it. What follows about `e2e::App` is the driver of the scenarios not yet rewritten (`e2e::old`). +`CONTRIBUTING.md` → "The end-to-end journeys" says how to run, watch, mend and extend them; `docs/architecture.md` → "The journeys, on the assembled window" lists the thirteen and what the driver does. What is worth knowing before touching one: -- Build the flavour first, every time `crates/` changed: `cargo build -p app --features e2e --target-dir target/e2e` (its own target directory: no other build overwrites it). Then `cargo test -p e2e --test NN_name` for one scenario, `cargo test -p e2e` for all of them, one file after the other — what CI runs on each OS, from the start of the run. `cargo test --workspace` runs with `--exclude e2e`. -- A scenario is `e2e/tests/NN_name.rs`, one `#[test]` of named `step`s. It launches its own application on its own `tempfile` profile, seeds its own state, and must pass alone. There are no groups to keep (D31): a new file is picked up by its name. -- Drive it through `e2e::App`: `wait_for`, `has`, `click`, `fill`, `type_text`, `press` (a physical key: the area keys read the position), `eventually`, `capture`, `relaunch` (a real restart through `--action quit`), `quit`. Add a method there before reaching for the protocol in a scenario. -- Wait on conditions (`eventually`), never a duration: `std::thread::sleep` is refused by `e2e/clippy.toml`; the one exception, asserting that **nothing** happens, carries an `#[expect]` saying so. `Settle` waits for egui, not for the core: its answer comes frames later, which is why `eventually` reads again. -- Address controls by `author_id` (the old `data-testid` names), never by text: the language is the machine's. Missing one? Give the widget its id through `widgets::address` / `widgets::interact`. -- What the protocol cannot reach goes through the flavour's two doors: a global action is `--action ` from a second launch; a file dialog answers `DEVNOTES_E2E_DIALOG` (`platform::dialog::from_scenario`). A file dropped from the explorer is not injectable: go through « Joindre ». -- A failure leaves `failure.png` and the application's log in `target/e2e/scenarios//`: read them before changing the scenario, and decide whether the app or the test is wrong. CI uploads the same folder per platform. -- Never point a scenario at a real profile: `--profile` is always a temporary directory. The inspection port has no authentication; the flavour never becomes a release. +- Build the flavour first, every time `crates/` changed: `cargo build -p app --features e2e --target-dir target/e2e` (its own target directory: no other build overwrites it). Then `cargo test -p e2e --test NN_name` for one journey, `cargo test -p e2e` for all — what CI runs on each OS. `cargo test --workspace` runs with `--exclude e2e`. +- A journey is `e2e/tests/NN_name.rs`: one `#[test]` of named `step`s, what the person does then what they see. A nominal path goes into the journey it belongs to, as a step; a new file only for a new goal (15 at most). Branches, edge cases and error codes are unit tests'. +- It is written on the SDK (`e2e/src/sdk/`, one file per area) alone: no `author_id`, coordinate or duration. An act it lacks is a method of its area, with a line of doc; an expectation carries the sentence of what the person would see. +- Inside the SDK: `expect` (reads the tree until it holds), `click`, `fill`, `fill_nth` and `replace` (wait for the keyboard), `click_until` (a click the screen can lose), `place` (waits for a control to hold still), `reach` and `scroll_to`. Wait on what the act changes, not on what was already there: the last answer, a toast, a row of the same name. `std::thread::sleep` is refused by `e2e/clippy.toml`. +- Controls are addressed by `author_id`, never by a translated text: the language is the machine's (CI runs in English). A journey that must read a word chooses its language first (`prefs().choose_language`). Missing an id? Give the widget one through `widgets::address` / `widgets::interact`. +- The window is 1440 × 900 at most (`window().widen()`), 1280 wide under CI's Xvfb, 1024 × 768 on Windows after a full screen: call `widen()` again after a presentation, and click what is in view. +- What the protocol cannot reach goes through the flavour's doors: a global action is `--action ` from a second launch; a file dialog answers the path `files().answer` wrote; updates come from `App::open_before_an_update`'s server. A file dropped from the explorer is not injectable: go through *Attach*. +- A failure leaves `failure.png` and the application's log in `target/e2e/scenarios//`: read them before changing the step, and decide whether the application or the journey is wrong. CI uploads the same folder per platform. +- Never point a journey at a real profile. The inspection port has no authentication; the flavour never becomes a release. - Lint: `cargo clippy --workspace --all-targets --all-features -- -D warnings`. diff --git a/.claude/skills/verify-change/SKILL.md b/.claude/skills/verify-change/SKILL.md index 2521980e1..d1300b06f 100644 --- a/.claude/skills/verify-change/SKILL.md +++ b/.claude/skills/verify-change/SKILL.md @@ -14,7 +14,7 @@ Run from the repo root; pick by what changed, and report only what actually ran. | `scripts/**`, `.github/**` | `node --test "scripts/*.test.mjs"` | | `docs/content/**` | `npm run docs` from `website/`, `cargo test -p engine docs`, `cargo test -p ui docs_quotes` | | `website/**` | from `website/`: `npm run lint`, `npm run test:scripts`, `npm test`, `npm run build`, and a look at the built page | -| A user journey, anything the assembled app does | `cargo build -p app --features e2e --target-dir target/e2e`, then `cargo test -p e2e` (or `--test NN_name` for the scenario it touches) (`desktop-e2e-testing`) | +| A user journey, anything the assembled app does | `cargo build -p app --features e2e --target-dir target/e2e`, then `cargo test -p e2e` (or `--test NN_name` for the journey it touches) (`desktop-e2e-testing`) | | Anything visible | `cargo run -p app -- --profile ` and a screenshot, both themes; or the kittest captures: `DEVNOTES_CAPTURES= cargo test -p ui app::captures` | | Dependencies | `dependency-audit`; the licence must be in `deny.toml` | diff --git a/CLAUDE.md b/CLAUDE.md index 713c4908d..ba8ee6f11 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -23,7 +23,7 @@ Principles: - Cargo workspace: `cargo check|build|test --workspace`, `cargo clippy --workspace --all-targets --all-features -- -D warnings` (⚠️ `--all-features` is what compiles the `e2e` flavour), `cargo fmt --all --check`, `cargo bench -p engine` (not in CI; `autobenches = false` is load-bearing; → "Benchmarks"). Every external dependency is declared once, in the root `[workspace.dependencies]`; a crate takes it with `dep.workspace = true` and adds only its own features (D33). Toolchain pinned in `rust-toolchain.toml`; `unsafe_code` forbidden in every crate (D7), `clippy::pedantic` denied. - No Node project at the root: the release scripts have no dependency. `node --test "scripts/*.test.mjs"` · `cargo run -p app --example icons` (writes `crates/app/icons/`; ⚠️ small `.ico` sizes come from `icons/source/`) · `node scripts/prettier.mjs` (copies the Prettier it pins into `crates/text/prettier/`, the formatter compiled in). Markdown, JSON and YAML have no formatter. The request-script libraries are bundled by `crates/engine/sandbox/build.mjs`, from that folder's own `package.json`. - Website (`website/`, Angular, devnotes.fr; its own `package.json`, outside the Cargo workspace): from `website/`, `npm ci` · `npm start` (port 4300) · `npm run build` (fetches the latest release, prerenders to `website/dist/`, checks every page and its download links) · `npm test` · `npm run lint` · `npm run test:scripts`. `website.yml` publishes it when `website/` or `docs/content/` changes on `main`, and after each release. → "The website". -- E2E: `cargo build -p app --features e2e --target-dir target/e2e`, then `cargo test -p e2e` (the driver is `e2e/` at the root; all scenarios, one after the other; `--test 01_first_launch` for one; `cargo test --workspace --exclude e2e` otherwise). `01`–`35` are the WebdriverIO scenarios ported, the rest are this application's own. → "The scenarios, on the assembled window". +- E2E: `cargo build -p app --features e2e --target-dir target/e2e`, then `cargo test -p e2e` (thirteen journeys in `e2e/tests/`, one after the other; `--test 01_first_day` for one; `cargo test --workspace --exclude e2e` otherwise). A journey is written on the SDK (`e2e/src/sdk/`) alone, with no `author_id`, coordinate or duration of its own (`CONTRIBUTING.md`). → "The journeys, on the assembled window". - Release is a `workflow_dispatch` after a version bump; the version is `[workspace.package] version` in `Cargo.toml` alone (D27), so a bump touches `Cargo.toml` and `Cargo.lock` (`cargo update --workspace`); `scripts/version.mjs` refuses a release where they disagree. `release.yml` runs `prepare` (checks, changelog written, nothing pushed) → `package` (`package.yml`: a job a system, one action a format under `.github/actions/package/`, signed and checked) → `finalize` (commit, tag, atomic push, release page): ⚠️ the irreversible last, so a failed release leaves nothing to undo. `packages.yml` calls `package.yml` on pull requests, then installs and updates. ⚠️ A version branch (`dev/x.y.z`) reaches `main` by a merge commit, never a squash: the release notes read what the merge brings. → "Releasing", `docs/releasing.md`. ## Things that will bite you @@ -96,13 +96,13 @@ Read at the `angular-reference` tag; the egui mechanism is in `docs/architecture ### Tests - State is tested against the real core on a temporary library; only the platform (dialogs, window, clipboard, notifications, clock) is faked, and no fake reimplements a core rule. → "Testing". -- ⚠️ An e2e scenario runs alone on a virgin profile, seeds its own state, waits on conditions (`eventually`), never durations, and addresses controls by `author_id` (the old `data-testid` names). → "One application per run, one run per scenario". +- ⚠️ An e2e journey runs alone on a virgin profile and acts through the SDK, which waits on conditions, never durations, and addresses controls by `author_id` (the old `data-testid` names). → "The journeys, on the assembled window". ## Tickets and pull requests - **A pull request's title is its changelog entry** (`scripts/release-notes.mjs`), and a ticket's title is where it comes from: both say **what changes, factually and briefly** — `: `, the area in one or two words (a head of three words or more before `: ` is all the notes keep; ⚠️ never a commit kind — `CI`, `Docs`, `Test`, `Build`, `Fix`, `Security`… is read as a prefix and dropped), then the control, the action, the result; ≤ 70 characters. No figure of speech, no implementation detail, no « of our own ». ✗ « Search the code through a bar of our own » → ✓ « Code editor: new find-and-replace bar with match count and options ». - **A ticket wears one section label**: `enhancement`, `change`, `bug` or `removal` for what someone using the application sees (the update prompt shows them), `security`, `documentation` for the guides and the README, `website` for the site and its pages (both on the release page alone, never in the application), or `refactor`/`test` for the rest, a fix to the CI or the tests included; a pull request that closes no ticket wears it itself. ⚠️ Without one, the release notes file it under « Under the hood » without a word. -- **A ticket's body opens on its context, then its change**: `**Context** —` what the application does today and where it was seen or who asked; `**Change** —` what will be different, in a sentence or two; then `**To do**` and `**Tests**` (naming the e2e scenario). A milestone's description lists what it changes, plainly. +- **A ticket's body opens on its context, then its change**: `**Context** —` what the application does today and where it was seen or who asked; `**Change** —` what will be different, in a sentence or two; then `**To do**` and `**Tests**` (naming the e2e journey and its step). A milestone's description lists what it changes, plainly. - **No other software in a title, a description or a milestone**, unless the feature reads, writes or plugs into it (an import format, an extension's host): never a comparison with another product. ## Security and verification @@ -113,4 +113,4 @@ Read at the `angular-reference` tag; the egui mechanism is in `docs/architecture ## Claude Code setup -- `.claude/skills/` is versioned. Local: `add-feature`, `egui-ui`, `platform-integration`, `database-migration`, `devnotes-security-review`, `verify-change`, `desktop-e2e-testing` (the `e2e/` driver), `backup-restore`, `bug-investigation`, `release-packaging`, `marketing-site`, `performance-profiling`, `dependency-audit`. Vendored, unmodified and pinned in `.claude/skills/PROVENANCE.md`: `frontend-design`, `webapp-testing` (`anthropics/skills`); `seo`, `core-web-vitals`, `accessibility` (`addyosmani/web-quality-skills`); `rust-guidelines` (`microsoft/rust-guidelines`, its `SKILL.md` ours). A vendored skill is generic: where it disagrees with this file or a local skill, the project wins. `frontend-design`, `webapp-testing`, `seo`, `core-web-vitals` and `accessibility` are for the website. `.claude/settings.json` holds the permission rules that back `.claude/rules/security.md`; `settings.local.json`, `launch.json` and `.mcp.json` stay local. +- `.claude/skills/` is versioned. Local: `add-feature`, `egui-ui`, `platform-integration`, `database-migration`, `devnotes-security-review`, `verify-change`, `desktop-e2e-testing` (the `e2e/` journeys and their SDK), `backup-restore`, `bug-investigation`, `release-packaging`, `marketing-site`, `performance-profiling`, `dependency-audit`. Vendored, unmodified and pinned in `.claude/skills/PROVENANCE.md`: `frontend-design`, `webapp-testing` (`anthropics/skills`); `seo`, `core-web-vitals`, `accessibility` (`addyosmani/web-quality-skills`); `rust-guidelines` (`microsoft/rust-guidelines`, its `SKILL.md` ours). A vendored skill is generic: where it disagrees with this file or a local skill, the project wins. `frontend-design`, `webapp-testing`, `seo`, `core-web-vitals` and `accessibility` are for the website. `.claude/settings.json` holds the permission rules that back `.claude/rules/security.md`; `settings.local.json`, `launch.json` and `.mcp.json` stay local. diff --git a/docs/architecture.md b/docs/architecture.md index 9be004836..9989abfbd 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -47,7 +47,7 @@ crates/platform/ what is asked of the operating system: paths, window, instan shortcuts, clipboard, dialogs, notifications, autostart, updater crates/ui/ the egui interface: the frame, its state, its screens, its widgets crates/app/ the `devnotes` binary (main), its icons (`--example icons`) and packages -e2e/ the end-to-end driver and its scenarios, on the assembled window +e2e/ the end-to-end driver, its SDK and the journeys, on the assembled window golden/ test data: exact outputs the tests compare with (its README says which) ``` @@ -985,7 +985,7 @@ be corrected without a build; that is given up. 2. `ui/src/api/tools.rs`: one function through `backend.compute`. 3. `ui/src/tools/catalogue/.rs`: a struct implementing `Tool`, its `make()`; `catalogue.rs`: an entry and a `mod`. A reference is `Reference::of(table)` and a line of `REFERENCES`. -4. `tools..*` in both locales, its kittest over a real core, a step in scenario 29, and its +4. `tools..*` in both locales, its kittest over a real core, a row in journey 8's table, and its state in `app::captures` by itself: `the_tools` walks the catalogue. What every tool draws alike is the kit, `tools/ui/`: `columns`, `line`, `section_head`, `text_area`, @@ -1536,8 +1536,8 @@ way — the kind menu names it and offers nothing. and gives back the selection it was taken over, then drops the selection, then leaves), a history of the scene's states, and an export as PNG or SVG (`drawing::export`), written with `tools::write_file` where `FileDialog` says. ⚠️ `rfd`'s dialog blocks until answered, so the whole - export runs on `compute`, never on the window's thread. An e2e scenario answers it through - `DEVNOTES_E2E_DIALOG` (`App::launch_answering`). + export runs on `compute`, never on the window's thread. A journey answers it through + `DEVNOTES_E2E_DIALOG` (`Files::answer`). - **A Note embeds one by its id**: `![title](devnotes:drawing/)`, the Markdown image of TipTap's extension, drawn by a node view that asks `drawing_picture` (`rich-text-drawings.ts`); the Note's body carries no picture. Inserted from the toolbar's « Insérer un dessin », whose @@ -4857,7 +4857,7 @@ first, and a closed tab closes its socket. written at the end of the script, and for a request the order the scripts run in, a level above a click from its settings on the same script. The extractions stand among the scripts after the answer. What runs them is the application relaunched as their host: a kittest bench is not that -binary, so running them is scenario 34's. A script that stopped before the send stands in place +binary, so running them is journey 10's. A script that stopped before the send stands in place of the answer, read back from its error's params (`ScriptStop::of_params`); after it, above the answer that came. « Open the script » goes to the request's own, or to the settings of what holds it, on the phase, the line marked until the next edit (`HttpState::script_focus`). @@ -5565,8 +5565,8 @@ note can be created, and the next open seeds only where there is none. The trigg strip scrolls itself into view, because it replaces a trigger further down a panel that scrolls and would otherwise appear below the fold. -`23-backups.e2e.ts` goes through that gate for real: its final scenario replaces the library, -unlocks the copy, and finds neither a note written after the copy nor Preferences open. +Journey 12 goes through that gate for real: it replaces the library, unlocks the copy, and finds +the note erased and nothing written after the copy. ### Attachments, and the one plaintext copy @@ -6690,7 +6690,7 @@ stress budget holds only if it stops keeping the bodies. ### Rust -`cargo test --workspace --exclude e2e` runs everything but the scenarios. +`cargo test --workspace --exclude e2e` runs everything but the journeys. `cargo clippy --workspace --all-targets --all-features -- -D warnings` (`--all-features` is what compiles the `e2e` flavour) and `cargo fmt --all --check` gate the code; `rustfmt.toml` sets lines of 110 columns, filled before they are cut, a chain of calls past 80 cut at each call. A commit that @@ -6764,59 +6764,76 @@ screens, two seconds each, assembled by `cargo run -p app --example tours -- ` from a second -launch for a global action (any flavour hears it, a desktop's shortcut runs it), and in this -flavour alone `--action close`, the event the close button sends (`ViewportCommand::Close` is -pushed as the same `ViewportEvent::Close`), and `--action tray:`, what the tray's menu -hands over; `platform::dialog::from_scenario`, a file dialog answering the path in -`DEVNOTES_E2E_DIALOG`. Whether the window is out of sight is `window-shown` or `window-hidden` in -the tree (`app::sight`), and `window-put-away` how many times it went, read from the commands the -application sent: the same answer on every system, whatever its window manager does. ⚠️ -macOS minimises a closed window, and a minimised window paints nothing: eframe runs `logic` alone -then, outside any pass, so a wrapper of the application reads the commands after `logic` and -after `ui`, where a plugin would miss the window brought back; a scenario reads nothing while it -is away, `App::act_hiding` takes the « not painting » answer there as the window gone, and the -count is read once it is back. `44_window_controls` clicks the title bar's own controls: -maximised then restored, as the next launch remembers, minimised, closed. `43_close_to_tray` closes, hides and brings the -window back by each way on every system; under Linux it also serves a session bus and a -StatusNotifierWatcher of its own, started after the application, and clicks the item's menu. ⚠️ **Its inspection port has no authentication**: a release -build of the flavour does not compile (`compile_error!`), and `lint-rust` checks that the -default build does not link `egui_inspection`. Its own target directory keeps every other build -from overwriting it. - -`e2e/`, at the root beside the product's crates, is the driver, and on it the **SDK of the -person's acts** (`e2e/src/sdk/`, one file per area) the journeys are written on: `CONTRIBUTING.md` → -"The end-to-end journeys". `App::launch` starts the flavour with `--profile ` and -`EGUI_INSPECTION=127.0.0.1:`, and speaks egui's inspection protocol: it reads the -AccessKit tree, finds a control by its `author_id`, clicks the middle of its box, types, presses -a key at its place (the area keys read the position), captures the window. `eventually` reads -the tree until its condition holds, with no `Settle` between reads: `Settle` waits for egui to -be idle, not for the core, whose answer arrives frames later, and each read already renders a -frame (up to 300 ms on WARP). `relaunch` asks `--action quit`, waits for the process to -end its queue drained, and starts it again on the same profile. A failed scenario leaves its -last screen and the application's log in `target/e2e/scenarios//`, beside its -captures. - -One file per scenario, `e2e/tests/_.rs`, one `#[test]` of named steps -(`e2e::step`): `cargo test -p e2e --test 01_first_launch` runs one, `cargo test -p e2e` all of -them, one file after the other. Each launches its own application on its own profile, so the -files never share a process. `cargo test --workspace` is run with `--exclude e2e`. -`e2e/clippy.toml` refuses `std::thread::sleep`: a scenario waits on conditions, never -durations. +on WARP; `DEVNOTES_E2E_PAINT_ALL` paints every frame, to watch a journey run), and the doors the +protocol has no way through — `--action ` from a second launch for a global action (any +flavour hears it, a desktop's shortcut runs it), and in this flavour alone `--action close`, the +event the close button sends (`ViewportCommand::Close` is pushed as the same +`ViewportEvent::Close`), and `--action tray:`, what the tray's menu hands over; +`platform::dialog::from_scenario`, a file dialog answering the path `DEVNOTES_E2E_DIALOG`'s file +holds; `DEVNOTES_E2E_UPDATES`, where a new version is looked for +(`platform::updater::scenario`). Whether the window is out of sight is `window-shown` or +`window-hidden` in the tree (`app::sight`), and `window-put-away` how many times it went, read +from the commands the application sent: the same answer on every system, whatever its window +manager does. ⚠️ macOS minimises a closed window, and a minimised window paints nothing: eframe +runs `logic` alone then, outside any pass, so a wrapper of the application reads the commands +after `logic` and after `ui`, where a plugin would miss the window brought back; a journey reads +nothing while it is away, `Driver::settle_out_of_sight` takes the « not painting » answer there +as the window gone, and the count is read once it is back. Under Linux, journey 7 serves a session +bus and a StatusNotifierWatcher of its own, and clicks the tray's real menu. ⚠️ **Its inspection +port has no authentication**: a release build of the flavour does not compile +(`compile_error!`), and `lint-rust` checks that the default build does not link +`egui_inspection`. Its own target directory keeps every other build from overwriting it. + +`e2e/`, at the root beside the product's crates, holds the driver (`driver.rs`) and on it the +**SDK of the person's acts** (`sdk/`, one file per area), the only thing a journey is written on: +`CONTRIBUTING.md` → "The end-to-end journeys". The driver starts the flavour with +`--profile ` and `EGUI_INSPECTION=127.0.0.1:`, and speaks egui's inspection +protocol: it reads the AccessKit tree, finds a control by its `author_id`, clicks the middle of its +box, types, presses a key at its place (the area keys read the position), captures the window. +`App::expect` reads the tree until its condition holds, with no `Settle` between reads: `Settle` +waits for egui to be idle, not for the core, whose answer arrives frames later, and each read +already renders a frame (up to 300 ms on WARP). A click is a press and a release in two frames: +in one, a menu opened by it is closed by it. `App::relaunch` asks `--action quit`, waits for the +process to end its queue drained, and starts it again on the same profile. The journeys' requests +go to a server of the suite's own (`server.rs`), never to the network. A failed journey leaves its +last screen and the application's log in `target/e2e/scenarios//`, beside its captures. + +| Journey | What is walked | +| ------------------------------ | -------------------------------------------------------------------------- | +| `01_first_day` | the first launch, the library made, the samples, the documentation | +| `02_snippet_to_paste` | a snippet written, found, filled and copied, a JSON explored | +| `03_keeping_a_note` | attachments, versions, the trash and undo, drafts over a relaunch | +| `04_other_kinds` | a Note, a todo list, a calculation and a drawing | +| `05_finding` | the search, the filters, the selection and the tags | +| `06_spaces_and_board` | spaces, folders and the board | +| `07_reaching_from_anywhere` | a second launch, the palette, the clipboard, the tray, the window put away | +| `08_tools` | the tools' home, the catalogue as one table, what is kept, the files | +| `09_calling_an_api` | collections, requests, answers, environments, code, the history | +| `10_scripts_and_runs` | scripts, tests, what stops a send, a collection run | +| `11_libraries_and_transfer` | several libraries, exports and imports | +| `12_looking_after_the_library` | the phrase, the copies, a damaged file, a forgotten phrase | +| `13_making_it_mine` | the preferences, the keys, the areas, the window, an update | + +One file per journey, one `#[test]` of named steps (`e2e::step`): +`cargo test -p e2e --test 01_first_day` runs one, `cargo test -p e2e` all of them, one file after +the other. Each launches its own application on its own profile, so the files never share a +process. `cargo test --workspace` is run with `--exclude e2e`. `e2e/clippy.toml` refuses +`std::thread::sleep`: a journey waits on conditions, never durations. In CI, the `e2e` job of `ci.yml` runs once per platform from `changes` on, beside the Rust tests: it builds the flavour into its cached `target/`, runs `cargo test -p e2e` — under `xvfb-run` with lavapipe and openbox on Linux (maximising a window is a window manager's answer, -which `44_window_controls` reads), on WARP on Windows — and uploads `scenarios/`. The scenarios are not split into groups -(plan, D31): when the suite grows long, it is split by file name, never by a list kept by hand. +which journey 13 reads), on WARP on Windows — and uploads `scenarios/`. The journeys are not split +into groups (plan, D31): were the suite to grow long, it is split by file name, never by a list +kept by hand. **The first job that fails stops everything**, whichever it is: lint, a Rust leg, Sonar, an e2e leg, an advisory. Its last step, `if: failure()`, dispatches `stop.yml` with the run's id, and @@ -6830,8 +6847,8 @@ across three merges while the run read `success`. A job whose failure reads as a weak signal, it is a false one: a flaky run blocking a merge until it is re-run is the price worth paying. -**What the scenarios do not reach**: the system's file dialog (the flavour answers the path the -scenario fixed), the tray menu, a global accelerator pressed on the machine (a second launch's +**What the journeys do not reach**: the system's file dialog (the flavour answers the path the +journey fixed), the tray's icon outside Linux, a global accelerator pressed on the machine (a second launch's `--action` stands for it), and the packages themselves — installed and updated by `packages.yml` (→ "Releasing"). diff --git a/e2e/examples/footprint.rs b/e2e/examples/footprint.rs index f1a50382e..7c68c728a 100644 --- a/e2e/examples/footprint.rs +++ b/e2e/examples/footprint.rs @@ -15,7 +15,7 @@ use std::path::PathBuf; use std::process::Command; use std::time::{Duration, Instant}; -use e2e::old::{App, PASSPHRASE}; +use e2e::{App, Area, PASSPHRASE}; /// Long enough for the window's last repaints and the backup of the day to end. const REST: Duration = Duration::from_secs(10); @@ -99,7 +99,7 @@ fn video(_id: u32) -> Option { /// A line of the table, after the rest and the idle average. #[expect(clippy::disallowed_methods, reason = "an average over a duration, not a wait for a condition")] fn report(app: &App, stage: &str) { - let id = app.id(); + let id = app.process(); std::thread::sleep(REST); let before = read(id); std::thread::sleep(IDLE); @@ -111,16 +111,13 @@ fn report(app: &App, stage: &str) { fn browse(app: &mut App) { for _ in 0..5 { - app.click_nth("note-card-open", 0); - app.wait_for("editor-close"); - app.click("editor-close"); - app.eventually("the editor closes", |tree| !tree.has("editor-close")); + app.notes().open_first(); + app.editor().close(); + } + for area in [Area::Http, Area::Tools, Area::Notes] { + app.window().go_to(area); + app.window().expect_area(area, "the area is on the screen"); } - app.click("area-option-http"); - app.wait_for("http-rail-title"); - app.click("area-option-tools"); - app.click("area-option-notes"); - app.wait_for("note-card-open"); } fn main() { @@ -129,8 +126,12 @@ fn main() { let new = arguments.next().is_some(); let started = Instant::now(); - let mut app = App::launch("footprint", &profile); - app.wait_for("vault-passphrase"); + let mut app = App::launch_on(&profile); + if new { + app.gate().expect_new_phrase_asked("the gate asks for a phrase"); + } else { + app.gate().expect_phrase_asked("the gate asks for the phrase"); + } println!("launch → gate: {} ms", started.elapsed().as_millis()); println!("| Stage | Working set MiB | Private MiB | Dedicated GPU MiB | Idle CPU |"); println!("| --- | --- | --- | --- | --- |"); @@ -138,12 +139,11 @@ fn main() { let started = Instant::now(); if new { - app.create_library(); + app.gate().create_library(PASSPHRASE); } else { - app.fill("vault-passphrase", PASSPHRASE); - app.click("vault-submit"); + app.gate().unlock(PASSPHRASE); } - app.wait_for("note-card-open"); + app.notes().expect_some_card("the cards are on the screen"); println!("unlock → first cards: {} ms", started.elapsed().as_millis()); report(&app, "unlocked, nothing touched"); @@ -151,7 +151,7 @@ fn main() { report(&app, "after opening notes and every area"); for _ in 0..NOTCHES { - app.wheel("canvas"); + app.notes().scroll_down(); } report(&app, "after scrolling the canvas"); app.quit(); diff --git a/e2e/src/driver.rs b/e2e/src/driver.rs index eef944ff0..57369dfa0 100644 --- a/e2e/src/driver.rs +++ b/e2e/src/driver.rs @@ -16,7 +16,7 @@ use egui_inspection::protocol::{self, Request, Response}; pub(crate) const PATIENCE: Duration = Duration::from_secs(30); /// Where the flavour is, unless `DEVNOTES_E2E_BIN` says otherwise. -pub(crate) fn binary() -> PathBuf { +fn binary() -> PathBuf { if let Some(path) = std::env::var_os("DEVNOTES_E2E_BIN") { return PathBuf::from(path); } @@ -31,7 +31,7 @@ pub(crate) fn binary() -> PathBuf { } /// Captures and what a failed journey leaves behind, unless `DEVNOTES_E2E_OUTPUT` says otherwise. -pub(crate) fn output() -> PathBuf { +fn output() -> PathBuf { std::env::var_os("DEVNOTES_E2E_OUTPUT") .map_or_else(|| Path::new(env!("CARGO_MANIFEST_DIR")).join("../target/e2e/scenarios"), PathBuf::from) } @@ -94,6 +94,11 @@ impl Tree { said.flatten().any(|text| text.contains(words)) } + /// What says exactly `words`. + pub(crate) fn saying(&self, words: &str) -> Option<&Node> { + self.nodes.iter().map(|(_, node)| node).find(|node| said(node) == words) + } + /// Whether anything inside a place says `words`. pub(crate) fn says_within(&self, place: Rect, words: &str) -> bool { self.nodes.iter().any(|(_, node)| { @@ -235,6 +240,10 @@ impl Driver { assert!(status.success(), "the second launch could not hand over {action:?}"); } + pub(crate) fn process(&self) -> u32 { + self.child.id() + } + pub(crate) fn tree(&mut self) -> Tree { match self.ask(&Request::GetTree) { Response::Tree { accesskit: Some(TreeUpdate { nodes, focus, .. }), .. } => { @@ -345,7 +354,7 @@ fn start(profile: &Path, terminal: &Path, set: &[(&'static str, OsString)]) -> ( } /// The port opens once the window and its adapter exist, half a second on Windows. -pub(crate) fn connect(port: u16, child: &mut Child) -> TcpStream { +fn connect(port: u16, child: &mut Child) -> TcpStream { let until = Instant::now() + PATIENCE; loop { if let Some(status) = child.try_wait().expect("the application is there") { @@ -365,12 +374,12 @@ pub(crate) fn connect(port: u16, child: &mut Child) -> TcpStream { } /// A port nobody listens on now: the system's choice, given back for the application to take. -pub(crate) fn free_port() -> u16 { +fn free_port() -> u16 { let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, 0)).expect("a local port is free"); listener.local_addr().expect("the port is known").port() } -pub(crate) fn exchange(stream: &mut TcpStream, request: &Request) -> std::io::Result { +fn exchange(stream: &mut TcpStream, request: &Request) -> std::io::Result { protocol::write_message(&mut *stream, request)?; protocol::read_message(&mut *stream) } diff --git a/e2e/src/lib.rs b/e2e/src/lib.rs index 34439a499..e2bf1c491 100644 --- a/e2e/src/lib.rs +++ b/e2e/src/lib.rs @@ -7,7 +7,6 @@ //! `cargo build -p app --features e2e --target-dir target/e2e`. mod driver; -pub mod old; mod sdk; mod server; diff --git a/e2e/src/old.rs b/e2e/src/old.rs deleted file mode 100644 index dfbf6a1b7..000000000 --- a/e2e/src/old.rs +++ /dev/null @@ -1,671 +0,0 @@ -//! The driver as the scenarios not yet rewritten know it. ⚠️ Goes with the last of them: a journey -//! is written on the SDK, and reaches nothing of this. - -use crate::driver::{PATIENCE, binary, connect, exchange, free_port, left, output, top}; -pub use crate::server::{serve, serve_socket}; -pub use crate::{PASSPHRASE, step}; - -use std::net::TcpStream; -use std::path::{Path, PathBuf}; -use std::process::{Child, Command, Stdio}; -use std::sync::{Mutex, MutexGuard}; -use std::time::Instant; - -use egui::accesskit::{Node, NodeId, TreeUpdate}; -use egui::{Event, Key, Modifiers, PointerButton, Pos2}; -use egui_inspection::protocol::{Request, Response}; - -/// One window at a time: the tests of a file run side by side, and a window another covers stops -/// painting under xvfb. -static ONE_WINDOW: Mutex<()> = Mutex::new(()); - -/// What the window shows at one frame. -pub struct Tree { - nodes: Vec<(NodeId, Node)>, - focus: Option, -} - -impl Tree { - pub fn find(&self, author_id: &str) -> Option<&Node> { - self.nodes - .iter() - .map(|(_, node)| node) - .find(|node| node.author_id() == Some(author_id)) - } - - /// The control that has the focus, as a failure names it. - pub fn focused(&self) -> String { - let node = self.nodes.iter().find(|(id, _)| Some(*id) == self.focus).map(|(_, node)| node); - match node { - Some(node) => format!( - "{} ({:?} {:?})", - node.author_id().unwrap_or("no author_id"), - node.role(), - node.label().unwrap_or_default() - ), - None => "nothing".to_owned(), - } - } - - pub fn has(&self, author_id: &str) -> bool { - self.find(author_id).is_some() - } - - pub fn count(&self, author_id: &str) -> usize { - self.all(author_id).len() - } - - /// Every node wearing `author_id`, in reading order: top to bottom, then left to right. - pub fn all(&self, author_id: &str) -> Vec<&Node> { - let mut found: Vec<&Node> = self - .nodes - .iter() - .map(|(_, node)| node) - .filter(|node| node.author_id() == Some(author_id)) - .collect(); - // The tree is in no order of its own. - found.sort_by(|a, b| top(a).total_cmp(&top(b)).then(left(a).total_cmp(&left(b)))); - found - } - - /// What each of them says, as [`Self::text`] does. - pub fn texts(&self, author_id: &str) -> Vec { - self.all(author_id) - .into_iter() - .map(|node| node.label().or(node.value()).unwrap_or_default().to_owned()) - .collect() - } - - /// Whether any node says `words`, read with plain spaces: a tool's answer is one of many. - pub fn mentions(&self, words: &str) -> bool { - let plain = |text: &str| text.replace([' ', ' '], " "); - self.nodes.iter().any(|(_, node)| { - [node.label(), node.value()] - .into_iter() - .flatten() - .any(|text| plain(text).contains(words)) - }) - } - - /// What a node says: its name, or its value for a node that has no name. - pub fn text(&self, author_id: &str) -> Option { - let node = self.find(author_id)?; - node.label().or(node.value()).map(str::to_owned) - } -} - -/// The application, running on `profile`: a real process, a real window. -pub struct App { - scenario: &'static str, - profile: PathBuf, - child: Child, - stream: TcpStream, - _alone: MutexGuard<'static, ()>, -} - -impl App { - /// Launches the flavour on `profile` and waits until it answers. - pub fn launch(scenario: &'static str, profile: &Path) -> Self { - Self::start(scenario, profile, Command::new(binary())) - } - - /// As `launch`, every file dialog answering `dialog`: no driver reaches the system's. - pub fn launch_answering(scenario: &'static str, profile: &Path, dialog: &Path) -> Self { - let mut command = Command::new(binary()); - let answer = profile.join("dialog-answer.txt"); - std::fs::write(&answer, dialog.display().to_string()).expect("the dialog's answer is written"); - command.env(platform::dialog::E2E_DIALOG, answer); - Self::start(scenario, profile, command) - } - - /// As `launch`, on the session bus at `address`: the one a scenario serves itself. - pub fn launch_on_bus(scenario: &'static str, profile: &Path, address: &str) -> Self { - let mut command = Command::new(binary()); - command.env("DBUS_SESSION_BUS_ADDRESS", address); - Self::start(scenario, profile, command) - } - - /// As `launch`, what the process writes on stderr — a terminal's — kept in `terminal`. A - /// file and not a pipe: what was written before a frame is there once the frame is. - pub fn launch_writing_to(scenario: &'static str, profile: &Path, terminal: &Path) -> Self { - let mut command = Command::new(binary()); - command.stderr(std::fs::File::create(terminal).expect("the terminal's file is created")); - Self::start(scenario, profile, command) - } - - fn start(scenario: &'static str, profile: &Path, mut command: Command) -> Self { - let alone = ONE_WINDOW.lock().unwrap_or_else(std::sync::PoisonError::into_inner); - let port = free_port(); - let mut child = command - .arg("--profile") - .arg(profile) - .env(egui_inspection::INSPECTION_ENV_VAR, format!("127.0.0.1:{port}")) - .stdout(Stdio::null()) - .spawn() - .expect("the e2e flavour starts"); - let stream = connect(port, &mut child); - App { scenario, profile: profile.to_path_buf(), child, stream, _alone: alone } - } - - /// The process, for what is read from outside it. - pub fn id(&self) -> u32 { - self.child.id() - } - - /// A second launch on the same profile asking for `action`: it hands it to this one and - /// exits, as the global shortcut's will. - pub fn act(&mut self, action: &str) { - self.hand_over(Some(action)); - self.ask(&Request::Settle { max_steps: 10 }); - } - - /// As `act`, for an action that puts the window out of sight. macOS minimises it, and a - /// minimised window paints nothing: the frame waited for is answered « not painting » there, - /// which says the action was done, the window away and its process alive. - pub fn act_hiding(&mut self, action: &str) { - self.hand_over(Some(action)); - let request = Request::Settle { max_steps: 10 }; - match exchange(&mut self.stream, &request) { - Ok(Response::Error { message }) - if cfg!(target_os = "macos") && message.contains("not painting") => {} - Ok(Response::Error { message }) => { - panic!("the application refused {request:?}: {message}") - } - Ok(_) => {} - Err(error) => panic!("the application stopped answering {request:?}: {error}"), - } - } - - /// A second launch asking for nothing, as the menu's entry starts one: the window comes back. - pub fn launch_again(&mut self) { - self.hand_over(None); - self.ask(&Request::Settle { max_steps: 10 }); - } - - /// A second launch asking for `action`, after which the process ends by itself. - pub fn ends_on(self, action: &str) { - self.hand_over(Some(action)); - self.ended(); - } - - /// Whether the process still runs: a window out of sight is not an application gone. - pub fn running(&mut self) -> bool { - self.child.try_wait().ok().flatten().is_none() - } - - fn hand_over(&self, action: Option<&str>) { - let mut command = Command::new(binary()); - command.arg("--profile").arg(&self.profile); - if let Some(action) = action { - command.arg("--action").arg(action); - } - let status = command.stdout(Stdio::null()).status().expect("the second launch runs"); - assert!(status.success(), "the second launch could not hand over {action:?}"); - } - - /// Closes the window as `Quit` does, waits for the process to end, and launches it again on - /// the same profile: what a person closing and reopening the application sees. - #[must_use] - pub fn relaunch(self) -> Self { - let scenario = self.scenario; - let profile = self.profile.clone(); - self.quit(); - App::launch(scenario, &profile) - } - - /// `Quit` with requests left with changes, the question answered without saving them. - pub fn quit_discarding(mut self) { - self.act("quit"); - self.click("http-leave-discard"); - self.ended(); - } - - /// As `relaunch`, for a scenario that leaves requests with changes. - #[must_use] - pub fn relaunch_discarding(self) -> Self { - let scenario = self.scenario; - let profile = self.profile.clone(); - self.quit_discarding(); - App::launch(scenario, &profile) - } - - /// Waits for the process to end by itself, its queue drained: a quit answered in the window. - pub fn ended(mut self) { - let ended = self.child.wait().expect("the application ends"); - assert!(ended.success(), "the application ended with {ended}"); - } - - /// Asks for `Quit` from a second launch, the way a global shortcut would, and waits for the - /// process to end, its queue drained. - pub fn quit(mut self) { - let asked = Command::new(binary()) - .arg("--profile") - .arg(&self.profile) - .args(["--action", "quit"]) - .status() - .expect("a second launch starts"); - assert!(asked.success(), "the running instance heard no quit"); - let ended = self.child.wait().expect("the application ends"); - assert!(ended.success(), "the application ended with {ended}"); - } - - pub fn tree(&mut self) -> Tree { - match self.ask(&Request::GetTree) { - Response::Tree { accesskit, .. } => match accesskit { - Some(TreeUpdate { nodes, focus, .. }) => Tree { nodes, focus: Some(focus) }, - None => Tree { nodes: Vec::new(), focus: None }, - }, - other => panic!("a tree was asked, {other:?} came back"), - } - } - - /// Reads the tree until `holds` is true of it: answers arrive from the core frames later. - /// No `Settle` between reads: each read renders a frame, and a frame costs up to 300 ms on - /// WARP. - pub fn eventually(&mut self, what: &str, holds: impl Fn(&Tree) -> bool) { - let until = Instant::now() + PATIENCE; - loop { - let tree = self.tree(); - if holds(&tree) { - return; - } - assert!( - Instant::now() < until, - "{what}: still not true after {PATIENCE:?}; the focus is on {}", - tree.focused() - ); - } - } - - pub fn wait_for(&mut self, author_id: &str) { - self.eventually(&format!("{author_id} is shown"), |tree| tree.has(author_id)); - } - - pub fn has(&mut self, author_id: &str) -> bool { - self.ask(&Request::Settle { max_steps: 10 }); - self.tree().has(author_id) - } - - /// Clicks the middle of a control, once it is shown. - pub fn click(&mut self, author_id: &str) { - self.click_where(author_id, |_| true); - } - - /// Clicks the first `author_id` that `which` picks, once it is shown: a row of a list, by - /// what the user named it. ⚠️ Shown means placed, and still: a node joins the tree a frame - /// before it has bounds, and a card just written was clicked in that frame; one still moving - /// (a menu opening, a list settling) was clicked where it no longer was. So the place is the - /// same in two reads in a row. - pub fn click_where(&mut self, author_id: &str, which: impl Fn(&Node) -> bool) { - self.click_with(author_id, PointerButton::Primary, which); - } - - /// As `click_where`, with another button: the middle one closes a tab. - pub fn click_with(&mut self, author_id: &str, button: PointerButton, which: impl Fn(&Node) -> bool) { - let until = Instant::now() + PATIENCE; - let mut last = None; - let bounds = loop { - let tree = self.tree(); - let placed = tree - .all(author_id) - .into_iter() - .find_map(|node| node.bounds().filter(|_| which(node))); - if let Some(bounds) = placed - && last == Some(bounds) - { - break bounds; - } - last = placed; - assert!( - Instant::now() < until, - "{author_id} is shown: still not true after {PATIENCE:?}; the focus is on {}", - tree.focused() - ); - }; - #[expect(clippy::cast_possible_truncation, reason = "points on a screen")] - let pos = - Pos2::new(f64::midpoint(bounds.x0, bounds.x1) as f32, f64::midpoint(bounds.y0, bounds.y1) as f32); - let press = |pressed| Event::PointerButton { pos, button, pressed, modifiers: Modifiers::NONE }; - self.apply(vec![Event::PointerMoved(pos)]); - self.apply(vec![press(true)]); - self.apply(vec![press(false)]); - } - - /// Two clicks at `at`, in points from the control's corner, sent together: one double click - /// however slowly the window paints. - pub fn double_click_in(&mut self, author_id: &str, at: (f32, f32)) { - self.wait_for(author_id); - let bounds = self - .tree() - .find(author_id) - .and_then(Node::bounds) - .unwrap_or_else(|| panic!("{author_id} has no place on screen")); - #[expect(clippy::cast_possible_truncation, reason = "points on a screen")] - let pos = Pos2::new(bounds.x0 as f32, bounds.y0 as f32) + at.into(); - let press = |pressed| Event::PointerButton { - pos, - button: PointerButton::Primary, - pressed, - modifiers: Modifiers::NONE, - }; - self.apply(vec![Event::PointerMoved(pos)]); - self.apply(vec![press(true), press(false), press(true), press(false)]); - } - - /// Ctrl+C as the window delivers it: a copy, not a key. - pub fn copy(&mut self) { - self.apply(vec![Event::Copy]); - } - - /// Until the system's clipboard holds text that `holds` accepts. - pub fn clipboard_holds(&mut self, what: &str, holds: impl Fn(&str) -> bool) { - use platform::clipboard::Clipboard; - let until = Instant::now() + PATIENCE; - loop { - let held = platform::clipboard::System.text().unwrap_or_default(); - if holds(&held) { - return; - } - assert!( - Instant::now() < until, - "{what}: still not true after {PATIENCE:?}; the clipboard holds {held:?}" - ); - // A frame between two reads. - let _ = self.tree(); - } - } - - /// A press at `from` and a release at `to`, in points from the control's corner. - pub fn drag_in(&mut self, author_id: &str, from: (f32, f32), to: (f32, f32)) { - self.wait_for(author_id); - let bounds = self - .tree() - .find(author_id) - .and_then(Node::bounds) - .unwrap_or_else(|| panic!("{author_id} has no place on screen")); - #[expect(clippy::cast_possible_truncation, reason = "points on a screen")] - let corner = Pos2::new(bounds.x0 as f32, bounds.y0 as f32); - let (from, to) = (corner + from.into(), corner + to.into()); - self.drag(from, to, PointerButton::Primary); - } - - /// A press at `from` and a release at `to`, in points on the window, the pointer moved - /// half way between: what a gesture needs to tell a drag from a click. - pub fn drag(&mut self, from: Pos2, to: Pos2, button: PointerButton) { - let press = |pos, pressed| Event::PointerButton { pos, button, pressed, modifiers: Modifiers::NONE }; - self.apply(vec![Event::PointerMoved(from)]); - self.apply(vec![press(from, true)]); - self.apply(vec![Event::PointerMoved(from + (to - from) / 2.0)]); - self.apply(vec![Event::PointerMoved(to)]); - self.apply(vec![press(to, false)]); - } - - /// The pointer over the first `author_id` in reading order, once it is shown: what a card - /// shows on hover. - pub fn hover(&mut self, author_id: &str) { - self.hover_nth(author_id, 0); - } - - /// The pointer over the `n`th `author_id` in reading order, counting from 0. - pub fn hover_nth(&mut self, author_id: &str, n: usize) { - self.eventually(&format!("{author_id} #{n} is shown"), |tree| tree.count(author_id) > n); - let tree = self.tree(); - let bounds = tree - .all(author_id) - .get(n) - .and_then(|node| node.bounds()) - .unwrap_or_else(|| panic!("{author_id} has no place on screen")); - #[expect(clippy::cast_possible_truncation, reason = "points on a screen")] - let pos = - Pos2::new(f64::midpoint(bounds.x0, bounds.x1) as f32, f64::midpoint(bounds.y0, bounds.y1) as f32); - self.apply(vec![Event::PointerMoved(pos)]); - } - - /// Clicks the `n`th `author_id` from the top, counting from 0: a choice among several whose - /// words are the system's language. - pub fn click_nth(&mut self, author_id: &str, n: usize) { - self.eventually(&format!("{author_id} #{n} is shown"), |tree| tree.count(author_id) > n); - let tree = self.tree(); - let target = tree.all(author_id)[n]; - let label = target.label().map(str::to_owned); - let at = top(target); - self.click_where(author_id, |node| { - node.label().map(str::to_owned) == label && (top(node) - at).abs() < 0.5 - }); - } - - /// Through the gate of a blank profile: the phrase twice, and the library opens. - pub fn create_library(&mut self) { - self.fill("vault-passphrase", PASSPHRASE); - self.fill("vault-confirmation", PASSPHRASE); - self.click("vault-submit"); - self.wait_for("area-notes"); - } - - /// Scrolls `within` down until `author_id` is drawn: a list draws only what is in view. - pub fn scroll_to(&mut self, within: &str, author_id: &str) { - self.wait_for(within); - for _ in 0..40 { - if self.has(author_id) { - return; - } - if !self.wheel(within) { - break; - } - } - self.wait_for(author_id); - } - - /// One notch down over `within`; `false` when nothing of that name is drawn. - pub fn wheel(&mut self, within: &str) -> bool { - let Some(bounds) = self.tree().find(within).and_then(Node::bounds) else { - return false; - }; - #[expect(clippy::cast_possible_truncation, reason = "points on a screen")] - let pos = - Pos2::new(f64::midpoint(bounds.x0, bounds.x1) as f32, f64::midpoint(bounds.y0, bounds.y1) as f32); - self.apply(vec![ - Event::PointerMoved(pos), - Event::MouseWheel { - unit: egui::MouseWheelUnit::Point, - delta: egui::vec2(0.0, -240.0), - phase: egui::TouchPhase::Move, - source: egui::MouseWheelSource::Wheel, - modifiers: Modifiers::NONE, - }, - ]); - true - } - - /// Scrolls `within` down until `author_id` stands above `under`: a panel draws what lies past - /// its edge too, clipped, where no click reaches it. - pub fn scroll_above(&mut self, within: &str, author_id: &str, under: &str) { - self.wait_for(author_id); - for _ in 0..40 { - let tree = self.tree(); - let place = |id| tree.find(id).and_then(Node::bounds); - let (Some(target), Some(limit)) = (place(author_id), place(under)) else { - break; - }; - if target.y1 < limit.y0 { - return; - } - let Some(bounds) = place(within) else { - break; - }; - #[expect(clippy::cast_possible_truncation, reason = "points on a screen")] - let pos = Pos2::new( - f64::midpoint(bounds.x0, bounds.x1) as f32, - f64::midpoint(bounds.y0, bounds.y1) as f32, - ); - self.apply(vec![ - Event::PointerMoved(pos), - Event::MouseWheel { - unit: egui::MouseWheelUnit::Point, - delta: egui::vec2(0.0, -120.0), - phase: egui::TouchPhase::Move, - source: egui::MouseWheelSource::Wheel, - modifiers: Modifiers::NONE, - }, - ]); - self.ask(&Request::Settle { max_steps: 10 }); - } - panic!("{author_id} never came above {under}"); - } - - /// Until `author_id` stands in the same place on two frames: a wheel's scroll glides, and a - /// click aimed at where it was lands on something else. - pub fn at_rest(&mut self, author_id: &str) { - let place = |app: &mut Self| { - let tree = app.tree(); - tree.find(author_id).and_then(Node::bounds).map(|bounds| (bounds.x0, bounds.y0)) - }; - let until = Instant::now() + PATIENCE; - let mut last = place(self); - loop { - self.ask(&Request::Settle { max_steps: 10 }); - let now = place(self); - if now.is_some() && now == last { - return; - } - assert!(Instant::now() < until, "{author_id} never came to rest"); - last = now; - } - } - - /// Back to the top of `within`: rows out of view are not drawn, so not counted. - pub fn scroll_top(&mut self, within: &str) { - self.wait_for(within); - let Some(bounds) = self.tree().find(within).and_then(Node::bounds) else { - return; - }; - #[expect(clippy::cast_possible_truncation, reason = "points on a screen")] - let pos = - Pos2::new(f64::midpoint(bounds.x0, bounds.x1) as f32, f64::midpoint(bounds.y0, bounds.y1) as f32); - self.apply(vec![ - Event::PointerMoved(pos), - Event::MouseWheel { - unit: egui::MouseWheelUnit::Point, - delta: egui::vec2(0.0, 100_000.0), - phase: egui::TouchPhase::Move, - source: egui::MouseWheelSource::Wheel, - modifiers: Modifiers::NONE, - }, - ]); - self.ask(&Request::Settle { max_steps: 10 }); - } - - /// Types into the control that has the focus. - pub fn type_text(&mut self, text: &str) { - self.apply(vec![Event::Text(text.to_owned())]); - } - - /// What the clipboard would hand the control that has the focus, as the window delivers it. - pub fn paste(&mut self, text: &str) { - self.apply(vec![Event::Paste(text.to_owned())]); - } - - /// Clicks a field, then types into it once it holds the focus: text typed a frame early - /// goes nowhere, as a passphrase lost on a slow first launch. - /// ⚠️ A click can land in a frame that drops it: clicked again until the focus moves. The gate - /// moves down when its libraries are listed: a click aimed before lands beside the field, - /// whose focus comes back by itself, and the phrase is typed into nothing. - pub fn fill(&mut self, author_id: &str, text: &str) { - if author_id == "vault-passphrase" { - self.wait_for("vault-library"); - self.at_rest(author_id); - } - let until = Instant::now() + PATIENCE; - 'clicked: loop { - self.click(author_id); - // A few frames, each read renders one: a second click at once would be a double. - for _ in 0..5 { - let tree = self.tree(); - if tree.focused().starts_with(author_id) { - break 'clicked; - } - assert!( - Instant::now() < until, - "{author_id} never took the focus; it is on {}", - tree.focused() - ); - } - } - self.type_text(text); - } - - /// A key pressed and released at its place: the area keys read the position, not the letter. - pub fn press(&mut self, key: Key, modifiers: Modifiers) { - self.press_laid_out(key, key, modifiers); - } - - /// A key of another layout than QWERTY: `typed` printed on it, standing where `at` does on - /// QWERTY (AZERTY's Q is at A). - pub fn press_laid_out(&mut self, typed: Key, at: Key, modifiers: Modifiers) { - let event = - |pressed| Event::Key { key: typed, physical_key: Some(at), pressed, repeat: false, modifiers }; - self.apply(vec![event(true)]); - self.apply(vec![event(false)]); - } - - /// The window's inside, in points. - pub fn resize(&mut self, width: u32, height: u32) { - self.ask(&Request::Resize { width, height }); - self.ask(&Request::Settle { max_steps: 10 }); - } - - /// The window as it stands, as `//.png`. - pub fn capture(&mut self, name: &str) -> PathBuf { - let png = match self.ask(&Request::GetScreenshot { pixels_per_point: Some(1.0) }) { - Response::Screenshot(png) => png, - other => panic!("a capture was asked, {other:?} came back"), - }; - let directory = output().join(self.scenario); - std::fs::create_dir_all(&directory).expect("the capture directory is made"); - let path = directory.join(format!("{name}.png")); - std::fs::write(&path, png.bytes).expect("the capture is written"); - path - } - - fn apply(&mut self, events: Vec) { - self.ask(&Request::ApplyEvents { events }); - } - - fn ask(&mut self, request: &Request) -> Response { - match exchange(&mut self.stream, request) { - Ok(Response::Error { message }) => { - panic!("the application refused {request:?}: {message}") - } - Ok(response) => response, - Err(error) => panic!("the application stopped answering {request:?}: {error}"), - } - } -} - -/// A failed scenario leaves its last screen and the application's log beside its captures. -impl Drop for App { - fn drop(&mut self) { - if std::thread::panicking() { - let directory = output().join(self.scenario); - let _ = std::fs::create_dir_all(&directory); - let screen = Request::GetScreenshot { pixels_per_point: Some(1.0) }; - if let Ok(Response::Screenshot(png)) = exchange(&mut self.stream, &screen) { - let _ = std::fs::write(directory.join("failure.png"), png.bytes); - } - keep_logs(&self.profile.join("logs"), &directory); - } - if let Ok(None) = self.child.try_wait() { - let _ = self.child.kill(); - let _ = self.child.wait(); - } - } -} - -fn keep_logs(logs: &Path, into: &Path) { - let Ok(entries) = std::fs::read_dir(logs) else { - return; - }; - for entry in entries.flatten() { - let _ = std::fs::copy(entry.path(), into.join(entry.file_name())); - } -} diff --git a/e2e/src/sdk/act.rs b/e2e/src/sdk/act.rs index 47fba7771..cc9d1e244 100644 --- a/e2e/src/sdk/act.rs +++ b/e2e/src/sdk/act.rs @@ -308,7 +308,7 @@ impl App { } /// The wheel over `within`, in points: down is negative. - fn wheel(&mut self, within: &str, points: f32) { + pub(super) fn wheel(&mut self, within: &str, points: f32) { let Some(bounds) = self.tree().find(within).and_then(Node::bounds) else { return; }; diff --git a/e2e/src/sdk/files.rs b/e2e/src/sdk/files.rs index d4d3e3bac..fb1f9545c 100644 --- a/e2e/src/sdk/files.rs +++ b/e2e/src/sdk/files.rs @@ -1,7 +1,7 @@ use std::path::{Path, PathBuf}; use super::App; -use crate::server; +use crate::{current_step, server}; /// The person's own files, and what they answer to the system's file dialogs: no driver reaches the /// dialog itself. @@ -36,6 +36,11 @@ impl Files<'_> { self.0.expect(says, |_| std::fs::read(&path).is_ok_and(|bytes| holds(&bytes))); } + /// No file was written there. + pub fn expect_none(&mut self, name: &str, says: &str) { + assert!(!self.path(name).exists(), "« {} »: {says}", current_step()); + } + /// A file was written, the same as another. pub fn expect_same(&mut self, name: &str, as_name: &str, says: &str) { let wanted = std::fs::read(self.path(as_name)).expect("the other file is read"); @@ -55,6 +60,17 @@ impl Files<'_> { } } +/// Writes over the pages of the one library's database, its header left: a file SQLite opens, and +/// refuses to read. +pub(super) fn damage_library(profile: &Path) { + let libraries = std::fs::read_dir(profile.join("libraries")).expect("the profile has a library"); + let library = libraries.flatten().next().expect("the profile has a library"); + let database = library.path().join("devnotes.sqlite3"); + let mut bytes = std::fs::read(&database).expect("the database is read"); + bytes[100..].fill(0x5a); + std::fs::write(&database, bytes).expect("the damaged database is written"); +} + /// Where the dialogs read their answer. pub(super) fn answer(room: &Path) -> PathBuf { room.join("dialog-answer.txt") diff --git a/e2e/src/sdk/gate.rs b/e2e/src/sdk/gate.rs index 10eec5c92..d9e7e5773 100644 --- a/e2e/src/sdk/gate.rs +++ b/e2e/src/sdk/gate.rs @@ -1,3 +1,5 @@ +use egui::accesskit::Node; + use super::App; use crate::driver::Tree; @@ -46,6 +48,60 @@ impl Gate<'_> { ); } + /// Has the gate open another library of the profile. + pub fn choose_library(&mut self, name: &str) { + self.0.click("vault-library-switch", "the menu of the libraries"); + let option = self.0.seen("the library in the menu", |tree| { + let option = tree.named("vault-library-switch-", name)?; + option.author_id().map(str::to_owned) + }); + self.0.click(&option, "the library in the menu"); + self.expect_library(name, "the gate asks for that one"); + } + + /// *Forgotten your passphrase?*: what it would do is said. + pub fn forget(&mut self) { + self.0.click("vault-forgotten", "« Forgotten your passphrase? »"); + self.0.expect("what would be lost is said", |tree| { + tree.has("vault-archive") && !tree.has("vault-passphrase") + }); + } + + /// Goes back to the phrase, nothing touched. + pub fn keep_trying(&mut self) { + self.0.click("vault-keep-trying", "the way back"); + self.expect_phrase_asked("the phrase is asked again"); + } + + /// Archives the library whose phrase is forgotten. + pub fn archive(&mut self) { + self.0.click("vault-archive-confirm", "the button that archives it"); + } + + /// Sets the damaged library aside. + pub fn set_aside(&mut self) { + self.0.click("vault-set-aside", "« Set it aside and start fresh »"); + } + + /// The gate asks for the phrase of this library. + pub fn expect_library(&mut self, name: &str, says: &str) { + self.0 + .expect(says, |tree| tree.find("vault-library-switch").and_then(Node::value) == Some(name)); + } + + /// The gate says the library is damaged, and starts nothing on it. + pub fn expect_damaged(&mut self, says: &str) { + self.0.expect(says, |tree| { + tree.has("vault-damaged") && tree.has("vault-set-aside") && !tree.has("area-switch") + }); + } + + /// The place something was put in is told. + pub fn expect_place_told(&mut self, words: &str, says: &str) { + self.0 + .expect(says, |tree| tree.texts("status-toast").iter().any(|said| said.contains(words))); + } + /// The gate asks for a phrase twice: this profile has no library yet. pub fn expect_new_phrase_asked(&mut self, says: &str) { self.0 diff --git a/e2e/src/sdk/http.rs b/e2e/src/sdk/http.rs index a5873d607..1f4c8535c 100644 --- a/e2e/src/sdk/http.rs +++ b/e2e/src/sdk/http.rs @@ -175,12 +175,11 @@ impl Http<'_> { /// Quits: DevNotes asks what becomes of the requests left with changes. pub fn ask_to_quit(&mut self) { self.0.driver.hand_over(Some("quit")); - self.0 - .expect("DevNotes asks about the changes", |tree| tree.has("http-leave-dialog")); + self.expect_asked_about_changes(1, "DevNotes asks about the changes"); } /// Stays, the changes as they are. - pub fn cancel_quitting(&mut self) { + pub fn cancel_leaving(&mut self) { self.0.click("http-leave-cancel", "« Cancel »"); self.0.expect("the question goes", |tree| !tree.has("http-leave-dialog")); } @@ -191,6 +190,17 @@ impl Http<'_> { self.0.ended(); } + /// Leaves without the changes. + pub fn leave_without_saving(&mut self) { + self.0.click("http-leave-discard", "the button that does not save"); + } + + /// DevNotes asks what becomes of as many requests with changes. + pub fn expect_asked_about_changes(&mut self, count: usize, says: &str) { + self.0 + .expect(says, |tree| tree.has("http-leave-dialog") && tree.count("http-leave-name") == count); + } + /// The rail lists these, top to bottom, a request after its method. pub fn expect_rows(&mut self, rows: &[&str], says: &str) { self.0.expect(says, |tree| tree.texts("http-node-name") == rows); diff --git a/e2e/src/sdk/libraries.rs b/e2e/src/sdk/libraries.rs new file mode 100644 index 000000000..d64b214e4 --- /dev/null +++ b/e2e/src/sdk/libraries.rs @@ -0,0 +1,105 @@ +use egui::accesskit::{Node, Rect}; + +use super::{App, Shortcut}; +use crate::driver::Tree; + +/// The libraries of the profile: *File → Libraries…*. +pub struct Libraries<'a>(pub(super) &'a mut App); + +impl Libraries<'_> { + /// Opens the panel. + pub fn open(&mut self) { + self.0.click("file-menu", "the « File » menu"); + self.0.click("file-libraries", "« Libraries… »"); + self.0.expect("the libraries are listed", |tree| tree.has("library-row")); + } + + /// Closes it. + pub fn close(&mut self) { + self.0.click("libraries-close", "the panel's cross"); + self.0.expect("the panel closes", |tree| !tree.has("library-row")); + } + + /// Makes a library: the gate asks for its phrase. + pub fn create(&mut self, name: &str) { + self.0.fill("library-new-name", "the new library's name", name); + self.0.click("library-create", "« Create »"); + self.0.gate().expect_new_phrase_asked("the gate asks for its phrase"); + } + + /// Renames the open library. + pub fn rename_the_open_one(&mut self, into: &str) { + let line = self.0.place("the open library", open_line); + self.click_on(line, "library-start-rename", "« Rename »"); + self.0.replace("library-rename", "the library's name", into); + self.0.press(Shortcut::Enter); + self.0.expect("the library has its new name", |tree| { + !tree.has("library-rename") && line_of(tree, into).is_some() + }); + } + + /// Asks to open another library. + pub fn switch_to(&mut self, name: &str) { + let line = self.line(name); + self.click_on(line, "library-switch", "« Switch »"); + } + + /// Asks to delete a library, named before anything goes. + pub fn ask_deletion(&mut self, name: &str) { + let line = self.line(name); + self.click_on(line, "library-delete", "« Delete »"); + self.0.expect("the deletion names the library", |tree| { + tree.text("library-confirm").is_some_and(|said| said.contains(name)) + }); + } + + /// Answers no to the deletion asked. + pub fn cancel_deletion(&mut self) { + self.0.click("library-cancel-delete", "« Cancel »"); + self.0.expect("the question goes", |tree| !tree.has("library-confirm")); + } + + /// Answers yes to the deletion asked. + pub fn confirm_deletion(&mut self) { + let listed = self.0.tree().count("library-row"); + self.0.click("library-confirm-delete", "« Delete »"); + self.0.expect("the library is gone", |tree| { + tree.count("library-row") + 1 == listed && !tree.has("library-confirm") + }); + } + + /// As many libraries are listed. + pub fn expect_listed(&mut self, count: usize, says: &str) { + self.0.expect(says, |tree| tree.count("library-row") == count); + } + + /// The open library cannot be deleted. + pub fn expect_open_one_kept(&mut self, says: &str) { + let line = self.0.place("the open library", open_line); + self.0 + .expect(says, |tree| !tree.all("library-delete").into_iter().any(|button| on(button, line))); + } + + fn line(&mut self, name: &str) -> Rect { + self.0.place("the library in the list", |tree| line_of(tree, name)) + } + + fn click_on(&mut self, line: Rect, id: &str, name: &str) { + self.0.click_where(id, name, |button| on(button, line)); + } +} + +/// Where a library's name stands in the list. +fn line_of(tree: &Tree, name: &str) -> Option { + tree.saying(name).and_then(Node::bounds) +} + +fn open_line(tree: &Tree) -> Option { + tree.find("library-open").and_then(Node::bounds) +} + +/// Whether a button stands on a line, whose words are less high. +fn on(button: &Node, line: Rect) -> bool { + let middle = f64::midpoint(line.y0, line.y1); + button.bounds().is_some_and(|bounds| (bounds.y0..bounds.y1).contains(&middle)) +} diff --git a/e2e/src/sdk/mod.rs b/e2e/src/sdk/mod.rs index 2bb56432b..bf2f830f2 100644 --- a/e2e/src/sdk/mod.rs +++ b/e2e/src/sdk/mod.rs @@ -18,6 +18,7 @@ mod help; mod history; mod http; mod json; +mod libraries; mod notes; mod palette; mod prefs; @@ -26,6 +27,7 @@ mod request; mod response; mod rich; mod runner; +mod security; mod selection; mod sends; mod shortcut; @@ -33,6 +35,7 @@ mod socket; mod tags; mod todo; mod tools; +mod transfer; mod trash; mod tray; mod window; @@ -54,6 +57,7 @@ pub use help::Help; pub use history::History; pub use http::Http; pub use json::{Json, JsonView}; +pub use libraries::Libraries; pub use notes::{Kind, Named, Notes, QuickFilter, Sample}; pub use palette::Palette; pub use prefs::{CardKey, DefaultKind, Density, Indent, Language, Page, Prefs, Switch, Theme}; @@ -62,6 +66,7 @@ pub use request::{Auth, Body, Method, Request, Script}; pub use response::{BodyView, Part, Response}; pub use rich::{DrawingSize, Presentation, Rich, RichTool}; pub use runner::Runner; +pub use security::Security; pub use selection::Selection; pub use sends::Sends; pub use shortcut::Shortcut; @@ -69,6 +74,7 @@ pub use socket::Socket; pub use tags::Tags; pub use todo::Todo; pub use tools::{Copied, Given, Tools}; +pub use transfer::{Export, Transfer}; pub use trash::Trash; pub use tray::{Tray, TrayEntry}; pub use window::{Area, Window}; @@ -140,12 +146,24 @@ impl App { Self::open(journey) } - fn launch(journey: &'static str, mut set: Vec<(&'static str, OsString)>) -> Self { - let room = TempDir::new().expect("a directory of the journey's own"); + /// DevNotes launched on a profile that outlives it, for a measure: the gate on the screen. + pub fn launch_on(profile: &Path) -> Self { + Self::start("measure", room(), profile.to_owned(), Vec::new()) + } + + fn launch(journey: &'static str, set: Vec<(&'static str, OsString)>) -> Self { + let room = room(); let profile = room.path().join("profile"); - for directory in [&profile, &room.path().join("files")] { - std::fs::create_dir(directory).expect("the journey's directories are made"); - } + std::fs::create_dir(&profile).expect("the journey's profile is made"); + Self::start(journey, room, profile, set) + } + + fn start( + journey: &'static str, + room: TempDir, + profile: PathBuf, + mut set: Vec<(&'static str, OsString)>, + ) -> Self { set.push((platform::dialog::E2E_DIALOG, files::answer(room.path()).into())); let driver = Driver::launch(journey, profile, terminal(room.path()), set); App { @@ -310,6 +328,21 @@ impl App { format!("ws://127.0.0.1:{}", server::serve_socket()) } + /// The libraries of the profile. + pub fn libraries(&mut self) -> Libraries<'_> { + Libraries(self) + } + + /// What leaves the library and what comes in. + pub fn transfer(&mut self) -> Transfer<'_> { + Transfer(self) + } + + /// The library's passphrase and its copies. + pub fn security(&mut self) -> Security<'_> { + Security(self) + } + /// The preferences. pub fn prefs(&mut self) -> Prefs<'_> { Prefs(self) @@ -403,6 +436,14 @@ impl App { self.gate().unlock(PASSPHRASE); } + /// Quits, has the library's database damaged while DevNotes is closed, and starts it again. + pub fn relaunch_damaged(&mut self) { + self.driver.hand_over(Some("quit")); + self.driver.ended(); + files::damage_library(self.profile()); + self.driver.start_again(); + } + /// *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"); @@ -426,6 +467,11 @@ impl App { self.driver.capture(name); } + /// The number the system knows the running process by. + pub fn process(&self) -> u32 { + self.driver.process() + } + /// DevNotes was launched without a line in the terminal. Said of Linux alone, where it is /// launched from one often enough for its lines to be read as faults. pub fn expect_silent_terminal(&mut self, says: &str) { @@ -460,6 +506,13 @@ impl App { } } +/// A directory of the journey's own, the person's files in it. +fn room() -> TempDir { + let room = TempDir::new().expect("a directory of the journey's own"); + std::fs::create_dir(room.path().join("files")).expect("the person's directory is made"); + room +} + fn terminal(room: &Path) -> PathBuf { room.join("terminal.txt") } diff --git a/e2e/src/sdk/notes.rs b/e2e/src/sdk/notes.rs index e3d7577db..5ba70057d 100644 --- a/e2e/src/sdk/notes.rs +++ b/e2e/src/sdk/notes.rs @@ -151,6 +151,20 @@ impl Notes<'_> { self.0.expect("the note opens", |tree| tree.has("editor-title")); } + /// Opens the first note listed. + pub fn open_first(&mut self) { + let card = self + .0 + .place("the first card", |tree| tree.find("note-card").and_then(Node::bounds)); + self.0.click_top(card); + self.0.expect("the note opens", |tree| tree.has("editor-title")); + } + + /// Scrolls the cards down by one notch of the wheel. + pub fn scroll_down(&mut self) { + self.0.wheel("canvas", -120.0); + } + /// 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 »"); @@ -169,6 +183,13 @@ impl Notes<'_> { .click_nth_where("note-card-item", item, "an item on the card", |node| within(node, card)); } + /// The title of a note, as its card writes it. + pub fn title_of(&mut self, note: impl Named) -> String { + self.0.seen("the note's card is on the screen", |tree| { + tree.texts("note-card-title").into_iter().find(|title| note.is(title)) + }) + } + /// Takes the keyboard to a note's card: the search finds it alone, and the arrow goes down to it. pub fn go_to_card(&mut self, title: &str) { self.search(title); @@ -313,6 +334,11 @@ impl Notes<'_> { }); } + /// Some card is on the screen, whatever it is. + pub fn expect_some_card(&mut self, says: &str) { + self.0.expect(says, |tree| tree.has("note-card")); + } + /// As many cards are on the screen. pub fn expect_cards(&mut self, count: usize, says: &str) { self.0 diff --git a/e2e/src/sdk/prefs.rs b/e2e/src/sdk/prefs.rs index 0faf51965..f71e697c5 100644 --- a/e2e/src/sdk/prefs.rs +++ b/e2e/src/sdk/prefs.rs @@ -16,6 +16,8 @@ pub enum Page { General, Variables, Shortcuts, + Security, + Copies, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -86,6 +88,8 @@ impl Prefs<'_> { 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"), + Page::Security => self.0.click("settings-page-security", "the « Security » page"), + Page::Copies => self.0.click("settings-page-backups", "the « Copies » page"), } } diff --git a/e2e/src/sdk/rail.rs b/e2e/src/sdk/rail.rs index a6be59fa0..2da1d5aa6 100644 --- a/e2e/src/sdk/rail.rs +++ b/e2e/src/sdk/rail.rs @@ -187,6 +187,19 @@ impl Rail<'_> { self.0.expect(says, |tree| is_shown(tree, name)); } + /// No space goes by this name. + pub fn expect_no_space(&mut self, name: &str, says: &str) { + self.0.expect(says, |tree| { + tree.has("space-option") && !tree.texts("space-option").iter().any(|row| row == name) + }); + } + + /// One space goes by this name. + pub fn expect_one_space(&mut self, name: &str, says: &str) { + self.0 + .expect(says, |tree| tree.texts("space-option").iter().filter(|row| *row == name).count() == 1); + } + /// As many spaces are listed. pub fn expect_spaces(&mut self, count: usize, says: &str) { self.0.expect(says, |tree| tree.count("space-option") == count); diff --git a/e2e/src/sdk/security.rs b/e2e/src/sdk/security.rs new file mode 100644 index 000000000..268390ee1 --- /dev/null +++ b/e2e/src/sdk/security.rs @@ -0,0 +1,87 @@ +use super::{App, Page}; + +/// The library's passphrase and its copies, on their pages of the preferences. +pub struct Security<'a>(pub(super) &'a mut App); + +impl Security<'_> { + /// Opens the dialog that changes the passphrase. + pub fn ask_change(&mut self) { + self.0.prefs().open(); + self.0.prefs().go_to(Page::Security); + self.0.click("setting-change-passphrase", "« Change… »"); + self.0.expect("the dialog opens", |tree| tree.has("change-passphrase")); + } + + /// Tries the change: the phrase as it is said to be, then the new one, twice. + pub fn try_change(&mut self, current: &str, next: &str) { + self.0.expect("the fields can be typed in", |tree| { + tree.find("change-passphrase-current").is_some_and(|field| !field.is_disabled()) + }); + self.0.fill("change-passphrase-current", "the current phrase", current); + self.0.fill("change-passphrase-next", "the new phrase", next); + self.0.fill("change-passphrase-confirmation", "its confirmation", next); + self.0.click("change-passphrase-submit", "« Change »"); + } + + /// Opens the page of the copies. + pub fn open_copies(&mut self) { + self.0.prefs().open(); + self.0.prefs().go_to(Page::Copies); + } + + /// Asks to put the last copy back: the page says what it would do. + pub fn ask_restore(&mut self) { + self.0 + .reach("settings-content", ("backup-restore", "« Restore »"), "settings-cancel"); + self.0.click("backup-restore", "« Restore »"); + self.0 + .expect("the page says what it would do", |tree| tree.has("backup-confirm")); + } + + /// Answers no. + pub fn cancel_restore(&mut self) { + self.0 + .reach("settings-content", ("backup-cancel", "« Cancel »"), "settings-cancel"); + self.0.click("backup-cancel", "« Cancel »"); + self.0.expect("the question goes", |tree| !tree.has("backup-confirm")); + } + + /// Answers yes: the gate asks for the phrase of the copy put back. + pub fn confirm_restore(&mut self) { + let yes = ("backup-confirm-restore", "the yes"); + self.0.reach("settings-content", yes, "settings-cancel"); + self.0.click("backup-confirm-restore", "the yes"); + self.0.gate().expect_phrase_asked("the gate asks for the phrase"); + } + + /// The change is refused, and says why. + pub fn expect_refused(&mut self, says: &str) { + self.0.expect(says, |tree| { + tree.has("change-passphrase") + && tree.text("change-passphrase-problem").is_some_and(|said| !said.is_empty()) + }); + } + + /// The passphrase is changed, and the session carries on. + pub fn expect_changed(&mut self, says: &str) { + self.0 + .expect(says, |tree| !tree.has("change-passphrase") && tree.has("settings-dialog")); + self.0.notes().clear_toasts(); + self.0.prefs().close(); + self.0.expect("the notes are still there", |tree| tree.has("note-card")); + } + + /// As many copies are kept, each with when it was taken. + pub fn expect_copies(&mut self, count: usize, says: &str) { + self.0.expect(says, |tree| { + let details = tree.texts("backup-detail"); + details.len() == count && details.iter().all(|detail| is_stamped(detail)) + }); + } +} + +/// Whether a copy says its instant first: « 2026-12-04_09-00-00 ». +fn is_stamped(words: &str) -> bool { + let stamp = words.split_whitespace().next().unwrap_or_default(); + stamp.len() == 19 && stamp.as_bytes()[10] == b'_' +} diff --git a/e2e/src/sdk/transfer.rs b/e2e/src/sdk/transfer.rs new file mode 100644 index 000000000..7fdaa706f --- /dev/null +++ b/e2e/src/sdk/transfer.rs @@ -0,0 +1,108 @@ +use super::{App, Shortcut}; + +/// What leaves the library and what comes in: the *File* menu's exports and imports, to and from +/// the file answered to the dialog. +pub struct Transfer<'a>(pub(super) &'a mut App); + +/// What an export takes. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Export { + Everything, + /// The space shown. + Space, + /// The cards ticked. + Selection, +} + +impl Transfer<'_> { + /// Asks for an export, whatever comes of it. + pub fn ask(&mut self, export: Export) { + self.0.click("file-menu", "the « File » menu"); + match export { + Export::Everything => self.0.click("file-option-exportAll", "« Export everything… »"), + Export::Space => self.0.click("file-option-exportSpace", "« Export the space… »"), + Export::Selection => self.0.click("file-option-exportSelection", "« Export the selection… »"), + } + } + + /// Exports in the clear. + pub fn export(&mut self, export: Export) { + self.ask(export); + self.0 + .click("passphrase-prompt-plain", "the button that leaves it in the clear"); + self.expect_prompt_closed(); + } + + /// Exports under a phrase. + pub fn export_sealed(&mut self, export: Export, phrase: &str) { + self.ask(export); + self.0.fill("passphrase-prompt-field", "the file's phrase", phrase); + self.0.fill("passphrase-prompt-confirmation", "its confirmation", phrase); + self.0.click("passphrase-prompt-submit", "« Protect »"); + self.expect_prompt_closed(); + } + + /// Gives the export asked up, by Esc on its phrase. + pub fn give_up(&mut self) { + self.0 + .expect("the export asks for a phrase", |tree| tree.has("passphrase-prompt")); + self.0.press(Shortcut::Escape); + self.expect_prompt_closed(); + } + + /// Imports the file. + pub fn import(&mut self) { + self.0.click("file-menu", "the « File » menu"); + self.0.click("file-option-import", "« Import… »"); + } + + /// Tries a phrase on the file imported. + pub fn try_phrase(&mut self, phrase: &str) { + self.0.expect("the import asks for the file's phrase", |tree| { + tree.find("passphrase-prompt-field").is_some_and(|field| !field.is_disabled()) + }); + self.0.fill("passphrase-prompt-field", "the file's phrase", phrase); + self.0.click("passphrase-prompt-submit", "« Open »"); + } + + /// *Copy selection as Markdown*. + pub fn copy_selection_as_markdown(&mut self) { + self.0.click("file-menu", "the « File » menu"); + self.0.click("file-option-copyMarkdown", "« Copy selection as Markdown »"); + } + + /// The operation reports, saying this among other things; the report is then dismissed. + pub fn expect_reported(&mut self, words: &str, says: &str) { + self.0 + .expect(says, |tree| tree.texts("status-toast").iter().any(|said| said.contains(words))); + self.0.notes().clear_toasts(); + } + + /// The phrase is not the file's, and the import says so. + pub fn expect_wrong_phrase(&mut self, says: &str) { + self.0 + .expect(says, |tree| tree.text("passphrase-prompt-problem").is_some_and(|said| !said.is_empty())); + } + + /// No phrase is asked: the operation ended before. + pub fn expect_nothing_asked(&mut self, says: &str) { + self.0 + .expect_at_rest(says, |tree| tree.has("file-menu") && !tree.has("passphrase-prompt")); + } + + /// The menu offers the selection's entries only when something is selected. + pub fn expect_selection_waiting(&mut self, says: &str) { + self.0.click("file-menu", "the « File » menu"); + self.0.expect(says, |tree| { + tree.is_disabled("file-option-exportSelection") + && tree.is_disabled("file-option-copyMarkdown") + && !tree.is_disabled("file-option-exportAll") + }); + self.0.press(Shortcut::Escape); + self.0.expect("the menu closes", |tree| !tree.has("file-option-exportAll")); + } + + fn expect_prompt_closed(&mut self) { + self.0.expect("the prompt closes", |tree| !tree.has("passphrase-prompt")); + } +} diff --git a/e2e/src/server.rs b/e2e/src/server.rs index 31301ef5a..42bbf3e9a 100644 --- a/e2e/src/server.rs +++ b/e2e/src/server.rs @@ -1,15 +1,14 @@ -//! A server on this machine for the scenarios' sends, as the reference's suite had: `/json` -//! answers a small JSON and sets a cookie, `/slow` the same after two seconds, `/echo` what it -//! was sent, `/redirect/N` N redirects then `/json`, `/large` more than an answer shows, `/bytes` -//! what is no text, `/png` a picture, anything else is a 404. Each connection is answered once, -//! then closed. +//! A server on this machine for the journeys' sends: `/json` answers a small JSON and sets a +//! cookie, `/slow` the same after two seconds, `/echo` what it was sent, `/redirect/N` N redirects +//! then `/json`, `/large` more than an answer shows, `/bytes` what is no text, `/png` a picture, +//! anything else is a 404. Each connection is answered once, then closed. use std::io::{Read, Write}; use std::net::{Ipv4Addr, TcpListener, TcpStream}; use std::time::Duration; -/// Its port: the server lives as long as the scenario's process. -pub fn serve() -> u16 { +/// Its port: the server lives as long as the journey's process. +pub(crate) fn serve() -> u16 { let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, 0)).expect("a local port is free"); let port = listener.local_addr().expect("the port is known").port(); std::thread::spawn(move || { @@ -59,8 +58,8 @@ Connection: close format!("{origin}/latest.json") } -/// A socket server echoing each text, for the scenarios' connections; its port. -pub fn serve_socket() -> u16 { +/// A socket server echoing each text, for the journeys' connections; its port. +pub(crate) fn serve_socket() -> u16 { let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, 0)).expect("a local port is free"); let port = listener.local_addr().expect("the port is known").port(); std::thread::spawn(move || { @@ -91,7 +90,7 @@ fn answer(mut stream: TcpStream) { let head = String::from_utf8_lossy(&head).into_owned(); let path = head.split_whitespace().nth(1).unwrap_or("/").to_owned(); if path.starts_with("/slow") { - #[expect(clippy::disallowed_methods, reason = "the server's own latency, not a scenario waiting")] + #[expect(clippy::disallowed_methods, reason = "the server's own latency, not a journey waiting")] std::thread::sleep(Duration::from_secs(2)); } let sent = body_of(&mut stream, &head); diff --git a/e2e/tests/10_library_transfer.rs b/e2e/tests/10_library_transfer.rs deleted file mode 100644 index 55d4539f3..000000000 --- a/e2e/tests/10_library_transfer.rs +++ /dev/null @@ -1,213 +0,0 @@ -//! Import, export and share from the File menu. Every operation reports, including when it -//! changed nothing; a sealed file opens only with its phrase; an export of nothing asks nothing -//! and leaves no file behind. -//! -//! Every dialog of the run answers the one path the scenario fixed. Nothing compares a word of -//! the reports: they are in the system's language, so what they name and the cards are read. - -use std::path::Path; - -use e2e::old::{App, step}; -use egui::{Key, Modifiers}; - -const CARDS: usize = 6; -const TITLE: &str = "Worth exporting"; -const FILE: &str = "library.devnotes"; -const PHRASE: &str = "an export passphrase"; -/// What an export before the archive looks like, from a version with a language unknown here; -/// its drawing carries a scene and no picture, as every export's. -const NEWER: &str = r#"{ - "version": 1, - "exportedAt": "2026-11-06T09:00:00Z", - "spaces": [{ "id": "elsewhere", "name": "Ailleurs" }], - "notes": [{ - "id": "written-by-a-newer-devnotes", - "spaceId": "elsewhere", - "title": "Ahead of this build", - "language": "from-the-future", - "content": "echo later", - "source": "", - "tags": [], - "pinned": false, - "createdAt": "2026-11-06T09:00:00Z", - "updatedAt": "2026-11-06T09:00:00Z", - "lifecycle": { "kind": "permanent" } - }, { - "id": "a-drawing-imported", - "spaceId": "elsewhere", - "title": "Imported sketch", - "kind": "drawing", - "language": "txt", - "content": "{\"version\":1,\"scene\":{\"objects\":[{\"type\":\"Rect\",\"left\":60,\"top\":45,\"width\":100,\"height\":50}]}}", - "source": "", - "tags": [], - "pinned": false, - "createdAt": "2026-11-06T09:00:00Z", - "updatedAt": "2026-11-06T09:00:00Z", - "lifecycle": { "kind": "permanent" } - }] -}"#; - -fn cards(app: &mut App, count: usize, what: &str) { - app.eventually(what, |tree| tree.count("note-card") == count); -} - -fn menu(app: &mut App, entry: &str) { - app.click("file-menu"); - app.click(&format!("file-option-{entry}")); -} - -/// The report of the last operation, left off the screen for the next one to be seen. -fn report(app: &mut App) -> String { - app.wait_for("status-toast"); - let said = app.tree().text("status-toast").unwrap_or_default(); - app.click("status-dismiss"); - app.eventually("the report is dismissed", |tree| !tree.has("status-toast")); - said -} - -fn write(app: &mut App, title: &str) { - app.click("new-note"); - app.fill("editor-title", title); - app.fill("editor-body", "echo hello"); - app.click("editor-close"); - app.eventually("the note is a card", |tree| !tree.has("editor-title")); -} - -/// The first card, purged: the second press of Delete writes, then the trash forgets it. -fn purge_first(app: &mut App) { - app.press(Key::ArrowDown, Modifiers::NONE); - app.press(Key::Delete, Modifiers::NONE); - app.wait_for("note-card-arming"); - app.press(Key::Delete, Modifiers::NONE); - app.click("undo-dismiss"); - app.click("trash-open"); - app.wait_for("trash-row"); - app.click("trash-purge"); - app.click("trash-purge"); - app.eventually("the trash is empty", |tree| tree.has("trash-empty-state")); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the panel is closed", |tree| !tree.has("trash-close")); -} - -fn is_archive(file: &Path) -> bool { - std::fs::read(file).is_ok_and(|bytes| bytes.starts_with(b"PK\x03\x04")) -} - -/// The one file the library's key does not protect carries a key of its own. -fn sealed_file(app: &mut App, file: &Path) { - step("a sealed file does not show what it holds", || { - menu(app, "exportAll"); - app.fill("passphrase-prompt-field", PHRASE); - app.fill("passphrase-prompt-confirmation", PHRASE); - app.click("passphrase-prompt-submit"); - let said = report(app); - assert!(said.contains(FILE), "{said}"); - let bytes = std::fs::read(file).unwrap(); - let readable = bytes.windows(TITLE.len()).any(|at| at == TITLE.as_bytes()); - assert!(!readable, "the title is readable in the file"); - }); - - step("it opens with its phrase, and only with it", || { - menu(app, "import"); - app.fill("passphrase-prompt-field", "not the phrase"); - app.click("passphrase-prompt-submit"); - app.eventually("the prompt says the phrase is wrong", |tree| { - tree.text("passphrase-prompt-problem").is_some_and(|said| !said.is_empty()) - }); - app.eventually("the prompt is open again", |tree| { - tree.find("passphrase-prompt-field").is_some_and(|field| !field.is_disabled()) - }); - app.fill("passphrase-prompt-field", PHRASE); - app.click("passphrase-prompt-submit"); - report(app); - app.eventually("the prompt closed", |tree| !tree.has("passphrase-prompt")); - }); -} - -#[test] -fn library_transfer() { - let profile = tempfile::tempdir().unwrap(); - let directory = tempfile::tempdir().unwrap(); - let file = directory.path().join(FILE); - let mut app = App::launch_answering("10_library_transfer", profile.path(), &file); - app.create_library(); - cards(&mut app, CARDS, "the samples are drawn"); - write(&mut app, TITLE); - cards(&mut app, CARDS + 1, "the note is drawn"); - - step("the menu greys what has nothing to act on", || { - app.click("file-menu"); - app.wait_for("file-option-exportSelection"); - let tree = app.tree(); - assert!(tree.find("file-option-exportSelection").unwrap().is_disabled()); - assert!(tree.find("file-option-copyMarkdown").unwrap().is_disabled()); - assert!(!tree.find("file-option-exportAll").unwrap().is_disabled()); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the menu is closed", |tree| !tree.has("file-option-exportAll")); - }); - - step("an export in the clear writes an archive and names it", || { - menu(&mut app, "exportAll"); - app.wait_for("passphrase-prompt"); - app.capture("protect-prompt"); - app.click("passphrase-prompt-plain"); - let said = report(&mut app); - assert!(said.contains(FILE), "{said}"); - assert!(said.contains(&(CARDS + 1).to_string()), "{said}"); - assert!(is_archive(&file)); - }); - - step("importing what is there adds nothing, and says so", || { - menu(&mut app, "import"); - assert!(!report(&mut app).is_empty()); - cards(&mut app, CARDS + 1, "nothing came in"); - }); - - step("a note gone for good comes back from the file", || { - purge_first(&mut app); - cards(&mut app, CARDS, "the note is gone"); - menu(&mut app, "import"); - report(&mut app); - cards(&mut app, CARDS + 1, "the note is back"); - }); - - sealed_file(&mut app, &file); - - step("a file from a newer version comes in rather than failing", || { - std::fs::write(&file, NEWER).unwrap(); - menu(&mut app, "import"); - report(&mut app); - // In its own space: a list draws only what is in view, and the window's size is the - // machine's. - app.click_where("space-option", |node| node.label() == Some("Ailleurs")); - app.eventually("the note from the future is drawn", |tree| { - tree.texts("note-card-title").contains(&"Ahead of this build".to_owned()) - }); - app.eventually("the drawing imported shows its picture", |tree| { - tree.has("note-card-drawing") && !tree.has("note-card-drawing-empty") - }); - }); - - step("Escape gives a prompt up, and nothing is written", || { - std::fs::remove_file(&file).unwrap(); - menu(&mut app, "exportAll"); - app.wait_for("passphrase-prompt"); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the prompt closed", |tree| !tree.has("passphrase-prompt")); - assert!(!file.exists()); - }); - - step("an empty space says so before any place is asked", || { - app.click("space-create-open"); - app.fill("space-create-input", "Rien dedans"); - app.press(Key::Enter, Modifiers::NONE); - cards(&mut app, 0, "the empty space is shown"); - menu(&mut app, "exportSpace"); - report(&mut app); - assert!(!app.has("passphrase-prompt")); - assert!(!file.exists()); - }); - - app.quit(); -} diff --git a/e2e/tests/10_scripts_and_runs.rs b/e2e/tests/10_scripts_and_runs.rs index ef5c5ffd7..9b40e01b1 100644 --- a/e2e/tests/10_scripts_and_runs.rs +++ b/e2e/tests/10_scripts_and_runs.rs @@ -157,7 +157,7 @@ fn what_is_left(mut app: App) { app.http().open("Login"); app.request().add_to_url("/changed"); app.http().ask_to_quit(); - app.http().cancel_quitting(); + app.http().cancel_leaving(); app.http().ask_to_quit(); app.http().save_and_quit(); }); diff --git a/e2e/tests/11_libraries_and_transfer.rs b/e2e/tests/11_libraries_and_transfer.rs new file mode 100644 index 000000000..aa9027902 --- /dev/null +++ b/e2e/tests/11_libraries_and_transfer.rs @@ -0,0 +1,210 @@ +//! Journey 11, « Several libraries, and moving notes between them »: a second library and its own +//! phrase, what a switch and a deletion ask, and the files notes leave and come in by. + +use e2e::{App, Area, Export, PASSPHRASE, step}; + +const FIRST: &str = "Personal"; +const SECOND: &str = "Office"; +const SECOND_PHRASE: &str = "another end-to-end passphrase"; +const FILE_PHRASE: &str = "a passphrase for a file"; +/// Only the first library holds it. +const SPACE: &str = "Travel"; +const FOLDER: &str = "Perf"; +const FILED: &str = "Slow query"; +const LOOSE: &str = "Nightly dump"; + +#[test] +fn libraries_and_transfer() { + let mut app = App::open("11_libraries_and_transfer"); + app.window().widen(); + + two_libraries(&mut app); + what_is_asked_first(&mut app); + leaving(&mut app); + coming_in(&mut app); + app.quit(); +} + +fn two_libraries(app: &mut App) { + step("a library alone is renamed, and cannot be deleted", || { + app.rail().new_space(SPACE); + app.libraries().open(); + app.libraries().expect_listed(1, "it is the only one"); + app.libraries().expect_open_one_kept("it offers no deletion"); + app.libraries().rename_the_open_one(FIRST); + app.capture("libraries"); + }); + + step("a second one is made, with its own phrase and its own samples, and renamed", || { + app.libraries().create("Work"); + app.gate().create_library(SECOND_PHRASE); + app.notes().expect_samples("it has its own samples"); + app.rail().expect_no_space(SPACE, "and nothing of the first"); + app.libraries().open(); + app.libraries().expect_listed(2, "both are listed"); + app.libraries().rename_the_open_one(SECOND); + app.libraries().close(); + }); + + step("the gate lists both, each opened by its own phrase", || { + app.relaunch(); + app.gate().expect_library(SECOND, "it asks for the last one open"); + app.gate().choose_library(FIRST); + app.gate().try_phrase(SECOND_PHRASE); + app.gate().expect_wrong_phrase("the other's phrase is refused"); + app.gate().choose_library(SECOND); + app.gate().unlock(SECOND_PHRASE); + app.rail().expect_no_space(SPACE, "the second is open"); + }); +} + +fn what_is_asked_first(app: &mut App) { + step("a switch asks before it loses a request left changed", || { + app.window().go_to(Area::Http); + app.http().new_draft(); + app.window().go_to(Area::Notes); + app.libraries().open(); + app.libraries().switch_to(FIRST); + app.http().expect_asked_about_changes(1, "the request is named"); + app.http().cancel_leaving(); + app.libraries().switch_to(FIRST); + app.http().leave_without_saving(); + app.gate().expect_library(FIRST, "the gate asks for the other library"); + app.gate().unlock(PASSPHRASE); + app.rail().expect_one_space(SPACE, "its own spaces are there"); + }); + + step("a deletion is named before it runs, and the open library has none", || { + app.libraries().open(); + app.libraries().create("Old"); + app.gate().create_library(SECOND_PHRASE); + app.libraries().open(); + app.libraries().expect_open_one_kept("the open one offers no deletion"); + app.libraries().switch_to(FIRST); + app.gate().unlock(PASSPHRASE); + app.libraries().open(); + app.libraries().ask_deletion("Old"); + app.libraries().cancel_deletion(); + app.libraries().expect_listed(3, "nothing went"); + app.libraries().ask_deletion("Old"); + app.libraries().confirm_deletion(); + app.libraries().close(); + }); +} + +fn leaving(app: &mut App) { + step("a space with a folder, its note, a note outside and a folder of nothing", || { + app.rail().show_space(SPACE); + app.rail().new_folder("Unused"); + app.rail().new_folder(FOLDER); + app.notes().write_snippet(LOOSE, "pg_dump shop"); + app.rail().open_folder(FOLDER); + app.notes().write_snippet(FILED, "EXPLAIN SELECT 1;"); + app.notes().leave_folder(); + }); + + step("everything is exported, under a phrase and in the clear", || { + app.transfer().expect_selection_waiting("a selection's entries wait for one"); + app.files().answer("sealed.devnotes"); + app.transfer().export_sealed(Export::Everything, FILE_PHRASE); + app.transfer().expect_reported("sealed.devnotes", "the report names the file"); + app.files() + .expect("sealed.devnotes", "nothing is read in it", |bytes| !holds(bytes, FILED)); + app.files().answer("everything.devnotes"); + app.transfer().export(Export::Everything); + app.transfer() + .expect_reported("everything.devnotes", "the report names the file"); + app.files() + .expect("everything.devnotes", "it is an archive", |bytes| bytes.starts_with(b"PK")); + }); + + step("a space is exported under a phrase, and a selection in the clear", || { + app.files().answer("space.devnotes"); + app.transfer().export_sealed(Export::Space, FILE_PHRASE); + app.transfer().expect_reported("space.devnotes", "the report names the file"); + app.selection().tick(LOOSE); + app.files().answer("selection.devnotes"); + app.transfer().export(Export::Selection); + app.transfer() + .expect_reported("selection.devnotes", "the report names the file"); + }); + + step("*Copy selection as Markdown* copies the note with all that says it", || { + app.transfer().copy_selection_as_markdown(); + app.clipboard().expect_saying(LOOSE, "its title"); + app.clipboard().expect_saying(SPACE, "its space"); + app.clipboard().expect_saying("pg_dump shop", "and its content"); + app.selection().clear(); + app.notes().clear_toasts(); + }); + + step("an export given up, or of nothing, asks nothing more and leaves no file", || { + app.files().answer("none.devnotes"); + app.transfer().ask(Export::Everything); + app.transfer().give_up(); + app.files().expect_none("none.devnotes", "nothing was written"); + app.rail().new_space("Empty"); + app.transfer().ask(Export::Space); + app.transfer().expect_reported("", "an empty space is said to be"); + app.transfer().expect_nothing_asked("no phrase is asked"); + app.files().expect_none("none.devnotes", "nothing was written"); + }); +} + +fn coming_in(app: &mut App) { + step("in the other library, a protected file opens with its phrase alone, arranged as it was", || { + app.libraries().open(); + app.libraries().switch_to(SECOND); + app.gate().unlock(SECOND_PHRASE); + app.files().answer("space.devnotes"); + app.transfer().import(); + app.transfer().try_phrase("not the file's phrase"); + app.transfer().expect_wrong_phrase("another phrase is refused"); + app.transfer().try_phrase(FILE_PHRASE); + app.transfer().expect_reported("2", "the two notes are said to have come in"); + app.rail().show_space(SPACE); + app.notes().expect_cards(2, "they are in their space"); + app.rail().expect_no_folder("Unused", "a folder of nothing did not come"); + app.rail().open_folder(FOLDER); + app.notes().expect_cards(1, "the folder holds its note"); + app.notes().expect_card(FILED, "the one it held"); + app.capture("imported"); + }); + + step("the same file again adds nothing, and says so", || { + app.transfer().import(); + app.transfer().try_phrase(FILE_PHRASE); + app.transfer().expect_reported("", "the import reports"); + app.rail().show_space(SPACE); + app.notes().expect_cards(2, "nothing came in"); + app.rail().expect_folders_named(FOLDER, 1, "nor a second folder"); + }); + + step("everything comes in, spaces merged by name", || { + app.files().answer("everything.devnotes"); + app.transfer().import(); + app.transfer().expect_reported("", "the import reports"); + app.rail().expect_one_space(SPACE, "the space is the same one"); + app.files().answer("selection.devnotes"); + app.transfer().import(); + app.transfer().expect_reported("", "the selection reports too"); + app.rail().show_space(SPACE); + app.notes().expect_cards(2, "its notes were there already"); + }); + + step("a note gone for good comes back from the file", || { + app.notes().delete_from_the_keyboard(LOOSE); + app.notes().dismiss_undo(); + app.notes().clear_search(); + app.trash().open(); + app.trash().empty(); + app.trash().close(); + app.transfer().import(); + app.transfer().expect_reported("", "the import reports"); + app.notes().expect_card(LOOSE, "the note is back"); + }); +} + +fn holds(bytes: &[u8], words: &str) -> bool { + bytes.windows(words.len()).any(|window| window == words.as_bytes()) +} diff --git a/e2e/tests/12_looking_after_the_library.rs b/e2e/tests/12_looking_after_the_library.rs new file mode 100644 index 000000000..8a90c8c95 --- /dev/null +++ b/e2e/tests/12_looking_after_the_library.rs @@ -0,0 +1,93 @@ +//! Journey 12, « Looking after the library »: its phrase changed, a copy put back, a damaged file +//! set aside and a forgotten phrase. It ends on a profile with no library. + +use e2e::{App, PASSPHRASE, Sample, step}; + +const NEXT: &str = "a second end-to-end passphrase"; +const LATER: &str = "Written after the copy"; + +#[test] +fn looking_after_the_library() { + let mut app = App::open("12_looking_after_the_library"); + app.window().widen(); + + step("a copy is taken at the first launch of the day, and no other", || { + app.relaunch_and_unlock(); + app.window().widen(); + app.security().open_copies(); + app.security().expect_copies(1, "the launch's copy is listed"); + app.capture("copies"); + app.prefs().close(); + app.relaunch_and_unlock(); + app.window().widen(); + app.security().open_copies(); + app.security().expect_copies(1, "a second launch took no other"); + app.prefs().close(); + }); + + step("the passphrase is changed, and the session carries on", || { + app.security().ask_change(); + app.security().try_change("not the current one", NEXT); + app.security().expect_refused("a wrong phrase changes nothing"); + app.security().try_change(PASSPHRASE, NEXT); + app.security().expect_changed("the phrase is changed"); + }); + + step("after a quit, the old phrase is refused and the new one opens", || { + app.relaunch(); + app.gate().try_phrase(PASSPHRASE); + app.gate().expect_wrong_phrase("the old phrase is refused"); + app.gate().unlock(NEXT); + app.window().widen(); + }); + + step("the copy taken before the change is put back, what it replaces set aside", || { + let gone = app.notes().title_of(Sample::SnippetToFormat); + app.notes().delete_from_the_keyboard(&gone); + app.notes().dismiss_undo(); + app.notes().clear_search(); + app.trash().open(); + app.trash().empty(); + app.trash().close(); + app.notes().write_snippet(LATER, "echo later"); + app.security().open_copies(); + app.security().ask_restore(); + app.capture("restore"); + app.security().cancel_restore(); + app.security().ask_restore(); + app.security().confirm_restore(); + app.gate() + .expect_place_told("replaced", "the place of the library it replaced is told"); + app.capture("restored"); + }); + + step("the copy opens with the new phrase, the library as it was", || { + app.gate().unlock(NEXT); + app.window().widen(); + app.notes().expect_samples("the note erased is back, what came after is gone"); + }); + + step("a damaged database is said, set aside, and the phrase unchanged", || { + app.relaunch_damaged(); + app.gate().try_phrase(NEXT); + app.gate().expect_damaged("the gate says so, and starts nothing on it"); + app.capture("damaged"); + app.gate().set_aside(); + app.gate().expect_place_told("damaged", "its place is told"); + app.gate().unlock(NEXT); + app.notes().expect_samples("a fresh library opens"); + }); + + step("a forgotten phrase archives the library, and the gate asks for a new one", || { + app.relaunch(); + app.gate().forget(); + app.capture("forgotten"); + app.gate().keep_trying(); + app.gate().forget(); + app.gate().archive(); + app.gate().expect_new_phrase_asked("a new library would begin"); + app.gate().expect_place_told("archived", "the place of the old one is told"); + }); + + app.quit(); +} diff --git a/e2e/tests/16_passphrase_change.rs b/e2e/tests/16_passphrase_change.rs deleted file mode 100644 index 54f191ea1..000000000 --- a/e2e/tests/16_passphrase_change.rs +++ /dev/null @@ -1,92 +0,0 @@ -//! What it proves is the shape of the change: the key file is rewritten, the notes are not, and -//! the session carries on. Read from the file rather than from what the application says of it. - -use std::path::{Path, PathBuf}; - -use e2e::old::{App, PASSPHRASE, step}; - -const NEXT: &str = "a second end-to-end passphrase"; - -/// The one key file of a profile, wherever its library lives. -fn key_file(directory: &Path) -> Option { - for entry in std::fs::read_dir(directory).ok()?.flatten() { - let path = entry.path(); - if path.is_dir() { - if path.ends_with("backups") { - continue; - } - if let Some(found) = key_file(&path) { - return Some(found); - } - } else if path.file_name().is_some_and(|name| name == "vault.json") { - return Some(path); - } - } - None -} - -fn security(app: &mut App) { - app.click("file-menu"); - app.click("file-preferences"); - app.click("settings-page-security"); - app.click("setting-change-passphrase"); - app.wait_for("change-passphrase"); -} - -fn fill_change(app: &mut App, current: &str) { - app.fill("change-passphrase-current", current); - app.fill("change-passphrase-next", NEXT); - app.fill("change-passphrase-confirmation", NEXT); - app.click("change-passphrase-submit"); -} - -#[test] -fn passphrase_change() { - let directory = tempfile::tempdir().unwrap(); - let profile = directory.path(); - let mut app = App::launch("16_passphrase_change", profile); - app.create_library(); - app.eventually("the samples are drawn", |tree| tree.has("note-card")); - let file = key_file(profile).expect("the library has its key file"); - let first = std::fs::read(&file).unwrap(); - - step("a change that cannot name the phrase rewrites nothing", || { - security(&mut app); - fill_change(&mut app, "not the current one"); - app.eventually("the phrase is refused", |tree| { - tree.text("change-passphrase-problem").is_some_and(|said| !said.is_empty()) - }); - assert_eq!(std::fs::read(&file).unwrap(), first); - assert!(app.has("change-passphrase"), "the dialog stays"); - }); - - step("the right phrase rewraps the key and leaves the notes", || { - app.eventually("the fields are free again", |tree| { - tree.find("change-passphrase-current").is_some_and(|field| !field.is_disabled()) - }); - fill_change(&mut app, PASSPHRASE); - app.eventually("the dialog closed", |tree| !tree.has("change-passphrase")); - // It stands over the dialog's buttons in a small window. - app.wait_for("status-toast"); - app.click("status-dismiss"); - app.eventually("the report is dismissed", |tree| !tree.has("status-toast")); - assert_ne!(std::fs::read(&file).unwrap(), first); - app.click("settings-close"); - app.eventually("the panel closed", |tree| !tree.has("settings-dialog")); - assert!(app.has("note-card"), "the session carries on"); - }); - - let mut app = app.relaunch(); - step("the new phrase opens the library, and the old one no longer", || { - app.fill("vault-passphrase", PASSPHRASE); - app.click("vault-submit"); - app.eventually("the old phrase is refused", |tree| { - tree.text("vault-problem").is_some_and(|said| !said.is_empty()) - }); - app.fill("vault-passphrase", NEXT); - app.click("vault-submit"); - app.wait_for("area-notes"); - }); - - app.quit(); -} diff --git a/e2e/tests/21_folders_travel.rs b/e2e/tests/21_folders_travel.rs deleted file mode 100644 index 594874b05..000000000 --- a/e2e/tests/21_folders_travel.rs +++ /dev/null @@ -1,106 +0,0 @@ -//! A space exported from one machine and imported on another comes back arranged: the notes in -//! their folders, the folders cited by nobody left behind, and a second import adds nothing. -//! -//! « The other machine » is a second profile: a genuinely fresh library. - -use e2e::old::{App, Tree, step}; -use egui::accesskit::Node; -use egui::{Key, Modifiers}; - -const SPACE: &str = "Voyage"; -const CITED: &str = "Perf"; -const UNCITED: &str = "Jamais citée"; -const FILED: &str = "EXPLAIN lent"; -const LOOSE: &str = "Dump nocturne"; - -fn named(name: &str) -> impl Fn(&Node) -> bool + '_ { - move |node| node.label() == Some(name) -} - -fn folders_named(tree: &Tree, name: &str) -> usize { - tree.texts("folder-option").iter().filter(|row| *row == name).count() -} - -fn write(app: &mut App, title: &str) { - app.click("new-note"); - app.fill("editor-title", title); - app.fill("editor-body", "SELECT 1;"); - app.click("editor-close"); - app.eventually("the note is a card", |tree| !tree.has("editor-title")); -} - -fn make_folder(app: &mut App, name: &str) { - app.click("folder-create-open"); - app.fill("folder-create-input", name); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the folder is listed", |tree| folders_named(tree, name) == 1); -} - -fn menu(app: &mut App, entry: &str) { - app.click("file-menu"); - app.click(&format!("file-option-{entry}")); -} - -fn report(app: &mut App) { - app.wait_for("status-toast"); - app.click("status-dismiss"); - app.eventually("the report is dismissed", |tree| !tree.has("status-toast")); -} - -#[test] -fn folders_travel() { - let directory = tempfile::tempdir().unwrap(); - let file = directory.path().join("arranged.devnotes"); - let first = tempfile::tempdir().unwrap(); - let mut app = App::launch_answering("21_folders_travel", first.path(), &file); - app.create_library(); - - step("a space with a folder that holds a note", || { - app.click("space-create-open"); - app.fill("space-create-input", SPACE); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the space is shown", |tree| tree.count("note-card") == 0); - make_folder(&mut app, UNCITED); - make_folder(&mut app, CITED); - write(&mut app, LOOSE); - app.click_where("folder-option", named(CITED)); - write(&mut app, FILED); - }); - - step("it leaves as a file", || { - menu(&mut app, "exportSpace"); - app.click("passphrase-prompt-plain"); - report(&mut app); - assert!(file.exists()); - }); - app.quit(); - - let second = tempfile::tempdir().unwrap(); - let mut app = App::launch_answering("21_folders_travel", second.path(), &file); - app.create_library(); - app.eventually("the samples are drawn", |tree| tree.has("note-card")); - - step("on the other side it arrives in its folder", || { - menu(&mut app, "import"); - report(&mut app); - app.click_where("space-option", named(SPACE)); - app.eventually("the two notes are drawn", |tree| tree.count("note-card") == 2); - let tree = app.tree(); - assert_eq!(folders_named(&tree, CITED), 1); - assert_eq!(folders_named(&tree, UNCITED), 0, "cited by nobody"); - app.click_where("folder-option", named(CITED)); - app.eventually("the folder holds its note", |tree| { - tree.count("note-card") == 1 && tree.texts("note-card-title").contains(&FILED.to_owned()) - }); - }); - - step("the same file a second time adds nothing", || { - menu(&mut app, "import"); - report(&mut app); - app.click_where("space-option", named(SPACE)); - app.eventually("still two notes", |tree| tree.count("note-card") == 2); - assert_eq!(folders_named(&app.tree(), CITED), 1); - }); - - app.quit(); -} diff --git a/e2e/tests/23_backups.rs b/e2e/tests/23_backups.rs deleted file mode 100644 index 992b6a0f6..000000000 --- a/e2e/tests/23_backups.rs +++ /dev/null @@ -1,101 +0,0 @@ -//! The copies, and the one gesture that puts one back. A copy is taken at unlock, so a real -//! relaunch comes first; the last step really replaces the library, and unlocks the copy. - -use e2e::old::{App, PASSPHRASE, step}; -use egui::accesskit::Node; - -const LATER: &str = "Written after the copy"; - -fn security(app: &mut App) { - app.click("file-menu"); - app.click("file-preferences"); - app.click("settings-page-backups"); - app.scroll_to("settings-content", "backup-row"); -} - -/// The strip opens further down a panel that scrolls: its buttons are clicked once they are in view. -fn strip_shown(app: &mut App) { - app.eventually("the strip is in view", |tree| { - let place = |id| tree.find(id).and_then(Node::bounds); - place("backup-confirm-restore") - .zip(place("settings-cancel")) - .is_some_and(|(button, footer)| button.y1 < footer.y0) - }); -} - -fn close(app: &mut App) { - app.click("settings-close"); - app.eventually("the panel closed", |tree| !tree.has("settings-dialog")); -} - -fn unlock(app: &mut App) { - app.fill("vault-passphrase", PASSPHRASE); - app.click("vault-submit"); - app.wait_for("area-notes"); -} - -fn is_stamped(words: &str) -> bool { - words - .split_whitespace() - .next() - .is_some_and(|stamp| stamp.len() == 19 && stamp.as_bytes()[10] == b'_') -} - -#[test] -fn backups() { - let profile = tempfile::tempdir().unwrap(); - let app = { - let mut app = App::launch("23_backups", profile.path()); - app.create_library(); - app.eventually("the samples are drawn", |tree| tree.has("note-card")); - app - }; - let mut app = app.relaunch(); - unlock(&mut app); - - step("the launch's copy is listed, with when and how big", || { - security(&mut app); - let detail = app.tree().text("backup-detail").unwrap_or_default(); - assert!(is_stamped(&detail), "{detail}"); - app.capture("backups"); - close(&mut app); - }); - - step("the trigger names what a restore would do, and runs none", || { - security(&mut app); - app.click("backup-restore"); - app.wait_for("backup-confirm"); - strip_shown(&mut app); - assert!(!app.has("backup-restore"), "the trigger gave way"); - assert!(app.has("settings-dialog")); - app.click("backup-cancel"); - app.eventually("the strip is gone", |tree| !tree.has("backup-confirm")); - close(&mut app); - }); - - step("it replaces the library and goes back to the gate", || { - app.click("new-note"); - app.fill("editor-title", LATER); - app.fill("editor-body", "echo later"); - app.click("editor-close"); - app.eventually("the note is a card", |tree| !tree.has("editor-title")); - - security(&mut app); - app.click("backup-restore"); - strip_shown(&mut app); - app.click("backup-confirm-restore"); - app.wait_for("vault-passphrase"); - assert!(!app.has("file-menu")); - assert!(!app.has("settings-dialog")); - app.wait_for("status-toast"); - }); - - step("the copy opens, without what was written after it", || { - unlock(&mut app); - app.eventually("the samples are drawn", |tree| tree.has("note-card")); - let titles = app.tree().texts("note-card-title"); - assert!(!titles.contains(&LATER.to_owned()), "{titles:?}"); - }); - - app.quit(); -} diff --git a/e2e/tests/24_forgotten_passphrase.rs b/e2e/tests/24_forgotten_passphrase.rs deleted file mode 100644 index 739ca48e7..000000000 --- a/e2e/tests/24_forgotten_passphrase.rs +++ /dev/null @@ -1,47 +0,0 @@ -//! The way out of a library whose phrase is forgotten: it archives the library and leaves the -//! profile with none, which is what turns the gate into the one that asks for a new phrase. - -use e2e::old::{App, PASSPHRASE, step}; - -#[test] -fn forgotten_passphrase() { - let profile = tempfile::tempdir().unwrap(); - let mut first = App::launch("24_forgotten_passphrase", profile.path()); - first.create_library(); - first.eventually("the samples are drawn", |tree| tree.has("note-card")); - let mut app = first.relaunch(); - app.wait_for("vault-passphrase"); - - step("a way out is offered from under the unlock button", || { - assert!(app.has("vault-forgotten")); - }); - - step("the field gives way to what would be lost", || { - app.click("vault-forgotten"); - app.wait_for("vault-archive"); - assert!(!app.has("vault-passphrase")); - }); - - step("it goes back to the field without touching anything", || { - app.click("vault-keep-trying"); - app.wait_for("vault-passphrase"); - assert!(!app.has("vault-archive")); - }); - - step("it archives and comes back asking for a new phrase", || { - app.click("vault-forgotten"); - app.click("vault-archive-confirm"); - app.wait_for("vault-confirmation"); - app.wait_for("status-toast"); - }); - - step("a new phrase opens a new library, seeded again", || { - app.fill("vault-passphrase", PASSPHRASE); - app.fill("vault-confirmation", PASSPHRASE); - app.click("vault-submit"); - app.wait_for("area-notes"); - app.eventually("the samples are drawn", |tree| tree.has("note-card")); - }); - - app.quit(); -} diff --git a/e2e/tests/25_libraries.rs b/e2e/tests/25_libraries.rs deleted file mode 100644 index 2e5e28950..000000000 --- a/e2e/tests/25_libraries.rs +++ /dev/null @@ -1,153 +0,0 @@ -//! Several libraries: created from the File menu and opened through the gate, each with its own -//! phrase and its own samples, a switch that asks before it loses an unsaved request, the way -//! between them from the gate itself, a deletion named before it runs, and a registry cut short -//! that loses no library. - -use e2e::old::{App, PASSPHRASE, Tree, step}; -use egui::{Key, Modifiers}; - -const OTHER: &str = "Boulot"; -/// Only the first library holds it, which is what tells the two rails apart. -const HOME: &str = "Maison"; - -fn panel(app: &mut App) { - app.click("file-menu"); - app.click("file-libraries"); - app.wait_for("library-row"); -} - -fn close_panel(app: &mut App) { - app.click("libraries-close"); - app.eventually("the panel is closed", |tree| !tree.has("library-row")); -} - -/// The library the gate asks for, as its menu names it. -fn gate_library(tree: &Tree) -> String { - tree.find("vault-library-switch") - .and_then(egui::accesskit::Node::value) - .unwrap_or_default() - .to_owned() -} - -fn pass_the_gate(app: &mut App) { - app.fill("vault-passphrase", PASSPHRASE); - if app.has("vault-confirmation") { - app.fill("vault-confirmation", PASSPHRASE); - } - app.click("vault-submit"); - app.wait_for("area-notes"); -} - -fn has_space(tree: &Tree, name: &str) -> bool { - tree.texts("space-option").iter().any(|row| row == name) -} - -/// A request begun in the HTTP area and left there, then back to the notes. -fn leave_a_request_unsaved(app: &mut App) { - app.press(Key::Num3, Modifiers::COMMAND); - app.click("http-tab-new"); - app.wait_for("http-url"); - app.press(Key::Num1, Modifiers::COMMAND); - app.wait_for("area-notes"); -} - -#[test] -fn libraries() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("25_libraries", profile.path()); - app.create_library(); - app.eventually("the samples are drawn", |tree| tree.has("note-card")); - app.click("space-create-open"); - app.fill("space-create-input", HOME); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the space is listed", |tree| has_space(tree, HOME)); - - step("the panel lists the one open, and says so", || { - panel(&mut app); - app.capture("libraries"); - let tree = app.tree(); - assert_eq!(tree.count("library-row"), 1); - assert!(tree.has("library-open")); - assert!(!tree.has("library-delete"), "the last cannot go"); - }); - - step("creating one goes straight to it, through the gate", || { - app.fill("library-new-name", OTHER); - app.click("library-create"); - app.wait_for("vault-confirmation"); - assert!(!app.has("file-menu")); - assert!(!app.has("library-row"), "the panel went with the library"); - pass_the_gate(&mut app); - }); - - step("it is a library of its own, seeded as a first launch", || { - app.eventually("its samples are drawn", |tree| tree.has("note-card")); - assert!(!has_space(&app.tree(), HOME)); - panel(&mut app); - assert_eq!(app.tree().count("library-row"), 2); - close_panel(&mut app); - }); - - step("a switch asks before it loses an unsaved request", || { - leave_a_request_unsaved(&mut app); - panel(&mut app); - app.click("library-switch"); - app.wait_for("http-leave-dialog"); - assert_eq!(app.tree().count("http-leave-name"), 1); - app.click("http-leave-cancel"); - app.eventually("the question is gone", |tree| !tree.has("http-leave-dialog")); - assert!(!app.has("vault-passphrase"), "nothing changed"); - - app.click("library-switch"); - app.click("http-leave-discard"); - app.wait_for("vault-passphrase"); - assert!(!app.has("vault-confirmation"), "this one has its phrase"); - }); - - step("the gate goes from one library to the other, and back", || { - app.click("vault-library-switch"); - app.click("vault-library-switch-1"); - app.eventually("the gate asks for the other", |tree| gate_library(tree) == OTHER); - app.click("vault-library-switch"); - app.click("vault-library-switch-0"); - app.eventually("the gate asks for the first", |tree| { - tree.has("vault-library-switch") && gate_library(tree) != OTHER - }); - }); - - step("what was left there is found", || { - pass_the_gate(&mut app); - app.eventually("its own spaces are listed", |tree| has_space(tree, HOME)); - }); - - step("a deletion is named before it takes anything", || { - panel(&mut app); - app.click("library-delete"); - app.wait_for("library-confirm"); - let said = app.tree().text("library-confirm").unwrap_or_default(); - assert!(said.contains(OTHER), "{said}"); - assert_eq!(app.tree().count("library-row"), 2); - app.click("library-confirm-delete"); - app.eventually("the library is erased", |tree| tree.count("library-row") == 1); - }); - - step("the one that is left offers no deletion", || { - assert!(!app.has("library-delete")); - close_panel(&mut app); - }); - - app.quit(); - let registry = profile.path().join("libraries.json"); - let whole = std::fs::read(®istry).unwrap(); - std::fs::write(®istry, &whole[..whole.len() / 2]).unwrap(); - let mut app = App::launch("25_libraries", profile.path()); - - step("a registry cut short still opens on the library", || { - app.wait_for("vault-passphrase"); - assert!(!app.has("vault-confirmation"), "not taken for a first launch"); - pass_the_gate(&mut app); - app.eventually("its own spaces are listed", |tree| has_space(tree, HOME)); - }); - - app.quit(); -} diff --git a/e2e/tests/36_recette_libraries.rs b/e2e/tests/36_recette_libraries.rs deleted file mode 100644 index 7a86eb7be..000000000 --- a/e2e/tests/36_recette_libraries.rs +++ /dev/null @@ -1,136 +0,0 @@ -//! The acceptance sheet's cases on libraries that no other scenario holds. A step opens on the -//! case it runs, so that a run can be read back into the sheet. - -use std::path::PathBuf; - -use e2e::old::{App, PASSPHRASE, step}; -use egui::{Key, Modifiers}; - -const OTHER: &str = "Recette 2"; -const RENAMED: &str = "Recette Deux"; -const ONLY_HERE: &str = "zq-isolation"; -const TOO_SHORT: &str = "abc"; - -fn panel(app: &mut App) { - app.click("file-menu"); - app.click("file-libraries"); - app.wait_for("library-row"); -} - -fn pass_the_gate(app: &mut App) { - app.fill("vault-passphrase", PASSPHRASE); - if app.has("vault-confirmation") { - app.fill("vault-confirmation", PASSPHRASE); - } - app.click("vault-submit"); - app.wait_for("area-notes"); -} - -/// The key file of the only library of `profile`. -fn key_file(profile: &std::path::Path) -> PathBuf { - let libraries = profile.join("libraries"); - let library = std::fs::read_dir(libraries).unwrap().next().unwrap().unwrap(); - library.path().join("vault.json") -} - -#[test] -fn recette_libraries() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("36_recette_libraries", profile.path()); - - step("LIB-01 the gate says the floor before anything is typed", || { - app.wait_for("vault-minimum"); - assert!(app.has("vault-confirmation")); - }); - - step("LIB-03 two different phrases are said to differ", || { - app.fill("vault-passphrase", PASSPHRASE); - app.fill("vault-confirmation", "correct horse battery stapler"); - app.wait_for("vault-problem"); - assert!(app.tree().find("vault-submit").is_some_and(egui::accesskit::Node::is_disabled)); - }); - - // A field that reveals keeps its role and no value: the picture is what says it. - step("LIB-04 show and hide take both fields together", || { - let hidden = std::fs::read(app.capture("phrase-hidden")).unwrap(); - app.click("vault-reveal"); - let shown = std::fs::read(app.capture("phrase-shown")).unwrap(); - assert_ne!(hidden, shown); - app.click("vault-reveal"); - }); - - step("LIB-05 the right phrase twice opens the canvas", || { - app.click("vault-confirmation"); - app.press(Key::Backspace, Modifiers::NONE); - app.click("vault-submit"); - app.wait_for("area-notes"); - }); - - step("LIB-14 a note of one library is not in the other", || { - app.click("new-note"); - app.fill("editor-title", ONLY_HERE); - app.click("editor-close"); - app.eventually("the note is a card", |tree| { - tree.texts("note-card").iter().any(|card| card == ONLY_HERE) - }); - panel(&mut app); - app.fill("library-new-name", OTHER); - app.click("library-create"); - app.wait_for("vault-confirmation"); - pass_the_gate(&mut app); - app.eventually("its samples are drawn", |tree| tree.has("note-card")); - app.fill("search-input", ONLY_HERE); - app.wait_for("search-matched"); - app.eventually("nothing is found", |tree| !tree.has("note-card")); - }); - - step("LIB-15 a library is renamed from the panel", || { - app.click("search-clear"); - panel(&mut app); - app.click("library-start-rename"); - app.click("library-rename"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(RENAMED); - app.press(Key::Enter, Modifiers::NONE); - let registry = profile.path().join("libraries.json"); - app.eventually("the registry names it", |_| { - std::fs::read_to_string(®istry).is_ok_and(|text| text.contains(RENAMED)) - }); - app.click("libraries-close"); - }); - - let mut app = app.relaunch(); - - step("LIB-08 no length rule at the unlock, only a refusal", || { - app.fill("vault-passphrase", TOO_SHORT); - app.click("vault-submit"); - app.wait_for("vault-problem"); - assert!(!app.has("vault-minimum")); - }); - app.quit(); -} - -#[test] -fn recette_a_lost_key_file() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("36_recette_key_file", profile.path()); - app.create_library(); - app.quit(); - let key = key_file(profile.path()); - let kept = key.with_extension("json.bak"); - std::fs::rename(&key, &kept).unwrap(); - - let mut app = App::launch("36_recette_key_file", profile.path()); - step("LIB-20 a library without its key file says so", || { - app.wait_for("vault-key-missing"); - assert!(!app.has("vault-passphrase")); - }); - app.quit(); - - std::fs::rename(&kept, &key).unwrap(); - let mut app = App::launch("36_recette_key_file", profile.path()); - step("LIB-20 the file put back, the phrase opens it again", || { - pass_the_gate(&mut app); - }); - app.quit(); -} diff --git a/e2e/tests/37_recette_socle.rs b/e2e/tests/37_recette_socle.rs deleted file mode 100644 index a571114cc..000000000 --- a/e2e/tests/37_recette_socle.rs +++ /dev/null @@ -1,368 +0,0 @@ -//! The acceptance sheet's cases on security, the window and the preferences that no other scenario -//! holds. A step opens on the case it runs, so that a run can be read back into the sheet. - -use std::path::{Path, PathBuf}; - -use e2e::old::{App, PASSPHRASE, Tree, step}; -use egui::accesskit::{Node, Toggled}; -use egui::{Key, Modifiers}; - -const NEXT: &str = "a second end-to-end passphrase"; -const SECRET: &str = "zq-secret-recette"; -const LATER: &str = "zq-apres-copie"; -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 ENGLISH: &str = "setting-locale-2"; - -fn preferences(app: &mut App) { - app.click("file-menu"); - app.click("file-preferences"); - app.wait_for("settings-dialog"); -} - -fn security(app: &mut App) { - preferences(app); - app.click("settings-page-backups"); - app.wait_for("setting-automatic-backups"); -} - -fn close(app: &mut App) { - app.click("settings-close"); - app.eventually("the panel closed", |tree| !tree.has("settings-dialog")); -} - -fn unlock(app: &mut App, phrase: &str) { - app.fill("vault-passphrase", phrase); - app.click("vault-submit"); - app.wait_for("area-notes"); - app.eventually("the cards are drawn", |tree| tree.has("note-card")); -} - -fn a_note(app: &mut App, title: &str, body: &str) { - app.click("new-note"); - app.fill("editor-title", title); - app.fill("editor-body", body); - app.click("editor-close"); - app.eventually("the editor closed", |tree| !tree.has("editor-title")); -} - -fn is_on(node: Option<&Node>) -> bool { - node.and_then(Node::toggled) == Some(Toggled::True) -} - -fn top_of(tree: &Tree) -> f64 { - tree.find("area-option-notes") - .and_then(Node::bounds) - .map_or(f64::INFINITY, |bounds| bounds.y0) -} - -fn switch_top(app: &mut App) -> f64 { - top_of(&app.tree()) -} - -fn files_under(directory: &Path, found: &mut Vec) { - for entry in std::fs::read_dir(directory).unwrap().flatten() { - let path = entry.path(); - if path.is_dir() { - files_under(&path, found); - } else { - found.push(path); - } - } -} - -fn the_library(profile: &Path) -> PathBuf { - let mut libraries = std::fs::read_dir(profile.join("libraries")).unwrap(); - libraries.next().unwrap().unwrap().path() -} - -#[test] -fn recette_security() { - let directory = tempfile::tempdir().unwrap(); - let profile = directory.path(); - let mut app = App::launch("37_recette_security", profile); - app.create_library(); - app.eventually("the samples are drawn", |tree| tree.has("note-card")); - let mut app = app.relaunch(); - unlock(&mut app, PASSPHRASE); - - step("SEC-01 the page holds the phrase and the copies", || { - security(&mut app); - assert!(is_on(app.tree().find("setting-automatic-backups"))); - app.capture("security"); - }); - - step("SEC-02 a copy of the launch, offered back", || { - app.scroll_to("settings-content", "backup-row"); - assert!(app.has("backup-restore")); - close(&mut app); - }); - - let mut app = app.relaunch(); - unlock(&mut app, PASSPHRASE); - - step("SEC-03 a second launch of the day takes no copy", || { - security(&mut app); - app.scroll_to("settings-content", "backup-row"); - assert_eq!(app.tree().count("backup-row"), 1); - }); - - step("SEC-05 a new phrase too short changes nothing", || { - app.click("settings-page-security"); - app.click("setting-change-passphrase"); - app.fill("change-passphrase-current", PASSPHRASE); - app.fill("change-passphrase-next", "court-08"); - app.fill("change-passphrase-confirmation", "court-08"); - app.wait_for("change-passphrase-problem"); - assert!(app.tree().find("change-passphrase-submit").is_some_and(Node::is_disabled)); - app.click("change-passphrase-cancel"); - app.eventually("the dialog closed", |tree| !tree.has("change-passphrase")); - }); - - step("SEC-06 the session carries on over a new phrase", || { - app.click("setting-change-passphrase"); - app.wait_for("change-passphrase-copies"); - app.capture("change-passphrase"); - app.fill("change-passphrase-current", PASSPHRASE); - app.fill("change-passphrase-next", NEXT); - app.fill("change-passphrase-confirmation", NEXT); - app.click("change-passphrase-submit"); - app.eventually("the dialog closed", |tree| !tree.has("change-passphrase")); - app.wait_for("status-toast"); - close(&mut app); - assert!(app.has("note-card"), "no phrase is asked again"); - }); - - restoring(&mut app, profile); - app.quit(); -} - -fn restoring(app: &mut App, profile: &Path) { - step("SEC-08 the restore says what leaves, and Cancel keeps it", || { - a_note(app, LATER, "echo after"); - security(app); - app.scroll_to("settings-content", "backup-row"); - app.click("backup-restore"); - app.wait_for("backup-confirm"); - app.capture("restore-confirm"); - app.click("backup-cancel"); - app.eventually("the strip is gone", |tree| !tree.has("backup-confirm")); - close(app); - app.eventually("the note stays", |tree| tree.texts("note-card-title").iter().any(|it| it == LATER)); - }); - - step("SEC-09 a restore sets the library aside in replaced", || { - security(app); - app.scroll_to("settings-content", "backup-row"); - app.click("backup-restore"); - app.scroll_above("settings-content", "backup-confirm-restore", "settings-cancel"); - app.click("backup-confirm-restore"); - app.wait_for("vault-passphrase"); - app.wait_for("status-toast"); - app.capture("restored"); - let replaced = the_library(profile).join("replaced"); - assert!(std::fs::read_dir(replaced).unwrap().next().is_some()); - }); - - step("SEC-10 a copy older than the change opens with the new phrase", || { - app.fill("vault-passphrase", PASSPHRASE); - app.click("vault-submit"); - app.eventually("the old phrase is refused", |tree| { - tree.text("vault-problem").is_some_and(|said| !said.is_empty()) - }); - unlock(app, NEXT); - }); - - step("SEC-09 what was written after the copy is gone", || { - let titles = app.tree().texts("note-card-title"); - assert!(!titles.contains(&LATER.to_owned()), "{titles:?}"); - }); -} - -#[test] -fn recette_nothing_readable_on_the_disk() { - let directory = tempfile::tempdir().unwrap(); - let profile = directory.path(); - let mut app = App::launch("37_recette_disk", profile); - app.create_library(); - a_note(&mut app, SECRET, SECRET); - app.quit(); - - step("SEC-12 neither title nor body can be read on the disk", || { - let mut files = Vec::new(); - files_under(&profile.join("libraries"), &mut files); - assert!(!files.is_empty()); - for file in files { - let bytes = std::fs::read(&file).unwrap(); - let found = bytes.windows(SECRET.len()).any(|window| window == SECRET.as_bytes()); - assert!(!found, "{} reads in the clear", file.display()); - } - }); -} - -#[test] -fn recette_window() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("37_recette_window", profile.path()); - app.create_library(); - app.eventually("the samples are drawn", |tree| tree.has("note-card")); - - step("APP-01 each area is found as it was left", || { - app.click("note-card"); - app.wait_for("editor-title"); - app.press(Key::Num2, Modifiers::COMMAND); - app.wait_for("area-tools"); - app.click("tools-entry-case"); - app.wait_for("tool-title"); - app.press(Key::Num3, Modifiers::COMMAND); - app.wait_for("http-rail-title"); - app.click("http-tab-new"); - app.wait_for("http-tab-open"); - app.press(Key::Num1, Modifiers::COMMAND); - app.wait_for("area-notes"); - app.wait_for("editor-title"); - app.press(Key::Num2, Modifiers::COMMAND); - app.wait_for("tool-title"); - app.press(Key::Num3, Modifiers::COMMAND); - app.wait_for("http-tab-open"); - app.press(Key::Num1, Modifiers::COMMAND); - app.wait_for("editor-title"); - app.click("editor-close"); - app.eventually("the editor closed", |tree| !tree.has("editor-title")); - }); - - step("APP-02 one state of the rail for the three areas", || { - let in_the_rail = switch_top(&mut app); - app.press(Key::B, Modifiers::COMMAND); - app.eventually("the bar took the switch", |tree| top_of(tree) < in_the_rail); - app.press(Key::Num2, Modifiers::COMMAND); - app.wait_for("area-tools"); - assert!(switch_top(&mut app) < in_the_rail); - app.press(Key::Num3, Modifiers::COMMAND); - app.wait_for("http-tab-open"); - assert!(switch_top(&mut app) < in_the_rail); - app.press(Key::B, Modifiers::COMMAND); - app.eventually("the rail took it back", |tree| top_of(tree) >= in_the_rail); - app.press(Key::Num1, Modifiers::COMMAND); - app.wait_for("area-notes"); - assert!(switch_top(&mut app) >= in_the_rail); - }); - - step("APP-07 the bar's theme switches in one click", || { - let word = app.tree().text("theme-toggle").unwrap_or_default(); - app.click("theme-toggle"); - app.eventually("the word changed", |tree| tree.text("theme-toggle").is_some_and(|now| now != word)); - }); - - let word = app.tree().text("theme-toggle").unwrap_or_default(); - let mut app = app.relaunch_discarding(); - unlock(&mut app, PASSPHRASE); - - step("APP-07 the theme survives a relaunch", || { - assert_eq!(app.tree().text("theme-toggle").unwrap_or_default(), word); - }); - - step("APP-13 quitting takes two clicks, a click elsewhere calls it off", || { - app.click("file-menu"); - let word = app.tree().text("file-quit").unwrap_or_default(); - app.click("file-quit"); - app.eventually("the entry asks", |tree| tree.text("file-quit").is_some_and(|now| now != word)); - app.press(Key::ArrowUp, Modifiers::NONE); - app.eventually("the arrows call it off", |tree| { - tree.text("file-quit").is_some_and(|now| now == word) - }); - app.click("file-quit"); - app.eventually("the entry asks again", |tree| tree.text("file-quit").is_some_and(|now| now != word)); - app.click("file-menu"); - app.eventually("the menu closed", |tree| !tree.has("file-quit")); - app.click("file-menu"); - assert_eq!(app.tree().text("file-quit").unwrap_or_default(), word); - app.click("file-quit"); - app.click("file-quit"); - }); - - app.ended(); -} - -#[test] -fn recette_preferences() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("37_recette_preferences", profile.path()); - app.create_library(); - - step("PRF-01 the panel: its pages and its footer", || { - preferences(&mut app); - for id in [ - "settings-page-general", - "settings-page-variables", - "settings-page-shortcuts", - "settings-page-security", - "settings-cancel", - "settings-apply", - "settings-close", - ] { - assert!(app.has(id), "{id}"); - } - app.capture("preferences"); - }); - - step("PRF-02 theme and density preview, Cancel takes both back", || { - app.click(THEME_DARK); - app.click(COMFORTABLE); - app.click("settings-apply"); - let word = app.tree().text("theme-toggle").unwrap_or_default(); - let before = std::fs::read(app.capture("density-before")).unwrap(); - app.click(THEME_LIGHT); - app.click(COMPACT); - app.eventually("the theme previews", |tree| tree.text("theme-toggle").is_some_and(|now| now != word)); - assert_ne!(before, std::fs::read(app.capture("density-after")).unwrap()); - app.click("settings-cancel"); - app.eventually("the panel closed", |tree| !tree.has("settings-dialog")); - assert_eq!(app.tree().text("theme-toggle").unwrap_or_default(), word); - preferences(&mut app); - assert!(is_on(app.tree().find(THEME_DARK))); - assert!(is_on(app.tree().find(COMFORTABLE))); - }); - - step("PRF-05 three changes waiting are counted, each way out does as it says", || { - app.click(THEME_LIGHT); - app.click(COMPACT); - app.click("setting-locale"); - app.click(ENGLISH); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the footer counts them", |tree| { - tree.text("settings-unapplied").is_some_and(|said| said.contains('3')) - }); - app.capture("unapplied"); - app.click("settings-discard"); - app.eventually("the panel closed", |tree| !tree.has("settings-dialog")); - preferences(&mut app); - assert!(is_on(app.tree().find(THEME_DARK))); - - app.click(THEME_LIGHT); - app.press(Key::Escape, Modifiers::NONE); - app.click("settings-apply-close"); - app.eventually("the panel closed", |tree| !tree.has("settings-dialog")); - preferences(&mut app); - assert!(is_on(app.tree().find(THEME_LIGHT))); - app.click(THEME_DARK); - close(&mut app); - }); - - step("PRF-15 a canvas key refuses the navigation's keys", || { - preferences(&mut app); - app.click("settings-page-shortcuts"); - app.scroll_above("settings-content", "shortcut-field-canvas.pin", "settings-cancel"); - app.click("shortcut-field-canvas.pin"); - assert!(app.has("settings-dialog")); - app.press(Key::ArrowUp, Modifiers::NONE); - app.wait_for("shortcut-error-canvas.pin"); - app.capture("reserved"); - app.press(Key::Escape, Modifiers::NONE); - assert!(app.has("settings-dialog")); - }); - - app.quit(); -}