diff --git a/e2e/src/driver.rs b/e2e/src/driver.rs index 613f0d8d..eef944ff 100644 --- a/e2e/src/driver.rs +++ b/e2e/src/driver.rs @@ -133,6 +133,12 @@ impl Tree { self.focused().is_some_and(|node| node.author_id() == Some(id)) } + /// Whether the `n`th control wearing `id` has the keyboard, in reading order. + pub(crate) fn nth_has_focus(&self, id: &str, n: usize) -> bool { + let nth = self.all(id).get(n).copied(); + nth.zip(self.focused()).is_some_and(|(nth, focused)| std::ptr::eq(nth, focused)) + } + /// What the control that has the keyboard says. pub(crate) fn focused_says(&self) -> String { self.focused().map(said).unwrap_or_default() diff --git a/e2e/src/sdk/act.rs b/e2e/src/sdk/act.rs index 6cb5d5e8..47fba777 100644 --- a/e2e/src/sdk/act.rs +++ b/e2e/src/sdk/act.rs @@ -156,6 +156,12 @@ impl App { self.click_at(middle(bounds), PointerButton::Secondary); } + /// The middle button, on the `n`th `id` in reading order, counting from 0. + pub(super) fn middle_click_nth(&mut self, id: &str, n: usize, name: &str) { + let bounds = self.place(name, |tree| tree.all(id).get(n).and_then(|node| node.bounds())); + self.click_at(middle(bounds), PointerButton::Middle); + } + /// A press and a release elsewhere, the pointer moved half way between: what a gesture needs to /// tell a drag from a click. pub(super) fn drag(&mut self, from: Pos2, to: Pos2) { @@ -203,6 +209,12 @@ impl App { self.type_text(text); } + /// As `fill`, the `n`th field wearing `id`, in reading order, counting from 0. + pub(super) fn fill_nth(&mut self, id: &str, n: usize, name: &str, text: &str) { + self.take_nth_keyboard(id, n, name); + self.type_text(text); + } + /// Types over what a field holds. ⚠️ Not by a second click, which selects a word only within /// the double click's delay: the machine's speed. pub(super) fn replace(&mut self, id: &str, name: &str, text: &str) { @@ -215,10 +227,14 @@ impl App { /// click can land in a frame that drops it; the next comes a few frames later — two at once /// would be a double click. pub(super) fn take_keyboard(&mut self, id: &str, name: &str) { + self.take_nth_keyboard(id, 0, name); + } + + fn take_nth_keyboard(&mut self, id: &str, n: usize, name: &str) { let until = Instant::now() + PATIENCE; loop { - self.click(id, name); - if (0..5).any(|_| self.tree().has_focus(id)) { + self.click_nth(id, n, name); + if (0..5).any(|_| self.tree().nth_has_focus(id, n)) { return; } assert!(Instant::now() < until, "« {} »: {name} never took the keyboard", current_step()); diff --git a/e2e/src/sdk/code.rs b/e2e/src/sdk/code.rs new file mode 100644 index 00000000..9c8db130 --- /dev/null +++ b/e2e/src/sdk/code.rs @@ -0,0 +1,65 @@ +use egui::accesskit::Node; + +use super::{App, Shortcut}; +use crate::driver::said; + +/// The request open, written as code. +pub struct Code<'a>(pub(super) &'a mut App); + +impl Code<'_> { + /// Opens the dialog. + pub fn open(&mut self) { + self.0.click("http-code-open", "« Code »"); + self.0.expect("the code is written", |tree| tree.has("http-code-output")); + } + + /// Closes it. + pub fn close(&mut self) { + self.0.press(Shortcut::Escape); + self.0.expect("the dialog closes", |tree| !tree.has("http-code-dialog")); + } + + /// Writes it for another target, found by the filter. + pub fn choose(&mut self, typed: &str, target: &str) { + self.0.replace("http-code-filter", "the filter of the targets", typed); + self.0.click_where("http-code-target", "the target", |row| said(row) == target); + } + + /// Resolves the variables, or leaves them as they are written. + pub fn flip_resolved(&mut self) { + self.0.click("http-code-resolve", "« Resolve the variables »"); + } + + /// Asks for the secrets in clear: the dialog asks before. + pub fn ask_secrets(&mut self) { + self.0.click("http-code-secrets", "« Include the secrets »"); + self.0 + .expect("the dialog asks before writing them", |tree| tree.has("http-code-secrets-ask")); + } + + /// Answers yes. + pub fn include_secrets(&mut self) { + self.0.click("http-code-secrets-yes", "the yes"); + } + + /// Copies the code. + pub fn copy(&mut self) { + self.0.click("http-code-copy", "« Copy »"); + } + + /// The code says this. + pub fn expect(&mut self, words: &str, says: &str) { + self.0.expect(says, |tree| { + let code = tree.find("http-code-output").and_then(Node::label); + code.is_some_and(|code| code.contains(words)) + }); + } + + /// The code says nothing of this. + pub fn expect_without(&mut self, words: &str, says: &str) { + self.0.expect(says, |tree| { + let code = tree.find("http-code-output").and_then(Node::label); + code.is_some_and(|code| !code.contains(words)) + }); + } +} diff --git a/e2e/src/sdk/environments.rs b/e2e/src/sdk/environments.rs new file mode 100644 index 00000000..bcbbb80c --- /dev/null +++ b/e2e/src/sdk/environments.rs @@ -0,0 +1,106 @@ +use egui::accesskit::Node; + +use super::App; +use crate::driver::{Tree, said}; + +/// The environments requests are sent with: their page, and the menu that chooses one. +pub struct Environments<'a>(pub(super) &'a mut App); + +impl Environments<'_> { + /// Opens their page, from the menu of the environments. + pub fn open(&mut self) { + self.0.click("http-environment-picker", "the menu of the environments"); + self.0.click("http-environment-manage", "« Manage »"); + self.0.expect("the environments open", |tree| tree.has("http-environments")); + } + + /// Goes back to the requests. + pub fn leave(&mut self) { + self.0.click("http-environments-open", "« Environments » in the rail"); + self.0.expect("the requests are back", |tree| !tree.has("http-environments")); + } + + /// Makes an environment. + pub fn create(&mut self, name: &str) { + self.0.click("http-environment-create-open", "« New environment »"); + self.0.fill("http-environment-create-input", "its name", name); + self.0.click("http-environment-create-submit", "« Create »"); + self.0.expect("it is shown", |tree| { + tree.find("http-environment-name").and_then(Node::value) == Some(name) + }); + } + + /// Gives the environment shown another colour, counted from 0. + pub fn choose_colour(&mut self, n: usize) { + self.0.click_nth("http-environment-colour", n, "a colour"); + self.0.expect("the colour is chosen", |tree| { + let colours = tree.all("http-environment-colour"); + colours + .get(n) + .is_some_and(|colour| crate::driver::is_on(colour) || colour.is_selected() == Some(true)) + }); + } + + /// Adds a variable to what is shown. + pub fn add_variable(&mut self, name: &str, value: &str) { + let at = self.0.tree().count("http-variable-name") - 1; + self.0.fill_nth("http-variable-name", at, "the variable's name", name); + self.type_value(at, value); + } + + /// Adds a secret to the environment shown: its value is masked. + pub fn add_secret(&mut self, name: &str, value: &str) { + let at = self.0.tree().count("http-variable-name") - 1; + self.add_variable(name, value); + self.0.click_nth("http-variable-kind", at, "the variable's kind"); + self.0.click("http-variable-kind-2", "« Secret »"); + self.0.expect("its value is masked", |tree| { + tree.has("http-variable-reveal") && nth_value(tree, at).is_some_and(|held| held != value) + }); + } + + /// Types the value of the variable a *Set in…* made. + pub fn type_value_of(&mut self, name: &str, value: &str) { + let at = self.0.seen("the variable is in the table", |tree| { + let mut names = tree.all("http-variable-name").into_iter(); + names.position(|field| field.value() == Some(name)) + }); + self.type_value(at, value); + } + + /// Asks before a request that could change something leaves with the environment shown. + pub fn protect(&mut self) { + self.0.click("http-environment-protected", "« Protected »"); + self.0 + .expect("the page says what it changes", |tree| tree.has("http-environment-protected-note")); + } + + /// Chooses the environment the requests are sent with, from its menu. + pub fn choose(&mut self, name: &str) { + self.0.click("http-environment-picker", "the menu of the environments"); + self.0 + .click_where("http-environment-option", "the environment in the menu", |option| { + said(option).contains(name) + }); + self.0.expect("it is the one chosen", |tree| { + tree.text("http-environment-picker").is_some_and(|said| said.contains(name)) + }); + } + + /// A variable of what is shown has this value, in clear. + pub fn expect_value(&mut self, value: &str, says: &str) { + self.0.expect(says, |tree| { + let mut values = tree.all("http-variable-value").into_iter(); + values.any(|field| field.value() == Some(value)) + }); + } + + fn type_value(&mut self, at: usize, value: &str) { + self.0.fill_nth("http-variable-value", at, "the variable's value", value); + self.0.expect("the value is typed", |tree| nth_value(tree, at) == Some(value)); + } +} + +fn nth_value(tree: &Tree, at: usize) -> Option<&str> { + tree.all("http-variable-value").get(at).copied().and_then(Node::value) +} diff --git a/e2e/src/sdk/files.rs b/e2e/src/sdk/files.rs index a841795c..d4d3e3ba 100644 --- a/e2e/src/sdk/files.rs +++ b/e2e/src/sdk/files.rs @@ -18,6 +18,12 @@ impl Files<'_> { self.put(name, server::PIXEL); } + /// Puts a file among the person's own: its path, as a script writes it. + pub fn put_apart(&mut self, name: &str, bytes: &[u8]) -> String { + self.put(name, bytes); + self.path(name).display().to_string().replace('\\', "/") + } + /// Answers this file to the dialogs from now on: the one to read, or the one to write. pub fn answer(&mut self, name: &str) { let path = self.path(name).display().to_string(); diff --git a/e2e/src/sdk/http.rs b/e2e/src/sdk/http.rs index 3f92d525..a5873d60 100644 --- a/e2e/src/sdk/http.rs +++ b/e2e/src/sdk/http.rs @@ -1,46 +1,210 @@ +use egui::accesskit::Node; +use egui::{Key, Modifiers, Pos2}; + use super::{App, Shortcut}; -use crate::driver::said; +use crate::driver::{Tree, said, within}; -/// The HTTP area: its rail, its tabs and the request that is open. +/// The HTTP area: its rail, its tabs, its cookies, and what it asks before DevNotes quits. pub struct Http<'a>(pub(super) &'a mut App); impl Http<'_> { - /// A collection, from the empty rail or its button. + /// A collection, from the empty rail. 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 »"); + /// A folder in a collection, from its ⋯ menu. + pub fn new_folder(&mut self, parent: &str, name: &str) { + self.open_menu(parent); + self.0.click("http-node-new-folder", "« New folder »"); 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); + /// A request in a collection or a folder, from its ⋯ menu. + pub fn new_request(&mut self, parent: &str, name: &str) { + self.new_of_kind(parent, "http-node-new-http", "« HTTP request »"); + self.name_new(name); + } + + /// A WebSocket in a collection or a folder, from its ⋯ menu. + pub fn new_socket(&mut self, parent: &str, name: &str) { + self.new_of_kind(parent, "http-node-new-websocket", "« WebSocket »"); + self.name_new(name); + } + + /// Clicks a row of the rail, which takes the keyboard: a request opens in its tab. + pub fn take_row(&mut self, name: &str) { + self.0 + .click_where("http-node-name", "the row in the rail", |node| is(node, name)); + } + + /// Opens a request from the rail. + pub fn open(&mut self, name: &str) { + self.take_row(name); + self.0.expect("the request opens", |tree| { + let shown = tree.find("http-request-name").and_then(Node::value); + tree.has("http-url") && shown == Some(name) + }); + } + + /// Folds a collection or a folder, or opens it. + pub fn fold(&mut self, name: &str) { + self.0 + .click_where("http-node-twisty", "the row's triangle", |node| said(node).ends_with(name)); + } + + /// Renames a row in place, by F2, the field left by a click elsewhere. + pub fn rename(&mut self, name: &str, into: &str) { + self.take_row(name); + self.0.key(Key::F2, Modifiers::NONE); + self.0.replace("http-rename-input", "the row's name", into); + self.0.click("http-rail-title", "the rail's title"); + self.expect_renamed(name, into); + } + + /// Renames a row in place, from its ⋯ menu, by Enter. + pub fn rename_from_the_menu(&mut self, name: &str, into: &str) { + self.open_menu(name); + self.0.click("http-node-rename", "« Rename »"); + self.0.replace("http-rename-input", "the row's name", into); 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)) + self.expect_renamed(name, into); + } + + /// Asks for a row's deletion from its ⋯ menu: the rail asks before. + pub fn ask_deletion(&mut self, name: &str) { + self.open_menu(name); + self.0.click("http-node-delete", "« Delete »"); + self.0 + .expect("the rail asks before deleting", |tree| tree.has("http-delete-confirm")); + } + + /// Answers no to the deletion asked. + pub fn cancel_deletion(&mut self) { + self.0.click("http-delete-cancel", "« Cancel »"); + self.0.expect("the question goes", |tree| !tree.has("http-delete-confirm")); + } + + /// Answers yes to the deletion asked. + pub fn confirm_deletion(&mut self) { + self.0.click("http-delete-submit", "« Delete »"); + self.0.expect("the question goes", |tree| !tree.has("http-delete-confirm")); + } + + /// Has every request under a collection send a *Bearer* token and a header, in its *Settings…*. + pub fn set_below(&mut self, collection: &str, token: &str, (name, value): (&str, &str)) { + self.open_menu(collection); + self.0.click("http-node-settings", "« Settings… »"); + self.0.click("http-auth-kind", "the auth's menu"); + // A collection has nothing above it: « Inherited » is not offered. + self.0.click("http-auth-kind-2", "« Bearer »"); + self.0.fill("http-auth-secret", "the token", token); + let first = self.0.seen("the headers below", |tree| { + let table = tree.find("http-settings-headers-table").and_then(Node::bounds)?; + tree.all("http-kv-key").into_iter().position(|cell| within(cell, table)) }); + self.0.fill_nth("http-kv-key", first, "the header", &format!("{name}: {value}")); + self.0.click("http-settings-save", "« Save »"); + self.0.expect("the settings close", |tree| !tree.has("http-settings-save")); } /// Opens a draft in a tab of its own. pub fn new_draft(&mut self) { + let tabs = self.0.tree().count("http-tab-open"); self.0.click("http-tab-new", "the button of a new request"); - self.0.expect("a draft opens in its tab", |tree| tree.has("http-url")); + self.0.expect("a draft opens in its tab", |tree| { + tree.has("http-url") && tree.count("http-tab-open") == tabs + 1 + }); } - /// Closes the only tab, its changes not kept. - pub fn close_tab_discarding(&mut self) { - self.0.click("http-tab-close", "the tab's cross"); - self.0.click("http-close-discard", "« Do not save »"); - self.0.expect("the tab closes", |tree| !tree.has("http-tab-open")); + /// Opens a GraphQL draft in a tab of its own. + pub fn new_graphql_draft(&mut self) { + self.0.click("http-tab-new-kind", "the menu beside the new request"); + self.0.click("http-new-kind-graphql", "« GraphQL »"); + self.0.expect("a draft opens in its tab", |tree| tree.has("http-graphql-query")); + } + + /// Shows the tab of a request. + pub fn show_tab(&mut self, name: &str) { + self.0 + .click_where("http-tab-open", "the request's tab", |tab| is_tab(tab, name)); + self.0.expect("the request is shown", |tree| { + tree.find("http-request-name").and_then(Node::value) == Some(name) + }); + } + + /// Closes the last tab by its cross, its changes not kept. + pub fn close_last_tab_discarding(&mut self) { + let tabs = self.0.tree().count("http-tab-open"); + self.0.click_nth("http-tab-close", tabs - 1, "the last tab's cross"); + self.discard(tabs); + } + + /// Closes the last tab by the middle button, its changes not kept. + pub fn close_last_tab_with_the_middle_button(&mut self) { + let tabs = self.0.tree().count("http-tab-open"); + self.0.middle_click_nth("http-tab-open", tabs - 1, "the last tab"); + self.discard(tabs); + } + + /// Drags the first tab past the second. + pub fn drag_first_tab(&mut self) { + let nth = |n: usize| move |tree: &Tree| tree.all("http-tab-open").get(n).and_then(|tab| tab.bounds()); + let (from, to) = (self.0.place("the first tab", nth(0)), self.0.place("the second tab", nth(1))); + #[expect(clippy::cast_possible_truncation, reason = "points on a screen")] + let at = |x: f64| Pos2::new(x as f32, f64::midpoint(from.y0, from.y1) as f32); + self.0.drag(at(from.x0 + 20.0), at(to.x1)); + } + + /// Opens the cookies kept. + pub fn open_cookies(&mut self) { + self.0.click("http-cookies-open", "« Cookies »"); + self.0.expect("the cookies are listed", |tree| tree.has("http-cookies-dialog")); + } + + /// Throws every cookie away, asked twice, and closes them. + pub fn throw_cookies_away(&mut self) { + self.0.click("http-cookies-clear", "« Clear »"); + self.0.click("http-cookies-clear-confirm", "« Clear » again"); + self.0.expect("no cookie is left", |tree| tree.has("http-cookies-empty")); + self.0.click("http-cookies-close", "the cookies' cross"); + self.0.expect("the cookies close", |tree| !tree.has("http-cookies-dialog")); + } + + /// 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")); + } + + /// Stays, the changes as they are. + pub fn cancel_quitting(&mut self) { + self.0.click("http-leave-cancel", "« Cancel »"); + self.0.expect("the question goes", |tree| !tree.has("http-leave-dialog")); + } + + /// Saves every change, and DevNotes ends. + pub fn save_and_quit(&mut self) { + self.0.click("http-leave-save", "the button that saves"); + self.0.ended(); + } + + /// 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); + } + + /// The move just made is said, with these words in it. + pub fn expect_move_said(&mut self, words: &str, says: &str) { + self.0 + .expect(says, |tree| tree.text("http-rail-moved").is_some_and(|said| said.contains(words))); + } + + /// The deletion asked says what would go. + pub fn expect_deletion_counted(&mut self, says: &str) { + self.0.expect(says, |tree| tree.has("http-delete-count")); } /// As many tabs are open. @@ -48,4 +212,67 @@ impl Http<'_> { self.0 .expect(says, |tree| tree.has("http-rail-title") && tree.count("http-tab-open") == count); } + + /// The tabs open are these, left to right. + pub fn expect_tabs_in_order(&mut self, names: &[&str], says: &str) { + self.0.expect(says, |tree| { + let tabs = tree.all("http-tab-open"); + tabs.len() == names.len() && tabs.iter().zip(names).all(|(tab, name)| is_tab(tab, name)) + }); + } + + /// This cookie is listed. + pub fn expect_cookie(&mut self, name: &str, says: &str) { + self.0 + .expect(says, |tree| tree.texts("http-cookie").iter().any(|it| it == name)); + } + + /// Opens the ⋯ menu of a row. + pub(super) fn open_menu(&mut self, name: &str) { + self.0 + .click_where("http-node-menu", "the row's « ⋯ »", |menu| said(menu).ends_with(name)); + } + + fn new_of_kind(&mut self, parent: &str, id: &str, name: &str) { + self.open_menu(parent); + self.0.click("http-node-new", "« New »"); + self.0.click(id, 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| has_row(tree, name)); + } + + fn expect_renamed(&mut self, name: &str, into: &str) { + self.0 + .expect("the row has its new name", |tree| has_row(tree, into) && !has_row(tree, name)); + } + + fn discard(&mut self, tabs: usize) { + self.0.click("http-close-discard", "« Do not save »"); + self.0.expect("the tab closes", |tree| { + !tree.has("http-close-dialog") && tree.count("http-tab-open") + 1 == tabs + }); + } +} + +fn has_row(tree: &Tree, name: &str) -> bool { + tree.all("http-node-name").into_iter().any(|row| is(row, name)) +} + +/// A row says its name, a request's after its method. +fn is(row: &Node, name: &str) -> bool { + named(&said(row), name) +} + +/// A tab says its method, its name, then whether it has changes. +fn is_tab(tab: &Node, name: &str) -> bool { + named(said(tab).split(',').next().unwrap_or_default(), name) +} + +fn named(said: &str, name: &str) -> bool { + said == name || said.split_once(' ').is_some_and(|(_, rest)| rest == name) } diff --git a/e2e/src/sdk/json.rs b/e2e/src/sdk/json.rs index c6865602..ec1ad044 100644 --- a/e2e/src/sdk/json.rs +++ b/e2e/src/sdk/json.rs @@ -45,6 +45,18 @@ impl Json<'_> { self.0.click_where("json-line", "the line of the tree", |node| at(node, path)); } + /// Selects an entry of the tree. + pub fn select_in_the_tree(&mut self, path: &str) { + self.flip_in_the_tree(path); + self.expect_selected(path, "the entry is selected"); + } + + /// The tree lists this entry. + pub fn expect_listed(&mut self, path: &str, says: &str) { + self.0 + .expect(says, |tree| tree.all("json-line").into_iter().any(|line| at(line, path))); + } + /// Opens every node. pub fn open_all(&mut self) { self.0.click("json-open-all", "« Open all »"); diff --git a/e2e/src/sdk/mod.rs b/e2e/src/sdk/mod.rs index f20314c9..2bb56432 100644 --- a/e2e/src/sdk/mod.rs +++ b/e2e/src/sdk/mod.rs @@ -6,8 +6,10 @@ mod attachments; mod board; mod calc; mod clipboard; +mod code; mod drawing; mod editor; +mod environments; mod fields; mod files; mod filters; @@ -20,9 +22,14 @@ mod notes; mod palette; mod prefs; mod rail; +mod request; +mod response; mod rich; +mod runner; mod selection; +mod sends; mod shortcut; +mod socket; mod tags; mod todo; mod tools; @@ -34,9 +41,11 @@ pub use attachments::Attachments; pub use board::{Board, Place}; pub use calc::Calc; pub use clipboard::Clipboard; +pub use code::Code; pub use drawing::{Drawing, Spot, Tool}; pub use editor::Editor; pub use egui::Key; +pub use environments::Environments; pub use fields::Fields; pub use files::Files; pub use filters::{FilterMenu, Filters, GroupBy, SortBy}; @@ -49,9 +58,14 @@ 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 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 selection::Selection; +pub use sends::Sends; pub use shortcut::Shortcut; +pub use socket::Socket; pub use tags::Tags; pub use todo::Todo; pub use tools::{Copied, Given, Tools}; @@ -78,6 +92,9 @@ pub struct App { clicked: Option, /// How many times the window had gone out of sight before it last did. put_away: u32, + /// The journey widened the window: a launch again does too, the system having fitted it to its + /// screen. + wide: bool, /// The bus the tray is served on. #[cfg(target_os = "linux")] session: Option, @@ -136,6 +153,7 @@ impl App { room, clicked: None, put_away: 0, + wide: false, #[cfg(target_os = "linux")] session: None, } @@ -247,6 +265,51 @@ impl App { Http(self) } + /// The request open. + pub fn request(&mut self) -> Request<'_> { + Request(self) + } + + /// The answer under the request open. + pub fn response(&mut self) -> Response<'_> { + Response(self) + } + + /// The WebSocket open. + pub fn socket(&mut self) -> Socket<'_> { + Socket(self) + } + + /// The environments requests are sent with. + pub fn environments(&mut self) -> Environments<'_> { + Environments(self) + } + + /// The request open, written as code. + pub fn code(&mut self) -> Code<'_> { + Code(self) + } + + /// The history of what was sent. + pub fn sends(&mut self) -> Sends<'_> { + Sends(self) + } + + /// A collection's run. + pub fn runner(&mut self) -> Runner<'_> { + Runner(self) + } + + /// A server on this machine that answers the journey's requests: its address. + pub fn serve_api(&mut self) -> String { + format!("http://127.0.0.1:{}", server::serve()) + } + + /// A WebSocket server on this machine that sends each text back: its address. + pub fn serve_socket(&mut self) -> String { + format!("ws://127.0.0.1:{}", server::serve_socket()) + } + /// The preferences. pub fn prefs(&mut self) -> Prefs<'_> { Prefs(self) @@ -308,7 +371,7 @@ impl App { /// 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.start_again(); self.gate().unlock(PASSPHRASE); } @@ -331,7 +394,7 @@ impl App { pub fn relaunch(&mut self) { self.driver.hand_over(Some("quit")); self.driver.ended(); - self.driver.start_again(); + self.start_again(); } /// As `relaunch`, through the gate with the journey's phrase. @@ -374,6 +437,13 @@ impl App { assert!(!cfg!(target_os = "linux") || !fault, "« {} »: {says}\n{wrote}", current_step()); } + fn start_again(&mut self) { + self.driver.start_again(); + if self.wide { + self.window().widen(); + } + } + /// DevNotes started a second time while it runs: the window comes back on the screen. fn launch_again(&mut self) { self.driver.hand_over(None); diff --git a/e2e/src/sdk/request.rs b/e2e/src/sdk/request.rs new file mode 100644 index 00000000..4e98fb94 --- /dev/null +++ b/e2e/src/sdk/request.rs @@ -0,0 +1,374 @@ +use egui::accesskit::Node; + +use super::{App, Shortcut}; +use crate::driver::{Tree, said}; + +/// The request open: its address, its parts, and what is done with it. +pub struct Request<'a>(pub(super) &'a mut App); + +/// A method of the menu. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Method { + Get, + Post, +} + +/// How a request authenticates. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Auth<'a> { + Inherited, + Basic { name: &'a str, password: &'a str }, + Bearer(&'a str), + ApiKey { name: &'a str, value: &'a str }, +} + +/// A body, as it is written in its part. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Body<'a> { + Json(&'a str), + /// A field and its value. + Form(&'a str, &'a str), + /// A field and its value, then a field that is the file answered to the dialog. + Multipart((&'a str, &'a str), &'a str), + /// The file answered to the dialog. + File, +} + +/// When a script runs. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Script { + Before, + After, + Tests, +} + +impl Request<'_> { + /// Types over the request's name. + pub fn type_name(&mut self, name: &str) { + self.0.replace("http-request-name", "the request's name", name); + } + + /// Types an address over the one written. + pub fn type_url(&mut self, url: &str) { + self.0.replace("http-url", "the address", url); + self.expect_url(url, "the address is typed"); + } + + /// Types at the end of the address. + pub fn add_to_url(&mut self, words: &str) { + self.0.take_keyboard("http-url", "the address"); + self.0.press(Shortcut::LineEnd); + self.0.type_text(words); + } + + /// Chooses a method. + pub fn choose_method(&mut self, method: Method) { + self.0.click("http-method", "the method's menu"); + match method { + Method::Get => self.0.click("http-method-0", "« GET »"), + Method::Post => self.0.click("http-method-1", "« POST »"), + } + } + + /// Ticks or unticks a parameter, counted from 0. + pub fn flip_param(&mut self, n: usize) { + self.go_to("params"); + self.0.click_nth("http-kv-enabled", n, "the parameter's box"); + } + + /// Types a header as it is read, « Name: value », in the first row. + pub fn type_header(&mut self, header: &str) { + self.go_to("headers"); + self.0.fill_nth("http-kv-key", 0, "the header's name", header); + } + + /// Chooses how it authenticates. + pub fn choose_auth(&mut self, auth: Auth<'_>) { + self.go_to("auth"); + self.0.click("http-auth-kind", "the auth's menu"); + match auth { + Auth::Inherited => self.0.click("http-auth-kind-0", "« Inherited »"), + Auth::Basic { name, password } => { + self.0.click("http-auth-kind-2", "« Basic »"); + self.0.replace("http-auth-username", "the name", name); + self.0.replace("http-auth-secret", "the password", password); + } + Auth::Bearer(token) => { + self.0.click("http-auth-kind-3", "« Bearer »"); + self.0.replace("http-auth-secret", "the token", token); + } + Auth::ApiKey { name, value } => { + self.0.click("http-auth-kind-4", "« API key »"); + self.0.replace("http-auth-key-name", "the key's name", name); + self.0.replace("http-auth-secret", "the key's value", value); + } + } + } + + /// Shows the auth's secret, or hides it again. + pub fn flip_secret(&mut self) { + self.go_to("auth"); + self.0.click("http-auth-reveal", "the secret's eye"); + } + + /// Writes a body. + pub fn type_body(&mut self, body: Body<'_>) { + self.go_to("body"); + match body { + Body::Json(text) => { + self.0.click("http-body-kind-1", "« JSON »"); + self.type_over("http-body-text", "the body", text); + } + Body::Form(key, value) => { + self.0.click("http-body-kind-3", "« Form »"); + self.0.fill_nth("http-kv-key", 0, "the field's name", key); + self.0.fill_nth("http-kv-value", 0, "the field's value", value); + } + Body::Multipart((key, value), file) => { + self.0.click("http-body-kind-4", "« Multipart »"); + self.0.fill_nth("http-part-key", 0, "the part's name", key); + self.0.fill_nth("http-part-value", 0, "the part's value", value); + self.0.fill_nth("http-part-key", 1, "the next part's name", file); + self.0.click_nth("http-part-kind", 1, "the next part's kind"); + self.0.click("http-part-choose", "the button that chooses its file"); + } + Body::File => { + self.0.click("http-body-kind-5", "« File »"); + self.0.click("http-body-choose", "the button that chooses the file"); + } + } + } + + /// Writes a script, over what it held. + pub fn type_script(&mut self, script: Script, code: &str) { + self.show_script(script); + self.type_over("http-script-code", "the script", code); + } + + /// Shows a script. + pub fn show_script(&mut self, script: Script) { + match script { + Script::Before => { + self.go_to("scripts"); + self.0.click("http-script-phase-0", "« Before the request »"); + } + Script::After => { + self.go_to("scripts"); + self.0.click("http-script-phase-1", "« After the response »"); + } + Script::Tests => self.go_to("tests"), + } + } + + /// Writes a GraphQL query. + pub fn type_query(&mut self, query: &str) { + self.go_to("query"); + self.type_over("http-graphql-query", "the query", query); + } + + /// Adds the variables the query lacks. + pub fn add_missing_variables(&mut self) { + self.0.click("http-graphql-add", "« Add »"); + } + + /// Sends it, Ctrl+Enter, whatever comes of it: the last answer is cleared before. + pub fn send(&mut self) { + if self.0.tree().has("http-response-clear") { + self.0.click("http-response-clear", "« Clear »"); + self.0 + .expect("the last answer is cleared", |tree| tree.has("http-response-idle")); + } + self.0.press(Shortcut::Send); + } + + /// Sends it to an address. + pub fn send_to(&mut self, url: &str) { + self.type_url(url); + self.send(); + } + + /// Cancels the send under way. + pub fn cancel_send(&mut self) { + self.0.expect("the send is under way", |tree| tree.has("http-response-sending")); + self.0.click("http-send", "« Cancel »"); + } + + /// Saves it, Ctrl+S. + pub fn save(&mut self) { + self.0.press(Shortcut::Save); + self.0.expect("the request is saved", |tree| tree.is_disabled("http-save")); + } + + /// Saves a draft, Ctrl+S, under a name, in the first place offered. + pub fn save_as(&mut self, name: &str) { + self.0.press(Shortcut::Save); + self.0.replace("http-save-name", "the request's name", name); + self.0.click("http-save-submit", "« Save »"); + self.0.expect("the request is saved", |tree| { + !tree.has("http-save-dialog") && tree.is_disabled("http-save") + }); + } + + /// Answers yes to the question of a protected environment. + pub fn send_anyway(&mut self) { + self.0.click("http-protected-send", "the yes"); + } + + /// Answers no to the question of a protected environment. + pub fn do_not_send(&mut self) { + self.0.click("http-protected-cancel", "« Cancel »"); + self.0.expect("the question goes", |tree| !tree.has("http-protected-confirm")); + } + + /// Points at a variable the request uses: its card. + pub fn point_at_variable(&mut self, name: &str) { + let written = format!("{{{{{name}}}}}"); + let place = self.0.place("the variable under the address", |tree| { + let mut chips = tree.all("http-used-variable").into_iter(); + chips.find(|chip| said(chip) == written).and_then(Node::bounds) + }); + self.0.move_over(place); + } + + /// Shows the secret of the card pointed at. + pub fn reveal_variable(&mut self) { + self.0.click("http-used-variable-reveal", "« Show »"); + } + + /// *Set in…*, on the card of a variable set nowhere. + pub fn define_variable(&mut self) { + self.0.click("http-used-variable-define", "« Set in… »"); + self.0.expect("where it goes is shown", |tree| tree.has("http-environments")); + } +} + +impl Request<'_> { + /// The address reads so. + pub fn expect_url(&mut self, url: &str, says: &str) { + self.0 + .expect(says, |tree| tree.find("http-url").and_then(Node::value) == Some(url)); + } + + /// The parameters are these, whether they are sent or not. + pub fn expect_params(&mut self, names: &[&str], says: &str) { + self.0.expect(says, |tree| { + let mut keys = values(tree, "http-kv-key"); + // The last row is the one to come. + keys.pop(); + keys == names + }); + } + + /// The first header is this, split into its two cells. + pub fn expect_first_header(&mut self, name: &str, value: &str, says: &str) { + self.0.expect(says, |tree| { + values(tree, "http-kv-key").first().map(String::as_str) == Some(name) + && values(tree, "http-kv-value").first().map(String::as_str) == Some(value) + }); + } + + /// The auth is inherited, and says from where. + pub fn expect_inherited_from(&mut self, name: &str, says: &str) { + self.go_to("auth"); + self.0 + .expect(says, |tree| tree.text("http-auth-inherited").is_some_and(|said| said.contains(name))); + } + + /// The auth's secret reads so. + pub fn expect_secret(&mut self, secret: &str, says: &str) { + self.0 + .expect(says, |tree| tree.find("http-auth-secret").and_then(Node::value) == Some(secret)); + } + + /// The auth's secret is masked. + pub fn expect_secret_masked(&mut self, secret: &str, says: &str) { + self.0.expect(says, |tree| { + tree.find("http-auth-secret") + .and_then(Node::value) + .is_some_and(|held| held != secret) + }); + } + + /// The body is a JSON that reads, and the type it leaves as is said. + pub fn expect_json_valid(&mut self, says: &str) { + self.0.expect(says, |tree| { + let sent_as = tree.text("http-body-type"); + tree.has("http-body-valid") && sent_as.is_some_and(|said| said.contains("application/json")) + }); + } + + /// The query's variables that have no value are named. + pub fn expect_missing_variable(&mut self, name: &str, says: &str) { + self.0.expect(says, |tree| { + tree.has("http-graphql-missing") + && tree.texts("http-graphql-variable").iter().any(|it| it == name) + }); + } + + /// The query lacks no variable. + pub fn expect_no_missing_variable(&mut self, says: &str) { + self.0 + .expect(says, |tree| tree.has("http-graphql-variables") && !tree.has("http-graphql-missing")); + } + + /// The card pointed at says a variable's value. + pub fn expect_variable_value(&mut self, value: &str, says: &str) { + self.0 + .expect(says, |tree| tree.text("http-used-variable-value").as_deref() == Some(value)); + } + + /// The card pointed at says where the variable comes from. + pub fn expect_variable_from(&mut self, place: &str, says: &str) { + self.0.expect(says, |tree| { + tree.text("http-used-variable-from").is_some_and(|said| said.contains(place)) + }); + } + + /// The card pointed at masks the variable's value. + pub fn expect_variable_masked(&mut self, says: &str) { + self.0.expect(says, |tree| { + tree.text("http-used-variable-value") + .is_some_and(|said| !said.is_empty() && said.chars().all(|it| it == '•')) + }); + } + + /// A protected environment asks before it leaves. + pub fn expect_asked_before_sending(&mut self, says: &str) { + self.0 + .expect(says, |tree| tree.has("http-protected-confirm") && !tree.has("http-response-status")); + } + + /// The script shown is this one. + pub fn expect_script(&mut self, code: &str, says: &str) { + self.0 + .expect(says, |tree| tree.find("http-script-code").and_then(Node::value) == Some(code)); + } + + /// Shows a part of the request, under « … » when the window is too narrow for its tab. + fn go_to(&mut self, part: &str) { + let tab = format!("http-section-{part}"); + let says = format!("the part « {part} » of the request"); + self.0.expect(&says, |tree| tree.has(&tab) || tree.has("http-section-more")); + if self.0.tree().has(&tab) { + self.0.click(&tab, &says); + } else { + self.0.click("http-section-more", "the parts left out"); + self.0.click(&format!("http-section-more-{part}"), &says); + } + } + + /// Types over what an editor of several lines holds. + fn type_over(&mut self, id: &str, name: &str, text: &str) { + self.0.take_keyboard(id, name); + self.0.press(Shortcut::SelectAll); + self.0.paste(text); + self.0 + .expect(&format!("{name} is typed"), |tree| tree.find(id).and_then(Node::value) == Some(text)); + } +} + +/// What the fields wearing `id` hold, in reading order. +fn values(tree: &Tree, id: &str) -> Vec { + let value = |node: &Node| node.value().unwrap_or_default().to_owned(); + tree.all(id).into_iter().map(value).collect() +} diff --git a/e2e/src/sdk/response.rs b/e2e/src/sdk/response.rs new file mode 100644 index 00000000..92ad5794 --- /dev/null +++ b/e2e/src/sdk/response.rs @@ -0,0 +1,198 @@ +use super::App; +use crate::driver::said; + +/// The answer under the request. +pub struct Response<'a>(pub(super) &'a mut App); + +/// How the body is read. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum BodyView { + Formatted, + Raw, + Graph, + Tree, +} + +/// A part of the answer. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Part { + Body, + Tests, + Headers, + Cookies, + Timeline, +} + +impl Response<'_> { + /// Reads the body another way. + pub fn show_as(&mut self, view: BodyView) { + let (id, name) = match view { + BodyView::Formatted => ("http-response-view-0", "« Formatted »"), + BodyView::Raw => ("http-response-view-1", "« Raw »"), + BodyView::Graph => ("http-response-view-2", "« Graph »"), + BodyView::Tree => ("http-response-view-3", "« Tree »"), + }; + self.0.click(id, name); + } + + /// Shows a part of the answer. + pub fn go_to(&mut self, part: Part) { + let (id, name) = match part { + Part::Body => ("http-response-section-body", "« Body »"), + Part::Tests => ("http-response-section-tests", "« Tests »"), + Part::Headers => ("http-response-section-headers", "« Headers »"), + Part::Cookies => ("http-response-section-cookies", "« Cookies »"), + Part::Timeline => ("http-response-section-timeline", "« Timeline »"), + }; + self.0.click(id, name); + } + + /// Keeps the entry selected in the explorer in a variable, by a rule each answer follows. + pub fn extract_to(&mut self, variable: &str) { + self.0.click("json-extract", "« Extract to a variable »"); + self.0.replace("http-extract-name", "the variable's name", variable); + self.0.click("http-extract-submit", "« Extract »"); + self.0.expect("the rule is made", |tree| !tree.has("http-extract-dialog")); + } + + /// Saves the whole body in the file answered to the dialog. + pub fn save_to_file(&mut self) { + self.0.click("http-response-save", "« Save as a file »"); + } + + /// Keeps the answer as a note, under this title. + pub fn save_as_note(&mut self, title: &str) { + self.0.click("http-response-save-note", "« Save as note »"); + self.0.replace("save-as-note-title", "the note's title", title); + self.0.click("save-as-note-submit", "« Save »"); + self.0.expect("the note is saved", |tree| !tree.has("save-as-note-title")); + } + + /// Opens the script that stopped the send, at its line. + pub fn open_script(&mut self) { + self.0.click("http-script-open", "« Open the script »"); + } + + /// Lets the file a script asked for be sent. + pub fn allow_file(&mut self) { + self.0.click("http-script-file-send", "the yes"); + } + + /// Refuses the file a script asked for. + pub fn refuse_file(&mut self) { + self.0.click("http-script-file-cancel", "« Cancel »"); + self.0.expect("the question goes", |tree| !tree.has("http-script-file-confirm")); + } + + /// Opens the console. + pub fn open_console(&mut self) { + self.0.click("http-console-unfold", "the console's bar"); + } + + /// Empties the console. + pub fn clear_console(&mut self) { + self.0.click("http-console-clear", "the console's « Clear »"); + self.0.expect("the console is empty", |tree| !tree.has("http-console-line")); + } + + /// The answer came, with this status. + pub fn expect_status(&mut self, status: &str, says: &str) { + self.0.expect(says, |tree| { + tree.text("http-response-status").as_deref() == Some(status) && !tree.has("http-response-sending") + }); + } + + /// The answer says how long it took and how much it weighs. + pub fn expect_time_and_size(&mut self, says: &str) { + self.0 + .expect(says, |tree| tree.has("http-response-time") && tree.has("http-response-size")); + } + + /// The body says this. + pub fn expect_body(&mut self, words: &str, says: &str) { + self.0.expect(says, |tree| { + let read = tree.text("http-response-pretty").or_else(|| tree.text("http-response-body")); + read.is_some_and(|body| body.contains(words)) + }); + } + + /// The part shown says this. + pub fn expect_saying(&mut self, words: &str, says: &str) { + self.0.expect(says, |tree| tree.mentions(words)); + } + + /// The timeline shows what was sent, beginning so. + pub fn expect_sent(&mut self, start: &str, says: &str) { + self.0 + .expect(says, |tree| tree.text("http-response-sent").is_some_and(|sent| sent.starts_with(start))); + } + + /// The timeline shows as many redirects. + pub fn expect_redirects(&mut self, count: usize, says: &str) { + self.0.expect(says, |tree| tree.count("http-response-redirect") == count); + } + + /// The answer set this cookie. + pub fn expect_cookie(&mut self, name: &str, says: &str) { + self.0 + .expect(says, |tree| tree.texts("http-response-cookie").iter().any(|it| it == name)); + } + + /// The body is a picture, shown. + pub fn expect_picture(&mut self, says: &str) { + self.0.expect(says, |tree| tree.has("http-response-image")); + } + + /// The send was cancelled. + pub fn expect_cancelled(&mut self, says: &str) { + self.0.expect(says, |tree| tree.has("http-response-cancelled")); + } + + /// The send was refused, and says this. + pub fn expect_refused(&mut self, words: &str, says: &str) { + self.0 + .expect(says, |tree| tree.text("http-response-failure").is_some_and(|said| said.contains(words))); + } + + /// A script stopped the send, its message and its line said. + pub fn expect_stopped(&mut self, message: &str, says: &str) { + self.0.expect(says, |tree| { + let stopped = tree.text("http-script-stop-message"); + tree.has("http-script-stop-where") && stopped.is_some_and(|said| said.contains(message)) + }); + } + + /// A script asks to send a file: nothing has left. + pub fn expect_file_asked(&mut self, name: &str, says: &str) { + self.0.expect(says, |tree| { + let asked = tree.text("http-script-file-confirm"); + !tree.has("http-response-status") && asked.is_some_and(|said| said.contains(name)) + }); + } + + /// Every test of the answer passed, this one among them. + pub fn expect_test_passed(&mut self, name: &str, says: &str) { + self.0.expect(says, |tree| { + tree.has("http-tests-passed") && tree.texts("http-test").iter().any(|it| it == name) + }); + } + + /// A test of the answer failed, with what it expected and what it received. + pub fn expect_test_failed(&mut self, name: &str, (expected, received): (&str, &str), says: &str) { + self.0.expect(says, |tree| { + let versus = tree.text("http-test-versus").unwrap_or_default(); + tree.has("http-tests-failed") + && tree.texts("http-test").iter().any(|it| it == name) + && versus.contains(expected) + && versus.contains(received) + }); + } + + /// The console heard this. + pub fn expect_console(&mut self, words: &str, says: &str) { + self.0.expect(says, |tree| { + let mut lines = tree.all("http-console-line").into_iter(); + lines.any(|line| said(line).contains(words)) + }); + } +} diff --git a/e2e/src/sdk/runner.rs b/e2e/src/sdk/runner.rs new file mode 100644 index 00000000..a93f657d --- /dev/null +++ b/e2e/src/sdk/runner.rs @@ -0,0 +1,105 @@ +use egui::accesskit::Node; + +use super::{App, Shortcut}; +use crate::driver::said; + +/// A collection's run: its order, its settings and its results. +pub struct Runner<'a>(pub(super) &'a mut App); + +impl Runner<'_> { + /// Opens the run of a collection, from its ⋯ menu. + pub fn open(&mut self, collection: &str) { + self.0.http().open_menu(collection); + self.0.click("http-node-run", "« Run »"); + self.0.expect("its requests are listed", |tree| tree.has("http-runner-row")); + } + + /// Types over how many times the collection runs. + pub fn set_iterations(&mut self, count: &str) { + self.0.replace("http-runner-iterations", "the iterations", count); + self.0.expect("as many iterations are asked", |tree| { + tree.find("http-runner-iterations").and_then(Node::value) == Some(count) + }); + } + + /// Takes the data file answered to the dialog: an iteration a row. + pub fn choose_data(&mut self) { + self.0.click("http-runner-data-choose", "« Data file »"); + self.0.expect("the file is read", |tree| tree.has("http-runner-data")); + } + + /// Leaves a request out, or takes it back, by Space on its row. + pub fn flip_request(&mut self, name: &str) { + self.take_request(name); + self.0.press(Shortcut::Space); + } + + /// Moves a request down, by Alt+↓ on its row. + pub fn move_down(&mut self, name: &str) { + self.take_request(name); + self.0.press(Shortcut::MoveDown); + } + + /// Turns *Stop at the first failure* over. + pub fn flip_stop(&mut self) { + self.0.click("http-runner-stop", "« Stop at the first failure »"); + } + + /// Runs the collection until it is over. + pub fn run(&mut self) { + self.0.click("http-runner-start", "« Run »"); + self.0.expect("the run is over", |tree| { + let figures = tree.text("http-runner-figures"); + !tree.has("http-runner-cancel") && figures.is_some_and(|said| said.ends_with(" s")) + }); + } + + /// Shows the requests that failed alone. + pub fn show_failed(&mut self) { + self.0.click("http-runner-filter-failed", "« Failed »"); + } + + /// Shows every request that ran again. + pub fn show_all(&mut self) { + self.0.click("http-runner-filter-all", "« All »"); + } + + /// The requests run in this order. + pub fn expect_order(&mut self, names: &[&str], says: &str) { + self.0.expect(says, |tree| tree.texts("http-runner-row") == names); + } + + /// The results list as many iterations, requests that passed and requests that failed. + pub fn expect_results(&mut self, iterations: usize, (passed, failed): (usize, usize), says: &str) { + self.0.expect(says, |tree| { + tree.count("http-runner-iteration") == iterations + && tree.count("http-runner-result-passed") == passed + && tree.count("http-runner-result-failed") == failed + }); + } + + /// A request is nowhere among the results. + pub fn expect_not_run(&mut self, name: &str, says: &str) { + self.0.expect(says, |tree| { + let results = ["http-runner-result-passed", "http-runner-result-failed"]; + let listed = |id: &&str| tree.texts(id).iter().any(|result| result.ends_with(name)); + tree.has("http-runner-figures") && !results.iter().any(listed) + }); + } + + /// What failed is open on the assertion that did. + pub fn expect_assertion(&mut self, test: &str, versus: &str, says: &str) { + self.0.expect(says, |tree| { + let mut tests = tree.all("http-runner-test").into_iter(); + tests.any(|line| said(line).contains(test) && said(line).contains(versus)) + }); + } + + fn take_request(&mut self, name: &str) { + self.0 + .click_where("http-runner-row", "the request in the run", |row| said(row) == name); + self.0.expect("the row has the keyboard", |tree| { + tree.has_focus("http-runner-row") && tree.focused_says() == name + }); + } +} diff --git a/e2e/src/sdk/sends.rs b/e2e/src/sdk/sends.rs new file mode 100644 index 00000000..22b5e568 --- /dev/null +++ b/e2e/src/sdk/sends.rs @@ -0,0 +1,65 @@ +use super::App; +use crate::driver::said; + +/// The history of what was sent. +pub struct Sends<'a>(pub(super) &'a mut App); + +impl Sends<'_> { + /// Opens its page, from the rail. + pub fn open(&mut self) { + self.0.click("http-history-open", "« History » in the rail"); + self.0.expect("the history is shown", |tree| tree.has("http-history")); + } + + /// Goes back to the requests. + pub fn leave(&mut self) { + self.0.click("http-history-open", "« History » in the rail"); + self.0.expect("the requests are back", |tree| !tree.has("http-history")); + } + + /// Reads the last send of a request. + pub fn read_last_of(&mut self, request: &str) { + self.0 + .click_where("http-history-item", "the send in the history", |item| said(item) == request); + self.0.expect("the send is shown", |tree| tree.has("http-history-url")); + } + + /// Reopens the send read, over what its request or its draft holds now. + pub fn reopen(&mut self) { + self.0.click("http-history-reopen", "« Reopen »"); + self.0 + .expect("the page answers", |tree| tree.has("http-history-replace") || !tree.has("http-history")); + if self.0.tree().has("http-history-replace") { + self.0.click("http-history-replace-confirm", "« Replace »"); + } + self.0 + .expect("the request is back", |tree| !tree.has("http-history") && tree.has("http-url")); + } + + /// Erases the first send listed. + pub fn erase_first(&mut self) { + let sends = self.0.tree().count("http-history-item"); + self.0.hover("http-history-item", "the first send"); + self.0.click("http-history-delete", "its cross"); + self.0.expect("it is gone", |tree| tree.count("http-history-item") + 1 == sends); + } + + /// Erases every send, asked twice. + pub fn erase_all(&mut self) { + self.0.click("http-history-clear", "« Clear »"); + self.0.click("http-history-clear-confirm", "« Clear » again"); + self.expect_none("nothing is listed any more"); + } + + /// Nothing is listed. + pub fn expect_none(&mut self, says: &str) { + self.0 + .expect(says, |tree| tree.has("http-history") && tree.has("http-history-empty")); + } + + /// The send read shows nothing of a secret. + pub fn expect_masked(&mut self, secret: &str, says: &str) { + self.0 + .expect(says, |tree| tree.has("http-history-url") && !tree.mentions(secret)); + } +} diff --git a/e2e/src/sdk/shortcut.rs b/e2e/src/sdk/shortcut.rs index ab122212..45978f18 100644 --- a/e2e/src/sdk/shortcut.rs +++ b/e2e/src/sdk/shortcut.rs @@ -34,8 +34,18 @@ pub enum Shortcut { Italic, /// Alt+↑: moves what has the keyboard up. MoveUp, + /// Alt+↓: moves what has the keyboard down. + MoveDown, + /// Alt+→: moves what has the keyboard into what is above it. + MoveIn, /// Alt+←: moves what has the keyboard out of what it is in. MoveOut, + /// Space. + Space, + /// Ctrl+Enter: sends the request open. + Send, + /// Ctrl+S: saves the request open. + Save, /// Del. Delete, /// Ctrl+Z. @@ -84,6 +94,11 @@ impl Shortcut { Self::NewDrawing => (Key::D, Modifiers::COMMAND | Modifiers::SHIFT), Self::Italic => (Key::I, Modifiers::COMMAND), Self::MoveUp => (Key::ArrowUp, Modifiers::ALT), + Self::MoveDown => (Key::ArrowDown, Modifiers::ALT), + Self::MoveIn => (Key::ArrowRight, Modifiers::ALT), + Self::Space => (Key::Space, Modifiers::NONE), + Self::Send => (Key::Enter, Modifiers::COMMAND), + Self::Save => (Key::S, Modifiers::COMMAND), Self::MoveOut => (Key::ArrowLeft, Modifiers::ALT), Self::Delete => (Key::Delete, Modifiers::NONE), Self::Undo => (Key::Z, Modifiers::COMMAND), diff --git a/e2e/src/sdk/socket.rs b/e2e/src/sdk/socket.rs new file mode 100644 index 00000000..7c0b270b --- /dev/null +++ b/e2e/src/sdk/socket.rs @@ -0,0 +1,47 @@ +use egui::accesskit::Node; + +use super::{App, Shortcut}; +use crate::driver::said; + +/// The WebSocket open: its message and its log. +pub struct Socket<'a>(pub(super) &'a mut App); + +impl Socket<'_> { + /// Connects it, or disconnects it. + pub fn flip_connection(&mut self) { + self.0.click("http-socket-connect", "« Connect »"); + } + + /// Sends a message, Ctrl+Enter. + pub fn send(&mut self, message: &str) { + self.0.replace("http-socket-message", "the message", message); + self.0.expect("the message is typed", |tree| { + tree.find("http-socket-message").and_then(Node::value) == Some(message) + }); + self.0.press(Shortcut::Send); + } + + /// Keeps the message written. + pub fn keep(&mut self) { + self.0.click("http-socket-keep", "« Keep »"); + self.0.expect("the message is kept", |tree| tree.has("http-socket-saved")); + } + + /// Sends the first message kept. + pub fn send_kept(&mut self) { + self.0.click("http-socket-saved-send", "the « Send » of the message kept"); + } + + /// The log has as many lines. + pub fn expect_log(&mut self, lines: usize, says: &str) { + self.0.expect(says, |tree| tree.count("http-socket-entry") == lines); + } + + /// The log says a message as many times: sent, and received. + pub fn expect_logged(&mut self, message: &str, times: usize, says: &str) { + self.0.expect(says, |tree| { + let lines = tree.all("http-socket-entry").into_iter(); + lines.filter(|line| said(line).contains(message)).count() == times + }); + } +} diff --git a/e2e/src/sdk/window.rs b/e2e/src/sdk/window.rs index 9ce5808f..10110f13 100644 --- a/e2e/src/sdk/window.rs +++ b/e2e/src/sdk/window.rs @@ -27,6 +27,7 @@ impl Window<'_> { /// Makes the window wide enough for a note beside its cards, or over them with its details. pub fn widen(&mut self) { + self.0.wide = true; self.0.driver.resize(1_440, 900); } diff --git a/e2e/src/server.rs b/e2e/src/server.rs index e7dc3b9f..31301ef5 100644 --- a/e2e/src/server.rs +++ b/e2e/src/server.rs @@ -1,7 +1,8 @@ //! 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`, `/bytes` what is no text, `/png` a picture, -//! anything else is a 404. Each connection is answered once, then closed. +//! 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}; @@ -147,6 +148,9 @@ fn reply(path: &str, head: &str, sent: &[u8]) -> Reply { if path.starts_with("/bytes") { return plain("200 OK", "application/octet-stream", &[0xff; 2048]); } + if path.starts_with("/large") { + return plain("200 OK", "text/plain", &vec![b'x'; 2 * 1024 * 1024]); + } if path.starts_with("/png") { return plain("200 OK", "image/png", PIXEL); } diff --git a/e2e/tests/09_calling_an_api.rs b/e2e/tests/09_calling_an_api.rs new file mode 100644 index 00000000..c3860817 --- /dev/null +++ b/e2e/tests/09_calling_an_api.rs @@ -0,0 +1,381 @@ +//! Journey 9, « Calling an API »: a collection and its requests, what a request is written with and +//! what its answer says, the environments it is sent with, the code it becomes and what is kept of +//! it. Everything is sent to a server of the journey's own. + +use e2e::{App, Area, Auth, Body, BodyView, Method, Part, Shortcut, step}; + +const COLLECTION: &str = "Shop"; +const FOLDER: &str = "Accounts"; + +#[test] +fn calling_an_api() { + let mut app = App::open("09_calling_an_api"); + let api = app.serve_api(); + app.window().widen(); + app.window().go_to(Area::Http); + + the_rail(&mut app); + the_tabs(&mut app); + what_a_request_is_made_of(&mut app, &api); + what_the_answer_says(&mut app, &api); + other_kinds_of_requests(&mut app, &api); + the_environments(&mut app, &api); + as_code(&mut app); + what_is_kept(&mut app, &api); + app.quit(); +} + +fn the_rail(app: &mut App) { + step("a collection, a folder and its requests are made from the empty rail", || { + app.http().new_collection(COLLECTION); + app.http().new_folder(COLLECTION, FOLDER); + app.http().new_request(FOLDER, "Login"); + app.http().new_socket(FOLDER, "Feed"); + app.http() + .expect_rows(&[COLLECTION, FOLDER, "GET Login", "WS Feed"], "each is where it was made"); + }); + + step("a request is moved by the keys, out of its folder and back into it", || { + app.http().take_row("Feed"); + app.press(Shortcut::MoveUp); + app.http() + .expect_rows(&[COLLECTION, FOLDER, "WS Feed", "GET Login"], "it is before the other"); + app.http().expect_move_said("Login", "what it passed is said"); + app.press(Shortcut::MoveOut); + app.http() + .expect_rows(&[COLLECTION, FOLDER, "GET Login", "WS Feed"], "it is out of the folder"); + app.press(Shortcut::MoveIn); + app.http().expect_move_said(FOLDER, "it is back in the folder"); + }); + + step("a request is renamed in place, by F2 and from its menu", || { + app.http().rename("Feed", "Live feed"); + app.http().rename_from_the_menu("Live feed", "Orders feed"); + }); + + step("a request and a folder are deleted once the rail has said what goes with them", || { + app.http().new_folder(COLLECTION, "Old"); + app.http().new_request("Old", "Forgotten"); + app.http().new_request(COLLECTION, "Spare"); + app.http().ask_deletion("Old"); + app.http().expect_deletion_counted("the rail says what is in the folder"); + app.http().cancel_deletion(); + app.http().ask_deletion("Old"); + app.http().confirm_deletion(); + app.http().ask_deletion("Spare"); + app.http().confirm_deletion(); + app.http() + .expect_rows(&[COLLECTION, FOLDER, "GET Login", "WS Orders feed"], "both are gone"); + }); +} + +fn the_tabs(app: &mut App) { + step("each request opens in its tab, and a draft asks before it closes", || { + app.http().open("Login"); + app.http().open("Orders feed"); + app.http().new_draft(); + app.http().close_last_tab_discarding(); + app.http().new_draft(); + app.http().close_last_tab_with_the_middle_button(); + app.capture("rail"); + }); + + step("a tab is dragged past the other, the folder folded, and both found over a relaunch", || { + app.http() + .expect_tabs_in_order(&["Login", "Orders feed"], "the tabs are as they were opened"); + app.http().drag_first_tab(); + app.http() + .expect_tabs_in_order(&["Orders feed", "Login"], "the first went past the other"); + app.http().fold(FOLDER); + app.http().expect_rows(&[COLLECTION, FOLDER], "the folder is folded"); + app.relaunch_and_unlock(); + app.http().expect_rows(&[COLLECTION, FOLDER], "it still is"); + app.http() + .expect_tabs_in_order(&["Orders feed", "Login"], "the tabs are in their order"); + app.http().fold(FOLDER); + }); +} + +fn what_a_request_is_made_of(app: &mut App, api: &str) { + step("the address and its parameters are kept in step", || { + app.http().open("Login"); + app.request().type_url(&format!("{api}/echo?page=2&q=x")); + app.request().expect_params(&["page", "q"], "the table follows the address"); + app.request().flip_param(0); + app.request() + .expect_url(&format!("{api}/echo?q=x"), "the address follows the table"); + }); + + step("a header is typed as it is read", || { + app.request().type_header("X-Trace: abc"); + app.request() + .expect_first_header("X-Trace", "abc", "it is split into its two cells"); + app.request().send(); + app.response().expect_body("x-trace: abc", "it was sent"); + }); + + step("the auth and the headers of the collection go with its requests", || { + app.http().set_below(COLLECTION, "from-the-shop", ("X-Tenant", "north")); + app.request() + .expect_inherited_from(COLLECTION, "the auth says where it is from"); + app.request().send(); + app.response() + .expect_body("Bearer from-the-shop", "the collection's token was sent"); + app.response().expect_body("x-tenant: north", "and its header"); + }); + + step("a request has an auth of its own: Basic, Bearer and an API key", || { + app.request().choose_auth(Auth::Basic { name: "ada", password: "secret" }); + app.request().send(); + app.response().expect_body("Basic YWRhOnNlY3JldA==", "Basic was sent"); + app.request().choose_auth(Auth::Bearer("own-token")); + app.request().expect_secret_masked("own-token", "the token is masked"); + app.request().flip_secret(); + app.request().expect_secret("own-token", "and shown when asked"); + app.request().send(); + app.response().expect_body("Bearer own-token", "Bearer was sent"); + app.request().choose_auth(Auth::ApiKey { name: "X-Api-Key", value: "k3y" }); + app.request().send(); + app.response().expect_body("x-api-key: k3y", "the key was sent"); + app.request().choose_auth(Auth::Inherited); + }); + + step("a body is written in JSON, as a form, in parts, and taken from a file", || { + app.files().put("invoice.txt", b"one invoice"); + app.files().answer("invoice.txt"); + app.request().choose_method(Method::Post); + app.request().type_body(Body::Json("{\"amount\": 4900}")); + app.request().expect_json_valid("the body reads, and its type is said"); + app.request().send(); + app.response().expect_body("{\"amount\": 4900}", "it left as it was written"); + app.request().type_body(Body::Form("city", "Lyon")); + app.request().send(); + app.response().expect_body("city=Lyon", "the form was sent"); + app.request().type_body(Body::Multipart(("city", "Lyon"), "invoice")); + app.request().send(); + app.response().expect_body("name=\"city\"", "the part was sent"); + app.response().expect_body("one invoice", "and the file"); + app.request().type_body(Body::File); + app.request().send(); + app.response().expect_body("one invoice", "the file alone was sent"); + app.capture("body-file"); + }); +} + +fn what_the_answer_says(app: &mut App, api: &str) { + step("the answer has its status, its time and its size, and its body four ways", || { + app.request().choose_method(Method::Get); + app.request().send_to(&format!("{api}/json")); + app.response().expect_status("200 OK", "the status is shown"); + app.response().expect_time_and_size("with how long it took and what it weighs"); + app.response().expect_body("Ada", "the body is formatted"); + app.response().show_as(BodyView::Raw); + app.response().expect_body("\"admin\":true", "it is read as it came"); + app.response().show_as(BodyView::Graph); + app.json().expect_nodes(2, "it is drawn as a graph"); + app.response().show_as(BodyView::Tree); + app.json().expect_listed("$.name", "it is a tree"); + app.capture("answer"); + }); + + step("its headers, its cookies and the exchange are read beside it, redirects too", || { + app.response().go_to(Part::Headers); + app.response().expect_saying("set-cookie", "its headers are listed"); + app.response().go_to(Part::Cookies); + app.response().expect_cookie("session", "its cookie is listed"); + app.request().send_to(&format!("{api}/redirect/3")); + app.response().go_to(Part::Timeline); + app.response().expect_redirects(3, "each redirect is shown"); + app.response() + .expect_sent(&format!("GET {api}/redirect/3"), "with what was sent"); + app.response().go_to(Part::Body); + app.request().send_to(&format!("{api}/png")); + app.response().expect_picture("a picture is shown"); + }); + + step("a slow send is cancelled", || { + app.request().send_to(&format!("{api}/slow")); + app.request().cancel_send(); + app.response().expect_cancelled("the send is over"); + }); + + step("Ctrl+S saves the request, and a draft into the collection", || { + app.request().save(); + app.http().new_draft(); + app.request().type_url(&format!("{api}/json")); + app.request().save_as("Health"); + app.http().expect_rows( + &[COLLECTION, FOLDER, "GET Login", "WS Orders feed", "GET Health"], + "the draft is in the collection", + ); + app.http().show_tab("Login"); + }); + + step("a value of the answer is kept in a variable by a rule, and the next request uses it", || { + app.request().send_to(&format!("{api}/json")); + app.response().show_as(BodyView::Tree); + app.json().select_in_the_tree("$.name"); + app.response().extract_to("who"); + app.request().send(); + app.response().expect_status("200 OK", "the rule is followed"); + app.request().send_to(&format!("{api}/echo?who={{{{who}}}}")); + app.response().expect_body("/echo?who=Ada", "the value was sent"); + }); + + step("the cookies the server set are listed, and thrown away", || { + app.http().open_cookies(); + app.http().expect_cookie("session", "the cookie is in the jar"); + app.http().throw_cookies_away(); + }); +} + +fn other_kinds_of_requests(app: &mut App, api: &str) { + step("a GraphQL request names the variables it lacks, and is sent", || { + app.http().new_graphql_draft(); + app.request().type_name("Products"); + app.request() + .type_query("query One($code: ID!) { product(code: $code) { id } }"); + app.request().expect_missing_variable("$code", "the variable is named"); + app.request().add_missing_variables(); + app.request().expect_no_missing_variable("it is added"); + app.request().send_to(&format!("{api}/echo")); + app.response().expect_body("query One", "the query was sent"); + app.http().close_last_tab_discarding(); + }); + + step("a WebSocket connects, its log shows what goes and comes, and a message kept is sent again", || { + let socket = app.serve_socket(); + app.http().open("Orders feed"); + app.request().type_url(&socket); + app.socket().flip_connection(); + app.socket().expect_log(1, "it is connected"); + app.socket().send("ping"); + app.socket().expect_logged("ping", 2, "the message went, and came back"); + app.socket().keep(); + app.socket().send_kept(); + app.socket().expect_logged("ping", 4, "it went again, and came back"); + app.capture("socket"); + app.socket().flip_connection(); + app.socket().expect_log(6, "it is disconnected"); + app.request().save(); + }); +} + +fn the_environments(app: &mut App, api: &str) { + step("two environments are made, each with its colour and its secret", || { + app.environments().open(); + app.environments().create("Local"); + app.environments().choose_colour(3); + app.environments().add_variable("base_url", api); + app.environments().add_secret("api_key", "l0cal"); + app.environments().create("Production"); + app.environments().choose_colour(4); + app.environments().add_variable("base_url", api); + app.environments().add_secret("api_key", "pr0d"); + app.environments().protect(); + app.capture("environments"); + app.environments().leave(); + }); + + step("a variable takes the value of the environment chosen, and its card says from where", || { + app.environments().choose("Local"); + app.http().open("Login"); + app.request().type_url("{{base_url}}/echo?key={{api_key}}"); + app.request().point_at_variable("base_url"); + app.request().expect_variable_value(api, "the card says its value"); + app.request().expect_variable_from("Local", "and where it is from"); + app.request().point_at_variable("api_key"); + app.request().expect_variable_masked("the secret is masked"); + app.request().reveal_variable(); + app.request().expect_variable_value("l0cal", "and shown when asked"); + app.request().send(); + app.response().expect_body("/echo?key=l0cal", "both were sent"); + }); + + step("a name set nowhere stops the send, and *Set in…* leads to where it goes", || { + app.request().type_url("{{base_url}}/echo?{{nowhere}}"); + app.request().send(); + app.response().expect_refused("nowhere", "the send is refused, the name said"); + app.request().point_at_variable("nowhere"); + app.request().define_variable(); + app.environments().type_value_of("nowhere", "found"); + app.environments().leave(); + app.request().send(); + app.response().expect_body("/echo?found", "it is set, and sent"); + }); + + step("a protected environment asks before a POST, not before a GET", || { + app.environments().choose("Production"); + app.request().type_url("{{base_url}}/echo?key={{api_key}}"); + app.request().send(); + app.response().expect_body("/echo?key=pr0d", "the GET left at once"); + app.request().choose_method(Method::Post); + app.request().send(); + app.request().expect_asked_before_sending("the POST waits for a yes"); + app.request().do_not_send(); + app.request().send(); + app.request().send_anyway(); + app.response().expect_body("POST /echo?key=pr0d", "the yes let it leave"); + }); +} + +fn as_code(app: &mut App) { + step("the request is written as code, its secret left as a variable until a yes", || { + app.code().open(); + app.code().expect("/echo?key=", "the address is there"); + app.code().expect_without("pr0d", "the secret is not"); + app.code().choose("fetch", "JavaScript · fetch"); + app.code().expect("await fetch(", "it is written for a browser"); + app.code().choose("elixir", "Elixir · Req"); + app.code().expect("Req.request!(", "and for Elixir"); + app.code().ask_secrets(); + app.code().include_secrets(); + app.code().expect("pr0d", "the secret is there"); + app.capture("code"); + app.code().copy(); + app.clipboard().expect_saying("Req.request!(", "the code is copied"); + app.code().close(); + }); +} + +fn what_is_kept(app: &mut App, api: &str) { + step("the history holds what was sent, its secrets masked", || { + app.sends().open(); + app.sends().read_last_of("Login"); + app.sends().expect_masked("pr0d", "the secret is nowhere"); + app.capture("history"); + }); + + step("a send is reopened in its request, another as a draft, and they are erased", || { + app.sends().reopen(); + app.request() + .expect_url(&format!("{api}/echo?key={{{{api_key}}}}"), "its request holds what was sent"); + app.request().save(); + app.sends().open(); + app.sends().read_last_of("Products"); + app.sends().reopen(); + app.http().expect_tabs(4, "a draft is open beside the requests"); + app.http().close_last_tab_discarding(); + app.sends().open(); + app.sends().erase_first(); + app.sends().erase_all(); + app.sends().leave(); + }); + + step("an answer is saved to a file, and another kept as a note", || { + app.environments().choose("Local"); + app.request().choose_method(Method::Get); + app.files().answer("large.txt"); + app.request().send_to(&format!("{api}/large")); + app.response().save_to_file(); + app.files() + .expect("large.txt", "the whole answer is in the file", |bytes| bytes.len() > 1024 * 1024); + app.request().send_to(&format!("{api}/json")); + app.response().save_as_note("Who is there"); + app.request().save(); + app.window().go_to(Area::Notes); + app.notes().open("Who is there"); + app.editor().expect_code_holding("Ada", "the note holds the answer"); + app.editor().close(); + }); +} diff --git a/e2e/tests/10_scripts_and_runs.rs b/e2e/tests/10_scripts_and_runs.rs new file mode 100644 index 00000000..ef5c5ffd --- /dev/null +++ b/e2e/tests/10_scripts_and_runs.rs @@ -0,0 +1,164 @@ +//! Journey 10, « Scripts, tests and runs »: what a request's scripts do before and after it is sent, +//! what its tests say, what stops a send or waits for a yes, and a collection run as a whole. + +use e2e::{App, Area, Part, Script, step}; + +const COLLECTION: &str = "Shop"; +const THROWS: &str = "\nthrow new Error('no stock');"; +const TEST: &str = "test('found', () => { expect(res.status).toBe(200); });"; + +#[test] +fn scripts_and_runs() { + let mut app = App::open("10_scripts_and_runs"); + let api = app.serve_api(); + app.window().widen(); + app.window().go_to(Area::Http); + app.http().new_collection(COLLECTION); + + scripts_and_tests(&mut app, &api); + what_stops_a_send(&mut app); + a_run(&mut app, &api); + what_is_left(app); +} + +fn scripts_and_tests(app: &mut App, api: &str) { + step("a script before the send adds a header, and the console hears it", || { + app.http().new_request(COLLECTION, "Order"); + app.request().type_url(&format!("{api}/echo")); + app.request() + .type_script(Script::Before, "req.headers.set('X-Order', '42');\nconsole.log('order prepared');"); + app.request().send(); + app.response().expect_body("x-order: 42", "the header was sent"); + app.response().open_console(); + app.response().expect_console("order prepared", "the console heard the script"); + app.response().expect_console(&format!("GET {api}/echo"), "and the send"); + }); + + step("a script after the answer keeps a value of it, which the next request uses", || { + app.request() + .type_script(Script::After, "env.set('who', res.json().name);\nconsole.log('value kept');"); + app.response().clear_console(); + app.request().send_to(&format!("{api}/json")); + app.response().expect_console("value kept", "the console heard it"); + app.request().type_script(Script::After, ""); + app.request().send_to(&format!("{api}/echo?who={{{{who}}}}")); + app.response().expect_body("/echo?who=Ada", "the value was sent"); + }); + + step("a test reads the answer, and says what it expected and what it received", || { + app.request().type_script(Script::Tests, TEST); + app.request().send_to(&format!("{api}/json")); + app.response().go_to(Part::Tests); + app.response().expect_test_passed("found", "the test passed"); + app.request().send_to(&format!("{api}/missing")); + app.response().go_to(Part::Tests); + app.response() + .expect_test_failed("found", ("200", "404"), "the test failed on the status"); + app.capture("tests"); + }); +} + +fn what_stops_a_send(app: &mut App) { + step("a script that throws stops the send, and leads back to its line", || { + app.request().type_script(Script::Before, THROWS); + app.request().show_script(Script::Tests); + app.request().send(); + app.response().expect_stopped("no stock", "the stop is said, and where"); + app.capture("stopped"); + app.response().open_script(); + app.request().expect_script(THROWS, "its script is shown"); + }); + + step("a file a script asks to send waits for a yes", || { + let key = app.files().put_apart("id_ed25519", b"not a key"); + app.request().type_script( + Script::Before, + &format!("pm.request.body.update({{ mode: 'file', file: {{ src: '{key}' }} }});"), + ); + app.request().send(); + app.response() + .expect_file_asked("id_ed25519", "the file is named, nothing left"); + app.capture("file-asked"); + app.response().refuse_file(); + app.request().send(); + app.response().expect_file_asked("id_ed25519", "it is asked again"); + app.response().allow_file(); + app.response().expect_status("404 Not Found", "the yes let it leave"); + app.request().type_script(Script::Before, ""); + app.request().save(); + }); +} + +fn a_run(app: &mut App, api: &str) { + step("a collection of three requests, two of them with a test", || { + for (name, path) in [("Login", "/json"), ("Client", "/missing")] { + app.http().new_request(COLLECTION, name); + app.request().type_url(&format!("{api}{path}")); + app.request().type_script(Script::Tests, TEST); + app.request().save(); + } + app.sends().open(); + app.sends().erase_all(); + app.sends().leave(); + }); + + step("it runs twice over, one request left out by Space, what failed open", || { + app.runner().open(COLLECTION); + app.runner().set_iterations("2"); + app.runner().flip_request("Order"); + app.runner().run(); + app.runner().expect_results(2, (2, 2), "each iteration ran the two others"); + app.runner().expect_not_run("Order", "the one left out did not run"); + app.runner() + .expect_assertion("found", "404", "what failed is open on its assertion"); + app.capture("run"); + app.runner().show_failed(); + app.runner().expect_results(2, (0, 2), "the failed are shown alone"); + app.runner().show_all(); + }); + + step("a data file gives it an iteration a row", || { + app.files().put("clients.csv", b"customer\ncus_1\ncus_2\ncus_3\n"); + app.files().answer("clients.csv"); + app.runner().choose_data(); + app.runner().run(); + app.runner().expect_results(3, (3, 3), "it ran once a row"); + }); + + step("a run writes nothing in the history", || { + app.sends().open(); + app.sends().expect_none("nothing is listed"); + app.sends().leave(); + }); + + step("the order is arranged, and *Stop at the first failure* ends the run", || { + app.runner().open(COLLECTION); + app.runner() + .expect_order(&["Order", "Login", "Client"], "they are in the collection's order"); + app.runner().move_down("Login"); + app.runner() + .expect_order(&["Order", "Client", "Login"], "the order is arranged"); + app.runner().flip_request("Order"); + app.runner().flip_stop(); + app.runner().run(); + app.runner().expect_results(1, (0, 1), "the first failure ended the run"); + }); +} + +fn what_is_left(mut app: App) { + step("the order arranged is kept over a relaunch", || { + app.relaunch_and_unlock(); + app.runner().open(COLLECTION); + app.runner() + .expect_order(&["Order", "Client", "Login"], "the order is the one arranged"); + }); + + step("quitting with a request left changed asks first", || { + app.http().open("Login"); + app.request().add_to_url("/changed"); + app.http().ask_to_quit(); + app.http().cancel_quitting(); + app.http().ask_to_quit(); + app.http().save_and_quit(); + }); +} diff --git a/e2e/tests/13_making_it_mine.rs b/e2e/tests/13_making_it_mine.rs index 9f17dee8..4196a483 100644 --- a/e2e/tests/13_making_it_mine.rs +++ b/e2e/tests/13_making_it_mine.rs @@ -206,7 +206,7 @@ fn the_areas(app: &mut App) { app.tools().expect_tool_open("the tool is as it was"); app.press(Shortcut::HttpArea); app.http().expect_tabs(1, "the draft is as it was"); - app.http().close_tab_discarding(); + app.http().close_last_tab_discarding(); }); step("the switch of the areas leads there too", || { diff --git a/e2e/tests/30_http.rs b/e2e/tests/30_http.rs deleted file mode 100644 index 7dcdc10d..00000000 --- a/e2e/tests/30_http.rs +++ /dev/null @@ -1,350 +0,0 @@ -//! The HTTP area: a collection begun from the empty rail, a folder and requests made from a row's -//! menu, a request moved with the keys, renamed in place, a fold kept across a relaunch, and the -//! collection deleted once the rail has said what goes with it. A request opens in its tab, -//! reopened at the next launch in the order the tabs were dragged to; a draft asks before it is -//! closed, by its × or the middle button. A body is read as it is typed, -//! and a GraphQL draft names the variables it lacks. -//! -//! Rows are read by their names, which the scenario types: the window speaks the system's -//! language. - -use e2e::old::{App, Tree, step}; -use egui::accesskit::Node; -use egui::{Key, Modifiers, PointerButton, Pos2}; - -const API: &str = "API Paiements"; - -/// The rail's rows, top to bottom: a request after its method. -fn rows(tree: &Tree) -> Vec { - tree.texts("http-node-name") -} - -fn ends(name: &str) -> impl Fn(&Node) -> bool + '_ { - move |node| node.label().is_some_and(|label| label.ends_with(name)) -} - -fn named(name: &str) -> impl Fn(&Node) -> bool + '_ { - move |node| node.label() == Some(name) -} - -fn create(app: &mut App, name: &str) { - app.fill("http-create-input", name); - app.press(Key::Enter, Modifiers::NONE); -} - -/// A row's `⋯`, then an entry of its menu, a sub-menu's through its parent. -fn choose(app: &mut App, row: &str, entries: &[&str]) { - app.click_where("http-node-menu", ends(row)); - for entry in entries { - app.click(entry); - } -} - -fn organise(app: &mut App) { - step("a collection begun from the empty rail", || { - app.press(Key::Num3, Modifiers::COMMAND); - app.wait_for("http-rail-empty"); - app.click("http-rail-empty-create"); - create(app, API); - app.eventually("the collection is listed", |tree| rows(tree) == [API]); - }); - step("a folder and two requests made from the rows' menus", || { - choose(app, API, &["http-node-new-folder"]); - create(app, "Auth"); - app.eventually("the folder is listed", |tree| rows(tree) == [API, "Auth"]); - choose(app, "Auth", &["http-node-new", "http-node-new-http"]); - create(app, "Login"); - app.eventually("the request is listed", |tree| rows(tree) == [API, "Auth", "GET Login"]); - choose(app, "Auth", &["http-node-new", "http-node-new-websocket"]); - create(app, "Flux"); - app.eventually("the socket is listed", |tree| rows(tree) == [API, "Auth", "GET Login", "WS Flux"]); - }); - step("a request moved with the keys, then out of its folder", || { - app.click_where("http-node-name", named("WS Flux")); - app.press(Key::ArrowUp, Modifiers::ALT); - app.eventually("the socket is first", |tree| rows(tree) == [API, "Auth", "WS Flux", "GET Login"]); - app.eventually("the move is said", |tree| { - tree.text("http-rail-moved").is_some_and(|said| said.contains("Login")) - }); - app.press(Key::ArrowLeft, Modifiers::ALT); - app.eventually("the socket is at the collection's root", |tree| { - rows(tree) == [API, "Auth", "GET Login", "WS Flux"] - }); - // Nothing is above a folder's first request but its folder: refused, and said. - app.click_where("http-node-name", named("GET Login")); - app.press(Key::ArrowRight, Modifiers::ALT); - app.eventually("the refusal is said", |tree| { - tree.text("http-rail-moved").is_some_and(|said| said.contains("Login")) - }); - }); - step("a request renamed in place, the field left", || { - app.click_where("http-node-name", named("WS Flux")); - app.press(Key::F2, Modifiers::NONE); - app.wait_for("http-rename-input"); - app.press(Key::End, Modifiers::NONE); - app.type_text(" live"); - app.click("http-rail-title"); - app.eventually("the new name is read back", |tree| { - rows(tree).contains(&"WS Flux live".to_owned()) && !tree.has("http-rename-input") - }); - }); -} - -fn tabs(tree: &Tree) -> Vec { - tree.texts("http-tab-open") -} - -/// The open tabs, in no order: a request clicked in the rail opens, the rows moved above too. -fn open(tree: &Tree) -> Vec { - let mut open = tabs(tree); - open.sort(); - open -} - -fn in_tabs(app: &mut App) { - step("a request opens in its tab, and a draft asks before it closes", || { - app.click_where("http-node-name", named("GET Login")); - app.eventually("the requests clicked have their tabs", |tree| { - open(tree) == ["GET Login", "WS Flux live"] - }); - app.click("http-tab-new"); - app.eventually("a draft opens beside them", |tree| tabs(tree).len() == 3); - app.click_nth("http-tab-close", 2); - app.wait_for("http-close-dialog"); - app.click("http-close-discard"); - app.eventually("the draft is gone", |tree| { - open(tree) == ["GET Login", "WS Flux live"] && !tree.has("http-close-dialog") - }); - }); -} - -/// The first tab dragged past the second, kept so after the relaunch; the middle button closes a -/// tab, asking first when it holds a draft. The order is answered by name: what was typed in a -/// tab is not reopened. -fn tabs_moved(app: &mut App) -> Vec { - let mut order = Vec::new(); - step("a tab dragged past the other takes its place", || { - let tree = app.tree(); - let before = tabs(&tree); - let bounds: Vec<_> = tree.all("http-tab-open").into_iter().filter_map(Node::bounds).collect(); - let [first, second, ..] = bounds[..] else { - panic!("two tabs at least: {before:?}"); - }; - #[expect(clippy::cast_possible_truncation, reason = "points on a screen")] - let at = |x: f64, rect: &egui::accesskit::Rect| { - Pos2::new(x as f32, f64::midpoint(rect.y0, rect.y1) as f32) - }; - let (from, to) = (at(first.x0 + 20.0, &first), at(second.x1, &second)); - app.drag(from, to, PointerButton::Primary); - order = before; - order.swap(0, 1); - app.eventually("the first two swapped", |tree| tabs(tree) == order); - }); - step("the middle button on a draft asks, then closes it", || { - app.click("http-tab-new"); - app.eventually("a draft opens beside them", |tree| tabs(tree).len() == order.len() + 1); - let draft = app.tree().texts("http-tab-open")[order.len()].clone(); - app.click_with("http-tab-open", PointerButton::Middle, named(&draft)); - app.wait_for("http-close-dialog"); - app.click("http-close-discard"); - app.eventually("the draft is gone", |tree| tabs(tree) == order && !tree.has("http-close-dialog")); - }); - order - .iter() - .map(|tab| tab.split(',').next().unwrap_or_default().to_owned()) - .collect() -} - -/// What the fields wearing `author_id` hold, top to bottom. -fn values(tree: &Tree, author_id: &str) -> Vec { - tree.all(author_id) - .into_iter() - .map(|node| node.value().unwrap_or_default().to_owned()) - .collect() -} - -/// Typed at the end of what a field holds. -fn append(app: &mut App, author_id: &str, words: &str) { - app.click(author_id); - app.press(Key::End, Modifiers::NONE); - app.type_text(words); -} - -fn compose(app: &mut App) { - step("the query and its table kept in step, a header split, Ctrl+S", || { - app.click_where("http-tab-open", named("GET Login")); - app.wait_for("http-url"); - append(app, "http-url", "?page=2&q=x"); - app.eventually("the table follows the URL", |tree| values(tree, "http-kv-key") == ["page", "q", ""]); - app.click_nth("http-kv-enabled", 0); - app.eventually("the URL follows the table", |tree| { - tree.find("http-url").and_then(Node::value).is_some_and(|url| url == "?q=x") - }); - app.click("http-section-headers"); - app.wait_for("http-implied-headers"); - app.click_nth("http-kv-key", 0); - app.type_text("Accept: application/json"); - app.eventually("the header is split into its two cells", |tree| { - values(tree, "http-kv-key").first().map(String::as_str) == Some("Accept") - && values(tree, "http-kv-value").first().map(String::as_str) == Some("application/json") - }); - app.press(Key::S, Modifiers::COMMAND); - app.eventually("the tab is saved", |tree| tabs(tree).contains(&"GET Login".to_owned())); - }); -} - -fn send(app: &mut App) { - step("sent from Rust on Ctrl+Enter: its status, time, size and body, then cleared", || { - let port = e2e::old::serve(); - app.click("http-url"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(&format!("http://127.0.0.1:{port}/json")); - app.press(Key::Enter, Modifiers::COMMAND); - app.eventually("the answer is shown", |tree| { - tree.text("http-response-status").as_deref() == Some("200 OK") - && tree.has("http-response-time") - && tree.has("http-response-size") - && tree.text("http-response-pretty").is_some_and(|body| body.contains("Ada")) - }); - app.click("http-response-section-timeline"); - app.eventually("the exchange is shown", |tree| { - tree.text("http-response-sent") - .is_some_and(|sent| sent.starts_with("GET http://127.0.0.1")) - }); - app.click("http-response-clear"); - app.wait_for("http-response-idle"); - }); - step("the send in the history, read again, then reopened", || { - app.click("http-history-open"); - app.wait_for("http-history-item"); - app.click("http-history-item"); - app.wait_for("http-history-url"); - app.eventually("it reads like an answer", |tree| { - tree.text("http-response-status").as_deref() == Some("200 OK") - }); - app.click("http-history-reopen"); - app.wait_for("http-history-replace"); - app.click("http-history-replace-confirm"); - app.wait_for("http-url"); - app.eventually("the page has gone", |tree| !tree.has("http-history")); - }); - step("the cookie the answer set, in the jar, then thrown away", || { - app.click("http-cookies-open"); - app.eventually("the cookie is listed", |tree| tree.text("http-cookie").as_deref() == Some("session")); - app.click("http-cookie-remove"); - app.wait_for("http-cookies-empty"); - app.click("http-cookies-close"); - app.eventually("the jar is closed", |tree| !tree.has("http-cookies-dialog")); - }); -} - -fn bodies(app: &mut App) { - step("a JSON body read as it is typed, said on a GET, taken back to none", || { - app.click("http-section-body"); - app.click("http-body-kind-1"); - app.fill("http-body-text", "{\"amount\":4900}"); - app.eventually("the body reads and its type is said", |tree| { - tree.has("http-body-valid") - && tree - .text("http-body-type") - .is_some_and(|said| said.contains("application/json")) - }); - app.wait_for("http-body-unusual"); - app.wait_for("http-body-unusual-mark"); - app.click("http-body-to-none"); - app.eventually("no body, no warning", |tree| { - !tree.has("http-body-unusual") && !tree.has("http-body-text") - }); - }); - step("a GraphQL draft: its variable named, then added", || { - app.click("http-tab-new-kind"); - app.click("http-new-kind-graphql"); - app.fill("http-graphql-query", "query One($code: ID!) { product(code: $code) { id } }"); - app.wait_for("http-graphql-missing"); - app.click("http-graphql-add"); - app.eventually("the variable has its null", |tree| { - !tree.has("http-graphql-missing") - && values(tree, "http-graphql-variables") - .first() - .is_some_and(|text| text.contains("\"code\": null")) - }); - app.click_nth("http-tab-close", 2); - app.wait_for("http-close-dialog"); - app.click("http-close-discard"); - app.eventually("the draft is gone", |tree| tabs(tree).len() == 2); - }); -} - -fn socket(app: &mut App) { - step("a socket connected, a message echoed, then disconnected", || { - let port = e2e::old::serve_socket(); - app.click_where("http-tab-open", named("WS Flux live")); - app.wait_for("http-socket-message"); - app.click("http-url"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(&format!("ws://127.0.0.1:{port}/")); - app.click("http-socket-connect"); - app.eventually("the socket is open", |tree| tree.count("http-socket-entry") == 1); - app.fill("http-socket-message", "ping"); - // A key overtakes what is still being typed: it would reach the area, not the message. - app.eventually("the message is typed", |tree| { - values(tree, "http-socket-message").first().map(String::as_str) == Some("ping") - }); - app.press(Key::Enter, Modifiers::COMMAND); - app.eventually("the message came back", |tree| tree.count("http-socket-entry") == 3); - app.click("http-socket-connect"); - app.eventually("the socket is closed", |tree| tree.count("http-socket-entry") == 4); - app.press(Key::S, Modifiers::COMMAND); - }); -} - -fn fold_kept(app: App, order: &[String]) -> App { - let mut app = app; - step("a folder folded, still folded after a relaunch", || { - app.click_where("http-node-twisty", ends("Auth")); - app.eventually("the folder is folded", |tree| rows(tree) == [API, "Auth", "WS Flux live"]); - }); - let mut app = app.relaunch_discarding(); - step("unlocked again, the HTTP area shows the fold", || { - app.fill("vault-passphrase", e2e::old::PASSPHRASE); - app.click("vault-submit"); - app.wait_for("area-http"); - app.eventually("the fold and the tab are kept", |tree| { - rows(tree) == [API, "Auth", "WS Flux live"] && tabs(tree) == order - }); - }); - app -} - -fn delete(app: &mut App) { - step("the collection deleted after saying what goes with it", || { - choose(app, API, &["http-node-delete"]); - app.wait_for("http-delete-count"); - app.click("http-delete-cancel"); - app.eventually("cancel keeps it", |tree| !tree.has("http-delete-confirm") && rows(tree).len() == 3); - choose(app, API, &["http-node-delete"]); - app.click("http-delete-submit"); - app.eventually("the rail is empty again", |tree| { - rows(tree).is_empty() && tree.has("http-rail-empty") && tabs(tree).is_empty() - }); - }); -} - -#[test] -fn http() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("30_http", profile.path()); - app.create_library(); - app.wait_for("note-card"); - - organise(&mut app); - in_tabs(&mut app); - compose(&mut app); - send(&mut app); - bodies(&mut app); - socket(&mut app); - let order = tabs_moved(&mut app); - let mut app = fold_kept(app, &order); - delete(&mut app); - app.quit(); -} diff --git a/e2e/tests/31_http_environments.rs b/e2e/tests/31_http_environments.rs deleted file mode 100644 index ffee3175..00000000 --- a/e2e/tests/31_http_environments.rs +++ /dev/null @@ -1,168 +0,0 @@ -//! The environment a request is sent with, and what a request sets for itself: the picker with no -//! environment yet, an auth and a setting saved and read back after a relaunch, then an -//! environment made, its secret kept, and the question it asks once protected. - -use e2e::old::{App, step}; -use egui::accesskit::Node; -use egui::{Key, Modifiers}; - -const API: &str = "API Paiements"; - -fn ends(name: &str) -> impl Fn(&Node) -> bool + '_ { - move |node| node.label().is_some_and(|label| label.ends_with(name)) -} - -fn create(app: &mut App, name: &str) { - app.fill("http-create-input", name); - app.press(Key::Enter, Modifiers::NONE); -} - -fn a_request(app: &mut App) { - step("a collection and a request to work on", || { - app.press(Key::Num3, Modifiers::COMMAND); - app.wait_for("http-rail-empty"); - app.click("http-rail-empty-create"); - create(app, API); - app.wait_for("http-node-menu"); - app.click_where("http-node-menu", ends(API)); - app.click("http-node-new"); - app.click("http-node-new-http"); - create(app, "Login"); - app.eventually("the request is listed", |tree| tree.texts("http-node-name").len() == 2); - app.click_where("http-node-name", ends("Login")); - app.wait_for("http-url"); - }); -} - -fn picker(app: &mut App) { - step("the picker offers the globals alone", || { - app.click("http-environment-picker"); - app.eventually("one entry, none", |tree| tree.count("http-environment-option") == 1); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("it closes", |tree| !tree.has("http-environment-option")); - }); -} - -fn own_parts(app: &mut App) { - step("an inherited auth said, a token and a timeout set, Ctrl+S", || { - app.click("http-section-auth"); - app.wait_for("http-auth-inherited"); - app.click("http-auth-kind"); - app.click("http-auth-kind-3"); - app.fill("http-auth-secret", "s3cret"); - app.click("http-section-settings"); - app.fill("http-transport-timeoutMs", "5000"); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("the field is settled", |tree| { - tree.find("http-transport-timeoutMs") - .and_then(Node::value) - .is_some_and(|value| value == "5000") - }); - app.press(Key::S, Modifiers::COMMAND); - }); -} - -fn an_environment(app: &mut App) { - step("an environment made, a secret typed, used from the picker", || { - app.click("http-environment-picker"); - app.click("http-environment-manage"); - app.wait_for("http-environments"); - app.click("http-environment-create-open"); - app.fill("http-environment-create-input", "Production"); - app.click("http-environment-create-submit"); - app.wait_for("http-environment-name"); - app.click_nth("http-variable-name", 0); - app.type_text("apiKey"); - app.click_nth("http-variable-value", 0); - app.type_text("s3cret"); - app.click_nth("http-variable-kind", 0); - app.click("http-variable-kind-2"); - app.eventually("the value is masked", |tree| { - tree.has("http-variable-reveal") - && tree - .find("http-variable-value") - .and_then(Node::value) - .is_some_and(|value| value != "s3cret") - }); - app.click("http-environment-use"); - app.eventually("it is the active one", |tree| !tree.has("http-environment-use")); - }); -} - -fn protected(app: &mut App) { - step("once protected, a POST asks before it leaves", || { - app.click("http-environment-protected"); - app.wait_for("http-environment-protected-note"); - app.click("http-environments-open"); - app.wait_for("http-url"); - app.click("http-method"); - app.click("http-method-1"); - let port = e2e::old::serve(); - app.click("http-url"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(&format!("http://127.0.0.1:{port}/json")); - app.click("http-send"); - app.wait_for("http-protected-confirm"); - assert!(!app.has("http-response-status"), "nothing left yet"); - app.click("http-protected-cancel"); - app.eventually("the question goes", |tree| !tree.has("http-protected-confirm")); - app.click("http-send"); - app.click("http-protected-send"); - app.wait_for("http-response-status"); - }); -} - -/// The active environment's secret, named in the URL: its chip's card says where it comes from, -/// masks it, and shows it when asked. -fn pointed_at(app: &mut App) { - step("a variable pointed at says where it is from, and its value", || { - app.click("http-url"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text("https://example.test/{{apiKey}}"); - app.wait_for("http-used-variable"); - app.hover("http-used-variable"); - app.eventually("the card masks the secret", |tree| { - tree.text("http-used-variable-value").as_deref() == Some("••••••••") - }); - app.click("http-used-variable-reveal"); - app.eventually("and shows it", |tree| { - tree.text("http-used-variable-value").as_deref() == Some("s3cret") - }); - }); -} - -fn read_back(app: App) -> App { - let mut app = app.relaunch(); - step("unlocked again, the secret is masked, then shown", || { - app.fill("vault-passphrase", e2e::old::PASSPHRASE); - app.click("vault-submit"); - app.wait_for("area-http"); - app.wait_for("http-url"); - app.click("http-section-auth"); - app.wait_for("http-auth-secret"); - app.click("http-auth-reveal"); - app.eventually("the token came back", |tree| { - tree.find("http-auth-secret") - .and_then(Node::value) - .is_some_and(|value| value == "s3cret") - }); - }); - app -} - -#[test] -fn http_environments() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("31_http_environments", profile.path()); - app.create_library(); - app.wait_for("note-card"); - - a_request(&mut app); - picker(&mut app); - own_parts(&mut app); - let mut app = read_back(app); - an_environment(&mut app); - protected(&mut app); - pointed_at(&mut app); - app.quit_discarding(); -} diff --git a/e2e/tests/32_http_code.rs b/e2e/tests/32_http_code.rs deleted file mode 100644 index 6b01ba4a..00000000 --- a/e2e/tests/32_http_code.rs +++ /dev/null @@ -1,89 +0,0 @@ -//! A request written for another tool: a draft saved into the collection its first save makes, -//! an environment's secret left as a variable until a yes, and the targets of the list. - -use e2e::old::{App, Tree, step}; -use egui::accesskit::Node; -use egui::{Key, Modifiers}; - -fn code(tree: &Tree) -> String { - tree.find("http-code-output") - .and_then(Node::label) - .unwrap_or_default() - .to_owned() -} - -fn named(name: &str) -> impl Fn(&Node) -> bool + '_ { - move |node| node.label() == Some(name) -} - -fn saved_draft(app: &mut App) { - step("a draft saved into the collection it lacks", || { - app.press(Key::Num3, Modifiers::COMMAND); - app.wait_for("http-rail-empty"); - app.click("http-tab-new"); - app.fill("http-url", "https://api.exemple.fr/{{path}}"); - app.press(Key::S, Modifiers::COMMAND); - app.wait_for("http-save-dialog"); - app.fill("http-save-collection", "Facturation"); - app.click("http-save-submit"); - app.eventually("the request is in the rail", |tree| { - tree.texts("http-node-name").len() == 2 && !tree.has("http-save-dialog") - }); - }); -} - -fn secret(app: &mut App) { - step("an environment that sets a secret and a path", || { - app.click("http-environment-picker"); - app.click("http-environment-manage"); - app.click("http-environment-create-open"); - app.fill("http-environment-create-input", "Staging"); - app.click("http-environment-create-submit"); - app.wait_for("http-environment-name"); - app.click_nth("http-variable-name", 0); - app.type_text("path"); - app.click_nth("http-variable-value", 0); - app.type_text("invoices"); - app.click("http-environment-use"); - app.eventually("it is the active one", |tree| !tree.has("http-environment-use")); - app.click("http-environments-open"); - app.wait_for("http-url"); - }); -} - -fn generated(app: &mut App) { - step("cURL from the active environment, then as written", || { - app.click("http-code-open"); - app.wait_for("http-code-dialog"); - app.eventually("the URL is resolved", |tree| code(tree).contains("https://api.exemple.fr/invoices")); - app.click("http-code-resolve"); - app.eventually("the URL is as written", |tree| { - code(tree).contains("https://api.exemple.fr/{{path}}") - }); - app.click("http-code-resolve"); - app.eventually("resolved again", |tree| code(tree).contains("/invoices")); - }); - step("other targets, one of them found by the filter", || { - app.click_where("http-code-target", named("JavaScript · fetch")); - app.eventually("the fetch call", |tree| code(tree).contains("await fetch(")); - app.fill("http-code-filter", "elixir"); - app.click_where("http-code-target", named("Elixir · Req")); - app.eventually("the Req call", |tree| code(tree).contains("Req.request!(")); - app.click("http-code-copy"); - app.press(Key::Escape, Modifiers::NONE); - app.eventually("the dialog closes", |tree| !tree.has("http-code-dialog")); - }); -} - -#[test] -fn http_code() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("32_http_code", profile.path()); - app.create_library(); - app.wait_for("note-card"); - - saved_draft(&mut app); - secret(&mut app); - generated(&mut app); - app.quit(); -} diff --git a/e2e/tests/34_http_scripts.rs b/e2e/tests/34_http_scripts.rs deleted file mode 100644 index 8c8c81c6..00000000 --- a/e2e/tests/34_http_scripts.rs +++ /dev/null @@ -1,161 +0,0 @@ -//! Scripts run for real: the application relaunches itself as their host. One keeps a value of the -//! answer in a variable, a test reads the answer, the console hears them, the answer is kept as a -//! note, a file a script asks to send waits for a yes, and a throw before the send stops it and -//! leads back to its line. - -use e2e::old::{App, Tree, step}; -use egui::accesskit::Node; -use egui::{Key, Modifiers}; - -fn ends(name: &str) -> impl Fn(&Node) -> bool + '_ { - move |node| node.label().is_some_and(|label| label.ends_with(name)) -} - -fn create(app: &mut App, name: &str) { - app.fill("http-create-input", name); - app.press(Key::Enter, Modifiers::NONE); -} - -fn request(app: &mut App) { - step("a request to the local server", || { - let port = e2e::old::serve(); - app.press(Key::Num3, Modifiers::COMMAND); - app.wait_for("http-rail-empty"); - app.click("http-rail-empty-create"); - create(app, "Boutique"); - app.wait_for("http-node-menu"); - app.click_where("http-node-menu", ends("Boutique")); - app.click("http-node-new"); - app.click("http-node-new-http"); - create(app, "Commander"); - app.eventually("the request is listed", |tree| tree.texts("http-node-name").len() == 2); - app.click_where("http-node-name", ends("Commander")); - app.fill("http-url", &format!("http://127.0.0.1:{port}/json")); - }); -} - -fn counted(tree: &Tree) -> Vec { - tree.texts("http-section-count") -} - -fn kept_value(app: &mut App) { - step("a script after the answer keeps a value in the globals", || { - app.click("http-section-scripts"); - app.wait_for("http-script-code"); - app.click("http-script-phase-1"); - app.fill("http-script-code", "env.set('who', res.json().name);"); - app.eventually("the tab counts it", |tree| counted(tree).contains(&"1".to_owned())); - app.press(Key::Enter, Modifiers::COMMAND); - app.wait_for("http-response-status"); - app.click("http-environments-open"); - app.eventually("the value is in the globals", |tree| { - tree.all("http-variable-value").iter().any(|node| node.value() == Some("Ada")) - }); - app.click("http-environments-open"); - app.wait_for("http-url"); - }); -} - -fn tests_and_console(app: &mut App) { - step("the tests of an answer, and what the console heard", || { - app.click("http-section-tests"); - app.fill("http-script-code", "test('the status is 200', () => { expect(res.status).toBe(200); });"); - app.eventually("the test is typed", |tree| { - tree.find("http-script-code") - .and_then(Node::value) - .is_some_and(|text| text.contains("toBe(200)")) - }); - app.press(Key::Enter, Modifiers::COMMAND); - app.wait_for("http-response-section-tests"); - app.click("http-response-section-tests"); - app.wait_for("http-tests-passed"); - app.click("http-console-unfold"); - app.wait_for("http-console-line"); - app.click("http-console-fold"); - app.wait_for("http-console-unfold"); - app.click("http-response-section-body"); - }); - step("the answer kept as a note", || { - app.click("http-response-save-note"); - app.wait_for("save-as-note-submit"); - app.eventually("the dialog is filled", |tree| { - tree.find("save-as-note-title") - .and_then(Node::value) - .is_some_and(|title| title.contains("Commander")) - }); - app.click("save-as-note-submit"); - app.eventually("the dialog closes", |tree| !tree.has("save-as-note")); - }); -} - -fn file_asked(app: &mut App, path: &str) { - step("a file a script asks to send waits for a yes", || { - app.click("http-section-scripts"); - app.click("http-script-phase-0"); - app.fill( - "http-script-code", - &format!("pm.request.body.update({{ mode: 'file', file: {{ src: '{path}' }} }});"), - ); - app.eventually("the script is typed", |tree| { - tree.find("http-script-code") - .and_then(Node::value) - .is_some_and(|text| text.contains("id_ed25519")) - }); - app.press(Key::Enter, Modifiers::COMMAND); - app.eventually("the file is named", |tree| { - tree.text("http-script-file-confirm") - .is_some_and(|said| said.contains("id_ed25519")) - }); - app.capture("file-asked"); - app.click("http-script-file-cancel"); - app.eventually("nothing left", |tree| { - !tree.has("http-script-file-confirm") && !tree.has("http-response-status") - }); - app.press(Key::Enter, Modifiers::COMMAND); - app.wait_for("http-script-file-confirm"); - app.click("http-script-file-send"); - app.wait_for("http-response-status"); - }); -} - -fn stopped(app: &mut App) { - step("a throw before the send stops it, and leads to its line", || { - app.click("http-section-scripts"); - app.click("http-script-phase-0"); - app.fill("http-script-code", "\nthrow new Error('refused');"); - // A key overtakes what is still being typed. - app.eventually("the script is typed", |tree| { - tree.find("http-script-code") - .and_then(Node::value) - .is_some_and(|text| text.contains("refused")) - }); - app.press(Key::Enter, Modifiers::COMMAND); - app.eventually("the stop is said", |tree| { - tree.text("http-script-stop-message") - .is_some_and(|said| said.contains("refused")) - }); - app.wait_for("http-script-stop-where"); - app.click("http-script-open"); - app.wait_for("http-script-code"); - }); -} - -#[test] -fn http_scripts() { - let profile = tempfile::tempdir().unwrap(); - let mut app = App::launch("34_http_scripts", profile.path()); - app.create_library(); - app.wait_for("note-card"); - - let outside = tempfile::tempdir().unwrap(); - let key = outside.path().join("id_ed25519"); - std::fs::write(&key, "not a key").unwrap(); - let path = key.display().to_string().replace('\\', "/"); - - request(&mut app); - kept_value(&mut app); - tests_and_console(&mut app); - file_asked(&mut app, &path); - stopped(&mut app); - app.quit_discarding(); -} diff --git a/e2e/tests/35_http_runner.rs b/e2e/tests/35_http_runner.rs deleted file mode 100644 index 904ef176..00000000 --- a/e2e/tests/35_http_runner.rs +++ /dev/null @@ -1,169 +0,0 @@ -//! A collection run: two requests over two iterations, each with its test, summed up, what failed -//! open on its assertion, nothing in the history; the rows of a data file; the order arranged kept -//! over a relaunch; and the quit that asks about a request left with changes. - -use e2e::old::{App, Tree, step}; -use egui::accesskit::Node; -use egui::{Key, Modifiers}; - -const API: &str = "Execution"; - -fn ends(name: &str) -> impl Fn(&Node) -> bool + '_ { - move |node| node.label().is_some_and(|label| label.ends_with(name)) -} - -fn create(app: &mut App, name: &str) { - app.fill("http-create-input", name); - app.press(Key::Enter, Modifiers::NONE); -} - -fn a_request(app: &mut App, name: &str, url: &str) { - app.click_where("http-node-menu", ends(API)); - app.click("http-node-new"); - app.click("http-node-new-http"); - create(app, name); - app.eventually("the request is listed", |tree| { - tree.all("http-node-name") - .iter() - .any(|node| node.label().is_some_and(|label| label.ends_with(name))) - }); - app.click_where("http-node-name", ends(name)); - app.fill("http-url", url); - app.click("http-section-tests"); - app.wait_for("http-script-code"); - app.fill("http-script-code", "test('found', () => { expect(res.status).toBe(200); });"); - app.eventually("the test is typed", |tree| { - tree.find("http-script-code") - .and_then(Node::value) - .is_some_and(|text| text.contains("toBe(200)")) - }); - app.click("http-save"); - app.eventually("the request is saved", |tree| tree.find("http-save").is_some_and(Node::is_disabled)); -} - -fn collection(app: &mut App) { - step("a collection of two requests with their tests", || { - let port = e2e::old::serve(); - app.press(Key::Num3, Modifiers::COMMAND); - app.wait_for("http-rail-empty"); - app.click("http-rail-empty-create"); - create(app, API); - app.wait_for("http-node-menu"); - a_request(app, "Login", &format!("http://127.0.0.1:{port}/json")); - a_request(app, "Client", &format!("http://127.0.0.1:{port}/missing")); - }); -} - -fn open_runner(app: &mut App) { - app.click_where("http-node-menu", ends(API)); - app.click("http-node-run"); - app.eventually("the order is read", |tree| tree.count("http-runner-row") == 2); -} - -fn figures(tree: &Tree) -> String { - tree.text("http-runner-figures").unwrap_or_default() -} - -fn over_iterations(app: &mut App) { - step("a run over two iterations, summed up", || { - open_runner(app); - app.click("http-runner-iterations"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text("2"); - app.eventually("the field says two iterations", |tree| { - tree.find("http-runner-iterations").and_then(Node::value) == Some("2") - }); - app.click("http-runner-start"); - app.eventually("the run is summed up", |tree| { - figures(tree).contains(" 2/4") && figures(tree).ends_with(" s") - }); - }); - step("each iteration apart, the failed requests open", || { - let tree = app.tree(); - assert_eq!(tree.count("http-runner-iteration"), 2); - assert_eq!(tree.count("http-runner-result-passed"), 2); - assert_eq!(tree.count("http-runner-result-failed"), 2); - assert_eq!(tree.count("http-runner-test"), 2); - app.click("http-runner-filter-failed"); - app.eventually("only the failed are shown", |tree| tree.count("http-runner-result-passed") == 0); - app.click("http-runner-filter-all"); - }); - step("a run writes no history", || { - app.click("http-history-open"); - app.wait_for("http-history"); - app.eventually("nothing is listed", |tree| tree.count("http-history-item") == 0); - }); -} - -fn over_a_file(app: &mut App) { - step("a data file gives an iteration a row", || { - open_runner(app); - app.click("http-runner-data-choose"); - app.wait_for("http-runner-data"); - app.click("http-runner-start"); - app.eventually("each row ran, and the run is over", |tree| { - tree.count("http-runner-iteration") == 3 && !tree.has("http-runner-cancel") - }); - }); -} - -fn order_kept(app: &mut App) { - step("the order moved by the keys", || { - app.click_nth("http-runner-row", 0); - app.eventually("the row has the focus", |tree| { - tree.focused().contains("http-runner-row") && tree.focused().contains("Login") - }); - app.press(Key::ArrowDown, Modifiers::ALT); - app.eventually("the rows are swapped", |tree| { - tree.all("http-runner-row") - .first() - .is_some_and(|row| row.label() == Some("Client")) - }); - }); -} - -#[test] -fn http_runner() { - let profile = tempfile::tempdir().unwrap(); - let files = tempfile::tempdir().unwrap(); - let csv = files.path().join("clients.csv"); - std::fs::write(&csv, "customer\ncus_1\ncus_2\ncus_3\n").unwrap(); - let mut app = App::launch_answering("35_http_runner", profile.path(), &csv); - app.create_library(); - app.wait_for("note-card"); - - collection(&mut app); - over_iterations(&mut app); - over_a_file(&mut app); - order_kept(&mut app); - - let mut app = app.relaunch(); - step("the order is still the one arranged", || { - app.fill("vault-passphrase", e2e::old::PASSPHRASE); - app.click("vault-submit"); - app.wait_for("area-http"); - app.wait_for("http-node-menu"); - open_runner(&mut app); - app.eventually("the order is the one kept", |tree| { - tree.all("http-runner-row") - .first() - .is_some_and(|row| row.label() == Some("Client")) - }); - }); - step("a quit asks about a request with changes", || { - app.click_where("http-node-name", ends("Login")); - app.wait_for("http-url"); - app.fill("http-url", "/changed"); - app.eventually("the request has changes", |tree| { - tree.find("http-save").is_some_and(|save| !save.is_disabled()) - }); - app.act("quit"); - app.wait_for("http-leave-dialog"); - app.click("http-leave-cancel"); - app.eventually("the question is gone", |tree| !tree.has("http-leave-dialog")); - app.act("quit"); - app.wait_for("http-leave-dialog"); - app.click("http-leave-save"); - }); - app.ended(); -} diff --git a/e2e/tests/40_recette_http.rs b/e2e/tests/40_recette_http.rs deleted file mode 100644 index 34b5ef14..00000000 --- a/e2e/tests/40_recette_http.rs +++ /dev/null @@ -1,273 +0,0 @@ -//! The acceptance sheet's main paths through the HTTP area that no other scenario walks whole, on -//! the local server. A step opens on the case it runs, so that a run can be read back into the -//! sheet. - -use e2e::old::{App, Tree, step}; -use egui::accesskit::Node; -use egui::{Key, Modifiers}; - -const COLLECTION: &str = "Recette API"; -const BASIC: &str = "http-auth-kind-2"; -const BEARER: &str = "http-auth-kind-3"; -const POST: &str = "http-method-1"; -const JSON_BODY: &str = "http-body-kind-1"; -const BIG: &str = r#"{"nom":"Recette","grand":12345678901234567890,"prix":1.10}"#; - -fn values(tree: &Tree, author_id: &str) -> Vec { - tree.all(author_id) - .into_iter() - .map(|node| node.value().unwrap_or_default().to_owned()) - .collect() -} - -fn url_of(tree: &Tree) -> String { - tree.find("http-url").and_then(Node::value).unwrap_or_default().to_owned() -} - -fn set_url(app: &mut App, url: &str) { - app.click("http-url"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text(url); -} - -fn send(app: &mut App, url: &str) { - set_url(app, url); - app.press(Key::Enter, Modifiers::COMMAND); - app.eventually("the answer is shown", |tree| { - tree.has("http-response-status") && !tree.has("http-response-sending") - }); -} - -fn answers(app: &mut App, words: &str) { - app.eventually(&format!("the answer says {words}"), |tree| { - tree.text("http-response-pretty") - .or_else(|| tree.text("http-response-body")) - .is_some_and(|body| body.contains(words)) - }); -} - -fn a_draft(app: &mut App) { - app.click("http-tab-new"); - app.wait_for("http-url"); -} - -fn http(scenario: &'static str, profile: &std::path::Path) -> App { - let mut app = App::launch(scenario, profile); - app.create_library(); - app.press(Key::Num3, Modifiers::COMMAND); - app.wait_for("http-rail-title"); - app -} - -#[test] -fn recette_composing() { - let profile = tempfile::tempdir().unwrap(); - let mut app = http("40_recette_composing", profile.path()); - app.resize(1100, 1100); - - step("HRQ-01 a new request writes nothing", || { - a_draft(&mut app); - set_url(&mut app, "https://exemple.fr/get"); - app.click_nth("http-tab-close", 0); - app.wait_for("http-close-dialog"); - app.capture("hrq-01"); - app.click("http-close-discard"); - app.wait_for("http-rail-empty"); - }); - - step("HRL-01 a first collection", || { - app.click("http-rail-empty-create"); - app.fill("http-create-input", COLLECTION); - app.press(Key::Enter, Modifiers::NONE); - app.eventually("it is listed", |tree| tree.texts("http-node-name") == [COLLECTION]); - }); - - step("HRQ-02 saved: a name is asked, and a place", || { - a_draft(&mut app); - set_url(&mut app, "https://exemple.fr/facture"); - app.press(Key::S, Modifiers::COMMAND); - app.wait_for("http-save-dialog"); - app.click("http-save-name"); - app.press(Key::A, Modifiers::COMMAND); - app.press(Key::Backspace, Modifiers::NONE); - app.click("http-save-submit"); - app.wait_for("http-save-missing"); - app.capture("hrq-02"); - app.fill("http-save-name", "Lire une facture"); - app.click("http-save-submit"); - app.eventually("it is in the rail", |tree| { - tree.texts("http-node-name").iter().any(|it| it.ends_with("Lire une facture")) - }); - }); - - step("HRQ-04 a saved request changed asks before it closes", || { - set_url(&mut app, "https://exemple.fr/autre"); - app.capture("hrq-04-dot"); - app.click_nth("http-tab-close", 0); - app.wait_for("http-close-modified"); - app.click("http-close-cancel"); - app.eventually("the dialog closed", |tree| !tree.has("http-close-dialog")); - }); - - step("HRQ-05 the URL and its table agree", || { - set_url(&mut app, "https://exemple.fr/get?page=2&q=café"); - app.eventually("the table reads the URL", |tree| { - values(tree, "http-kv-key").starts_with(&["page".to_owned(), "q".to_owned()]) - }); - app.click_nth("http-kv-enabled", 1); - app.eventually("q leaves the URL and stays in the table", |tree| { - !url_of(tree).contains("q=") && values(tree, "http-kv-key")[1] == "q" - }); - app.click_nth("http-kv-key", 2); - app.type_text("limit"); - app.click_nth("http-kv-value", 2); - app.type_text("10"); - app.eventually("limit joins the URL", |tree| url_of(tree).contains("limit=10")); - append_to_url(&mut app, "&x={{page}}"); - app.eventually("a variable stays as written", |tree| url_of(tree).contains("{{page}}")); - }); - - step("HRQ-06 headers pasted are as many rows, typed ones split", || { - app.click("http-section-headers"); - app.wait_for("http-implied-headers"); - app.click_nth("http-kv-key", 0); - app.paste("Accept: application/json\nX-Trace: abc\nX-Tenant: recette"); - app.eventually("three rows", |tree| { - values(tree, "http-kv-key").starts_with(&[ - "Accept".to_owned(), - "X-Trace".to_owned(), - "X-Tenant".to_owned(), - ]) - }); - let last = app.tree().count("http-kv-key") - 1; - app.click_nth("http-kv-key", last); - app.type_text("X-Recette: 1"); - app.eventually("key and value apart", |tree| { - values(tree, "http-kv-key").contains(&"X-Recette".to_owned()) - && values(tree, "http-kv-value").contains(&"1".to_owned()) - }); - }); - - what_goes_with_it(&mut app); - app.quit_discarding(); -} - -fn what_goes_with_it(app: &mut App) { - step("HRQ-09 what leaves unasked is said", || { - a_draft(app); - set_url(app, "https://exemple.fr/post"); - app.click("http-section-body"); - app.click(JSON_BODY); - app.fill("http-body-text", "{}"); - app.click("http-section-headers"); - app.eventually("the implied headers are said", |tree| { - let said = tree.texts("http-implied-value").join(" "); - said.contains("DevNotes/") && said.contains("*/*") && said.contains("application/json") - }); - app.capture("hrq-09"); - }); - - step("HRL-06 a folder deleted says which change goes with it", || { - app.click_where("http-node-menu", |node| node.label().is_some_and(|it| it.ends_with(COLLECTION))); - app.click("http-node-delete"); - app.wait_for("http-delete-unsaved"); - app.capture("hrl-06"); - app.click("http-delete-cancel"); - app.eventually("nothing went", |tree| !tree.has("http-delete-unsaved")); - assert_eq!(app.tree().count("http-node-name"), 2); - }); -} - -fn append_to_url(app: &mut App, words: &str) { - app.click("http-url"); - app.press(Key::End, Modifiers::NONE); - app.type_text(words); -} - -#[test] -fn recette_sending() { - let profile = tempfile::tempdir().unwrap(); - let mut app = http("40_recette_sending", profile.path()); - let port = e2e::old::serve(); - let at = |path: &str| format!("http://127.0.0.1:{port}{path}"); - a_draft(&mut app); - - step("HRQ-10 Basic, its password hidden until asked", || { - app.click("http-section-auth"); - app.click("http-auth-kind"); - app.click(BASIC); - app.fill("http-auth-username", "ada"); - app.fill("http-auth-secret", "secret"); - app.capture("hrq-10-hidden"); - send(&mut app, &at("/echo")); - answers(&mut app, "Basic YWRhOnNlY3JldA=="); - }); - - step("HRQ-11 Bearer", || { - app.click("http-auth-kind"); - app.click(BEARER); - app.click("http-auth-secret"); - app.press(Key::A, Modifiers::COMMAND); - app.type_text("jeton-recette"); - send(&mut app, &at("/echo")); - answers(&mut app, "Bearer jeton-recette"); - }); - - step("HHI-02 the history masks both", || { - app.click("http-history-open"); - app.wait_for("http-history-item"); - app.click("http-history-item"); - app.wait_for("http-history-url"); - app.capture("hhi-02"); - app.eventually("no secret is read", |tree| { - !tree.mentions("jeton-recette") && !tree.mentions("YWRhOnNlY3JldA==") - }); - app.click("http-history-reopen"); - app.eventually("back to the request", |tree| !tree.has("http-history")); - }); - - step("HRQ-14 a JSON body leaves as it was written", || { - app.click("http-method"); - app.click(POST); - app.click("http-section-body"); - app.click(JSON_BODY); - app.click("http-body-text"); - app.paste(BIG); - send(&mut app, &at("/echo")); - answers(&mut app, BIG); - }); - - step("HRS-02 a send under way is said, and cancelled", || { - set_url(&mut app, &at("/slow")); - app.press(Key::Enter, Modifiers::COMMAND); - app.wait_for("http-response-sending"); - app.capture("hrs-02"); - app.click("http-send"); - app.wait_for("http-response-cancelled"); - }); - - step("HRS-04 the views of a body", || { - app.click("http-method"); - app.click("http-method-0"); - send(&mut app, &at("/json")); - for view in ["http-response-view-0", "http-response-view-1", "http-response-view-3"] { - app.click(view); - app.capture(view); - } - app.click("http-response-view-0"); - send(&mut app, &at("/png")); - app.wait_for("http-response-image"); - send(&mut app, &at("/bytes")); - app.wait_for("http-response-binary"); - app.capture("hrs-04-binary"); - }); - - step("HRS-06 redirects are followed and counted", || { - send(&mut app, &at("/redirect/3")); - app.click("http-response-section-timeline"); - app.wait_for("http-response-redirect"); - app.capture("hrs-06"); - }); - - app.quit_discarding(); -}