diff --git a/crates/izlek-web/src/rules.rs b/crates/izlek-web/src/rules.rs index 27afb0c..4d4cbb4 100644 --- a/crates/izlek-web/src/rules.rs +++ b/crates/izlek-web/src/rules.rs @@ -40,8 +40,11 @@ struct RuleLine { id: String, /// "When status becomes", or "When a task stops being". when: String, - /// "Done", or "blocked", or empty when the trigger has no second half. - what: String, + /// "Done", or "blocked". `None` when the trigger has no second half — + /// which is not the same as an empty one: the sentence prints this in a + /// term box, and a box with nothing in it is what "When someone is + /// assigned □ send" was. + what: Option, subject: String, /// "assignees", "everyone on board", or "its creator". audience: String, @@ -168,92 +171,94 @@ fn sentence_of( trigger: &Trigger, columns: &[Column], lang: Lang, -) -> (String, String, String, Option) { +) -> (String, Option, String, Option) { match trigger { // No column is every column, and "becomes " has nothing to // name then — the sentence changes shape rather than printing a word // for "any". Trigger::StatusBecomes(None) => ( t(lang, Key::WhenStatusChanges).to_string(), - String::new(), + None, "status".to_string(), None, ), Trigger::StatusBecomes(Some(column_id)) => ( t(lang, Key::WhenStatusBecomes).to_string(), - columns - .iter() - .find(|column| &column.id == column_id) - // A rule can outlive the column it names. Saying so is - // better than printing an id nobody can read. - .map(|column| column.name.clone()) - .unwrap_or_else(|| t(lang, Key::ColumnGone).to_string()), + Some( + columns + .iter() + .find(|column| &column.id == column_id) + // A rule can outlive the column it names. Saying so is + // better than printing an id nobody can read. + .map(|column| column.name.clone()) + .unwrap_or_else(|| t(lang, Key::ColumnGone).to_string()), + ), "status".to_string(), Some(column_id.clone()), ), Trigger::Unblocked => ( t(lang, Key::WhenTaskStopsBeingBlocked).to_string(), - t(lang, Key::BlockedWord).to_string(), + Some(t(lang, Key::BlockedWord).to_string()), "unblocked".to_string(), None, ), Trigger::Created => ( t(lang, Key::WhenTaskCreated).to_string(), - String::new(), + None, "created".to_string(), None, ), Trigger::Assigned => ( t(lang, Key::WhenSomeoneAssigned).to_string(), - String::new(), + None, "assigned".to_string(), None, ), Trigger::Unassigned => ( t(lang, Key::WhenSomeoneUnassigned).to_string(), - String::new(), + None, "unassigned".to_string(), None, ), Trigger::Commented => ( t(lang, Key::WhenCommentWritten).to_string(), - String::new(), + None, "commented".to_string(), None, ), Trigger::DeadlineSet => ( t(lang, Key::WhenDeadlineSet).to_string(), - String::new(), + None, "deadline_set".to_string(), None, ), Trigger::DeadlineCleared => ( t(lang, Key::WhenDeadlineRemoved).to_string(), - String::new(), + None, "deadline_cleared".to_string(), None, ), Trigger::Retitled => ( t(lang, Key::WhenTaskRenamed).to_string(), - String::new(), + None, "retitled".to_string(), None, ), Trigger::Linked => ( t(lang, Key::WhenTaskLinked).to_string(), - String::new(), + None, "linked".to_string(), None, ), Trigger::Unlinked => ( t(lang, Key::WhenTaskUnlinked).to_string(), - String::new(), + None, "unlinked".to_string(), None, ), Trigger::Deleted => ( t(lang, Key::WhenTaskDeleted).to_string(), - String::new(), + None, "deleted".to_string(), None, ), @@ -827,7 +832,11 @@ async fn rule_row(
(rule.when.clone()) - (rule.what.clone()) + // A trigger with no second half prints no term box. The box + // only exists to hold a word. + if let Some(what) = &rule.what { + (what.clone()) + } (t(lang, Key::SendConnector)) (rule.subject.clone()) (t(lang, Key::ToConnector)) diff --git a/crates/izlek-web/tests/http.rs b/crates/izlek-web/tests/http.rs index 4d97fd1..c4a2633 100644 --- a/crates/izlek-web/tests/http.rs +++ b/crates/izlek-web/tests/http.rs @@ -3271,6 +3271,60 @@ async fn a_rule_with_no_subject_is_refused_and_says_why() { assert!(answer.body.contains("EmptySubject"), "{}", answer.body); } +#[tokio::test] +async fn a_trigger_with_nothing_to_name_prints_no_term_box() { + // "When someone is assigned" names no column, and the sentence used to + // print the term box anyway, with nothing in it — an empty rounded box + // sitting between the words. The absence was carried as an empty string, + // so the renderer could not tell "no term" from "a term that is blank". + let app = App::open().await; + let admin_cookie = admin(&app).await; + let column = first_column(&app).await; + + // One rule that has a term, and one that has none. + app.post( + "/api/create_rule", + Some(&admin_cookie), + &[ + ("trigger", "status"), + ("column_id", &column), + ("subject", "A card reached the column."), + ("audience", "assignees"), + ], + ) + .await; + app.post( + "/api/create_rule", + Some(&admin_cookie), + &[ + ("trigger", "assigned"), + ("column_id", ""), + ("subject", "You have been assigned a task."), + ("audience", "assignees"), + ], + ) + .await; + + let page = app.get("/rules", Some(&admin_cookie)).await; + let page = String::from_utf8_lossy(&page.bytes); + // The rule with no column is on the page at all — without this the + // assertion below passes by having nothing to assert on. + assert!( + page.contains("When someone is assigned"), + "the triggerless rule was never created, so this test proves nothing" + ); + assert!( + !page.contains(r#""#), + "a trigger with no second half still prints an empty term box" + ); + // The rule that does name a column still shows it, so this did not fix + // the box by removing it. + assert!( + page.contains(r#""#), + "the term box is gone from the rule that has a term" + ); +} + #[tokio::test] async fn a_rule_may_not_be_hung_off_a_column_that_is_not_on_this_board() { let app = App::open().await;