A term box exists to hold a word
Browse files at this commitf121bd53a4d3ba55d2dec7a642c2a4691868f25cParent: ecc25a3- fix
- a term box exists to hold a word
2 changed files +86 -23
- crates/izlek-web/src/rules.rs +32 -23
- crates/izlek-web/tests/http.rs +54 -0
crates/izlek-web/src/rules.rsmodified+32 -23
| @@ -40,8 +40,11 @@ struct RuleLine { | ||
| 40 | 40 | id: String, |
| 41 | 41 | /// "When status becomes", or "When a task stops being". |
| 42 | 42 | when: String, |
| 43 | - /// "Done", or "blocked", or empty when the trigger has no second half. | |
| 44 | - what: String, | |
| 43 | + /// "Done", or "blocked". `None` when the trigger has no second half — | |
| 44 | + /// which is not the same as an empty one: the sentence prints this in a | |
| 45 | + /// term box, and a box with nothing in it is what "When someone is | |
| 46 | + /// assigned □ send" was. | |
| 47 | + what: Option<String>, | |
| 45 | 48 | subject: String, |
| 46 | 49 | /// "assignees", "everyone on board", or "its creator". |
| 47 | 50 | audience: String, |
| @@ -168,92 +171,94 @@ fn sentence_of( | ||
| 168 | 171 | trigger: &Trigger, |
| 169 | 172 | columns: &[Column], |
| 170 | 173 | lang: Lang, |
| 171 | -) -> (String, String, String, Option<String>) { | |
| 174 | +) -> (String, Option<String>, String, Option<String>) { | |
| 172 | 175 | match trigger { |
| 173 | 176 | // No column is every column, and "becomes <a column>" has nothing to |
| 174 | 177 | // name then — the sentence changes shape rather than printing a word |
| 175 | 178 | // for "any". |
| 176 | 179 | Trigger::StatusBecomes(None) => ( |
| 177 | 180 | t(lang, Key::WhenStatusChanges).to_string(), |
| 178 | - String::new(), | |
| 181 | + None, | |
| 179 | 182 | "status".to_string(), |
| 180 | 183 | None, |
| 181 | 184 | ), |
| 182 | 185 | Trigger::StatusBecomes(Some(column_id)) => ( |
| 183 | 186 | t(lang, Key::WhenStatusBecomes).to_string(), |
| 184 | - columns | |
| 185 | - .iter() | |
| 186 | - .find(|column| &column.id == column_id) | |
| 187 | - // A rule can outlive the column it names. Saying so is | |
| 188 | - // better than printing an id nobody can read. | |
| 189 | - .map(|column| column.name.clone()) | |
| 190 | - .unwrap_or_else(|| t(lang, Key::ColumnGone).to_string()), | |
| 187 | + Some( | |
| 188 | + columns | |
| 189 | + .iter() | |
| 190 | + .find(|column| &column.id == column_id) | |
| 191 | + // A rule can outlive the column it names. Saying so is | |
| 192 | + // better than printing an id nobody can read. | |
| 193 | + .map(|column| column.name.clone()) | |
| 194 | + .unwrap_or_else(|| t(lang, Key::ColumnGone).to_string()), | |
| 195 | + ), | |
| 191 | 196 | "status".to_string(), |
| 192 | 197 | Some(column_id.clone()), |
| 193 | 198 | ), |
| 194 | 199 | Trigger::Unblocked => ( |
| 195 | 200 | t(lang, Key::WhenTaskStopsBeingBlocked).to_string(), |
| 196 | - t(lang, Key::BlockedWord).to_string(), | |
| 201 | + Some(t(lang, Key::BlockedWord).to_string()), | |
| 197 | 202 | "unblocked".to_string(), |
| 198 | 203 | None, |
| 199 | 204 | ), |
| 200 | 205 | Trigger::Created => ( |
| 201 | 206 | t(lang, Key::WhenTaskCreated).to_string(), |
| 202 | - String::new(), | |
| 207 | + None, | |
| 203 | 208 | "created".to_string(), |
| 204 | 209 | None, |
| 205 | 210 | ), |
| 206 | 211 | Trigger::Assigned => ( |
| 207 | 212 | t(lang, Key::WhenSomeoneAssigned).to_string(), |
| 208 | - String::new(), | |
| 213 | + None, | |
| 209 | 214 | "assigned".to_string(), |
| 210 | 215 | None, |
| 211 | 216 | ), |
| 212 | 217 | Trigger::Unassigned => ( |
| 213 | 218 | t(lang, Key::WhenSomeoneUnassigned).to_string(), |
| 214 | - String::new(), | |
| 219 | + None, | |
| 215 | 220 | "unassigned".to_string(), |
| 216 | 221 | None, |
| 217 | 222 | ), |
| 218 | 223 | Trigger::Commented => ( |
| 219 | 224 | t(lang, Key::WhenCommentWritten).to_string(), |
| 220 | - String::new(), | |
| 225 | + None, | |
| 221 | 226 | "commented".to_string(), |
| 222 | 227 | None, |
| 223 | 228 | ), |
| 224 | 229 | Trigger::DeadlineSet => ( |
| 225 | 230 | t(lang, Key::WhenDeadlineSet).to_string(), |
| 226 | - String::new(), | |
| 231 | + None, | |
| 227 | 232 | "deadline_set".to_string(), |
| 228 | 233 | None, |
| 229 | 234 | ), |
| 230 | 235 | Trigger::DeadlineCleared => ( |
| 231 | 236 | t(lang, Key::WhenDeadlineRemoved).to_string(), |
| 232 | - String::new(), | |
| 237 | + None, | |
| 233 | 238 | "deadline_cleared".to_string(), |
| 234 | 239 | None, |
| 235 | 240 | ), |
| 236 | 241 | Trigger::Retitled => ( |
| 237 | 242 | t(lang, Key::WhenTaskRenamed).to_string(), |
| 238 | - String::new(), | |
| 243 | + None, | |
| 239 | 244 | "retitled".to_string(), |
| 240 | 245 | None, |
| 241 | 246 | ), |
| 242 | 247 | Trigger::Linked => ( |
| 243 | 248 | t(lang, Key::WhenTaskLinked).to_string(), |
| 244 | - String::new(), | |
| 249 | + None, | |
| 245 | 250 | "linked".to_string(), |
| 246 | 251 | None, |
| 247 | 252 | ), |
| 248 | 253 | Trigger::Unlinked => ( |
| 249 | 254 | t(lang, Key::WhenTaskUnlinked).to_string(), |
| 250 | - String::new(), | |
| 255 | + None, | |
| 251 | 256 | "unlinked".to_string(), |
| 252 | 257 | None, |
| 253 | 258 | ), |
| 254 | 259 | Trigger::Deleted => ( |
| 255 | 260 | t(lang, Key::WhenTaskDeleted).to_string(), |
| 256 | - String::new(), | |
| 261 | + None, | |
| 257 | 262 | "deleted".to_string(), |
| 258 | 263 | None, |
| 259 | 264 | ), |
| @@ -827,7 +832,11 @@ async fn rule_row( | ||
| 827 | 832 | |
| 828 | 833 | <div class="rule-sentence"> |
| 829 | 834 | <span>(rule.when.clone())</span> |
| 830 | - <span class="rule-term">(rule.what.clone())</span> | |
| 835 | + // A trigger with no second half prints no term box. The box | |
| 836 | + // only exists to hold a word. | |
| 837 | + if let Some(what) = &rule.what { | |
| 838 | + <span class="rule-term">(what.clone())</span> | |
| 839 | + } | |
| 831 | 840 | <span>(t(lang, Key::SendConnector))</span> |
| 832 | 841 | <span class="rule-term">(rule.subject.clone())</span> |
| 833 | 842 | <span>(t(lang, Key::ToConnector))</span> |
crates/izlek-web/tests/http.rsmodified+54 -0
| @@ -3271,6 +3271,60 @@ async fn a_rule_with_no_subject_is_refused_and_says_why() { | ||
| 3271 | 3271 | assert!(answer.body.contains("EmptySubject"), "{}", answer.body); |
| 3272 | 3272 | } |
| 3273 | 3273 | |
| 3274 | +#[tokio::test] | |
| 3275 | +async fn a_trigger_with_nothing_to_name_prints_no_term_box() { | |
| 3276 | + // "When someone is assigned" names no column, and the sentence used to | |
| 3277 | + // print the term box anyway, with nothing in it — an empty rounded box | |
| 3278 | + // sitting between the words. The absence was carried as an empty string, | |
| 3279 | + // so the renderer could not tell "no term" from "a term that is blank". | |
| 3280 | + let app = App::open().await; | |
| 3281 | + let admin_cookie = admin(&app).await; | |
| 3282 | + let column = first_column(&app).await; | |
| 3283 | + | |
| 3284 | + // One rule that has a term, and one that has none. | |
| 3285 | + app.post( | |
| 3286 | + "/api/create_rule", | |
| 3287 | + Some(&admin_cookie), | |
| 3288 | + &[ | |
| 3289 | + ("trigger", "status"), | |
| 3290 | + ("column_id", &column), | |
| 3291 | + ("subject", "A card reached the column."), | |
| 3292 | + ("audience", "assignees"), | |
| 3293 | + ], | |
| 3294 | + ) | |
| 3295 | + .await; | |
| 3296 | + app.post( | |
| 3297 | + "/api/create_rule", | |
| 3298 | + Some(&admin_cookie), | |
| 3299 | + &[ | |
| 3300 | + ("trigger", "assigned"), | |
| 3301 | + ("column_id", ""), | |
| 3302 | + ("subject", "You have been assigned a task."), | |
| 3303 | + ("audience", "assignees"), | |
| 3304 | + ], | |
| 3305 | + ) | |
| 3306 | + .await; | |
| 3307 | + | |
| 3308 | + let page = app.get("/rules", Some(&admin_cookie)).await; | |
| 3309 | + let page = String::from_utf8_lossy(&page.bytes); | |
| 3310 | + // The rule with no column is on the page at all — without this the | |
| 3311 | + // assertion below passes by having nothing to assert on. | |
| 3312 | + assert!( | |
| 3313 | + page.contains("When someone is assigned"), | |
| 3314 | + "the triggerless rule was never created, so this test proves nothing" | |
| 3315 | + ); | |
| 3316 | + assert!( | |
| 3317 | + !page.contains(r#"<span class="rule-term"></span>"#), | |
| 3318 | + "a trigger with no second half still prints an empty term box" | |
| 3319 | + ); | |
| 3320 | + // The rule that does name a column still shows it, so this did not fix | |
| 3321 | + // the box by removing it. | |
| 3322 | + assert!( | |
| 3323 | + page.contains(r#"<span class="rule-term">"#), | |
| 3324 | + "the term box is gone from the rule that has a term" | |
| 3325 | + ); | |
| 3326 | +} | |
| 3327 | + | |
| 3274 | 3328 | #[tokio::test] |
| 3275 | 3329 | async fn a_rule_may_not_be_hung_off_a_column_that_is_not_on_this_board() { |
| 3276 | 3330 | let app = App::open().await; |