use super::*; const NOW: &str = "2026-08-30T09:00:00.000Z"; fn empty<'a>() -> AskedInput<'a> { AskedInput { now: NOW, ..AskedInput::default() } } fn keys(rows: &[AskedRow]) -> Vec<(&'static str, usize)> { rows.iter().map(|r| (r.key.as_str(), r.count)).collect() } #[test] fn is_empty_when_nothing_waits_so_the_band_hides_itself() { let rows = asked_rows(&empty()); assert!(rows.is_empty()); assert_eq!(asked_total(&rows), 0); } fn invite(starts_at: &str, my_response: Option<&str>, organizer_is_self: bool) -> DecidableEvent { DecidableEvent { starts_at: starts_at.into(), my_response: my_response.map(Into::into), organizer_is_self, } } // RULE: An invite is an event someone else organizes that the owner has not answered (needs_action), still ahead; the owner's own events — no organizer, no attendees, no reply — never count, because Home said "2 invites to answer" over two of the owner's own Google events. #[test] fn counts_only_upcoming_invites_with_no_answer() { let events = [ invite("2026-09-01T09:00:00.000Z", Some("needs_action"), false), invite("2026-09-02T09:00:00.000Z", Some("accepted"), false), invite("2026-08-01T09:00:00.000Z", Some("needs_action"), false), // The owner's own events, ahead and unanswered: never an invite. invite("2026-09-03T09:00:00.000Z", None, true), invite("2026-09-04T09:00:00.000Z", Some("needs_action"), true), // Someone else's event with no reply on it (a subscribed calendar). invite("2026-09-05T09:00:00.000Z", None, false), ]; let rows = asked_rows(&AskedInput { events: &events, ..empty() }); assert_eq!(keys(&rows), [("invites", 1)]); } /// Only the owner has the password, and a wrong guess is no guess at all — the /// one document state that passes the rule. #[test] fn a_document_locked_by_a_password_is_asked() { let rows = asked_rows(&AskedInput { locked_documents: 2, ..empty() }); assert_eq!(keys(&rows), [("passwords", 2)]); } #[test] fn raises_the_ai_access_row_as_a_single_row_never_a_count() { let rows = asked_rows(&AskedInput { ai_access_needed: true, ..empty() }); assert_eq!(keys(&rows), [("aiAccess", 1)]); } /// An invite two days out is a decision waiting; the same invite read from a /// `now` that is past it is not. If this function reached for a clock the /// second case would depend on the day the suite ran. #[test] fn reads_now_from_the_seam_never_the_wall_clock() { let events = [invite("2026-09-01T09:00:00.000Z", Some("needs_action"), false)]; assert_eq!( keys(&asked_rows(&AskedInput { events: &events, ..empty() })), [("invites", 1)] ); assert!(asked_rows(&AskedInput { events: &events, now: "2026-09-02T09:00:00.000Z", ..empty() }) .is_empty()); } // ── The words and the surface ───────────────────────────────────────────── // // The block that exercises them TOGETHER — the snapshot's `decide` — is // `cotton-ffi`'s, beside the read that builds it. /// TOTAL over the queue's keys: a key with no surface would draw a row whose /// tap goes nowhere, which is the silent-hole class these tables exist to /// refuse. `match` makes it a compile error rather than a test failure for a /// NEW key — this catches an existing one being emptied. #[test] fn every_row_core_can_produce_names_a_surface() { for key in ASKED_KEYS { assert!( !asked_path(key).is_empty(), "no path for {}", key.as_str() ); } } /// An invite is answered on the calendar, a password on the locked documents, /// AI access in Settings. #[test] fn each_row_opens_its_own_surface() { assert_eq!(asked_path(AskedKey::Invites), "/calendar?show=invites"); assert_eq!(asked_path(AskedKey::Passwords), "/documents?status=locked"); assert_eq!(asked_path(AskedKey::AiAccess), "/passwords"); } #[test] fn a_label_says_what_it_counts_in_both_numbers() { assert_eq!( asked_label(AskedKey::Invites, 2, &[]), "2 invites to answer" ); assert_eq!( asked_label(AskedKey::Passwords, 1, &[]), "1 document needs your password" ); assert_eq!( asked_label(AskedKey::Passwords, 3, &[]), "3 documents need your password" ); assert_eq!( asked_label(AskedKey::AiAccess, 1, &[]), "AI access needed to file" ); } /// The AI-access row is a STATE, not a count: "1 AI access needed to file" /// would read as a queue of one. #[test] fn the_ai_access_row_carries_no_figure() { for count in [0, 1, 9] { assert_eq!( asked_label(AskedKey::AiAccess, count, &[]), "AI access needed to file" ); } } #[test] fn plural_figures_keep_english_grouping() { let row = LineRow { set: "home".into(), line: "asked.invites.other".into(), words: "{n} invites waiting".into() }; assert_eq!(asked_label(AskedKey::Invites, 3, &[row]), "3 invites waiting", "a rewording is a row"); assert_eq!( asked_label(AskedKey::Invites, 1000, &[]), "1,000 invites to answer" ); assert_eq!( asked_label(AskedKey::Invites, 1_000_000, &[]), "1,000,000 invites to answer" ); }