Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ serde_json.workspace = true
tempfile.workspace = true
tungstenite.workspace = true

# The watcher and host a Linux scenario serves on a bus of its own.
[target.'cfg(target_os = "linux")'.dev-dependencies]
# The watcher and host a Linux journey serves on a bus of its own.
[target.'cfg(target_os = "linux")'.dependencies]
zbus.workspace = true

[lints]
Expand Down
12 changes: 12 additions & 0 deletions e2e/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@ impl Driver {
self.ask(&Request::Settle { max_steps: 10 });
}

/// Until what puts the window out of sight is done. A minimised window paints nothing, as one
/// closed to the tray on macOS: the frame waited for is answered « not painting », which says
/// the window is away and its process alive.
pub(crate) fn settle_out_of_sight(&mut self) {
match exchange(&mut self.stream, &Request::Settle { max_steps: 10 }) {
Ok(Response::Error { message }) if message.contains("not painting") => {}
Ok(Response::Error { message }) => panic!("the application refused to wait: {message}"),
Ok(_) => {}
Err(error) => panic!("the application stopped answering: {error}"),
}
}

pub(crate) fn apply(&mut self, events: Vec<Event>) {
self.ask(&Request::ApplyEvents { events });
}
Expand Down
28 changes: 27 additions & 1 deletion e2e/src/sdk/http.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
use super::App;
use super::{App, Shortcut};
use crate::driver::said;

/// The HTTP area: its rail, its tabs and the request that is open.
pub struct Http<'a>(pub(super) &'a mut App);

impl Http<'_> {
/// A collection, from the empty rail or its button.
pub fn new_collection(&mut self, name: &str) {
self.0.click("http-rail-empty-create", "the button of a first collection");
self.name_new(name);
}

/// A request in a collection, from its ⋯ menu.
pub fn new_request(&mut self, collection: &str, name: &str) {
self.0.click_where("http-node-menu", "the collection's « ⋯ »", |menu| {
said(menu).ends_with(collection)
});
self.0.click("http-node-new", "« New »");
self.0.click("http-node-new-http", "« HTTP request »");
self.name_new(name);
}

/// Names what is being made in the rail.
fn name_new(&mut self, name: &str) {
self.0.fill("http-create-input", "the new one's name", name);
self.0.press(Shortcut::Enter);
self.0.expect("it is in the rail", |tree| {
tree.texts("http-node-name").iter().any(|node| node.ends_with(name))
});
}

/// Opens a draft in a tab of its own.
pub fn new_draft(&mut self) {
self.0.click("http-tab-new", "the button of a new request");
Expand Down
72 changes: 67 additions & 5 deletions e2e/src/sdk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod history;
mod http;
mod json;
mod notes;
mod palette;
mod prefs;
mod rail;
mod rich;
Expand All @@ -26,6 +27,7 @@ mod tags;
mod todo;
mod tools;
mod trash;
mod tray;
mod window;

pub use attachments::Attachments;
Expand All @@ -44,6 +46,7 @@ pub use history::History;
pub use http::Http;
pub use json::{Json, JsonView};
pub use notes::{Kind, Named, Notes, QuickFilter, Sample};
pub use palette::Palette;
pub use prefs::{CardKey, DefaultKind, Density, Indent, Language, Page, Prefs, Switch, Theme};
pub use rail::Rail;
pub use rich::{DrawingSize, Presentation, Rich, RichTool};
Expand All @@ -53,6 +56,7 @@ pub use tags::Tags;
pub use todo::Todo;
pub use tools::Tools;
pub use trash::Trash;
pub use tray::{Tray, TrayEntry};
pub use window::{Area, Window};

use std::ffi::OsString;
Expand All @@ -72,6 +76,20 @@ pub struct App {
room: TempDir,
/// When the last click was.
clicked: Option<Instant>,
/// How many times the window had gone out of sight before it last did.
put_away: u32,
/// The bus the tray is served on.
#[cfg(target_os = "linux")]
session: Option<tray::linux::Session>,
}

/// What a person asks of DevNotes from anywhere, by a key of the whole machine. A second launch
/// stands for the key, which no driver presses.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Global {
Palette,
NewNote,
PasteFromClipboard,
}

impl App {
Expand All @@ -91,6 +109,20 @@ impl App {
Self::launch(journey, vec![(platform::updater::E2E_UPDATES, served.into())]).with_a_library()
}

/// As `open`, the tray on a bus of the journey's own under Linux.
pub fn open_with_a_tray(journey: &'static str) -> Self {
#[cfg(target_os = "linux")]
{
let session = tray::linux::Session::start();
let bus = vec![("DBUS_SESSION_BUS_ADDRESS", session.address.clone().into())];
let mut app = Self::launch(journey, bus);
app.session = Some(session);
app.with_a_library()
}
#[cfg(not(target_os = "linux"))]
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");
let profile = room.path().join("profile");
Expand All @@ -99,7 +131,14 @@ impl App {
}
set.push((platform::dialog::E2E_DIALOG, files::answer(room.path()).into()));
let driver = Driver::launch(journey, profile, terminal(room.path()), set);
App { driver, room, clicked: None }
App {
driver,
room,
clicked: None,
put_away: 0,
#[cfg(target_os = "linux")]
session: None,
}
}

fn with_a_library(mut self) -> Self {
Expand Down Expand Up @@ -218,6 +257,16 @@ impl App {
Help(self)
}

/// The palette.
pub fn palette(&mut self) -> Palette<'_> {
Palette(self)
}

/// The icon in the system's tray.
pub fn tray(&mut self) -> Tray<'_> {
Tray(self)
}

