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

nordisk/gunnar-ui

crates/gunnar-ui-server/tests/buyer_words.rs

//! ★ **Lane BUYFLOW-4: Gunnar's buy pages say buyer words only** (owner: customer-never-sees-caps,
//! one-monetize-only). The text a buyer sees on the sign-up and welcome pages — not comments,
//! styles or scripts' code — names none of the operator's machinery (lay, estate, guest,
//! operator, cap, …: `monetize_site_buy::rules::OPERATOR_WORDS`). The shared script's own
//! sentences are checked in monetize-site-buy. The footer's company name is the seller's.

/// What of an HTML page a buyer reads: its text and its labels.
fn visible(html: &str) -> Vec<String> {
    let mut s = html.to_owned();
    for (open, close) in [("<!--", "-->"), ("<style", "</style>"), ("<script", "</script>")] {
        while let Some(a) = s.find(open) {
            let b = s[a..].find(close).map(|b| a + b + close.len()).unwrap_or(s.len());
            s.replace_range(a..b, "\n");
        }
    }
    let mut out = Vec::new();
    for attr in ["aria-label=\"", "title=\"", "placeholder=\"", "alt=\""] {
        for part in s.split(attr).skip(1) {
            out.push(part.split('"').next().unwrap_or_default().to_owned());
        }
    }
    let mut text = String::new();
    let mut in_tag = false;
    for c in s.chars() {
        match c {
            '<' => in_tag = true,
            '>' => {
                in_tag = false;
                text.push('\n');
            }
            c if !in_tag => text.push(c),
            _ => {}
        }
    }
    out.extend(text.lines().map(str::trim).filter(|l| !l.is_empty()).map(str::to_owned));
    out
}

#[test]
fn gunnars_buy_pages_name_no_operator_machinery() {
    let mut bad = Vec::new();
    for (name, page) in [("signup.html", include_str!("../src/auth/signup.html")), ("welcome.html", include_str!("../src/auth/welcome.html"))] {
        for line in visible(page) {
            let seller = line.replace("Ignalina ApS", "");
            if monetize_site_buy::rules::operator_words_in(&seller) {
                bad.push(format!("{name}: {line}"));
            }
        }
    }
    assert!(bad.is_empty(), "a buyer reads the operator's words:\n{}", bad.join("\n"));
}

#[test]
fn the_page_reader_reads_what_a_buyer_sees() {
    let seen = visible("<!-- the estate --><style>.estate{}</style><p title=\"An operator's cap\">Your instance</p><script>x('laid')</script>");
    assert_eq!(seen, vec!["An operator's cap".to_owned(), "Your instance".to_owned()]);
}