forge
Explore
Log in

Don't you dare go Hollow

A term box exists to hold a word

Browse files at this commit

f121bd53a4d3ba55d2dec7a642c2a4691868f25cAhmet Kaan GümüşParent: ecc25a3
  • fix
    • a term box exists to hold a word
Show full message
🐛 fix(rules): a term box exists to hold a word

"When someone is assigned □ send ..." — an empty rounded box between the
words, on every trigger that names no column.

The sentence carried its second half as a `String`, and a trigger with
nothing to name set it to `""`. The renderer could not tell "no term" from
"a term that happens to be blank", so it drew the box either way. Making it
an `Option<String>` is the whole fix: the eleven triggers with nothing to
name now say `None`, and the box is inside the `if let` that unwraps it, so
an empty one cannot be rendered.

The test asserts the empty box is gone AND that the rule which does name a
column still shows its term — the first assertion alone is passed by
deleting the feature. It also asserts the triggerless rule reached the page,
because the first version of it created no such rule and passed against the
bug it was written to catch.
crates/izlek-web/src/rules.rsmodified+32 -23
@@ -40,8 +40,11 @@ struct RuleLine {
4040 id: String,
4141 /// "When status becomes", or "When a task stops being".
4242 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>,
4548 subject: String,
4649 /// "assignees", "everyone on board", or "its creator".
4750 audience: String,
@@ -168,92 +171,94 @@ fn sentence_of(
168171 trigger: &Trigger,
169172 columns: &[Column],
170173 lang: Lang,
171-) -> (String, String, String, Option<String>) {
174+) -> (String, Option<String>, String, Option<String>) {
172175 match trigger {
173176 // No column is every column, and "becomes <a column>" has nothing to
174177 // name then — the sentence changes shape rather than printing a word
175178 // for "any".
176179 Trigger::StatusBecomes(None) => (
177180 t(lang, Key::WhenStatusChanges).to_string(),
178- String::new(),
181+ None,
179182 "status".to_string(),
180183 None,
181184 ),
182185 Trigger::StatusBecomes(Some(column_id)) => (
183186 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+ ),
191196 "status".to_string(),
192197 Some(column_id.clone()),
193198 ),
194199 Trigger::Unblocked => (
195200 t(lang, Key::WhenTaskStopsBeingBlocked).to_string(),
196- t(lang, Key::BlockedWord).to_string(),
201+ Some(t(lang, Key::BlockedWord).to_string()),
197202 "unblocked".to_string(),
198203 None,
199204 ),
200205 Trigger::Created => (
201206 t(lang, Key::WhenTaskCreated).to_string(),
202- String::new(),
207+ None,
203208 "created".to_string(),
204209 None,
205210 ),
206211 Trigger::Assigned => (
207212 t(lang, Key::WhenSomeoneAssigned).to_string(),
208- String::new(),
213+ None,
209214 "assigned".to_string(),
210215 None,
211216 ),
212217 Trigger::Unassigned => (
213218 t(lang, Key::WhenSomeoneUnassigned).to_string(),
214- String::new(),
219+ None,
215220 "unassigned".to_string(),
216221 None,
217222 ),
218223 Trigger::Commented => (
219224 t(lang, Key::WhenCommentWritten).to_string(),
220- String::new(),
225+ None,
221226 "commented".to_string(),
222227 None,
223228 ),
224229 Trigger::DeadlineSet => (
225230 t(lang, Key::WhenDeadlineSet).to_string(),
226- String::new(),
231+ None,
227232 "deadline_set".to_string(),
228233 None,
229234 ),
230235 Trigger::DeadlineCleared => (
231236 t(lang, Key::WhenDeadlineRemoved).to_string(),
232- String::new(),
237+ None,
233238 "deadline_cleared".to_string(),
234239 None,
235240 ),
236241 Trigger::Retitled => (
237242 t(lang, Key::WhenTaskRenamed).to_string(),
238- String::new(),
243+ None,
239244 "retitled".to_string(),
240245 None,
241246 ),
242247 Trigger::Linked => (
243248 t(lang, Key::WhenTaskLinked).to_string(),
244- String::new(),
249+ None,
245250 "linked".to_string(),
246251 None,
247252 ),
248253 Trigger::Unlinked => (
249254 t(lang, Key::WhenTaskUnlinked).to_string(),
250- String::new(),
255+ None,
251256 "unlinked".to_string(),
252257 None,
253258 ),
254259 Trigger::Deleted => (
255260 t(lang, Key::WhenTaskDeleted).to_string(),
256- String::new(),
261+ None,
257262 "deleted".to_string(),
258263 None,
259264 ),
@@ -827,7 +832,11 @@ async fn rule_row(
827832
828833 <div class="rule-sentence">
829834 <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+ }
831840 <span>(t(lang, Key::SendConnector))</span>
832841 <span class="rule-term">(rule.subject.clone())</span>
833842 <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() {
32713271 assert!(answer.body.contains("EmptySubject"), "{}", answer.body);
32723272 }
32733273
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+
32743328 #[tokio::test]
32753329 async fn a_rule_may_not_be_hung_off_a_column_that_is_not_on_this_board() {
32763330 let app = App::open().await;