| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
use std::fmt; |
| 17 |
|
| 18 |
use makeover_layout::Tone; |
| 19 |
use quasi_router::screen::Act; |
| 20 |
use quasi_router::{Action, Node}; |
| 21 |
|
| 22 |
|
| 23 |
const REGION: &str = "promo-codes-list"; |
| 24 |
|
| 25 |
|
| 26 |
#[must_use] |
| 27 |
pub fn html(code_id: impl fmt::Display) -> String { |
| 28 |
fragment( |
| 29 |
Act::new( |
| 30 |
"Delete", |
| 31 |
Action::delete(format!("/api/promo-codes/{code_id}")).replacing(REGION), |
| 32 |
) |
| 33 |
.tone(Tone::Danger) |
| 34 |
.confirm("Delete this code? It will no longer be usable."), |
| 35 |
) |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
#[must_use] |
| 44 |
pub fn expired_html() -> String { |
| 45 |
fragment( |
| 46 |
Act::new( |
| 47 |
"Delete all expired", |
| 48 |
Action::delete("/api/promo-codes/expired").replacing(REGION), |
| 49 |
) |
| 50 |
.tone(Tone::Danger) |
| 51 |
.confirm("Delete all expired promo codes?"), |
| 52 |
) |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
fn fragment(act: Act) -> String { |
| 58 |
use quasi_axum::Serves as _; |
| 59 |
|
| 60 |
quasi_webview::Webview::new().fragment(&Node::Act(act)) |
| 61 |
} |
| 62 |
|
| 63 |
#[cfg(test)] |
| 64 |
mod tests { |
| 65 |
#[test] |
| 66 |
fn deleting_one_code_names_its_route_its_region_and_its_prompt() { |
| 67 |
let html = super::html("11"); |
| 68 |
|
| 69 |
assert!( |
| 70 |
html.contains(r#"hx-delete="/api/promo-codes/11""#), |
| 71 |
"{html}" |
| 72 |
); |
| 73 |
assert!( |
| 74 |
html.contains(r##"hx-target="#promo-codes-list""##), |
| 75 |
"{html}" |
| 76 |
); |
| 77 |
assert!( |
| 78 |
html.contains(r#"hx-confirm="Delete this code? It will no longer be usable.""#), |
| 79 |
"{html}" |
| 80 |
); |
| 81 |
} |
| 82 |
|
| 83 |
#[test] |
| 84 |
fn the_bulk_delete_asks_about_the_set_it_acts_on() { |
| 85 |
let html = super::expired_html(); |
| 86 |
|
| 87 |
assert!( |
| 88 |
html.contains(r#"hx-delete="/api/promo-codes/expired""#), |
| 89 |
"{html}" |
| 90 |
); |
| 91 |
assert!( |
| 92 |
html.contains(r#"hx-confirm="Delete all expired promo codes?""#), |
| 93 |
"{html}" |
| 94 |
); |
| 95 |
} |
| 96 |
|
| 97 |
#[test] |
| 98 |
fn both_deletes_say_they_are_dangerous() { |
| 99 |
assert!(super::html("11").contains(r#"data-tone="danger""#)); |
| 100 |
assert!(super::expired_html().contains(r#"data-tone="danger""#)); |
| 101 |
} |
| 102 |
} |
| 103 |
|