| 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 |
use std::fmt; |
| 34 |
|
| 35 |
use makeover_layout::Tone; |
| 36 |
use quasi_router::screen::Act; |
| 37 |
use quasi_router::{Action, Node}; |
| 38 |
|
| 39 |
|
| 40 |
#[must_use] |
| 41 |
pub fn delete_collection_html(collection_id: impl fmt::Display) -> String { |
| 42 |
fragment( |
| 43 |
Act::new( |
| 44 |
"Delete", |
| 45 |
Action::delete(format!("/api/collections/{collection_id}")).replacing_enclosing(), |
| 46 |
) |
| 47 |
.tone(Tone::Danger) |
| 48 |
.confirm("Delete this collection?"), |
| 49 |
) |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
#[must_use] |
| 58 |
pub fn remove_from_wishlist_html(item_id: impl fmt::Display) -> String { |
| 59 |
fragment( |
| 60 |
Act::new( |
| 61 |
"Remove", |
| 62 |
Action::post(format!("/api/wishlists/{item_id}")) |
| 63 |
.replacing(format!("wishlist-row-{item_id}")), |
| 64 |
) |
| 65 |
.tone(Tone::Danger) |
| 66 |
.confirm("Remove from wishlist?"), |
| 67 |
) |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
fn fragment(act: Act) -> String { |
| 73 |
use quasi_axum::Serves as _; |
| 74 |
|
| 75 |
quasi_webview::Webview::new().fragment(&Node::Act(act)) |
| 76 |
} |
| 77 |
|
| 78 |
#[cfg(test)] |
| 79 |
mod tests { |
| 80 |
|
| 81 |
#[test] |
| 82 |
fn deleting_a_collection_replaces_the_row_it_is_in() { |
| 83 |
let html = super::delete_collection_html("c1"); |
| 84 |
|
| 85 |
assert!( |
| 86 |
html.contains(r#"hx-delete="/api/collections/c1""#), |
| 87 |
"{html}" |
| 88 |
); |
| 89 |
assert!(html.contains(r#"hx-target="closest [data-row]""#), "{html}"); |
| 90 |
assert!( |
| 91 |
html.contains(r#"hx-confirm="Delete this collection?""#), |
| 92 |
"{html}" |
| 93 |
); |
| 94 |
} |
| 95 |
|
| 96 |
#[test] |
| 97 |
fn removing_from_the_wishlist_names_the_row_the_page_already_has() { |
| 98 |
let html = super::remove_from_wishlist_html("i7"); |
| 99 |
|
| 100 |
assert!(html.contains(r#"hx-post="/api/wishlists/i7""#), "{html}"); |
| 101 |
assert!(html.contains(r##"hx-target="#wishlist-row-i7""##), "{html}"); |
| 102 |
assert!( |
| 103 |
html.contains(r#"hx-confirm="Remove from wishlist?""#), |
| 104 |
"{html}" |
| 105 |
); |
| 106 |
} |
| 107 |
|
| 108 |
#[test] |
| 109 |
fn both_removals_say_they_are_dangerous() { |
| 110 |
assert!(super::delete_collection_html("c1").contains(r#"data-tone="danger""#)); |
| 111 |
assert!(super::remove_from_wishlist_html("i7").contains(r#"data-tone="danger""#)); |
| 112 |
} |
| 113 |
} |
| 114 |
|