| 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 |
use makeover_layout as layout; |
| 41 |
use quasi_router::screen::{Choice, Field}; |
| 42 |
use quasi_router::{Action, Node, RegionKind, Slot}; |
| 43 |
use quasi_webview::Webview; |
| 44 |
|
| 45 |
|
| 46 |
pub const REGION: &str = "user-support"; |
| 47 |
|
| 48 |
|
| 49 |
const TICKET: &str = "/api/support/ticket"; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
const RESULT: &str = "support-result"; |
| 54 |
|
| 55 |
|
| 56 |
#[must_use] |
| 57 |
pub fn fragment(email: &str) -> String { |
| 58 |
use quasi_axum::Serves as _; |
| 59 |
|
| 60 |
let mut slot = Slot::new(REGION, RegionKind::Pane); |
| 61 |
for node in body(email) { |
| 62 |
slot = slot.with(node); |
| 63 |
} |
| 64 |
Webview::new().fragment(&Node::Region(slot)) |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
#[must_use] |
| 69 |
pub fn fill(email: &str) -> String { |
| 70 |
use quasi_axum::Serves as _; |
| 71 |
|
| 72 |
let mut out = String::new(); |
| 73 |
for node in body(email) { |
| 74 |
out.push_str(&Webview::new().fragment(&node)); |
| 75 |
} |
| 76 |
out |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
fn body(email: &str) -> Vec<Node> { |
| 81 |
vec![ |
| 82 |
Node::section("Support"), |
| 83 |
Node::text( |
| 84 |
"Every response is from a real person. We will never use AI to handle your questions.", |
| 85 |
), |
| 86 |
Node::text(format!( |
| 87 |
"We monitor the platform proactively and may have already opened a ticket for your \ |
| 88 |
issue. Check your email at {email} before submitting." |
| 89 |
)), |
| 90 |
ticket_form(), |
| 91 |
|
| 92 |
|
| 93 |
Node::Region(Slot::new(RESULT, RegionKind::Pane)), |
| 94 |
response_times(), |
| 95 |
] |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
fn ticket_form() -> Node { |
| 100 |
Node::Form { |
| 101 |
|
| 102 |
|
| 103 |
action: Action::post(TICKET).awaiting(), |
| 104 |
submit: "Submit".into(), |
| 105 |
fields: vec![ |
| 106 |
Field::select("category", "Category", categories()).required(), |
| 107 |
length( |
| 108 |
placeholder( |
| 109 |
Field::new(layout::FieldKind::Text, "subject", "Subject").required(), |
| 110 |
"Brief description of the issue", |
| 111 |
), |
| 112 |
200, |
| 113 |
), |
| 114 |
length( |
| 115 |
placeholder( |
| 116 |
Field::new(layout::FieldKind::Textarea, "message", "Message").required(), |
| 117 |
"What happened? What did you expect? Include any relevant details.", |
| 118 |
), |
| 119 |
5000, |
| 120 |
), |
| 121 |
], |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
fn categories() -> Vec<Choice> { |
| 131 |
[ |
| 132 |
("bug", "Bug report"), |
| 133 |
("billing", "Billing or payments"), |
| 134 |
("account", "Account access"), |
| 135 |
("content", "Content or uploads"), |
| 136 |
("security", "Security concern"), |
| 137 |
("other", "Other"), |
| 138 |
] |
| 139 |
.into_iter() |
| 140 |
.map(|(value, label)| Choice::new(value, label)) |
| 141 |
.collect() |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
fn response_times() -> Node { |
| 146 |
super::own_prose( |
| 147 |
"Response times:\n\n\ |
| 148 |
- Security issues: same day\n\ |
| 149 |
- Billing and account access: 24 hours\n\ |
| 150 |
- Everything else: 1-2 business days\n\n\ |
| 151 |
For urgent security issues, email <security@makenot.work> directly.", |
| 152 |
) |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
fn placeholder(mut field: Field, text: &str) -> Field { |
| 158 |
field.placeholder = Some(text.to_owned()); |
| 159 |
field |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
fn length(mut field: Field, max: u32) -> Field { |
| 168 |
field.max_length = Some(max); |
| 169 |
field |
| 170 |
} |
| 171 |
|
| 172 |
#[cfg(test)] |
| 173 |
mod tests { |
| 174 |
use super::*; |
| 175 |
use quasi_axum::Serves; |
| 176 |
|
| 177 |
fn render() -> String { |
| 178 |
let mut out = String::new(); |
| 179 |
for node in &body("ada@example.com") { |
| 180 |
out.push_str(&Webview::new().fragment(node)); |
| 181 |
} |
| 182 |
out |
| 183 |
} |
| 184 |
|
| 185 |
#[test] |
| 186 |
fn the_form_addresses_a_route_the_api_answers() { |
| 187 |
|
| 188 |
|
| 189 |
let api = include_str!("../routes/api/mod.rs"); |
| 190 |
assert!(api.contains(TICKET), "registered route"); |
| 191 |
} |
| 192 |
|
| 193 |
#[test] |
| 194 |
fn the_readers_own_address_is_shown_and_escaped() { |
| 195 |
let html = render(); |
| 196 |
assert!(html.contains("ada@example.com"), "{html}"); |
| 197 |
|
| 198 |
let mut out = String::new(); |
| 199 |
for node in &body("<script>x()</script>") { |
| 200 |
out.push_str(&Webview::new().fragment(node)); |
| 201 |
} |
| 202 |
assert!(!out.contains("<script>x()"), "{out}"); |
| 203 |
} |
| 204 |
|
| 205 |
#[test] |
| 206 |
fn every_category_is_offered_and_the_placeholder_option_is_not() { |
| 207 |
let html = render(); |
| 208 |
|
| 209 |
for label in [ |
| 210 |
"Bug report", |
| 211 |
"Billing or payments", |
| 212 |
"Account access", |
| 213 |
"Content or uploads", |
| 214 |
"Security concern", |
| 215 |
"Other", |
| 216 |
] { |
| 217 |
assert!(html.contains(label), "missing {label}: {html}"); |
| 218 |
} |
| 219 |
|
| 220 |
assert!(!html.contains("Select a category"), "{html}"); |
| 221 |
} |
| 222 |
|
| 223 |
#[test] |
| 224 |
fn the_wait_is_said_once_and_no_spinner_is_spelled() { |
| 225 |
let html = render(); |
| 226 |
|
| 227 |
|
| 228 |
assert!(!html.contains("htmx-indicator"), "{html}"); |
| 229 |
assert!(!html.contains("hx-indicator"), "{html}"); |
| 230 |
assert!(!html.contains("spinner"), "{html}"); |
| 231 |
} |
| 232 |
|
| 233 |
#[test] |
| 234 |
fn both_free_text_fields_carry_the_limit_the_api_validates() { |
| 235 |
let html = render(); |
| 236 |
assert!(html.contains("maxlength=\"200\""), "{html}"); |
| 237 |
assert!(html.contains("maxlength=\"5000\""), "{html}"); |
| 238 |
} |
| 239 |
|
| 240 |
#[test] |
| 241 |
fn the_answer_has_somewhere_to_land() { |
| 242 |
let html = render(); |
| 243 |
assert!(html.contains(&format!("id=\"{RESULT}\"")), "{html}"); |
| 244 |
} |
| 245 |
|
| 246 |
#[test] |
| 247 |
fn the_inline_fill_carries_no_region_because_the_strip_draws_one() { |
| 248 |
let inline = fill("ada@example.com"); |
| 249 |
assert!(!inline.contains(&format!("id=\"{REGION}\"")), "{inline}"); |
| 250 |
assert!(inline.contains("Support"), "{inline}"); |
| 251 |
} |
| 252 |
} |
| 253 |
|