| 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 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
use std::time::Duration; |
| 69 |
|
| 70 |
use makeover_layout as layout; |
| 71 |
use quasi_router::{ |
| 72 |
Action, Cell, Cells, Choice, Column, Consult, Document, Field, Meter, Node, RegionKind, |
| 73 |
Request, Response, RouteError, Row, Screen, Slot, |
| 74 |
}; |
| 75 |
use quasi_webview::Webview; |
| 76 |
|
| 77 |
use crate::Billing; |
| 78 |
use crate::fee_calculator::{self, Inputs, Outcome, Verdict}; |
| 79 |
use crate::tier_prices::TierPrices; |
| 80 |
|
| 81 |
|
| 82 |
pub const PATH: &str = "/pricing"; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
const COMPARE: &str = "/pricing/compare"; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
const CALCULATOR: &str = "pricing-calculator"; |
| 93 |
|
| 94 |
|
| 95 |
const PAGE: &str = "pricing-page"; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
const MEASURE: layout::Measure = layout::Measure::Contained; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
pub const RESULTS: &str = "results-panel"; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
const SETTLES: Duration = Duration::from_millis(300); |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
const ITEM_PRICE: &str = "item_price"; |
| 117 |
const SALES: &str = "sales"; |
| 118 |
const TIER: &str = "tier"; |
| 119 |
const PRICE_MODE: &str = "price_mode"; |
| 120 |
const OTHER_PCT: &str = "other_pct"; |
| 121 |
const OTHER_PER_SALE: &str = "other_per_sale"; |
| 122 |
|
| 123 |
|
| 124 |
const FOUNDER: &str = "founder"; |
| 125 |
|
| 126 |
const LIST: &str = "list"; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
pub struct Pricing { |
| 135 |
|
| 136 |
|
| 137 |
pub billing: Billing, |
| 138 |
|
| 139 |
|
| 140 |
pub founder_window_open: bool, |
| 141 |
|
| 142 |
|
| 143 |
pub changelog_published: bool, |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
struct Dials { |
| 152 |
inputs: Inputs, |
| 153 |
|
| 154 |
tier: &'static str, |
| 155 |
|
| 156 |
mode: &'static str, |
| 157 |
} |
| 158 |
|
| 159 |
impl Dials { |
| 160 |
|
| 161 |
fn read(state: &Pricing, carried: &quasi_router::Params) -> Self { |
| 162 |
let prices = &state.billing.tier_prices; |
| 163 |
let number = |name: &str| { |
| 164 |
carried |
| 165 |
.get(name) |
| 166 |
.map(str::trim) |
| 167 |
.and_then(|v| v.parse::<f64>().ok()) |
| 168 |
}; |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
let mode = match (state.founder_window_open, carried.get(PRICE_MODE)) { |
| 174 |
(false, _) => LIST, |
| 175 |
(true, Some(LIST)) => LIST, |
| 176 |
(true, _) => FOUNDER, |
| 177 |
}; |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
let (tier, tier_cost) = match carried.get(TIER) { |
| 183 |
Some(raw) => match raw.trim().parse::<f64>() { |
| 184 |
Ok(dollars) if dollars >= 0.0 => (Tier::BASIC.key, dollars), |
| 185 |
_ => { |
| 186 |
let tier = Tier::named(raw).unwrap_or(Tier::BASIC); |
| 187 |
(tier.key, f64::from(tier.price(prices, mode))) |
| 188 |
} |
| 189 |
}, |
| 190 |
None => (Tier::BASIC.key, f64::from(Tier::BASIC.price(prices, mode))), |
| 191 |
}; |
| 192 |
|
| 193 |
let mut inputs = state |
| 194 |
.billing |
| 195 |
.fee_calculator |
| 196 |
.default_inputs(f64::from(prices.basic_std)); |
| 197 |
if let Some(v) = number(ITEM_PRICE) { |
| 198 |
inputs.item_price = v; |
| 199 |
} |
| 200 |
if let Some(v) = number(SALES) { |
| 201 |
inputs.sales_per_month = v; |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
if let Some(v) = number(OTHER_PCT) { |
| 207 |
inputs.other_pct = v / 100.0; |
| 208 |
} |
| 209 |
if let Some(v) = number(OTHER_PER_SALE) { |
| 210 |
inputs.other_per_sale = v; |
| 211 |
} |
| 212 |
inputs.tier_cost = tier_cost; |
| 213 |
|
| 214 |
Self { |
| 215 |
inputs: state.billing.fee_calculator.sanitize(inputs), |
| 216 |
tier, |
| 217 |
mode, |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
fn outcome(&self, state: &Pricing) -> Outcome { |
| 223 |
state.billing.fee_calculator.compute(self.inputs) |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
struct Tier { |
| 233 |
|
| 234 |
key: &'static str, |
| 235 |
|
| 236 |
label: &'static str, |
| 237 |
|
| 238 |
|
| 239 |
fits: &'static str, |
| 240 |
} |
| 241 |
|
| 242 |
impl Tier { |
| 243 |
const BASIC: Self = Self { |
| 244 |
key: "basic", |
| 245 |
label: "Basic", |
| 246 |
fits: "Fits text, blogs, newsletters.", |
| 247 |
}; |
| 248 |
const SMALL_FILES: Self = Self { |
| 249 |
key: "small_files", |
| 250 |
label: "Small Files", |
| 251 |
fits: "Fits audio, plugins, binaries.", |
| 252 |
}; |
| 253 |
const BIG_FILES: Self = Self { |
| 254 |
key: "big_files", |
| 255 |
label: "Big Files", |
| 256 |
fits: "Fits video, games, large software.", |
| 257 |
}; |
| 258 |
const EVERYTHING: Self = Self { |
| 259 |
key: "everything", |
| 260 |
label: "Everything", |
| 261 |
fits: "Big Files envelope plus first access to high-cost features as they ship.", |
| 262 |
}; |
| 263 |
|
| 264 |
|
| 265 |
const ALL: [Self; 4] = [ |
| 266 |
Self::BASIC, |
| 267 |
Self::SMALL_FILES, |
| 268 |
Self::BIG_FILES, |
| 269 |
Self::EVERYTHING, |
| 270 |
]; |
| 271 |
|
| 272 |
|
| 273 |
fn named(key: &str) -> Option<Self> { |
| 274 |
Self::ALL.into_iter().find(|tier| tier.key == key) |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
fn price(&self, prices: &TierPrices, mode: &str) -> i32 { |
| 279 |
let founder = mode == FOUNDER; |
| 280 |
match self.key { |
| 281 |
"small_files" => { |
| 282 |
if founder { |
| 283 |
prices.small_files_founder |
| 284 |
} else { |
| 285 |
prices.small_files_std |
| 286 |
} |
| 287 |
} |
| 288 |
"big_files" => { |
| 289 |
if founder { |
| 290 |
prices.big_files_founder |
| 291 |
} else { |
| 292 |
prices.big_files_std |
| 293 |
} |
| 294 |
} |
| 295 |
"everything" => { |
| 296 |
if founder { |
| 297 |
prices.everything_founder |
| 298 |
} else { |
| 299 |
prices.everything_std |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
_ => { |
| 305 |
if founder { |
| 306 |
prices.basic_founder |
| 307 |
} else { |
| 308 |
prices.basic_std |
| 309 |
} |
| 310 |
} |
| 311 |
} |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
fn detail(&self, prices: &TierPrices, mode: &str) -> String { |
| 317 |
let price = self.price(prices, mode); |
| 318 |
match self.key { |
| 319 |
"small_files" => format!( |
| 320 |
"${price}/mo. {}/file, {} total. {}", |
| 321 |
prices.small_files_per_file, prices.small_files_total, self.fits |
| 322 |
), |
| 323 |
"big_files" => format!( |
| 324 |
"${price}/mo. {}/file, {} total. {}", |
| 325 |
prices.big_files_per_file, prices.big_files_total, self.fits |
| 326 |
), |
| 327 |
|
| 328 |
|
| 329 |
"everything" => format!("${price}/mo. {}", self.fits), |
| 330 |
_ => format!( |
| 331 |
"${price}/mo. {}/file, {} total. {}", |
| 332 |
prices.basic_per_file, prices.basic_total, self.fits |
| 333 |
), |
| 334 |
} |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
pub fn screen(state: &Pricing, request: Request) -> Result<Response, RouteError> { |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
let carried = request.carried; |
| 344 |
let dials = Dials::read(state, &carried); |
| 345 |
Ok(page(state, &dials).into()) |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
pub fn compare(state: &Pricing, request: Request) -> Result<Response, RouteError> { |
| 353 |
let carried = request.carried; |
| 354 |
let dials = Dials::read(state, &carried); |
| 355 |
Ok(Response::fragment( |
| 356 |
RESULTS, |
| 357 |
Node::Region(results(&dials.outcome(state))), |
| 358 |
)) |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
fn page(state: &Pricing, dials: &Dials) -> Screen { |
| 363 |
Screen::list_detail("Pricing Calculator - Makenotwork", false) |
| 364 |
.measured(MEASURE) |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
.documented(Document::default().classed(crate::shell::body_class(MEASURE, &[]))) |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
.summarised( |
| 381 |
"Work out what you keep on every sale here, against whatever the \ |
| 382 |
platform you sell on now deducts. 0% platform fee, only the \ |
| 383 |
payment processor's ~3%.", |
| 384 |
) |
| 385 |
.with( |
| 386 |
Slot::new(PAGE, RegionKind::Pane) |
| 387 |
.with(Node::page("Pricing Calculator")) |
| 388 |
.with(Node::text("See what you keep on every sale.")) |
| 389 |
.with(Node::Region(calculator(state, dials))) |
| 390 |
.with(Node::act("Join the Alpha", Action::get("/join"))) |
| 391 |
.with(Node::List { |
| 392 |
rows: vec![ |
| 393 |
Row::new("Home").activate(Action::get("/")), |
| 394 |
Row::new("Browse as guest").activate(Action::get("/discover")), |
| 395 |
], |
| 396 |
more: None, |
| 397 |
}) |
| 398 |
.with(Node::Region(footer(state))), |
| 399 |
) |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
fn calculator(state: &Pricing, dials: &Dials) -> Slot { |
| 404 |
let prices = &state.billing.tier_prices; |
| 405 |
let inputs = dials.inputs; |
| 406 |
|
| 407 |
let mut slot = Slot::group(CALCULATOR) |
| 408 |
.consulting(Consult::new(Action::get(COMPARE).replacing(RESULTS)).after(SETTLES)) |
| 409 |
.with(Node::section("What you sell")) |
| 410 |
.with(Node::field(dial( |
| 411 |
ITEM_PRICE, |
| 412 |
"Price per item", |
| 413 |
inputs.item_price, |
| 414 |
fee_calculator::MAX_ITEM_PRICE, |
| 415 |
"1", |
| 416 |
"USD", |
| 417 |
))) |
| 418 |
.with(Node::field(dial( |
| 419 |
SALES, |
| 420 |
"Sales per month", |
| 421 |
inputs.sales_per_month, |
| 422 |
fee_calculator::MAX_SALES, |
| 423 |
"1", |
| 424 |
"/mo", |
| 425 |
))); |
| 426 |
|
| 427 |
|
| 428 |
if state.founder_window_open { |
| 429 |
slot = slot.with(Node::banner( |
| 430 |
layout::Tone::Success, |
| 431 |
"Founder pricing open. Half off creator tiers, locked for life. The \ |
| 432 |
calculator is using founder prices.", |
| 433 |
)); |
| 434 |
} |
| 435 |
|
| 436 |
slot = slot |
| 437 |
.with(Node::section("Your content tier")) |
| 438 |
.with(Node::text( |
| 439 |
"Every tier is the complete platform: profile, project pages, forum, \ |
| 440 |
discovery, memberships, analytics, full data export. The tier picks \ |
| 441 |
the file-size envelope, not the feature set.", |
| 442 |
)); |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
if state.founder_window_open { |
| 448 |
slot = slot.with(Node::field( |
| 449 |
Field::radio( |
| 450 |
PRICE_MODE, |
| 451 |
"Calculate with", |
| 452 |
vec![ |
| 453 |
Choice::new(FOUNDER, "Founder price"), |
| 454 |
Choice::new(LIST, "List price"), |
| 455 |
], |
| 456 |
) |
| 457 |
.value(dials.mode), |
| 458 |
)); |
| 459 |
} |
| 460 |
|
| 461 |
slot = slot |
| 462 |
.with(Node::field( |
| 463 |
Field::radio( |
| 464 |
TIER, |
| 465 |
"Content tier", |
| 466 |
Tier::ALL |
| 467 |
.iter() |
| 468 |
.map(|tier| { |
| 469 |
Choice::new(tier.key, tier.label).detailing(tier.detail(prices, dials.mode)) |
| 470 |
}) |
| 471 |
.collect(), |
| 472 |
) |
| 473 |
.value(dials.tier), |
| 474 |
)) |
| 475 |
.with(Node::section("Wherever else you sell")) |
| 476 |
.with(Node::text( |
| 477 |
"Fill in what the other platform takes. Use its total deduction, its \ |
| 478 |
own cut plus any payment processing it adds, which is the figure you \ |
| 479 |
can read off a payout. We hold no rates for anyone but ourselves, so \ |
| 480 |
nothing here can go stale or be picked to flatter us.", |
| 481 |
)) |
| 482 |
.with(Node::field(dial( |
| 483 |
OTHER_PCT, |
| 484 |
"Their cut", |
| 485 |
inputs.other_pct * 100.0, |
| 486 |
fee_calculator::MAX_OTHER_PCT * 100.0, |
| 487 |
"0.1", |
| 488 |
"%", |
| 489 |
))) |
| 490 |
.with(Node::field(dial( |
| 491 |
OTHER_PER_SALE, |
| 492 |
"Their fee per sale", |
| 493 |
inputs.other_per_sale, |
| 494 |
fee_calculator::MAX_OTHER_PER_SALE, |
| 495 |
"0.05", |
| 496 |
"USD", |
| 497 |
))) |
| 498 |
.with(Node::Region(results(&dials.outcome(state)))); |
| 499 |
|
| 500 |
slot |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
fn dial( |
| 513 |
name: &'static str, |
| 514 |
label: &'static str, |
| 515 |
value: f64, |
| 516 |
max: f64, |
| 517 |
step: &'static str, |
| 518 |
unit: &'static str, |
| 519 |
) -> Field { |
| 520 |
let mut field = Field::new(layout::FieldKind::Number, name, label) |
| 521 |
.value(fmt_dial(value)) |
| 522 |
.step(step) |
| 523 |
.unit(unit); |
| 524 |
field.min = Some("0".to_string()); |
| 525 |
field.max = Some(fmt_dial(max)); |
| 526 |
field |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
fn results(outcome: &Outcome) -> Slot { |
| 535 |
let mut slot = Slot::new(RESULTS, RegionKind::Pane) |
| 536 |
.with(Node::banner(tone(outcome.verdict), &outcome.headline)) |
| 537 |
.with(Node::Table { |
| 538 |
columns: vec![ |
| 539 |
Column::new("Monthly") |
| 540 |
.width(layout::Width::Fill) |
| 541 |
.priority(layout::Priority::Essential), |
| 542 |
Column::new("Here") |
| 543 |
.width(layout::Width::Content) |
| 544 |
.priority(layout::Priority::Essential), |
| 545 |
Column::new("The other platform") |
| 546 |
.width(layout::Width::Content) |
| 547 |
.priority(layout::Priority::Essential), |
| 548 |
], |
| 549 |
rows: vec![ |
| 550 |
Cells::new([ |
| 551 |
Cell::new("You sell"), |
| 552 |
Cell::new(outcome.gross.clone()), |
| 553 |
Cell::new(outcome.gross.clone()), |
| 554 |
]), |
| 555 |
Cells::new([ |
| 556 |
Cell::new("You keep"), |
| 557 |
Cell::new(outcome.mnw_keep.clone()), |
| 558 |
Cell::new(outcome.other_keep.clone()), |
| 559 |
]), |
| 560 |
Cells::new([ |
| 561 |
Cell::new("Total fees"), |
| 562 |
Cell::new(outcome.mnw_rate.clone()), |
| 563 |
Cell::new(outcome.other_rate.clone()), |
| 564 |
]), |
| 565 |
], |
| 566 |
more: None, |
| 567 |
}); |
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
if let Some(crossover) = outcome.crossover_sales { |
| 574 |
slot = slot |
| 575 |
.with(Node::section("Where each one wins")) |
| 576 |
.with(Node::Meter( |
| 577 |
Meter::new( |
| 578 |
outcome.sales_per_month.round().max(0.0) as u32, |
| 579 |
crossover.ceil().max(1.0) as u32, |
| 580 |
) |
| 581 |
.tone(tone(outcome.verdict)) |
| 582 |
.label("sales a month to the crossover"), |
| 583 |
)); |
| 584 |
} |
| 585 |
|
| 586 |
if let Some(note) = &outcome.crossover_note { |
| 587 |
slot = slot.with(Node::text(note)); |
| 588 |
} |
| 589 |
|
| 590 |
slot.with(Node::text( |
| 591 |
"Our side of this uses the payment processor's published US card rates. \ |
| 592 |
Yours is whatever you type in, so check it against a real payout rather \ |
| 593 |
than a pricing page: some platforms quote their cut before processing \ |
| 594 |
and some after.", |
| 595 |
)) |
| 596 |
.with(Node::text( |
| 597 |
"Selling small-ticket items? Payment processors charge a fixed fee per \ |
| 598 |
sale (~$0.30) that hits harder on $1-5 items. That is an industry-wide \ |
| 599 |
constraint and it applies wherever you sell. Bundling items into \ |
| 600 |
collections lets fans buy in groups at a single transaction cost \ |
| 601 |
instead of paying per-item processing.", |
| 602 |
)) |
| 603 |
} |
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
const fn tone(verdict: Verdict) -> layout::Tone { |
| 611 |
match verdict { |
| 612 |
Verdict::MnwAhead => layout::Tone::Success, |
| 613 |
Verdict::Even => layout::Tone::Neutral, |
| 614 |
Verdict::OtherAheadForNow | Verdict::OtherAhead => layout::Tone::Warning, |
| 615 |
} |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
fn footer(state: &Pricing) -> Slot { |
| 624 |
let mut rows = vec![ |
| 625 |
Row::new("Pricing").activate(Action::get("/pricing")), |
| 626 |
Row::new("Creators").activate(Action::get("/creators")), |
| 627 |
Row::new("Docs").activate(Action::get("/docs")), |
| 628 |
Row::new("Legal").activate(Action::get("/policy")), |
| 629 |
Row::new("Credits").activate(Action::get("/docs/credits")), |
| 630 |
]; |
| 631 |
|
| 632 |
|
| 633 |
if state.changelog_published { |
| 634 |
rows.push(Row::new("Changelog").activate(Action::get("/changelog"))); |
| 635 |
} |
| 636 |
rows.push(Row::new("Contact").activate(Action::external("mailto:info@makenot.work"))); |
| 637 |
rows.push(Row::new("Status").activate(Action::get("/health"))); |
| 638 |
|
| 639 |
Slot::new("site-footer", RegionKind::Pane) |
| 640 |
.with(Node::List { rows, more: None }) |
| 641 |
.with(Node::text("(c) 2026 Make Creative, LLC")) |
| 642 |
} |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
fn fmt_dial(v: f64) -> String { |
| 649 |
let s = format!("{v:.2}"); |
| 650 |
s.trim_end_matches('0').trim_end_matches('.').to_string() |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
#[must_use] |
| 673 |
pub fn renderer() -> Webview { |
| 674 |
let shell = crate::shell::described() |
| 675 |
.with_body_first(crate::shell::skip_link(PAGE)) |
| 676 |
.with_body_last(crate::shell::body_last()) |
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
.with_chrome(crate::quasi::shortcuts::chrome()); |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
Webview::new().with_shell(shell) |
| 695 |
} |
| 696 |
|
| 697 |
#[cfg(test)] |
| 698 |
mod tests { |
| 699 |
use super::*; |
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
fn state(founder_window_open: bool) -> Pricing { |
| 707 |
crate::tier_prices::TierPrices::install_test_default(); |
| 708 |
Pricing { |
| 709 |
billing: Billing { |
| 710 |
payments: None, |
| 711 |
payment_caps: crate::payments::PaymentCapabilities::default(), |
| 712 |
tier_prices: crate::tier_prices::TierPrices::global().clone(), |
| 713 |
runway_config: crate::tier_prices::RunwayConfig { |
| 714 |
quarters: 0, |
| 715 |
last_updated_iso: String::new(), |
| 716 |
}, |
| 717 |
fee_calculator: crate::fee_calculator::FeeCalculator::load( |
| 718 |
"docs/business/assumptions.toml", |
| 719 |
), |
| 720 |
}, |
| 721 |
founder_window_open, |
| 722 |
changelog_published: false, |
| 723 |
} |
| 724 |
} |
| 725 |
|
| 726 |
fn carrying(pairs: &[(&str, &str)]) -> quasi_router::Params { |
| 727 |
pairs.iter().copied().collect() |
| 728 |
} |
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
fn approx(got: f64, want: f64, what: &str) { |
| 733 |
assert!((got - want).abs() < 1e-9, "{what}: got {got}, want {want}"); |
| 734 |
} |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
#[test] |
| 742 |
fn the_region_asks_and_nothing_names_a_dial() { |
| 743 |
let state = state(true); |
| 744 |
let screen = page(&state, &Dials::read(&state, &carrying(&[]))); |
| 745 |
|
| 746 |
let asking = screen.consulting(); |
| 747 |
assert_eq!(asking.len(), 1, "one panel recomputes, not several"); |
| 748 |
let consult = &asking[0].consults[0]; |
| 749 |
assert_eq!(consult.action.route(), Some(COMPARE)); |
| 750 |
assert_eq!(consult.after, SETTLES); |
| 751 |
assert!( |
| 752 |
consult.sends.is_empty(), |
| 753 |
"a dial inside the region rides along by containment, so nothing \ |
| 754 |
should be named: {:?}", |
| 755 |
consult.sends |
| 756 |
); |
| 757 |
} |
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
#[test] |
| 763 |
fn the_region_contains_every_dial_the_route_reads() { |
| 764 |
let state = state(true); |
| 765 |
let screen = page(&state, &Dials::read(&state, &carrying(&[]))); |
| 766 |
let names: Vec<&str> = screen.consulting()[0] |
| 767 |
.questions() |
| 768 |
.iter() |
| 769 |
.map(|field| field.name.as_str()) |
| 770 |
.collect(); |
| 771 |
|
| 772 |
assert_eq!( |
| 773 |
names, |
| 774 |
[ |
| 775 |
ITEM_PRICE, |
| 776 |
SALES, |
| 777 |
PRICE_MODE, |
| 778 |
TIER, |
| 779 |
OTHER_PCT, |
| 780 |
OTHER_PER_SALE |
| 781 |
] |
| 782 |
); |
| 783 |
} |
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
#[test] |
| 788 |
fn the_mode_is_not_asked_once_the_window_shuts() { |
| 789 |
let state = state(false); |
| 790 |
let screen = page(&state, &Dials::read(&state, &carrying(&[]))); |
| 791 |
let names: Vec<&str> = screen.consulting()[0] |
| 792 |
.questions() |
| 793 |
.iter() |
| 794 |
.map(|field| field.name.as_str()) |
| 795 |
.collect(); |
| 796 |
|
| 797 |
assert!(!names.contains(&PRICE_MODE), "{names:?}"); |
| 798 |
} |
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
#[test] |
| 803 |
fn the_mode_picks_which_rate_the_tier_costs() { |
| 804 |
let state = state(true); |
| 805 |
let prices = &state.billing.tier_prices; |
| 806 |
assert_ne!( |
| 807 |
prices.basic_founder, prices.basic_std, |
| 808 |
"the assumptions make this vacuous if the two rates are equal" |
| 809 |
); |
| 810 |
|
| 811 |
let founder = Dials::read(&state, &carrying(&[(TIER, "basic")])); |
| 812 |
let list = Dials::read(&state, &carrying(&[(TIER, "basic"), (PRICE_MODE, LIST)])); |
| 813 |
|
| 814 |
approx( |
| 815 |
founder.inputs.tier_cost, |
| 816 |
f64::from(prices.basic_founder), |
| 817 |
"founder rate", |
| 818 |
); |
| 819 |
approx( |
| 820 |
list.inputs.tier_cost, |
| 821 |
f64::from(prices.basic_std), |
| 822 |
"list rate", |
| 823 |
); |
| 824 |
} |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
#[test] |
| 829 |
fn a_link_cannot_price_a_window_that_has_closed() { |
| 830 |
let state = state(false); |
| 831 |
let dials = Dials::read(&state, &carrying(&[(TIER, "basic"), (PRICE_MODE, FOUNDER)])); |
| 832 |
|
| 833 |
assert_eq!(dials.mode, LIST); |
| 834 |
approx( |
| 835 |
dials.inputs.tier_cost, |
| 836 |
f64::from(state.billing.tier_prices.basic_std), |
| 837 |
"a shut window prices at list", |
| 838 |
); |
| 839 |
} |
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
#[test] |
| 844 |
fn an_older_link_carrying_a_price_is_read_as_dollars() { |
| 845 |
let state = state(true); |
| 846 |
let dials = Dials::read(&state, &carrying(&[(TIER, "24"), (SALES, "100")])); |
| 847 |
|
| 848 |
approx(dials.inputs.tier_cost, 24.0, "the price the link carried"); |
| 849 |
approx(dials.inputs.sales_per_month, 100.0, "sales"); |
| 850 |
} |
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
#[test] |
| 855 |
fn the_cut_is_typed_whole_and_held_as_a_fraction() { |
| 856 |
let state = state(false); |
| 857 |
let dials = Dials::read(&state, &carrying(&[(OTHER_PCT, "12.6")])); |
| 858 |
|
| 859 |
approx(dials.inputs.other_pct, 0.126, "12.6% as a fraction"); |
| 860 |
} |
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
#[test] |
| 870 |
fn the_document_carries_the_class_the_template_carried() { |
| 871 |
let screen = page(&state(false), &Dials::read(&state(false), &carrying(&[]))); |
| 872 |
|
| 873 |
assert_eq!( |
| 874 |
screen.document.body_class.as_deref(), |
| 875 |
Some(crate::shell::body_class(MEASURE, &[]).as_str()) |
| 876 |
); |
| 877 |
assert_eq!(screen.document.body_class.as_deref(), Some("centered-page")); |
| 878 |
} |
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
#[test] |
| 883 |
fn the_panel_meters_the_crossover_only_when_there_is_one() { |
| 884 |
let state = state(false); |
| 885 |
let calculator = &state.billing.fee_calculator; |
| 886 |
|
| 887 |
let ahead = calculator.compute(Inputs { |
| 888 |
item_price: 25.0, |
| 889 |
sales_per_month: 40.0, |
| 890 |
tier_cost: 16.0, |
| 891 |
other_pct: 0.126, |
| 892 |
other_per_sale: 0.30, |
| 893 |
}); |
| 894 |
assert!(has_meter(&results(&ahead)), "a crossover with no meter"); |
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
let never = calculator.compute(Inputs { |
| 899 |
item_price: 5.0, |
| 900 |
sales_per_month: 500.0, |
| 901 |
tier_cost: 16.0, |
| 902 |
other_pct: 0.01, |
| 903 |
other_per_sale: 0.0, |
| 904 |
}); |
| 905 |
assert!(!has_meter(&results(&never)), "metered against nothing"); |
| 906 |
} |
| 907 |
|
| 908 |
fn has_meter(slot: &Slot) -> bool { |
| 909 |
slot.body |
| 910 |
.iter() |
| 911 |
.any(|placed| matches!(placed.node, Node::Meter(_))) |
| 912 |
} |
| 913 |
} |
| 914 |
|