| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
use makeover_webview::Emit; |
| 49 |
use makeover_webview::form::escape_into; |
| 50 |
use quasi_router::{Band, Binding, Brand, Chrome, Disclose, Panel, Place}; |
| 51 |
|
| 52 |
use crate::node::{Doc, Fires, action_attrs, class_into, node_html}; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
pub const OVERLAY_ID: &str = "quasi-overlay"; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
pub(crate) fn chrome_html(chrome: &Chrome, opts: &Emit, doc: &Doc<'_>, out: &mut String) { |
| 68 |
for binding in &chrome.bindings { |
| 69 |
binding_html(binding, out); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
if !chrome.bindings.is_empty() || !chrome.panels.is_empty() || !chrome.nav.is_empty() { |
| 86 |
out.push_str("<!-- quasi: overlay container; an Outcome::Over lands here -->"); |
| 87 |
out.push_str("<div id=\""); |
| 88 |
out.push_str(OVERLAY_ID); |
| 89 |
out.push_str("\" data-chrome=\"overlay\"></div>"); |
| 90 |
} |
| 91 |
for panel in &chrome.panels { |
| 92 |
panel_html(panel, opts, doc, out); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
pub const DISCLOSE_ID: &str = "quasi-disclose"; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
#[must_use] |
| 141 |
pub fn header_html(chrome: &Chrome, at: Option<&str>, opts: &Emit) -> String { |
| 142 |
let mut out = String::with_capacity(512); |
| 143 |
match &chrome.band { |
| 144 |
Some(band) => band_html(band, &chrome.nav, at, opts, &Doc::bare(), &mut out), |
| 145 |
None => nav_html(&chrome.nav, at, opts, &mut out), |
| 146 |
} |
| 147 |
out |
| 148 |
} |
| 149 |
|
| 150 |
pub(crate) fn band_html( |
| 151 |
band: &Band, |
| 152 |
places: &[Place], |
| 153 |
at: Option<&str>, |
| 154 |
opts: &Emit, |
| 155 |
doc: &Doc<'_>, |
| 156 |
out: &mut String, |
| 157 |
) { |
| 158 |
out.push_str("<header class=\""); |
| 159 |
class_into("chrome-band", opts, out); |
| 160 |
out.push_str("\" role=\"banner\" data-chrome=\"band\">"); |
| 161 |
|
| 162 |
if let Some(brand) = &band.brand { |
| 163 |
brand_html(brand, opts, out); |
| 164 |
} |
| 165 |
|
| 166 |
if band.disclose == Disclose::Narrow { |
| 167 |
disclose_html(opts, out); |
| 168 |
} |
| 169 |
|
| 170 |
if let Some(search) = &band.search { |
| 171 |
out.push_str("<div class=\""); |
| 172 |
class_into("chrome-search", opts, out); |
| 173 |
out.push_str("\" role=\"search\">"); |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
node_html( |
| 178 |
&quasi_router::Node::Field(Box::new(search.clone())), |
| 179 |
opts, |
| 180 |
doc, |
| 181 |
out, |
| 182 |
); |
| 183 |
out.push_str("</div>"); |
| 184 |
} |
| 185 |
|
| 186 |
nav_html(places, at, opts, out); |
| 187 |
|
| 188 |
out.push_str("</header>"); |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
fn brand_html(brand: &Brand, opts: &Emit, out: &mut String) { |
| 201 |
let (before, mark, after) = brand.parts(); |
| 202 |
out.push_str("<a class=\""); |
| 203 |
class_into("chrome-brand", opts, out); |
| 204 |
out.push('"'); |
| 205 |
action_attrs(&brand.action, Fires::Click, None, None, false, out); |
| 206 |
out.push('>'); |
| 207 |
escape_into(before, out); |
| 208 |
if !mark.is_empty() { |
| 209 |
out.push_str("<span class=\""); |
| 210 |
class_into("chrome-brand-mark", opts, out); |
| 211 |
out.push_str("\">"); |
| 212 |
escape_into(mark, out); |
| 213 |
out.push_str("</span>"); |
| 214 |
} |
| 215 |
escape_into(after, out); |
| 216 |
out.push_str("</a>"); |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
fn disclose_html(opts: &Emit, out: &mut String) { |
| 226 |
out.push_str("<input type=\"checkbox\" id=\""); |
| 227 |
out.push_str(DISCLOSE_ID); |
| 228 |
out.push_str("\" class=\""); |
| 229 |
class_into("chrome-disclose-state", opts, out); |
| 230 |
out.push_str("\" aria-hidden=\"true\"><label for=\""); |
| 231 |
out.push_str(DISCLOSE_ID); |
| 232 |
out.push_str("\" class=\""); |
| 233 |
class_into("chrome-disclose", opts, out); |
| 234 |
out.push_str("\" aria-label=\"Toggle navigation menu\">"); |
| 235 |
out.push_str("<span></span><span></span><span></span></label>"); |
| 236 |
} |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
pub(crate) fn nav_html(places: &[Place], at: Option<&str>, opts: &Emit, out: &mut String) { |
| 257 |
if places.is_empty() { |
| 258 |
return; |
| 259 |
} |
| 260 |
out.push_str("<nav class=\""); |
| 261 |
class_into("chrome-nav", opts, out); |
| 262 |
out.push_str("\" data-chrome=\"nav\">"); |
| 263 |
place_list(places, at, opts, out); |
| 264 |
out.push_str("</nav>"); |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
fn place_list(places: &[Place], at: Option<&str>, opts: &Emit, out: &mut String) { |
| 269 |
out.push_str("<ul>"); |
| 270 |
for place in places { |
| 271 |
out.push_str("<li>"); |
| 272 |
place_html(place, at, opts, out); |
| 273 |
if !place.within.is_empty() { |
| 274 |
place_list(&place.within, at, opts, out); |
| 275 |
} |
| 276 |
out.push_str("</li>"); |
| 277 |
} |
| 278 |
out.push_str("</ul>"); |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
fn place_html(place: &Place, at: Option<&str>, opts: &Emit, out: &mut String) { |
| 287 |
let current = at.is_some_and(|key| place.holds(key)); |
| 288 |
out.push_str("<a class=\""); |
| 289 |
class_into("chrome-place", opts, out); |
| 290 |
out.push('"'); |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
out.push_str(" data-place=\""); |
| 301 |
escape_into(&place.key, out); |
| 302 |
out.push('"'); |
| 303 |
if current { |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
out.push_str(" aria-current=\"page\""); |
| 308 |
} |
| 309 |
action_attrs(&place.action, Fires::Click, None, None, false, out); |
| 310 |
out.push('>'); |
| 311 |
escape_into(&place.label, out); |
| 312 |
out.push_str("</a>"); |
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
fn panel_html(panel: &Panel, opts: &Emit, doc: &Doc<'_>, out: &mut String) { |
| 322 |
out.push_str("<div id=\""); |
| 323 |
escape_into(&panel.id, out); |
| 324 |
out.push_str("\" class=\""); |
| 325 |
class_into("chrome-panel", opts, out); |
| 326 |
|
| 327 |
|
| 328 |
out.push_str("\" data-role=\""); |
| 329 |
out.push_str(role_name(panel.role)); |
| 330 |
out.push_str("\">"); |
| 331 |
node_html(&panel.content, opts, doc, out); |
| 332 |
out.push_str("</div>"); |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
fn role_name(role: quasi_router::Role) -> &'static str { |
| 340 |
match role { |
| 341 |
quasi_router::Role::Activity => "activity", |
| 342 |
quasi_router::Role::Status => "status", |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
fn binding_html(binding: &Binding, out: &mut String) { |
| 348 |
let Some(filter) = trigger_filter(&binding.key) else { |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
return; |
| 353 |
}; |
| 354 |
|
| 355 |
out.push_str("<button type=\"button\" hidden data-chrome aria-label=\""); |
| 356 |
escape_into(&binding.label, out); |
| 357 |
out.push('"'); |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
if !binding.action.destination.is_back() { |
| 368 |
out.push_str(" hx-target=\"#"); |
| 369 |
out.push_str(OVERLAY_ID); |
| 370 |
out.push('"'); |
| 371 |
} |
| 372 |
|
| 373 |
action_attrs(&binding.action, Fires::Key(&filter), None, None, false, out); |
| 374 |
out.push_str("></button>"); |
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
fn trigger_filter(key: &str) -> Option<String> { |
| 383 |
let mut ctrl = false; |
| 384 |
let mut alt = false; |
| 385 |
let mut shift = false; |
| 386 |
let mut meta = false; |
| 387 |
let mut base = None; |
| 388 |
|
| 389 |
for part in key.split('+') { |
| 390 |
let part = part.trim(); |
| 391 |
if part.is_empty() { |
| 392 |
return None; |
| 393 |
} |
| 394 |
match part.to_ascii_lowercase().as_str() { |
| 395 |
"ctrl" | "control" => ctrl = true, |
| 396 |
"alt" | "option" => alt = true, |
| 397 |
"shift" => shift = true, |
| 398 |
"meta" | "cmd" | "super" => meta = true, |
| 399 |
|
| 400 |
|
| 401 |
_ if base.is_some() => return None, |
| 402 |
_ => base = Some(part.to_string()), |
| 403 |
} |
| 404 |
} |
| 405 |
|
| 406 |
let base = base?; |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
let value = if base.chars().count() == 1 { |
| 411 |
base |
| 412 |
} else { |
| 413 |
named_key(&base)? |
| 414 |
}; |
| 415 |
|
| 416 |
let mut filter = format!("key=='{}'", js_string(&value)); |
| 417 |
for (held, name) in [ |
| 418 |
(ctrl, "ctrlKey"), |
| 419 |
(alt, "altKey"), |
| 420 |
(meta, "metaKey"), |
| 421 |
(shift, "shiftKey"), |
| 422 |
] { |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
if held { |
| 427 |
filter.push_str("&&"); |
| 428 |
filter.push_str(name); |
| 429 |
} else if name != "shiftKey" { |
| 430 |
filter.push_str("&&!"); |
| 431 |
filter.push_str(name); |
| 432 |
} |
| 433 |
} |
| 434 |
Some(filter) |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
fn named_key(name: &str) -> Option<String> { |
| 444 |
let named = match name { |
| 445 |
"escape" | "esc" => "Escape", |
| 446 |
"enter" | "return" => "Enter", |
| 447 |
"tab" => "Tab", |
| 448 |
"space" => " ", |
| 449 |
"backspace" => "Backspace", |
| 450 |
"delete" | "del" => "Delete", |
| 451 |
"up" | "arrowup" => "ArrowUp", |
| 452 |
"down" | "arrowdown" => "ArrowDown", |
| 453 |
"left" | "arrowleft" => "ArrowLeft", |
| 454 |
"right" | "arrowright" => "ArrowRight", |
| 455 |
"home" => "Home", |
| 456 |
"end" => "End", |
| 457 |
"pageup" => "PageUp", |
| 458 |
"pagedown" => "PageDown", |
| 459 |
_ => return None, |
| 460 |
}; |
| 461 |
Some(named.to_string()) |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
fn js_string(value: &str) -> String { |
| 470 |
value.replace('\\', "\\\\").replace('\'', "\\'") |
| 471 |
} |
| 472 |
|
| 473 |
#[cfg(test)] |
| 474 |
mod tests { |
| 475 |
use super::*; |
| 476 |
|
| 477 |
#[test] |
| 478 |
fn a_modifier_key_names_what_is_held_and_what_is_not() { |
| 479 |
let filter = trigger_filter("ctrl+k").expect("parsed"); |
| 480 |
assert!(filter.contains("key=='k'")); |
| 481 |
assert!(filter.contains("&&ctrlKey")); |
| 482 |
|
| 483 |
assert!(filter.contains("&&!altKey")); |
| 484 |
assert!(filter.contains("&&!metaKey")); |
| 485 |
} |
| 486 |
|
| 487 |
#[test] |
| 488 |
fn shift_is_asserted_when_asked_for_and_never_denied() { |
| 489 |
|
| 490 |
|
| 491 |
let plain = trigger_filter("?").expect("parsed"); |
| 492 |
assert!(!plain.contains("shiftKey")); |
| 493 |
let held = trigger_filter("shift+a").expect("parsed"); |
| 494 |
assert!(held.contains("&&shiftKey")); |
| 495 |
assert!(!held.contains("!shiftKey")); |
| 496 |
} |
| 497 |
|
| 498 |
#[test] |
| 499 |
fn a_key_that_prints_nothing_is_named_the_way_the_dom_names_it() { |
| 500 |
assert!( |
| 501 |
trigger_filter("escape") |
| 502 |
.expect("parsed") |
| 503 |
.contains("'Escape'") |
| 504 |
); |
| 505 |
assert!( |
| 506 |
trigger_filter("arrowup") |
| 507 |
.expect("parsed") |
| 508 |
.contains("'ArrowUp'") |
| 509 |
); |
| 510 |
} |
| 511 |
|
| 512 |
#[test] |
| 513 |
fn a_name_this_renderer_does_not_understand_is_ignored() { |
| 514 |
|
| 515 |
|
| 516 |
assert!(trigger_filter("dpad-left").is_none()); |
| 517 |
assert!(trigger_filter("ctrl+j+k").is_none()); |
| 518 |
assert!(trigger_filter("ctrl+").is_none()); |
| 519 |
assert!(trigger_filter("").is_none()); |
| 520 |
} |
| 521 |
|
| 522 |
#[test] |
| 523 |
fn a_quote_in_a_key_cannot_close_the_filter_it_sits_in() { |
| 524 |
let filter = trigger_filter("'").expect("parsed"); |
| 525 |
assert!(filter.contains("\\'"), "{filter}"); |
| 526 |
} |
| 527 |
|
| 528 |
#[test] |
| 529 |
fn a_bound_key_that_goes_back_listens_for_that_key_and_calls_no_route() { |
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
let mut out = String::new(); |
| 539 |
chrome_html( |
| 540 |
&Chrome::new().bind("escape", "Back", quasi_router::Action::back()), |
| 541 |
&Emit::default(), |
| 542 |
&Doc::bare(), |
| 543 |
&mut out, |
| 544 |
); |
| 545 |
|
| 546 |
assert!(out.contains("call history.back()"), "{out}"); |
| 547 |
assert!(out.contains("keydown[key=='Escape'"), "{out}"); |
| 548 |
assert!(out.contains("from window"), "{out}"); |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
assert!(!out.contains("hx-get"), "{out}"); |
| 553 |
assert!(!out.contains("hx-trigger"), "{out}"); |
| 554 |
assert!(!out.contains("hx-target"), "{out}"); |
| 555 |
} |
| 556 |
|
| 557 |
#[test] |
| 558 |
fn an_app_with_no_chrome_emits_nothing_at_all() { |
| 559 |
let mut out = String::new(); |
| 560 |
chrome_html(&Chrome::new(), &Emit::default(), &Doc::bare(), &mut out); |
| 561 |
assert!(out.is_empty()); |
| 562 |
} |
| 563 |
|
| 564 |
#[test] |
| 565 |
fn a_panel_carries_the_address_an_answer_aims_at() { |
| 566 |
use quasi_router::Node; |
| 567 |
|
| 568 |
let chrome = Chrome::new().presenting( |
| 569 |
"timer", |
| 570 |
quasi_router::Role::Activity, |
| 571 |
Node::text("00:12:04"), |
| 572 |
); |
| 573 |
let mut out = String::new(); |
| 574 |
chrome_html(&chrome, &Emit::default(), &Doc::bare(), &mut out); |
| 575 |
assert!(out.contains("id=\"timer\""), "{out}"); |
| 576 |
assert!(out.contains("chrome-panel"), "{out}"); |
| 577 |
assert!(out.contains("00:12:04"), "{out}"); |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
assert!(out.contains(OVERLAY_ID), "{out}"); |
| 583 |
} |
| 584 |
|
| 585 |
#[test] |
| 586 |
fn the_overlay_container_says_what_it_is_and_says_it_outside_itself() { |
| 587 |
use quasi_router::Node; |
| 588 |
|
| 589 |
let chrome = Chrome::new().presenting( |
| 590 |
"timer", |
| 591 |
quasi_router::Role::Activity, |
| 592 |
Node::text("00:12:04"), |
| 593 |
); |
| 594 |
let mut out = String::new(); |
| 595 |
chrome_html(&chrome, &Emit::default(), &Doc::bare(), &mut out); |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
let comment = out.find("<!-- quasi: overlay").expect("annotated"); |
| 600 |
let container = out.find("<div id=\"quasi-overlay\"").expect("emitted"); |
| 601 |
assert!(comment < container, "{out}"); |
| 602 |
assert!(out.contains("data-chrome=\"overlay\""), "{out}"); |
| 603 |
} |
| 604 |
|
| 605 |
#[test] |
| 606 |
fn two_panels_each_say_what_they_are_for_and_keep_the_class_a_stylesheet_knows() { |
| 607 |
use quasi_router::{Node, Role}; |
| 608 |
|
| 609 |
let chrome = Chrome::new() |
| 610 |
.presenting("timer", Role::Activity, Node::text("00:12:04")) |
| 611 |
.presenting("sync", Role::Status, Node::text("Synced")); |
| 612 |
let mut out = String::new(); |
| 613 |
chrome_html(&chrome, &Emit::default(), &Doc::bare(), &mut out); |
| 614 |
|
| 615 |
assert!(out.contains("id=\"timer\""), "{out}"); |
| 616 |
assert!(out.contains("id=\"sync\""), "{out}"); |
| 617 |
assert!(out.contains("data-role=\"activity\""), "{out}"); |
| 618 |
assert!(out.contains("data-role=\"status\""), "{out}"); |
| 619 |
|
| 620 |
|
| 621 |
assert_eq!(out.matches("chrome-panel").count(), 2, "{out}"); |
| 622 |
} |
| 623 |
|
| 624 |
#[test] |
| 625 |
fn the_nav_is_links_because_the_places_are_addresses() { |
| 626 |
use quasi_router::{Action, Place}; |
| 627 |
|
| 628 |
let places = [Place::new("time", "Time", Action::get("/day"))]; |
| 629 |
let mut out = String::new(); |
| 630 |
nav_html(&places, None, &Emit::default(), &mut out); |
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
assert!(out.contains("<nav"), "{out}"); |
| 635 |
assert!(out.contains("data-chrome=\"nav\""), "{out}"); |
| 636 |
assert!(out.contains("<a "), "{out}"); |
| 637 |
assert!(out.contains("Time"), "{out}"); |
| 638 |
} |
| 639 |
|
| 640 |
#[test] |
| 641 |
fn the_place_the_screen_names_is_the_one_marked_current() { |
| 642 |
use quasi_router::{Action, Place}; |
| 643 |
|
| 644 |
let places = [ |
| 645 |
Place::new("work", "Work", Action::get("/tasks")).within([ |
| 646 |
Place::new("tasks", "Tasks", Action::get("/tasks")), |
| 647 |
Place::new("board", "Board", Action::get("/board")), |
| 648 |
]), |
| 649 |
Place::new("time", "Time", Action::get("/day")), |
| 650 |
]; |
| 651 |
|
| 652 |
let mut out = String::new(); |
| 653 |
nav_html(&places, Some("board"), &Emit::default(), &mut out); |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
assert_eq!(out.matches("aria-current=\"page\"").count(), 2, "{out}"); |
| 659 |
let work = out.find("Work").expect("drawn"); |
| 660 |
let time = out.find("Time").expect("drawn"); |
| 661 |
assert!(out[..work].contains("aria-current"), "the tab is marked"); |
| 662 |
assert!(!out[time - 60..time].contains("aria-current"), "{out}"); |
| 663 |
} |
| 664 |
|
| 665 |
#[test] |
| 666 |
fn a_screen_that_is_not_a_place_marks_nothing() { |
| 667 |
use quasi_router::{Action, Place}; |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
let places = [Place::new("time", "Time", Action::get("/day"))]; |
| 673 |
let mut out = String::new(); |
| 674 |
nav_html(&places, None, &Emit::default(), &mut out); |
| 675 |
assert!(!out.contains("aria-current"), "{out}"); |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
let mut other = String::new(); |
| 681 |
nav_html(&places, Some("nowhere"), &Emit::default(), &mut other); |
| 682 |
assert!(!other.contains("aria-current"), "{other}"); |
| 683 |
} |
| 684 |
|
| 685 |
#[test] |
| 686 |
fn the_nav_comes_before_the_content_it_navigates() { |
| 687 |
use quasi_http::Serves as _; |
| 688 |
use quasi_router::{Action, Node, Place, Screen, Slot}; |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
let webview = |
| 695 |
crate::Webview::new().with_shell(crate::Shell::default().with_chrome( |
| 696 |
Chrome::new().offering(Place::new("time", "Time", Action::get("/day"))), |
| 697 |
)); |
| 698 |
let screen = Screen::list_detail("Day", false) |
| 699 |
.at_place("time") |
| 700 |
.with(Slot::new("body", quasi_router::RegionKind::Pane).with(Node::text("the day"))); |
| 701 |
|
| 702 |
let out = webview.screen(&screen); |
| 703 |
let nav = out.find("data-chrome=\"nav\"").expect("drawn"); |
| 704 |
let main = out.find("<main").expect("drawn"); |
| 705 |
assert!(nav < main, "{out}"); |
| 706 |
assert!(out.contains("aria-current=\"page\""), "{out}"); |
| 707 |
} |
| 708 |
|
| 709 |
#[test] |
| 710 |
fn a_nav_alone_still_gets_the_overlay_container() { |
| 711 |
use quasi_router::{Action, Place}; |
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
let chrome = Chrome::new().offering(Place::new("time", "Time", Action::get("/day"))); |
| 716 |
let mut out = String::new(); |
| 717 |
chrome_html(&chrome, &Emit::default(), &Doc::bare(), &mut out); |
| 718 |
assert!(out.contains(OVERLAY_ID), "{out}"); |
| 719 |
} |
| 720 |
|
| 721 |
#[test] |
| 722 |
fn a_binding_carries_the_transport_and_the_overlay_lands_in_the_container() { |
| 723 |
use quasi_router::Action; |
| 724 |
|
| 725 |
let chrome = Chrome::new().bind("ctrl+k", "Search", Action::get("/palette")); |
| 726 |
let mut out = String::new(); |
| 727 |
chrome_html(&chrome, &Emit::default(), &Doc::bare(), &mut out); |
| 728 |
assert!(out.contains("hx-get=\"/palette\""), "{out}"); |
| 729 |
assert!(out.contains("hx-target=\"#quasi-overlay\""), "{out}"); |
| 730 |
assert!(out.contains("from:body"), "{out}"); |
| 731 |
assert!(out.contains("aria-label=\"Search\""), "{out}"); |
| 732 |
assert!( |
| 733 |
out.contains("<div id=\"quasi-overlay\" data-chrome=\"overlay\"></div>"), |
| 734 |
"{out}" |
| 735 |
); |
| 736 |
} |
| 737 |
|
| 738 |
#[test] |
| 739 |
fn a_binding_this_renderer_cannot_read_leaves_the_rest_working() { |
| 740 |
use quasi_router::Action; |
| 741 |
|
| 742 |
let chrome = Chrome::new() |
| 743 |
.bind("dpad-left", "Nope", Action::get("/nope")) |
| 744 |
.bind("ctrl+k", "Search", Action::get("/palette")); |
| 745 |
let mut out = String::new(); |
| 746 |
chrome_html(&chrome, &Emit::default(), &Doc::bare(), &mut out); |
| 747 |
assert!(!out.contains("/nope"), "{out}"); |
| 748 |
assert!(out.contains("/palette"), "{out}"); |
| 749 |
} |
| 750 |
} |
| 751 |
|