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 {
40 id: String,40 id: String,
41 /// "When status becomes", or "When a task stops being".41 /// "When status becomes", or "When a task stops being".
42 when: String,42 when: String,
43- /// "Done", or "blocked", or empty when the trigger has no second half.43+ /// "Done", or "blocked". `None` when the trigger has no second half —
44- what: String,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 subject: String,48 subject: String,
46 /// "assignees", "everyone on board", or "its creator".49 /// "assignees", "everyone on board", or "its creator".
47 audience: String,50 audience: String,
@@ -168,92 +171,94 @@ fn sentence_of(
168 trigger: &Trigger,171 trigger: &Trigger,
169 columns: &[Column],172 columns: &[Column],
170 lang: Lang,173 lang: Lang,
171-) -> (String, String, String, Option<String>) {174+) -> (String, Option<String>, String, Option<String>) {
172 match trigger {175 match trigger {
173 // No column is every column, and "becomes <a column>" has nothing to176 // No column is every column, and "becomes <a column>" has nothing to
174 // name then — the sentence changes shape rather than printing a word177 // name then — the sentence changes shape rather than printing a word
175 // for "any".178 // for "any".
176 Trigger::StatusBecomes(None) => (179 Trigger::StatusBecomes(None) => (
177 t(lang, Key::WhenStatusChanges).to_string(),180 t(lang, Key::WhenStatusChanges).to_string(),
178- String::new(),181+ None,
179 "status".to_string(),182 "status".to_string(),
180 None,183 None,
181 ),184 ),
182 Trigger::StatusBecomes(Some(column_id)) => (185 Trigger::StatusBecomes(Some(column_id)) => (
183 t(lang, Key::WhenStatusBecomes).to_string(),186 t(lang, Key::WhenStatusBecomes).to_string(),
184- columns187+ Some(
185- .iter()188+ columns
186- .find(|column| &column.id == column_id)189+ .iter()
187- // A rule can outlive the column it names. Saying so is190+ .find(|column| &column.id == column_id)
188- // better than printing an id nobody can read.191+ // A rule can outlive the column it names. Saying so is
189- .map(|column| column.name.clone())192+ // better than printing an id nobody can read.
190- .unwrap_or_else(|| t(lang, Key::ColumnGone).to_string()),193+ .map(|column| column.name.clone())
194+ .unwrap_or_else(|| t(lang, Key::ColumnGone).to_string()),
195+ ),
191 "status".to_string(),196 "status".to_string(),
192 Some(column_id.clone()),197 Some(column_id.clone()),
193 ),198 ),
194 Trigger::Unblocked => (199 Trigger::Unblocked => (
195 t(lang, Key::WhenTaskStopsBeingBlocked).to_string(),200 t(lang, Key::WhenTaskStopsBeingBlocked).to_string(),
196- t(lang, Key::BlockedWord).to_string(),201+ Some(t(lang, Key::BlockedWord).to_string()),
197 "unblocked".to_string(),202 "unblocked".to_string(),
198 None,203 None,
199 ),204 ),
200 Trigger::Created => (205 Trigger::Created => (
201 t(lang, Key::WhenTaskCreated).to_string(),206 t(lang, Key::WhenTaskCreated).to_string(),
202- String::new(),207+ None,
203 "created".to_string(),208 "created".to_string(),
204 None,209 None,
205 ),210 ),
206 Trigger::Assigned => (211 Trigger::Assigned => (
207 t(lang, Key::WhenSomeoneAssigned).to_string(),212 t(lang, Key::WhenSomeoneAssigned).to_string(),
208- String::new(),213+ None,
209 "assigned".to_string(),214 "assigned".to_string(),
210 None,215 None,
211 ),216 ),
212 Trigger::Unassigned => (217 Trigger::Unassigned => (
213 t(lang, Key::WhenSomeoneUnassigned).to_string(),218 t(lang, Key::WhenSomeoneUnassigned).to_string(),
214- String::new(),219+ None,
215 "unassigned".to_string(),220 "unassigned".to_string(),
216 None,221 None,
217 ),222 ),
218 Trigger::Commented => (223 Trigger::Commented => (
219 t(lang, Key::WhenCommentWritten).to_string(),224 t(lang, Key::WhenCommentWritten).to_string(),
220- String::new(),225+ None,
221 "commented".to_string(),226 "commented".to_string(),
222 None,227 None,
223 ),228 ),
224 Trigger::DeadlineSet => (229 Trigger::DeadlineSet => (
225 t(lang, Key::WhenDeadlineSet).to_string(),230 t(lang, Key::WhenDeadlineSet).to_string(),
226- String::new(),231+ None,
227 "deadline_set".to_string(),232 "deadline_set".to_string(),
228 None,233 None,
229 ),234 ),
230 Trigger::DeadlineCleared => (235 Trigger::DeadlineCleared => (
231 t(lang, Key::WhenDeadlineRemoved).to_string(),236 t(lang, Key::WhenDeadlineRemoved).to_string(),
232- String::new(),237+ None,
233 "deadline_cleared".to_string(),238 "deadline_cleared".to_string(),
234 None,239 None,
235 ),240 ),
236 Trigger::Retitled => (241 Trigger::Retitled => (
237 t(lang, Key::WhenTaskRenamed).to_string(),242 t(lang, Key::WhenTaskRenamed).to_string(),
238- String::new(),243+ None,
239 "retitled".to_string(),244 "retitled".to_string(),
240 None,245 None,
241 ),246 ),
242 Trigger::Linked => (247 Trigger::Linked => (
243 t(lang, Key::WhenTaskLinked).to_string(),248 t(lang, Key::WhenTaskLinked).to_string(),
244- String::new(),249+ None,
245 "linked".to_string(),250 "linked".to_string(),
246 None,251 None,
247 ),252 ),
248 Trigger::Unlinked => (253 Trigger::Unlinked => (
249 t(lang, Key::WhenTaskUnlinked).to_string(),254 t(lang, Key::WhenTaskUnlinked).to_string(),
250- String::new(),255+ None,
251 "unlinked".to_string(),256 "unlinked".to_string(),
252 None,257 None,
253 ),258 ),
254 Trigger::Deleted => (259 Trigger::Deleted => (
255 t(lang, Key::WhenTaskDeleted).to_string(),260 t(lang, Key::WhenTaskDeleted).to_string(),
256- String::new(),261+ None,
257 "deleted".to_string(),262 "deleted".to_string(),
258 None,263 None,
259 ),264 ),
@@ -827,7 +832,11 @@ async fn rule_row(
827 832
828 <div class="rule-sentence">833 <div class="rule-sentence">
829 <span>(rule.when.clone())</span>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 <span>(t(lang, Key::SendConnector))</span>840 <span>(t(lang, Key::SendConnector))</span>
832 <span class="rule-term">(rule.subject.clone())</span>841 <span class="rule-term">(rule.subject.clone())</span>
833 <span>(t(lang, Key::ToConnector))</span>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 assert!(answer.body.contains("EmptySubject"), "{}", answer.body);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 #[tokio::test]3328 #[tokio::test]
3275 async fn a_rule_may_not_be_hung_off_a_column_that_is_not_on_this_board() {3329 async fn a_rule_may_not_be_hung_off_a_column_that_is_not_on_this_board() {
3276 let app = App::open().await;3330 let app = App::open().await;