A task tells its story newest first
Browse files at this commitf7fb32ed05b1c1a3c49c7a772eb5459431979efeParent: 7fa61f4- fix
- a task tells its story newest first
2 changed files +32 -4
crates/izlek-core/src/store/turso_store.rsmodified+1 -1
| @@ -3341,7 +3341,7 @@ impl DetailReads for TursoStore { | |||
| 3341 | "SELECT a.id, a.kind, a.detail, a.created_at, u.id, u.display_name, \ | 3341 | "SELECT a.id, a.kind, a.detail, a.created_at, u.id, u.display_name, \ |
| 3342 | (u.photo IS NOT NULL) \ | 3342 | (u.photo IS NOT NULL) \ |
| 3343 | FROM activity a LEFT JOIN user u ON u.id = a.actor_id \ | 3343 | FROM activity a LEFT JOIN user u ON u.id = a.actor_id \ |
| 3344 | - WHERE a.task_id = ?1 ORDER BY a.created_at, a.rowid", | 3344 | + WHERE a.task_id = ?1 ORDER BY a.created_at DESC, a.rowid DESC", |
| 3345 | params![task_id], | 3345 | params![task_id], |
| 3346 | ) | 3346 | ) |
| 3347 | .await | 3347 | .await |
crates/izlek-core/tests/store.rsmodified+31 -3
| @@ -2732,14 +2732,15 @@ async fn saving_a_task_records_only_what_changed() { | |||
| 2732 | assert_eq!(detail.title, "second title"); | 2732 | assert_eq!(detail.title, "second title"); |
| 2733 | assert_eq!(detail.description, "some prose"); | 2733 | assert_eq!(detail.description, "some prose"); |
| 2734 | assert_eq!(detail.deadline_input(), "2026-09-12"); | 2734 | assert_eq!(detail.deadline_input(), "2026-09-12"); |
| 2735 | + // Newest first, as everywhere else: the deadline was the last thing set. | ||
| 2735 | let kinds: Vec<&ActivityKind> = detail.activity.iter().map(|e| &e.kind).collect(); | 2736 | let kinds: Vec<&ActivityKind> = detail.activity.iter().map(|e| &e.kind).collect(); |
| 2736 | assert_eq!( | 2737 | assert_eq!( |
| 2737 | kinds, | 2738 | kinds, |
| 2738 | [ | 2739 | [ |
| 2739 | - &ActivityKind::Created, | 2740 | + &ActivityKind::DeadlineSet, |
| 2740 | - &ActivityKind::Retitled, | ||
| 2741 | &ActivityKind::Described, | 2741 | &ActivityKind::Described, |
| 2742 | - &ActivityKind::DeadlineSet | 2742 | + &ActivityKind::Retitled, |
| 2743 | + &ActivityKind::Created | ||
| 2743 | ] | 2744 | ] |
| 2744 | ); | 2745 | ); |
| 2745 | } | 2746 | } |
| @@ -5249,3 +5250,30 @@ async fn the_engine_delivers_a_notice_that_owes_no_rule() { | |||
| 5249 | assert!(owed.is_empty(), "a delivered notice is no longer owed: {owed:?}"); | 5250 | assert!(owed.is_empty(), "a delivered notice is no longer owed: {owed:?}"); |
| 5250 | std::fs::remove_dir_all(dir).ok(); | 5251 | std::fs::remove_dir_all(dir).ok(); |
| 5251 | } | 5252 | } |
| 5253 | + | ||
| 5254 | +/// A task's own history reads newest first, the same way every other feed in | ||
| 5255 | +/// the app does — the oldest line is the last one, not the first. | ||
| 5256 | +#[tokio::test] | ||
| 5257 | +async fn a_tasks_activity_reads_newest_first() { | ||
| 5258 | + let (scratch, workspace, admin) = workspace_with_admin().await; | ||
| 5259 | + let store = &scratch.store; | ||
| 5260 | + let task = add_task(store, &workspace, "Backlog", "order me", None, &admin).await; | ||
| 5261 | + | ||
| 5262 | + for word in ["one", "two", "three"] { | ||
| 5263 | + store | ||
| 5264 | + .add_comment(&task, &admin, word, OffsetDateTime::now_utc()) | ||
| 5265 | + .await | ||
| 5266 | + .unwrap(); | ||
| 5267 | + } | ||
| 5268 | + | ||
| 5269 | + let activity = store.activity_for_task(&task).await.unwrap(); | ||
| 5270 | + let stamps: Vec<_> = activity.iter().map(|line| line.at).collect(); | ||
| 5271 | + assert!( | ||
| 5272 | + stamps.windows(2).all(|pair| pair[0] >= pair[1]), | ||
| 5273 | + "not newest first: {stamps:?}" | ||
| 5274 | + ); | ||
| 5275 | + // Creation is the oldest thing that ever happens to a task, so it is last | ||
| 5276 | + // now; a comment — the most recent act here — leads. | ||
| 5277 | + assert_eq!(activity.first().map(|line| line.kind.clone()), Some(ActivityKind::Commented), "{activity:?}"); | ||
| 5278 | + assert_eq!(activity.last().map(|line| line.kind.clone()), Some(ActivityKind::Created), "{activity:?}"); | ||
| 5279 | +} | ||