Lines
87.23 %
Functions
91.67 %
Branches
100 %
//! The template source box is sized for code on both template pages.
use anyhow::{Result, ensure};
use serde_json::json;
use super::harness::{Harness, with_harness};
use super::page::{login, open, wait_for};
const SOURCE: &str = "(set-draft-note \"Groceries\")";
const SOURCE_BOX: &str = r#"
const box = document.querySelector('textarea[name="source"]');
const form = box.closest('form').getBoundingClientRect();
const style = getComputedStyle(box);
return {
ratio: box.getBoundingClientRect().width / form.width,
whiteSpace: style.whiteSpace,
font: style.fontFamily,
resize: style.resize,
rows: box.getBoundingClientRect().height / parseFloat(style.lineHeight),
};
"#;
async fn check_source_box(h: &Harness, path: &str) -> Result<()> {
open(h, path).await?;
let found = h.driver.run(SOURCE_BOX, vec![]).await?;
ensure!(
found["ratio"].as_f64().is_some_and(|r| r >= 0.8),
"{path}: the box is not the form width: {found}"
);
found["whiteSpace"] == json!("pre"),
"{path}: the box wraps: {found}"
found["font"]
.as_str()
.is_some_and(|f| f.contains("monospace")),
"{path}: the box is not monospace: {found}"
found["resize"] == json!("vertical"),
"{path}: the box does not resize vertically: {found}"
found["rows"].as_f64().is_some_and(|r| r >= 15.0),
"{path}: the box is too short: {found}"
Ok(())
}
async fn create_template(h: &Harness) -> Result<String> {
server::user::User { id: h.tenant.id }
.create_template(SOURCE.to_string(), Some("e2e".to_string()))
.await?;
open(h, "/template/list").await?;
// The rows arrive by an htmx load after the page is ready.
let href = wait_for(
&h.driver,
"const a = document.querySelector('a[href^=\"/template/edit/\"]'); \
return a && a.getAttribute('href');",
vec![],
"an edit link on the template list",
)
href.as_str()
.map(str::to_owned)
.ok_or_else(|| anyhow::anyhow!("no edit link on the template list"))
async fn editors(h: &Harness) -> Result<()> {
login(h).await?;
check_source_box(h, "/template/create").await?;
let edit = create_template(h).await?;
check_source_box(h, &edit).await
#[supp_macro::shared_runtime_test]
async fn template_source_box_is_sized_for_code() -> Result<()> {
with_harness(|h| Box::pin(editors(h))).await