| 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 |
mod compiled; |
| 44 |
|
| 45 |
pub use compiled::*; |
| 46 |
|
| 47 |
use quasi_router::Node; |
| 48 |
use quasi_router::stage::{Plan, Residual}; |
| 49 |
use quasi_webview::Webview; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
type Staged = (&'static str, fn(&Plan) -> Node); |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
fn roster() -> Vec<Staged> { |
| 62 |
vec![ |
| 63 |
("POLICY", |plan| { |
| 64 |
Node::Region(super::policy::page_region_staged(plan)) |
| 65 |
}), |
| 66 |
("TEAM", |plan| { |
| 67 |
Node::Region(super::team::page_region_staged(plan)) |
| 68 |
}), |
| 69 |
("USE_CASES", |plan| { |
| 70 |
Node::Region(super::use_cases::page_region_staged(plan)) |
| 71 |
}), |
| 72 |
("FAN_PLUS", |plan| { |
| 73 |
Node::Region(super::fan_plus::page_region_staged(plan)) |
| 74 |
}), |
| 75 |
("COLLECTIONS", |plan| { |
| 76 |
Node::Region(super::collections::page_region_staged(plan)) |
| 77 |
}), |
| 78 |
("EXPORT_PORTAL", |plan| { |
| 79 |
Node::Region(super::export_portal::page_region_staged(plan)) |
| 80 |
}), |
| 81 |
("GIT_REPOS", |plan| { |
| 82 |
Node::Region(super::git_repos::page_region_staged(plan)) |
| 83 |
}), |
| 84 |
|
| 85 |
|
| 86 |
("FORUMS_LIBRARY", |plan| { |
| 87 |
super::forum_memberships::library_pane_staged(plan) |
| 88 |
}), |
| 89 |
("FORUMS_SETTINGS", |plan| { |
| 90 |
super::forum_memberships::settings_pane_staged(plan) |
| 91 |
}), |
| 92 |
("BUYER_CONTACTS", |plan| { |
| 93 |
super::buyer_contacts::pane_staged(plan) |
| 94 |
}), |
| 95 |
("LIBRARY_CONTACTS", |plan| { |
| 96 |
super::library_contacts::pane_staged(plan) |
| 97 |
}), |
| 98 |
("PAYOUT_SUMMARY", |plan| { |
| 99 |
super::payout_summary::card_staged(plan) |
| 100 |
}), |
| 101 |
("CREATORS", |plan| { |
| 102 |
Node::Region(super::creators::page_region_staged(plan)) |
| 103 |
}), |
| 104 |
("SSH_KEYS", |plan| super::ssh_keys::pane_staged(plan)), |
| 105 |
("GIT_EXPLORE", |plan| { |
| 106 |
Node::Region(super::git_explore::page_region_staged(plan)) |
| 107 |
}), |
| 108 |
("FEED", |plan| { |
| 109 |
Node::Region(super::feeds::page_region_staged(plan)) |
| 110 |
}), |
| 111 |
("USER_ANALYTICS", |plan| { |
| 112 |
super::user_analytics::pane_staged(plan) |
| 113 |
}), |
| 114 |
] |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
#[must_use] |
| 130 |
pub fn settled(residual: &'static Residual) -> std::borrow::Cow<'static, str> { |
| 131 |
std::borrow::Cow::Borrowed( |
| 132 |
residual |
| 133 |
.settled() |
| 134 |
.expect("a settled screen's residual is one literal"), |
| 135 |
) |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
#[must_use] |
| 144 |
pub fn derive(shape: fn(&Plan) -> Node) -> Residual { |
| 145 |
quasi_webview::stage::derive(&Webview::new(), shape) |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
#[must_use] |
| 150 |
pub fn generate() -> String { |
| 151 |
let mut out = String::from( |
| 152 |
"//! Generated by `cargo run --bin export-residuals`. Do not edit.\n\ |
| 153 |
//!\n\ |
| 154 |
//! Every staged screen's markup with the request taken out of it, as a\n\ |
| 155 |
//! `static` the compiler builds. See the module above this one for why\n\ |
| 156 |
//! this is generated rather than derived at startup, and for the test\n\ |
| 157 |
//! that fails when it is stale.\n\n\ |
| 158 |
// Not formatted, because the staleness test compares this file with what\n\ |
| 159 |
// `generate` produces, byte for byte. `cargo fmt` rewrapping a `static`\n\ |
| 160 |
// here would fail that test against markup nobody had changed, and the\n\ |
| 161 |
// obvious repair -- regenerate, then format -- puts it straight back.\n\ |
| 162 |
// Nothing reads this file for pleasure; the markup in it is one line per\n\ |
| 163 |
// screen whatever the layout.\n\ |
| 164 |
#![cfg_attr(rustfmt, rustfmt::skip)]\n\n", |
| 165 |
); |
| 166 |
for (name, shape) in roster() { |
| 167 |
out.push_str(&derive(shape).as_rust(name)); |
| 168 |
out.push('\n'); |
| 169 |
} |
| 170 |
out |
| 171 |
} |
| 172 |
|
| 173 |
#[cfg(test)] |
| 174 |
mod tests { |
| 175 |
use super::*; |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
#[test] |
| 183 |
fn every_committed_residual_matches_a_fresh_one() { |
| 184 |
let committed = include_str!("residuals/compiled.rs"); |
| 185 |
|
| 186 |
assert_eq!( |
| 187 |
committed, |
| 188 |
generate(), |
| 189 |
"the committed residuals are stale: run `cargo run --bin export-residuals`", |
| 190 |
); |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
struct Settled { |
| 200 |
|
| 201 |
path: &'static str, |
| 202 |
|
| 203 |
residual: &'static Residual, |
| 204 |
|
| 205 |
screen: fn() -> quasi_router::Screen, |
| 206 |
|
| 207 |
region: fn() -> Node, |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
fn one_literal_screens() -> Vec<Settled> { |
| 219 |
vec![ |
| 220 |
Settled { |
| 221 |
path: crate::quasi::policy::PATH, |
| 222 |
residual: &POLICY, |
| 223 |
screen: crate::quasi::policy::page_screen, |
| 224 |
region: || Node::Region(crate::quasi::policy::page_region()), |
| 225 |
}, |
| 226 |
Settled { |
| 227 |
path: crate::quasi::team::PATH, |
| 228 |
residual: &TEAM, |
| 229 |
screen: crate::quasi::team::page_screen, |
| 230 |
region: || Node::Region(crate::quasi::team::page_region()), |
| 231 |
}, |
| 232 |
] |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
#[test] |
| 248 |
fn a_settled_screen_is_one_literal() { |
| 249 |
for screen in one_literal_screens() { |
| 250 |
let ops = screen.residual.ops(); |
| 251 |
|
| 252 |
assert_eq!(ops.len(), 1, "{}: {ops:?}", screen.path); |
| 253 |
assert!( |
| 254 |
matches!(ops[0], quasi_router::stage::Op::Lit(_)), |
| 255 |
"{}: {ops:?}", |
| 256 |
screen.path, |
| 257 |
); |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
#[test] |
| 270 |
fn what_a_residual_holds_appears_in_its_document_verbatim() { |
| 271 |
use quasi_axum::Serves as _; |
| 272 |
|
| 273 |
for screen in one_literal_screens() { |
| 274 |
let document = Webview::new().screen(&(screen.screen)()); |
| 275 |
let body = screen |
| 276 |
.residual |
| 277 |
.settled() |
| 278 |
.expect("a settled screen's residual is one literal"); |
| 279 |
|
| 280 |
assert!(document.contains(body), "{}: {document}", screen.path); |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
#[test] |
| 291 |
fn a_residual_serves_what_the_renderer_serves() { |
| 292 |
use quasi_axum::Serves as _; |
| 293 |
|
| 294 |
for screen in one_literal_screens() { |
| 295 |
let rendered = Webview::new().fragment(&(screen.region)()); |
| 296 |
|
| 297 |
assert_eq!( |
| 298 |
screen |
| 299 |
.residual |
| 300 |
.settled() |
| 301 |
.expect("a settled screen's residual is one literal"), |
| 302 |
rendered, |
| 303 |
"{}", |
| 304 |
screen.path, |
| 305 |
); |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
#[test] |
| 322 |
fn the_use_cases_residual_fills_to_what_the_renderer_builds() { |
| 323 |
use quasi_axum::Serves as _; |
| 324 |
|
| 325 |
for prices in [crate::tier_prices::TierPrices::default(), odd_prices()] { |
| 326 |
let filled = crate::quasi::use_cases::page_region_serve(&USE_CASES, &prices); |
| 327 |
let rendered = Webview::new() |
| 328 |
.fragment(&Node::Region(crate::quasi::use_cases::page_region(&prices))); |
| 329 |
|
| 330 |
assert_eq!(filled, rendered); |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
#[test] |
| 342 |
fn the_use_cases_residual_is_nine_holes_and_literals() { |
| 343 |
use quasi_router::stage::Op; |
| 344 |
|
| 345 |
let ops = USE_CASES.ops(); |
| 346 |
let holes = ops |
| 347 |
.iter() |
| 348 |
.filter(|op| matches!(op, Op::Hole { .. })) |
| 349 |
.count(); |
| 350 |
|
| 351 |
assert_eq!(holes, 9, "one per card's tier line: {ops:?}"); |
| 352 |
assert!( |
| 353 |
ops.iter() |
| 354 |
.all(|op| matches!(op, Op::Lit(_) | Op::Hole { .. })), |
| 355 |
"a branch or a loop reached the residual: {ops:?}", |
| 356 |
); |
| 357 |
} |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
fn odd_prices() -> crate::tier_prices::TierPrices { |
| 374 |
crate::tier_prices::TierPrices { |
| 375 |
basic_std: 4321, |
| 376 |
small_files_std: 5678, |
| 377 |
big_files_std: 8765, |
| 378 |
everything_std: 9876, |
| 379 |
basic_total: "3GB".to_owned(), |
| 380 |
small_files_total: "40GB".to_owned(), |
| 381 |
big_files_total: "700GB".to_owned(), |
| 382 |
everything_total: "9TB".to_owned(), |
| 383 |
..Default::default() |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
fn stated_prices() -> crate::tier_prices::TierPrices { |
| 392 |
crate::tier_prices::TierPrices { |
| 393 |
basic_total: "1GB".to_owned(), |
| 394 |
small_files_total: "20GB".to_owned(), |
| 395 |
big_files_total: "500GB".to_owned(), |
| 396 |
everything_total: "5TB".to_owned(), |
| 397 |
..Default::default() |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
#[test] |
| 415 |
fn the_fan_plus_residual_fills_to_what_the_renderer_builds_on_every_branch() { |
| 416 |
use crate::quasi::fan_plus::{Standing, page_region, page_region_serve}; |
| 417 |
use quasi_axum::Serves as _; |
| 418 |
|
| 419 |
let standings = [ |
| 420 |
Standing::Visitor, |
| 421 |
Standing::Unsubscribed, |
| 422 |
Standing::Member { period_end: None }, |
| 423 |
Standing::Member { |
| 424 |
period_end: Some("March 3, 2027".to_owned()), |
| 425 |
}, |
| 426 |
]; |
| 427 |
|
| 428 |
for standing in &standings { |
| 429 |
for just_subscribed in [false, true] { |
| 430 |
let filled = page_region_serve(&FAN_PLUS, standing, just_subscribed); |
| 431 |
let rendered = |
| 432 |
Webview::new().fragment(&Node::Region(page_region(standing, just_subscribed))); |
| 433 |
|
| 434 |
assert_eq!(filled, rendered, "just_subscribed={just_subscribed}"); |
| 435 |
} |
| 436 |
} |
| 437 |
} |
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
#[test] |
| 447 |
fn the_fan_plus_residual_holds_every_reader_s_markup() { |
| 448 |
let compiled = format!("{:?}", FAN_PLUS.ops()); |
| 449 |
|
| 450 |
for words in [ |
| 451 |
"Fan+ membership is active", |
| 452 |
"Support the platform", |
| 453 |
"Join Fan+", |
| 454 |
"Create an account", |
| 455 |
"now a Fan+ member", |
| 456 |
] { |
| 457 |
assert!(compiled.contains(words), "{words} is not in the residual"); |
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
#[test] |
| 474 |
fn the_collections_residual_fills_to_what_the_renderer_builds() { |
| 475 |
use quasi_axum::Serves as _; |
| 476 |
|
| 477 |
for items in [0, 1, 3] { |
| 478 |
for is_public in [true, false] { |
| 479 |
let loaded = crate::quasi::collections::sample(items, is_public); |
| 480 |
let filled = crate::quasi::collections::page_region_serve(&COLLECTIONS, &loaded); |
| 481 |
let rendered = Webview::new().fragment(&Node::Region( |
| 482 |
crate::quasi::collections::page_region(&loaded), |
| 483 |
)); |
| 484 |
|
| 485 |
assert_eq!(filled, rendered, "items={items} is_public={is_public}"); |
| 486 |
} |
| 487 |
} |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
#[test] |
| 498 |
fn the_collections_residual_holds_its_row_body_once() { |
| 499 |
use quasi_router::stage::Op; |
| 500 |
|
| 501 |
fn loops(ops: &[Op]) -> usize { |
| 502 |
ops.iter() |
| 503 |
.map(|op| match op { |
| 504 |
Op::Loop(body) => 1 + loops(body), |
| 505 |
Op::Branch(body) => loops(body), |
| 506 |
_ => 0, |
| 507 |
}) |
| 508 |
.sum() |
| 509 |
} |
| 510 |
|
| 511 |
assert_eq!(loops(COLLECTIONS.ops()), 1, "one loop, over the items"); |
| 512 |
assert!( |
| 513 |
format!("{:?}", COLLECTIONS.ops()).contains("Creator"), |
| 514 |
"the table's headings are compiled, not built per request", |
| 515 |
); |
| 516 |
} |
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
#[test] |
| 527 |
fn the_export_portal_residual_fills_to_what_the_renderer_builds() { |
| 528 |
use crate::quasi::export_portal::Page; |
| 529 |
use quasi_axum::Serves as _; |
| 530 |
|
| 531 |
let pages = [ |
| 532 |
Page { |
| 533 |
has_content: false, |
| 534 |
content_size: "No files".to_owned(), |
| 535 |
}, |
| 536 |
Page { |
| 537 |
has_content: true, |
| 538 |
content_size: "1.4 GB + audio/cover files".to_owned(), |
| 539 |
}, |
| 540 |
Page { |
| 541 |
has_content: true, |
| 542 |
content_size: "17 KB".to_owned(), |
| 543 |
}, |
| 544 |
]; |
| 545 |
|
| 546 |
for page in &pages { |
| 547 |
let filled = crate::quasi::export_portal::page_region_serve(&EXPORT_PORTAL, page); |
| 548 |
let rendered = Webview::new().fragment(&Node::Region( |
| 549 |
crate::quasi::export_portal::page_region(page), |
| 550 |
)); |
| 551 |
|
| 552 |
assert_eq!(filled, rendered, "has_content={}", page.has_content); |
| 553 |
} |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
#[test] |
| 562 |
fn the_export_portal_residual_holds_its_five_cards() { |
| 563 |
use quasi_router::stage::Op; |
| 564 |
|
| 565 |
let compiled = format!("{:?}", EXPORT_PORTAL.ops()); |
| 566 |
for route in [ |
| 567 |
"/api/export/projects", |
| 568 |
"/api/export/sales", |
| 569 |
"/api/export/splits", |
| 570 |
"/api/export/purchases", |
| 571 |
"/api/export/followers", |
| 572 |
] { |
| 573 |
assert!(compiled.contains(route), "{route} is not in the residual"); |
| 574 |
} |
| 575 |
|
| 576 |
fn loops(ops: &[Op]) -> usize { |
| 577 |
ops.iter() |
| 578 |
.map(|op| match op { |
| 579 |
Op::Loop(body) => 1 + loops(body), |
| 580 |
Op::Branch(body) => loops(body), |
| 581 |
_ => 0, |
| 582 |
}) |
| 583 |
.sum() |
| 584 |
} |
| 585 |
assert_eq!(loops(EXPORT_PORTAL.ops()), 0, "the cards are unrolled"); |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
#[test] |
| 599 |
fn the_git_repos_residual_fills_to_what_the_renderer_builds() { |
| 600 |
use quasi_axum::Serves as _; |
| 601 |
|
| 602 |
for count in [0, 1, 3] { |
| 603 |
for is_owner in [true, false] { |
| 604 |
let loaded = crate::quasi::git_repos::sample(count, is_owner); |
| 605 |
let filled = crate::quasi::git_repos::page_region_serve(&GIT_REPOS, &loaded); |
| 606 |
let rendered = Webview::new() |
| 607 |
.fragment(&Node::Region(crate::quasi::git_repos::page_region(&loaded))); |
| 608 |
|
| 609 |
assert_eq!(filled, rendered, "count={count} is_owner={is_owner}"); |
| 610 |
} |
| 611 |
} |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
#[test] |
| 621 |
fn the_git_repos_residual_compiles_its_badges() { |
| 622 |
let compiled = format!("{:?}", GIT_REPOS.ops()); |
| 623 |
|
| 624 |
assert!( |
| 625 |
compiled.contains("badge"), |
| 626 |
"the badge markup is not compiled", |
| 627 |
); |
| 628 |
assert!( |
| 629 |
!compiled.contains("private"), |
| 630 |
"a visibility word was baked into a literal", |
| 631 |
); |
| 632 |
} |
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
#[test] |
| 645 |
fn both_forum_residuals_fill_to_what_the_renderer_builds() { |
| 646 |
use crate::quasi::forum_memberships::{ |
| 647 |
library_pane, library_pane_serve, sample, settings_pane, settings_pane_serve, |
| 648 |
}; |
| 649 |
use quasi_axum::Serves as _; |
| 650 |
|
| 651 |
let none: Vec<_> = Vec::new(); |
| 652 |
let some = vec![ |
| 653 |
sample("rust", "moderator"), |
| 654 |
sample("audio", "member"), |
| 655 |
sample("film", "member"), |
| 656 |
]; |
| 657 |
|
| 658 |
for memberships in [&none, &some] { |
| 659 |
for base in ["https://mt.example.com", ""] { |
| 660 |
assert_eq!( |
| 661 |
library_pane_serve(&FORUMS_LIBRARY, memberships, base), |
| 662 |
Webview::new().fragment(&library_pane(memberships, base)), |
| 663 |
"library: {} memberships, base {base:?}", |
| 664 |
memberships.len(), |
| 665 |
); |
| 666 |
assert_eq!( |
| 667 |
settings_pane_serve(&FORUMS_SETTINGS, memberships, base), |
| 668 |
Webview::new().fragment(&settings_pane(memberships, base)), |
| 669 |
"settings: {} memberships, base {base:?}", |
| 670 |
memberships.len(), |
| 671 |
); |
| 672 |
} |
| 673 |
} |
| 674 |
} |
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
#[test] |
| 684 |
fn the_contact_residuals_fill_to_what_the_renderer_builds() { |
| 685 |
use quasi_axum::Serves as _; |
| 686 |
|
| 687 |
for count in [0, 1, 3] { |
| 688 |
let buyers: Vec<_> = (0..count) |
| 689 |
.map(|n| crate::quasi::buyer_contacts::sample(&format!("buyer{n}"))) |
| 690 |
.collect(); |
| 691 |
assert_eq!( |
| 692 |
crate::quasi::buyer_contacts::pane_serve(&BUYER_CONTACTS, &buyers), |
| 693 |
Webview::new().fragment(&crate::quasi::buyer_contacts::pane(&buyers)), |
| 694 |
"buyer contacts, {count} buyers", |
| 695 |
); |
| 696 |
} |
| 697 |
|
| 698 |
for buyers in [0, 2] { |
| 699 |
for shared in [0, 2] { |
| 700 |
let held: Vec<_> = (0..buyers) |
| 701 |
.map(|n| crate::quasi::library_contacts::sample_buyer(&format!("buyer{n}"))) |
| 702 |
.collect(); |
| 703 |
let with: Vec<_> = (0..shared) |
| 704 |
.map(|n| { |
| 705 |
crate::quasi::library_contacts::sample_creator( |
| 706 |
&format!("{n}"), |
| 707 |
&format!("creator{n}"), |
| 708 |
&format!("Creator {n}"), |
| 709 |
) |
| 710 |
}) |
| 711 |
.collect(); |
| 712 |
|
| 713 |
assert_eq!( |
| 714 |
crate::quasi::library_contacts::pane_serve(&LIBRARY_CONTACTS, &held, &with), |
| 715 |
Webview::new().fragment(&crate::quasi::library_contacts::pane(&held, &with)), |
| 716 |
"library contacts, {buyers} buyers and {shared} shared", |
| 717 |
); |
| 718 |
} |
| 719 |
} |
| 720 |
} |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
#[test] |
| 737 |
fn the_ssh_keys_residual_fills_to_what_the_renderer_builds() { |
| 738 |
use crate::quasi::ssh_keys::{pane, pane_serve, sample_key, sample_token}; |
| 739 |
use quasi_axum::Serves as _; |
| 740 |
|
| 741 |
let installed = crate::theming::console_theme_options(None); |
| 742 |
assert!( |
| 743 |
installed.len() > 1, |
| 744 |
"the picker needs more than one option to be worth filling" |
| 745 |
); |
| 746 |
|
| 747 |
for key_count in [0, 2] { |
| 748 |
for token_count in [0, 2] { |
| 749 |
let keys: Vec<_> = (0..key_count) |
| 750 |
.map(|n| sample_key(&format!("k{n}"), &format!("SHA256:{n}"))) |
| 751 |
.collect(); |
| 752 |
let tokens: Vec<_> = (0..token_count) |
| 753 |
.map(|n| sample_token(&format!("t{n}"), &format!("token{n}"))) |
| 754 |
.collect(); |
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
let none_marked: Vec<_> = installed |
| 759 |
.iter() |
| 760 |
.map(|theme| crate::theming::ThemeOption { |
| 761 |
id: theme.id.clone(), |
| 762 |
name: theme.name.clone(), |
| 763 |
selected: false, |
| 764 |
}) |
| 765 |
.collect(); |
| 766 |
let cases = installed |
| 767 |
.iter() |
| 768 |
.map(|theme| crate::theming::console_theme_options(Some(&theme.id))) |
| 769 |
.chain(std::iter::once(none_marked)); |
| 770 |
|
| 771 |
for themes in cases { |
| 772 |
let marked = themes.iter().position(|theme| theme.selected); |
| 773 |
assert_eq!( |
| 774 |
pane_serve(&SSH_KEYS, "max", &keys, &tokens, &themes), |
| 775 |
Webview::new().fragment(&pane("max", &keys, &tokens, &themes)), |
| 776 |
"ssh keys, {key_count} keys, {token_count} tokens, theme {marked:?}", |
| 777 |
); |
| 778 |
} |
| 779 |
} |
| 780 |
} |
| 781 |
} |
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
#[test] |
| 816 |
fn the_analytics_residual_fills_to_what_the_renderer_builds() { |
| 817 |
use crate::quasi::user_analytics::{pane, pane_serve, sample}; |
| 818 |
use quasi_axum::Serves as _; |
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
let strips: &[&[Option<bool>]] = &[ |
| 823 |
&[], |
| 824 |
&[None], |
| 825 |
&[Some(true)], |
| 826 |
&[Some(false)], |
| 827 |
&[None, Some(true), Some(false)], |
| 828 |
]; |
| 829 |
|
| 830 |
for bars in [0, 1, 5] { |
| 831 |
|
| 832 |
|
| 833 |
for projects in [0, 1, 3] { |
| 834 |
for totals in [0, 2] { |
| 835 |
for deltas in strips { |
| 836 |
let read = sample(bars, projects, totals, deltas); |
| 837 |
assert_eq!( |
| 838 |
pane_serve(&USER_ANALYTICS, &read), |
| 839 |
Webview::new().fragment(&pane(&read)), |
| 840 |
"analytics, {bars} bars, {projects} projects, \ |
| 841 |
{totals} totals, {} cards", |
| 842 |
deltas.len(), |
| 843 |
); |
| 844 |
} |
| 845 |
} |
| 846 |
} |
| 847 |
} |
| 848 |
} |
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
#[test] |
| 864 |
fn the_git_listing_residual_fills_to_what_the_renderer_builds() { |
| 865 |
use crate::quasi::git_explore::{loaded, page_region, page_region_serve}; |
| 866 |
use quasi_axum::Serves as _; |
| 867 |
|
| 868 |
for (page, has_more) in [(1, true), (2, true), (3, false), (1, false)] { |
| 869 |
for count in [0, 3] { |
| 870 |
for signed_in in [true, false] { |
| 871 |
let held = loaded(count, page, has_more, signed_in); |
| 872 |
assert_eq!( |
| 873 |
page_region_serve(&GIT_EXPLORE, &held), |
| 874 |
Webview::new().fragment(&Node::Region(page_region(&held))), |
| 875 |
"page {page}, has_more {has_more}, {count} repos, signed in {signed_in}", |
| 876 |
); |
| 877 |
} |
| 878 |
} |
| 879 |
} |
| 880 |
} |
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
#[test] |
| 894 |
fn the_feed_residual_fills_to_what_the_renderer_builds() { |
| 895 |
use crate::quasi::feeds::{Page, page_region, page_region_serve}; |
| 896 |
use quasi_axum::Serves as _; |
| 897 |
|
| 898 |
let items = crate::quasi::feeds::sample_items(); |
| 899 |
let range: Vec<u32> = (1..=4).collect(); |
| 900 |
|
| 901 |
for current in 1..=4 { |
| 902 |
for held in [items.as_slice(), &[]] { |
| 903 |
let page = Page { |
| 904 |
items: held, |
| 905 |
total_items: 80, |
| 906 |
current_page: current, |
| 907 |
total_pages: 4, |
| 908 |
pagination_range: &range, |
| 909 |
showing_start: 1, |
| 910 |
showing_end: 20, |
| 911 |
}; |
| 912 |
assert_eq!( |
| 913 |
page_region_serve(&FEED, &page), |
| 914 |
Webview::new().fragment(&Node::Region(page_region(&page))), |
| 915 |
"page {current} of 4, {} items", |
| 916 |
held.len(), |
| 917 |
); |
| 918 |
} |
| 919 |
} |
| 920 |
|
| 921 |
|
| 922 |
let page = Page { |
| 923 |
items: &items, |
| 924 |
total_items: 2, |
| 925 |
current_page: 1, |
| 926 |
total_pages: 1, |
| 927 |
pagination_range: &[], |
| 928 |
showing_start: 1, |
| 929 |
showing_end: 2, |
| 930 |
}; |
| 931 |
assert_eq!( |
| 932 |
page_region_serve(&FEED, &page), |
| 933 |
Webview::new().fragment(&Node::Region(page_region(&page))), |
| 934 |
"one page", |
| 935 |
); |
| 936 |
} |
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
#[test] |
| 946 |
fn the_payout_residual_fills_to_what_the_renderer_builds() { |
| 947 |
use crate::quasi::payout_summary::{card, card_serve, sample}; |
| 948 |
use quasi_axum::Serves as _; |
| 949 |
|
| 950 |
let balance = sample(); |
| 951 |
for held in [Some(&balance), None] { |
| 952 |
for payouts_enabled in [true, false] { |
| 953 |
assert_eq!( |
| 954 |
card_serve(&PAYOUT_SUMMARY, held, payouts_enabled), |
| 955 |
Webview::new().fragment(&card(held, payouts_enabled)), |
| 956 |
"balance={} payouts_enabled={payouts_enabled}", |
| 957 |
held.is_some(), |
| 958 |
); |
| 959 |
} |
| 960 |
} |
| 961 |
} |
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
#[test] |
| 971 |
fn the_creators_residual_fills_to_what_the_renderer_builds() { |
| 972 |
use crate::quasi::creators::{Standing, page_region, page_region_serve}; |
| 973 |
use quasi_axum::Serves as _; |
| 974 |
|
| 975 |
for standing in [Standing::Visitor, Standing::Reader, Standing::Creator] { |
| 976 |
for prices in [stated_prices(), odd_prices()] { |
| 977 |
for total in [0, 7] { |
| 978 |
assert_eq!( |
| 979 |
page_region_serve(&CREATORS, &standing, total, &prices), |
| 980 |
Webview::new() |
| 981 |
.fragment(&Node::Region(page_region(&standing, total, &prices))), |
| 982 |
"total={total}", |
| 983 |
); |
| 984 |
} |
| 985 |
} |
| 986 |
} |
| 987 |
} |
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
#[test] |
| 997 |
fn the_creators_residual_unrolls_its_tier_table() { |
| 998 |
use quasi_router::stage::Op; |
| 999 |
|
| 1000 |
let compiled = format!("{:?}", CREATORS.ops()); |
| 1001 |
for tier in ["Basic", "Small Files", "Big Files", "Everything"] { |
| 1002 |
assert!(compiled.contains(tier), "{tier} is not in the residual"); |
| 1003 |
} |
| 1004 |
|
| 1005 |
fn loops(ops: &[Op]) -> usize { |
| 1006 |
ops.iter() |
| 1007 |
.map(|op| match op { |
| 1008 |
Op::Loop(body) => 1 + loops(body), |
| 1009 |
Op::Branch(body) => loops(body), |
| 1010 |
_ => 0, |
| 1011 |
}) |
| 1012 |
.sum() |
| 1013 |
} |
| 1014 |
assert_eq!(loops(CREATORS.ops()), 0, "the tiers are unrolled"); |
| 1015 |
} |
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
#[test] |
| 1028 |
fn every_described_screen_is_on_the_seam_or_says_why_not() { |
| 1029 |
use crate::quasi::{DOCUMENT_PATHS, PATHS, PUBLIC_DOCUMENT_PATHS}; |
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
const OFF_THE_SEAM: &[&str] = &[]; |
| 1044 |
|
| 1045 |
let described = PATHS.len() + DOCUMENT_PATHS.len() + PUBLIC_DOCUMENT_PATHS.len(); |
| 1046 |
|
| 1047 |
assert_eq!( |
| 1048 |
described, |
| 1049 |
roster().len() + OFF_THE_SEAM.len(), |
| 1050 |
"{} described screens, {} on the seam, {} named as off it", |
| 1051 |
described, |
| 1052 |
roster().len(), |
| 1053 |
OFF_THE_SEAM.len(), |
| 1054 |
); |
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
for path in OFF_THE_SEAM { |
| 1059 |
assert!( |
| 1060 |
PATHS.contains(path) |
| 1061 |
|| DOCUMENT_PATHS.contains(path) |
| 1062 |
|| PUBLIC_DOCUMENT_PATHS.contains(path), |
| 1063 |
"{path} is named as off the seam and is not a described address", |
| 1064 |
); |
| 1065 |
} |
| 1066 |
} |
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
#[test] |
| 1080 |
fn every_screen_on_the_seam_is_checked() { |
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
const HOLED: usize = 15; |
| 1087 |
|
| 1088 |
assert_eq!( |
| 1089 |
roster().len(), |
| 1090 |
one_literal_screens().len() + HOLED, |
| 1091 |
"a screen on the seam is not checked: give it a row in \ |
| 1092 |
`one_literal_screens`, or a filling test and a bump to HOLED", |
| 1093 |
); |
| 1094 |
} |
| 1095 |
} |
| 1096 |
|