/// The window itself.
pub fn window(&mut self) -> Window<'_> {
Window(self)
Expand Down Expand Up @@ -246,6 +295,23 @@ impl App {
self.key_printed(Key::Semicolon, place, modifiers);
}

/// Asks for something from anywhere on the machine, the window in sight or not.
pub fn press_global(&mut self, global: Global) {
self.driver.hand_over(Some(match global {
Global::Palette => "palette",
Global::NewNote => "new-note",
Global::PasteFromClipboard => "capture",
}));
self.driver.settle();
}

/// DevNotes ends by itself, everything written; started again, its library is unlocked.
pub fn start_after_the_end(&mut self) {
self.driver.ended();
self.driver.start_again();
self.gate().unlock(PASSPHRASE);
}

/// Types a text where the keyboard is.
pub fn type_text(&mut self, text: &str) {
self.driver.apply(vec![Event::Text(text.to_owned())]);
Expand Down Expand Up @@ -319,10 +385,6 @@ impl App {
self.driver.ended();
}

fn start_again(&mut self) {
self.driver.start_again();
}

fn profile(&self) -> &Path {
self.driver.profile()
}
Expand Down
93 changes: 93 additions & 0 deletions e2e/src/sdk/palette.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use super::{App, Shortcut};

/// The palette, over the window or over whatever was on the screen.
pub struct Palette<'a>(pub(super) &'a mut App);

impl Palette<'_> {
/// Opens it by its key in the window.
pub fn open(&mut self) {
self.0.press(Shortcut::Palette);
self.expect_open("the palette opens");
}

/// Types over what its field holds.
pub fn search(&mut self, words: &str) {
self.0.press(Shortcut::SelectAll);
self.0.type_text(words);
}

/// Narrows it to a place or a tag: what is typed, then Enter on the first answer.
pub fn narrow_to(&mut self, words: &str) {
self.search(words);
self.0.expect("the palette offers where to search", |tree| {
tree.count("palette-option") > 0 && !tree.has("palette-chip")
});
self.0.press(Shortcut::Enter);
self.0.expect("the palette is narrowed", |tree| tree.has("palette-chip"));
}

/// Takes the first answer, by Enter.
pub fn choose_first(&mut self) {
self.0.press(Shortcut::Enter);
self.expect_closed("the palette closes");
}

/// Copies the first answer.
pub fn copy_first(&mut self) {
self.0.copy();
}

/// Closes it.
pub fn close(&mut self) {
self.0.press(Shortcut::Escape);
self.expect_closed("the palette closes");
}

/// The palette is open, the keyboard in its field.
pub fn expect_open(&mut self, says: &str) {
self.0.expect(says, |tree| tree.has_focus("palette-input"));
}

/// The palette is not on the screen.
pub fn expect_closed(&mut self, says: &str) {
self.0.expect(says, |tree| !tree.has("palette-input"));
}

/// Some answers are listed, whatever they are.
pub fn expect_answers(&mut self, says: &str) {
self.0
.expect(says, |tree| tree.count("palette-option") > 0 && !tree.has("palette-empty"));
}

/// There is one answer, whatever it is.
pub fn expect_one_answer(&mut self, says: &str) {
self.0.expect(says, |tree| tree.count("palette-option") == 1);
}

/// This is the one answer.
pub fn expect_only(&mut self, words: &str, says: &str) {
self.0.expect(says, |tree| {
let answers = tree.texts("palette-option");
answers.len() == 1 && answers[0].contains(words)
});
}

/// This is among the answers.
pub fn expect_found(&mut self, words: &str, says: &str) {
self.0
.expect(says, |tree| tree.texts("palette-option").iter().any(|answer| answer.contains(words)));
}

/// Nothing is found, and a note named after what was typed is offered.
pub fn expect_creation_offered(&mut self, says: &str) {
self.0.expect(says, |tree| {
tree.has("palette-create") && tree.has("palette-empty") && tree.count("palette-option") == 0
});
}

/// The commands are listed.
pub fn expect_commands(&mut self, says: &str) {
self.0
.expect(says, |tree| tree.count("palette-option") >= 5 && tree.has("palette-group"));
}
}
2 changes: 2 additions & 0 deletions e2e/src/sdk/prefs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub enum Indent {
pub enum Switch {
WrapLines,
CloseToTray,
MinimizeToTray,
CopyAcknowledged,
}

Expand Down Expand Up @@ -165,6 +166,7 @@ impl Prefs<'_> {
match switch {
Switch::WrapLines => self.choose("setting-code-wrap", "the switch of the wrapped lines"),
Switch::CloseToTray => self.choose("setting-close-to-tray", "« Close to tray »"),
Switch::MinimizeToTray => self.choose("setting-minimize-to-tray", "« Minimize to tray »"),
Switch::CopyAcknowledged => {
self.choose("setting-copy-confirmation", "the switch of the copy's acknowledgement");
}
Expand Down
3 changes: 3 additions & 0 deletions e2e/src/sdk/shortcut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub enum Shortcut {
Undo,
/// Ctrl+A.
SelectAll,
/// Ctrl+Alt+P: the palette.
Palette,
/// Ctrl+K: the search.
Search,
/// Ctrl+F.
Expand Down Expand Up @@ -84,6 +86,7 @@ impl Shortcut {
Self::Delete => (Key::Delete, Modifiers::NONE),
Self::Undo => (Key::Z, Modifiers::COMMAND),
Self::SelectAll => (Key::A, Modifiers::COMMAND),
Self::Palette => (Key::P, Modifiers::COMMAND | Modifiers::ALT),
Self::Search => (Key::K, Modifiers::COMMAND),
Self::Find => (Key::F, Modifiers::COMMAND),
Self::GoToLine => (Key::G, Modifiers::COMMAND | Modifiers::ALT),
Expand Down
Loading
Loading