mod support;
use support::inspect::{Inspector, representative_store, urlencode};
#[test]
fn anchored_range_fact_still_renders_after_map_bucketing() {
let store = representative_store();
let insp = Inspector::spawn(store.repo.path());
let unit = insp.get_json(&format!("/api/revisions/{}", urlencode(&store.revision_id)));
let obs = &unit["observations"][0]["target"];
assert_eq!(obs["filePath"], "src/lib.rs");
assert_eq!(obs["startLine"], 2);
assert_eq!(obs["endLine"], 2);
let object = insp.get_json(&format!("/api/snapshots/{}", urlencode(&store.snapshot_id)));
let files = object["snapshot"]["files"].as_array().unwrap();
assert!(
files
.iter()
.any(|f| f["new_path"] == "src/lib.rs" || f["old_path"] == "src/lib.rs"),
"the snapshot carries the file the range fact anchors to"
);
}
#[test]
fn diff_css_styles_the_accordion_from_tokens_not_raw_hex() {
let store = representative_store();
let css = Inspector::spawn(store.repo.path()).get_text("/app.css");
assert!(
css.contains("data-expanded"),
"app.css drives the accordion body off internal render state"
);
assert!(
css.contains(".dfile-head") && css.contains("cursor"),
"the file header reads as clickable"
);
}
#[test]
fn anchored_fact_remains_reachable_in_a_default_open_file() {
let store = representative_store();
let insp = Inspector::spawn(store.repo.path());
let unit = insp.get_json(&format!("/api/revisions/{}", urlencode(&store.revision_id)));
assert_eq!(unit["observations"][0]["target"]["filePath"], "src/lib.rs");
}
#[test]
fn diff_modal_has_a_sticky_file_navigator() {
let store = representative_store();
let html = Inspector::spawn(store.repo.path()).get_text("/");
assert!(
html.contains("id=\"diff-nav\""),
"the modal carries a file/fact navigator region"
);
assert!(
html.contains("aria-label=\"diff files\""),
"the navigator exposes a stable label"
);
}
#[test]
fn diff_modal_has_dialog_semantics_and_an_initial_focus_target() {
let store = representative_store();
let html = Inspector::spawn(store.repo.path()).get_text("/");
assert!(
html.contains("id=\"diff-modal\"")
&& html.contains("role=\"dialog\"")
&& html.contains("aria-modal=\"true\""),
"diff overlay should expose dialog semantics matching modal behavior"
);
assert!(
html.contains("aria-labelledby=\"diff-title\""),
"diff dialog should be labelled by its visible title"
);
assert!(
html.contains("id=\"diff-close\"") && html.contains("aria-label=\"close diff\""),
"diff close button should be the reachable initial focus target"
);
}
#[test]
fn drow_noted_gutter_is_a_clickable_marker() {
let store = representative_store();
let insp = Inspector::spawn(store.repo.path());
let css = insp.get_text("/app.css");
assert!(
css.contains(".drow-noted"),
"the annotated-row gutter marker is styled"
);
}
#[test]
fn low_signal_collapse_styles_a_one_line_header() {
let store = representative_store();
let css = Inspector::spawn(store.repo.path()).get_text("/app.css");
assert!(
css.contains("dfile-lowsignal") || css.contains("[data-lowsignal]"),
"app.css styles the collapsed low-signal header"
);
}
#[test]
fn binary_file_renders_collapsed_by_default() {
let repo = support::git_repo::GitRepo::new();
repo.write("README.md", "base\n");
repo.commit_all("base");
std::fs::write(repo.path().join("logo.png"), [0u8, 1, 2, 0, 255, 0, 13]).unwrap();
support::inspect::capture(repo.path());
let insp = Inspector::spawn(repo.path());
let revisions = insp.get_json("/api/revisions");
let snapshot_id = revisions["entries"][0]["snapshotId"]
.as_str()
.expect("the captured revision exposes its snapshot id");
let object = insp.get_json(&format!("/api/snapshots/{}", urlencode(snapshot_id)));
let files = object["snapshot"]["files"].as_array().unwrap();
let png = files
.iter()
.find(|f| f["new_path"] == "logo.png" || f["old_path"] == "logo.png")
.expect("the captured snapshot carries the binary file");
assert_eq!(
png["is_binary"], true,
"the binary file is flagged is_binary"
);
assert!(
png["hunks"].as_array().is_none_or(|h| h.is_empty()),
"the binary file carries no content hunks"
);
}
#[test]
fn snapshot_endpoint_emphasizes_changed_word() {
let repo = support::git_repo::GitRepo::new();
repo.write(
"src/lib.rs",
"pub fn compute() -> u32 {\n let total = a;\n total\n}\n",
);
repo.commit_all("base");
repo.write(
"src/lib.rs",
"pub fn compute() -> u32 {\n let total = b;\n total\n}\n",
);
support::inspect::capture(repo.path());
let insp = Inspector::spawn(repo.path());
let revisions = insp.get_json("/api/revisions");
let snapshot_id = revisions["entries"][0]["snapshotId"]
.as_str()
.expect("the captured revision exposes its snapshot id");
let object = insp.get_json(&format!("/api/snapshots/{}", urlencode(snapshot_id)));
let rows = object["snapshot"]["files"][0]["hunks"][0]["rows"]
.as_array()
.expect("the modified file carries a hunk with rows");
let added = rows
.iter()
.find(|row| row["kind"] == "added")
.expect("the hunk carries an added row");
let emphasis = added["emphasis"]
.as_array()
.expect("the changed added row carries an emphasis array");
assert_eq!(emphasis.len(), 1, "only the changed word is emphasized");
let start = emphasis[0]["start"].as_u64().unwrap();
let end = emphasis[0]["end"].as_u64().unwrap();
assert!(end > start, "the emphasis span is a non-empty UTF-16 range");
let context = rows
.iter()
.find(|row| row["kind"] == "context")
.expect("the hunk carries a context row");
assert!(
context.get("emphasis").is_none(),
"context rows omit emphasis"
);
}