| 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 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
use makeover_layout as layout; |
| 63 |
use quasi_declare::declare; |
| 64 |
use quasi_router::{Document, Request, Response, RouteError}; |
| 65 |
use quasi_webview::Webview; |
| 66 |
|
| 67 |
use crate::tier_prices::TierPrices; |
| 68 |
|
| 69 |
|
| 70 |
pub const PATH: &str = "/use-cases"; |
| 71 |
|
| 72 |
|
| 73 |
pub const PAGE_REGION: &str = "use-cases"; |
| 74 |
|
| 75 |
|
| 76 |
const PROFILES: &str = "use-case-profiles"; |
| 77 |
|
| 78 |
|
| 79 |
const UNIVERSAL: &str = "everyone-gets"; |
| 80 |
|
| 81 |
const MEASURE: layout::Measure = layout::Measure::Wide; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
fn tier_line(priced: &str, prices: &TierPrices) -> String { |
| 103 |
match priced { |
| 104 |
"basic" => format!( |
| 105 |
"Basic ${}/mo \u{b7} {}, {}/file", |
| 106 |
prices.basic_std, prices.basic_total, prices.basic_per_file |
| 107 |
), |
| 108 |
"small-files" => format!( |
| 109 |
"Small Files ${}/mo \u{b7} {}, {}/file", |
| 110 |
prices.small_files_std, prices.small_files_total, prices.small_files_per_file |
| 111 |
), |
| 112 |
"big-files" => format!( |
| 113 |
"Big Files ${}/mo \u{b7} {}, {}/file", |
| 114 |
prices.big_files_std, prices.big_files_total, prices.big_files_per_file |
| 115 |
), |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
"basic-or-small-files" => format!( |
| 120 |
"Basic ${}/mo or Small Files ${}/mo", |
| 121 |
prices.basic_std, prices.small_files_std |
| 122 |
), |
| 123 |
other => panic!("content/use-cases.toml names a tier line that does not exist: {other}"), |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
#[cfg(test)] |
| 129 |
const TIER_LINES: &[&str] = &["basic", "small-files", "big-files", "basic-or-small-files"]; |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
#[must_use] |
| 141 |
pub fn prices(viewer: &super::Viewer) -> TierPrices { |
| 142 |
use axum::extract::FromRef as _; |
| 143 |
|
| 144 |
crate::Billing::from_ref(&viewer.app).tier_prices |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
pub fn screen(viewer: &super::Viewer, _request: Request) -> Result<Response, RouteError> { |
| 155 |
Ok(page_screen(&prices(viewer)).into()) |
| 156 |
} |
| 157 |
|
| 158 |
declare! { |
| 159 |
|
| 160 |
pub(crate) shape page_screen(prices: &TierPrices) -> Screen; |
| 161 |
|
| 162 |
screen single "Use Cases - Makenotwork" { |
| 163 |
measured MEASURE; |
| 164 |
documented Document::default().classed(crate::shell::body_class(MEASURE, &["use-cases-page"])); |
| 165 |
summarised "A flat monthly fee and no platform cut, for musicians, podcasters, writers, \ |
| 166 |
developers and six more kinds of creator."; |
| 167 |
|
| 168 |
include page_region(prices); |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
declare! { |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
#[staged] |
| 191 |
pub(crate) shape page_region(prices: &TierPrices) -> Slot; |
| 192 |
|
| 193 |
region PAGE_REGION as Pane { |
| 194 |
page "Use Cases"; |
| 195 |
text "A flat monthly fee. 0% platform cut. Who it's built for:"; |
| 196 |
|
| 197 |
section "Available now"; |
| 198 |
region PROFILES as Group { |
| 199 |
for profile in copy "content/use-cases.toml" as profiles { |
| 200 |
|
| 201 |
|
| 202 |
region profile.anchor as Group { |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
section profile.title; |
| 212 |
text profile.who; |
| 213 |
text profile.description; |
| 214 |
list { |
| 215 |
for feature in profile.features { |
| 216 |
row feature; |
| 217 |
} |
| 218 |
} |
| 219 |
text super::use_cases::tier_line(profile.priced, prices); |
| 220 |
} |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
section "Everyone gets"; |
| 225 |
region UNIVERSAL as Group { |
| 226 |
list { |
| 227 |
for gets in copy "content/use-cases.toml" as universal { |
| 228 |
row gets.name { |
| 229 |
secondary gets.sentence; |
| 230 |
} |
| 231 |
} |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
act "Join the Alpha" to get "/join" navigating; |
| 236 |
for onward in copy "content/use-cases.toml" as onward { |
| 237 |
act onward.label to get onward.route navigating; |
| 238 |
} |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
#[must_use] |
| 246 |
pub fn renderer(viewer: &super::Viewer) -> Webview { |
| 247 |
Webview::new().with_shell(viewer.document_shell().with_body_first(format!( |
| 248 |
"{}{}", |
| 249 |
crate::shell::skip_link(PAGE_REGION), |
| 250 |
crate::shell::site_header(viewer.user.as_ref()), |
| 251 |
))) |
| 252 |
} |
| 253 |
|
| 254 |
#[cfg(test)] |
| 255 |
mod tests { |
| 256 |
use super::*; |
| 257 |
|
| 258 |
fn prices() -> TierPrices { |
| 259 |
TierPrices::default() |
| 260 |
} |
| 261 |
|
| 262 |
fn html() -> String { |
| 263 |
use quasi_axum::Serves as _; |
| 264 |
|
| 265 |
Webview::new().screen(&page_screen(&prices())) |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
#[test] |
| 272 |
fn the_document_carries_the_classes_the_template_carried() { |
| 273 |
let screen = page_screen(&prices()); |
| 274 |
|
| 275 |
assert_eq!( |
| 276 |
screen.document.body_class.as_deref(), |
| 277 |
Some("padded-page use-cases-page") |
| 278 |
); |
| 279 |
let rendered = html(); |
| 280 |
assert!( |
| 281 |
rendered.contains("class=\"padded-page use-cases-page\""), |
| 282 |
"{rendered}" |
| 283 |
); |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
fn copy() -> toml::Table { |
| 293 |
include_str!("../../content/use-cases.toml") |
| 294 |
.parse() |
| 295 |
.expect("the use-cases copy is TOML") |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
#[test] |
| 301 |
fn every_profile_keeps_its_card_and_its_anchor() { |
| 302 |
let html = html(); |
| 303 |
|
| 304 |
let copy = copy(); |
| 305 |
let profiles = copy["profiles"].as_array().expect("a list of profiles"); |
| 306 |
assert_eq!(profiles.len(), 9, "the template drew nine"); |
| 307 |
for profile in profiles { |
| 308 |
let anchor = profile["anchor"].as_str().expect("an anchor"); |
| 309 |
assert!(html.contains(anchor), "{anchor} missing"); |
| 310 |
for field in ["who", "title", "description"] { |
| 311 |
let text = profile[field].as_str().expect("words"); |
| 312 |
let escaped = crate::helpers::escape_html(text); |
| 313 |
assert!(html.contains(&escaped), "{anchor}: {field} missing"); |
| 314 |
} |
| 315 |
for feature in profile["features"].as_array().expect("a list") { |
| 316 |
let feature = feature.as_str().expect("words"); |
| 317 |
let escaped = crate::helpers::escape_html(feature); |
| 318 |
assert!(html.contains(&escaped), "{feature} missing from {anchor}"); |
| 319 |
} |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
#[test] |
| 330 |
fn every_priced_name_in_the_copy_is_one_of_the_four() { |
| 331 |
let copy = copy(); |
| 332 |
|
| 333 |
for profile in copy["profiles"].as_array().expect("a list of profiles") { |
| 334 |
let priced = profile["priced"].as_str().expect("a tier line name"); |
| 335 |
assert!( |
| 336 |
TIER_LINES.contains(&priced), |
| 337 |
"{priced} is not one of {TIER_LINES:?}", |
| 338 |
); |
| 339 |
} |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
#[test] |
| 344 |
fn the_universal_list_and_the_onward_links_come_from_the_copy() { |
| 345 |
let html = html(); |
| 346 |
|
| 347 |
let copy = copy(); |
| 348 |
for gets in copy["universal"].as_array().expect("a list") { |
| 349 |
for field in ["name", "sentence"] { |
| 350 |
let text = gets[field].as_str().expect("words"); |
| 351 |
let escaped = crate::helpers::escape_html(text); |
| 352 |
assert!(html.contains(&escaped), "{text} missing"); |
| 353 |
} |
| 354 |
} |
| 355 |
for onward in copy["onward"].as_array().expect("a list") { |
| 356 |
let route = onward["route"].as_str().expect("a route"); |
| 357 |
assert!(html.contains(route), "{route} missing"); |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
#[test] |
| 365 |
fn every_tier_line_comes_from_the_live_prices() { |
| 366 |
let mut prices = prices(); |
| 367 |
prices.basic_std = 4321; |
| 368 |
prices.small_files_std = 5678; |
| 369 |
prices.big_files_std = 8765; |
| 370 |
|
| 371 |
let html = { |
| 372 |
use quasi_axum::Serves as _; |
| 373 |
Webview::new().screen(&page_screen(&prices)) |
| 374 |
}; |
| 375 |
|
| 376 |
assert!(html.contains("4321"), "the Basic price is not read: {html}"); |
| 377 |
assert!(html.contains("5678"), "the Small Files price is not read"); |
| 378 |
assert!(html.contains("8765"), "the Big Files price is not read"); |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
#[test] |
| 384 |
fn the_educators_card_names_both_tiers_it_fits_in() { |
| 385 |
let mut prices = prices(); |
| 386 |
prices.basic_std = 4321; |
| 387 |
prices.small_files_std = 5678; |
| 388 |
|
| 389 |
let line = tier_line("basic-or-small-files", &prices); |
| 390 |
|
| 391 |
assert!(line.contains("4321") && line.contains("5678"), "{line}"); |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
#[test] |
| 396 |
fn the_page_spells_no_spinner() { |
| 397 |
let html = html(); |
| 398 |
|
| 399 |
for spelling in ["htmx-indicator", "spinner", "loading-text", "loading-state"] { |
| 400 |
assert!(!html.contains(spelling), "{spelling} survives in {html}"); |
| 401 |
} |
| 402 |
} |
| 403 |
} |
| 404 |
|