Initial impl
This commit is contained in:
commit
4b729c5d32
133 files changed
+20475
No files matched your search
@@ -0,0 +1,148 @@
|
||||
//! Renders the real UI to PNG files for a visual check. Needs a GPU (or a
|
||||
//! software Vulkan driver), so it is ignored by default:
|
||||
//!
|
||||
//! REQLITE_RENDER_DIR=/tmp/shots cargo test -p reqlite-app --test render -- --ignored
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use egui_kittest::Harness;
|
||||
use reqlite_app::action::Action;
|
||||
use reqlite_app::state::{RequestTab, ResponseTab};
|
||||
use reqlite_app::ReqliteApp;
|
||||
use reqlite_core::http::{BodyStore, HttpClient, HttpError, ResolvedRequest, Response, Timings};
|
||||
use reqlite_core::CancelToken;
|
||||
|
||||
struct Canned;
|
||||
|
||||
impl HttpClient for Canned {
|
||||
async fn send(&self, req: ResolvedRequest, _c: CancelToken) -> Result<Response, HttpError> {
|
||||
let body = r#"{"id":42,"name":"Ada Lovelace","email":"ada@example.com","roles":["admin","author"],"active":true,"manager":null,"stats":{"posts":128,"score":9.75}}"#;
|
||||
Ok(Response {
|
||||
status: 200,
|
||||
reason: "OK".into(),
|
||||
http_version: "HTTP/2".into(),
|
||||
headers: vec![
|
||||
("content-type".into(), "application/json; charset=utf-8".into()),
|
||||
("cache-control".into(), "no-store".into()),
|
||||
("x-request-id".into(), "7f3a9c2e".into()),
|
||||
],
|
||||
size: body.len() as u64,
|
||||
body: BodyStore::InMemory(Arc::new(body.as_bytes().to_vec())),
|
||||
timings: Timings {
|
||||
dns: Duration::from_millis(4),
|
||||
connect: Duration::from_millis(19),
|
||||
tls: Duration::from_millis(48),
|
||||
ttfb: Duration::from_millis(112),
|
||||
total: Duration::from_millis(118),
|
||||
},
|
||||
effective_url: req.url,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn shoot(h: &mut Harness<'_, ReqliteApp>, name: &str) {
|
||||
let Ok(dir) = std::env::var("REQLITE_RENDER_DIR") else {
|
||||
return;
|
||||
};
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
for _ in 0..3 {
|
||||
h.step();
|
||||
}
|
||||
let img = h.render().expect("render");
|
||||
img.save(format!("{dir}/{name}.png")).unwrap();
|
||||
}
|
||||
|
||||
fn wait(h: &mut Harness<'_, ReqliteApp>, done: impl Fn(&ReqliteApp) -> bool) {
|
||||
let start = Instant::now();
|
||||
while !done(h.state()) {
|
||||
assert!(start.elapsed() < Duration::from_secs(5));
|
||||
h.step();
|
||||
std::thread::sleep(Duration::from_millis(10));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "needs a GPU; run with --ignored"]
|
||||
fn screenshots() {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let root = dir.path().canonicalize().unwrap();
|
||||
std::fs::create_dir(root.join("orders")).unwrap();
|
||||
std::fs::write(
|
||||
root.join("users.http"),
|
||||
"### List users\nGET {{base_url}}/users?limit=20&sort=name\nAccept: application/json\n\n### Create user\n# @name create-user\nPOST {{base_url}}/users\nContent-Type: application/json\nAuthorization: Bearer {{token}}\n\n{\n \"name\": \"Ada\",\n \"team\": \"{{team}}\"\n}\n\n### Delete user\nDELETE {{base_url}}/users/{{id}}\n",
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(
|
||||
root.join("orders/orders.http"),
|
||||
"### Get order\nGET {{base_url}}/orders/1\n",
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(
|
||||
root.join("http-client.env.json"),
|
||||
r#"{"dev": {"base_url": "http://localhost:8080", "team": "core"}, "prod": {"base_url": "https://api.example.com"}}"#,
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(
|
||||
root.join("http-client.private.env.json"),
|
||||
r#"{"dev": {"token": "dev-secret"}}"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let app = ReqliteApp::new(None, rt.handle().clone(), Arc::new(Canned), None);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1280.0, 800.0))
|
||||
.wgpu()
|
||||
.build_ui_state(
|
||||
|ui, app: &mut ReqliteApp| {
|
||||
egui_extras::install_image_loaders(ui.ctx());
|
||||
app.frame(ui)
|
||||
},
|
||||
app,
|
||||
);
|
||||
shoot(&mut h, "01-welcome");
|
||||
|
||||
h.state_mut().dispatch(Action::OpenCollection(root.clone()));
|
||||
wait(&mut h, |a| {
|
||||
a.state.collection.as_ref().is_some_and(|c| !c.envs.names().is_empty())
|
||||
});
|
||||
h.state_mut().dispatch(Action::SelectEnv(Some("dev".into())));
|
||||
h.state_mut().dispatch(Action::OpenRequest {
|
||||
file: root.join("users.http"),
|
||||
index: 1,
|
||||
});
|
||||
let id = h.state().state.active.unwrap();
|
||||
h.state_mut().dispatch(Action::SetRequestTab(id, RequestTab::Body));
|
||||
shoot(&mut h, "02-collection-body-tab");
|
||||
|
||||
h.state_mut().dispatch(Action::SetRequestTab(id, RequestTab::Headers));
|
||||
h.state_mut().dispatch(Action::Send(id));
|
||||
wait(&mut h, |a| {
|
||||
a.state
|
||||
.active_tab()
|
||||
.and_then(|t| t.response.as_ref())
|
||||
.is_some_and(|r| r.prepared.is_some())
|
||||
});
|
||||
shoot(&mut h, "03-json-response");
|
||||
|
||||
h.state_mut().dispatch(Action::SearchOpen(id, true));
|
||||
h.state_mut().dispatch(Action::SearchQuery(id, "a".into()));
|
||||
h.state_mut().dispatch(Action::SetRequestTab(id, RequestTab::Source));
|
||||
shoot(&mut h, "04-source-and-search");
|
||||
|
||||
h.state_mut().dispatch(Action::SetResponseTab(id, ResponseTab::Timings));
|
||||
h.state_mut().dispatch(Action::SetRequestTab(id, RequestTab::Auth));
|
||||
shoot(&mut h, "05-auth-and-timings");
|
||||
|
||||
h.state_mut().dispatch(Action::OpenEnvEditor);
|
||||
shoot(&mut h, "06-env-editor");
|
||||
h.state_mut().dispatch(Action::EnvEditorClose);
|
||||
|
||||
let mut s = h.state().state.settings.clone();
|
||||
s.theme = reqlite_app::settings::ThemeChoice::Light;
|
||||
h.state_mut().dispatch(Action::SettingsChanged(s));
|
||||
h.state_mut().dispatch(Action::SetResponseTab(id, ResponseTab::Body));
|
||||
h.state_mut().dispatch(Action::SetRequestTab(id, RequestTab::Params));
|
||||
shoot(&mut h, "07-light-theme");
|
||||
}
|
||||
Reference in new issue
Block a user