Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/facett

facett-console/tests/a11y.rs

//! **FC-4 interaction-layer proof for facett-console.** Before FC-4 the whole
//! console — scrollback, the prompt/input line, and the cursor — was painted on a
//! single `Sense::hover()` alloc: zero accesskit nodes, so `get_by_role` / a robot
//! driver / screen reader could see *nothing* of the typed input or the
//! scrollback. This renders a real [`Console`] headless through `egui_kittest`
//! with a known input string + a couple of scrollback lines, then asserts:
//!
//! * the input line rode in as a `Role::TextInput` node whose accesskit **value**
//!   is exactly the typed string (so a value query reads back the input), and
//! * the scrollback region rode in as a labelled node findable by its label.

use egui::accesskit::Role;
use egui_kittest::Harness;
use egui_kittest::kittest::{NodeT, Queryable};

use facett_core::Facet;
use facett_console::Console;

#[test]
fn input_line_exposes_typed_text_and_scrollback_is_labelled() {
    let mut c = Console::new("term");
    // Inject real state: two scrollback lines + a known in-progress input string.
    c.push_line("\x1b[32m[001]\x1b[0m built ok");
    c.push_line("running tests ...");
    c.set_input("cargo test --all");

    let mut harness = Harness::new_ui(move |ui| {
        c.ui(ui);
    });
    harness.run();

    // (1) The input line is an accesskit TextInput carrying the typed string as its
    // value — the whole point of FC-4 for a console: the typed input is queryable.
    let input = harness.get_by_role(Role::TextInput);
    let node = input.accesskit_node();
    assert_eq!(node.role(), Role::TextInput, "input line must expose a TextInput role (FC-4)");
    assert_eq!(
        node.value(),
        Some("cargo test --all".to_string()),
        "the input line's accesskit value must be the current typed string"
    );

    // (2) The scrollback region rode in as a labelled node carrying its line count;
    // its label is derived from the real line count (2 pushed lines).
    let scrollback = harness.get_by_label("console — 2 lines").accesskit_node();
    assert_eq!(
        scrollback.numeric_value(),
        Some(2.0),
        "the scrollback region must carry its line count as numeric_value"
    );
    #[cfg(feature = "testmatrix")]
    facett_core::testmatrix::emit(
        "Console",
        "fc4_input_and_scrollback_nodes",
        node.value() == Some("cargo test --all".to_string())
            && scrollback.numeric_value() == Some(2.0),
        "TextInput value='cargo test --all', scrollback=2 lines",
    );
}