test: reconcile restart-only language integration

- Import the locale used by the stream capture identity regressions locally.
- Exercise recent server events in both startup languages without expecting a saved language to retranslate the running app.
This commit is contained in:
omar committed 2026-11-28 08:06:51 +03:00
1 parent f9ae872168
commit 89a9be03e8
3 files changed
+76 -63

No files matched your search

@@ -272,6 +272,7 @@ pub(super) async fn on_control(ctx:Arc<RuntimeServices>,key:&SessionKey,value:&s
#[cfg(test)]
mod tests {
use super::*;
use crate::ui::i18n::Language;
#[test]
fn capture_actions_reject_a_replacement_on_the_same_tab_and_source(){
+73 -63
View File
@@ -1018,76 +1018,86 @@ fn run_publisher_fixture(scenario: PublisherFixture) {
}
#[test]
fn recent_server_events_reproject_same_timestamp_in_english_and_russian() {
fn recent_server_events_reproject_same_timestamp_in_startup_language() {
use crate::ui::settings::{Field, Preference, SettingValue, SettingsAction};
use serde_json::json;
use super::identities::ack;
if !headless::install_for_test() { return; }
let temp = tempfile::tempdir().unwrap();
let root = temp.path().join("profile");
initialize_native_root(&root).unwrap();
let mut profile = ProfileServices::open(&root).unwrap();
profile.identities.onboard("Recent events QA").unwrap();
profile.prefs.set(json!({"notificationDeviceId":"none"})).unwrap();
drop(profile);
for (language, next, panel, title) in [
("en", "ru", "Recent Server Events", "Could not connect to clock-fixture.invalid"),
("ru", "en", "Последние события сервера", "Не удалось подключиться к clock-fixture.invalid"),
] {
let temp = tempfile::tempdir().unwrap();
let root = temp.path().join("profile");
initialize_native_root(&root).unwrap();
let mut profile = ProfileServices::open(&root).unwrap();
profile.identities.onboard("Recent events QA").unwrap();
profile.prefs.set(json!({"notificationDeviceId":"none", "language":language})).unwrap();
drop(profile);
run_ui(&AppConfig::isolated(root), async |runtime, ui| {
let shell = ui.global::<ShellBridge>();
const EN_PANEL: &str = "Recent Server Events";
const RU_PANEL: &str = "Последние события сервера";
const EN_EVENT: &str = "Could not connect to clock-fixture.invalid";
const RU_EVENT: &str = "Не удалось подключиться к clock-fixture.invalid";
let command = wait(runtime, "Recent Server Events command", |s| {
(s.settings.loaded && s.settings.prefs["chatUse24hTime"] == true).then(|| {
shell.get_actions().iter().find(|action| action.enabled && action.label == EN_PANEL)
}).flatten()
}).await?;
let owner = runtime.services.lock().unwrap().upgrade().ok_or("runtime closed")?;
let manager = &owner.connected.connections;
let key = manager.key("c1").await.map_err(|e| e.to_string())?;
manager.fixture_control(&key, json!({
"event":"state", "state":"disconnected", "previous_state":"connecting",
"reason":{"code":"connect_failed"}, "address":"clock-fixture.invalid", "generation":key.generation
})).await.map_err(|e| e.to_string())?;
shell.invoke_invoke(command.id);
let row = wait(runtime, "initial 24-hour recent event", |_| {
if shell.get_title() != EN_PANEL { return None; }
shell.get_entries().iter().find(|row| row.title == EN_EVENT)
}).await?;
let time_24h = row.subtitle.as_str();
let (hour, minute) = time_24h.split_once(':').ok_or("missing clock separator")?;
assert_eq!((hour.len(), minute.len()), (2, 2));
let (hour, minute): (u8, u8) = (hour.parse().unwrap(), minute.parse().unwrap());
assert!(hour < 24 && minute < 60);
let hour_12 = (hour + 11) % 12 + 1;
let en_12h = format!("{hour_12}:{minute:02} {}", if hour < 12 { "AM" } else { "PM" });
let ru_period = match hour { 0..=3 => "ночи", 4..=11 => "утра", 12..=16 => "дня", _ => "вечера" };
let ru_12h = format!("{hour_12}:{minute:02} {ru_period}");
let canonical = owner.notifications.lock().unwrap().event_log(&key).unwrap().clone();
assert!(canonical.iter().any(|entry| entry.key == "notify.log.connection_failed"));
for (preference, value, panel, title, clock) in [
(Preference::ChatUse24hTime, SettingValue::Bool(false), EN_PANEL, EN_EVENT, en_12h.as_str()),
(Preference::Language, SettingValue::Text("ru".into()), RU_PANEL, RU_EVENT, ru_12h.as_str()),
(Preference::ChatUse24hTime, SettingValue::Bool(true), RU_PANEL, RU_EVENT, time_24h),
(Preference::ChatUse24hTime, SettingValue::Bool(false), RU_PANEL, RU_EVENT, ru_12h.as_str()),
] {
let serial = runtime.snapshot().settings_completed + 1;
let expected = value.json();
runtime.dispatch_settings(SettingsAction::Edit { field: Field::Preference(preference), value }).map_err(|e| e.message)?;
let snapshot = ack(runtime, serial, "recent event preference saved", None).await?;
assert_eq!(snapshot.settings.prefs[preference.key()], expected);
wait(runtime, &format!("recent event with clock {clock}"), |_| {
(shell.get_title() == panel && shell.get_entries().iter().any(|entry| {
entry.id == row.id && entry.title == title && entry.subtitle == clock
})).then_some(())
run_ui(&AppConfig::isolated(root), async move |runtime, ui| {
let shell = ui.global::<ShellBridge>();
let command = wait(runtime, "Recent Server Events command", |s| {
(s.settings.loaded && s.settings.prefs["chatUse24hTime"] == true).then(|| {
shell.get_actions().iter().find(|action| action.enabled && action.label == panel)
}).flatten()
}).await?;
assert_eq!(owner.notifications.lock().unwrap().event_log(&key).unwrap(), &canonical);
}
Ok(())
}).unwrap();
let owner = runtime.services.lock().unwrap().upgrade().ok_or("runtime closed")?;
let manager = &owner.connected.connections;
let key = manager.key("c1").await.map_err(|e| e.to_string())?;
manager.fixture_control(&key, json!({
"event":"state", "state":"disconnected", "previous_state":"connecting",
"reason":{"code":"connect_failed"}, "address":"clock-fixture.invalid", "generation":key.generation
})).await.map_err(|e| e.to_string())?;
shell.invoke_invoke(command.id);
let row = wait(runtime, "initial 24-hour recent event", |_| {
if shell.get_title() != panel { return None; }
shell.get_entries().iter().find(|row| row.title == title)
}).await?;
let time_24h = row.subtitle.as_str();
let (hour, minute) = time_24h.split_once(':').ok_or("missing clock separator")?;
assert_eq!((hour.len(), minute.len()), (2, 2));
let (hour, minute): (u8, u8) = (hour.parse().unwrap(), minute.parse().unwrap());
assert!(hour < 24 && minute < 60);
let hour_12 = (hour + 11) % 12 + 1;
let period = if language == "ru" {
match hour { 0..=3 => "ночи", 4..=11 => "утра", 12..=16 => "дня", _ => "вечера" }
} else if hour < 12 { "AM" } else { "PM" };
let time_12h = format!("{hour_12}:{minute:02} {period}");
let canonical = owner.notifications.lock().unwrap().event_log(&key).unwrap().clone();
assert!(canonical.iter().any(|entry| entry.key == "notify.log.connection_failed"));
for (preference, value, clock) in [
(Preference::ChatUse24hTime, SettingValue::Bool(false), time_12h.as_str()),
(Preference::Language, SettingValue::Text(next.into()), time_12h.as_str()),
(Preference::ChatUse24hTime, SettingValue::Bool(true), time_24h),
(Preference::ChatUse24hTime, SettingValue::Bool(false), time_12h.as_str()),
] {
let serial = runtime.snapshot().settings_completed + 1;
let expected = value.json();
runtime.dispatch_settings(SettingsAction::Edit { field: Field::Preference(preference), value }).map_err(|e| e.message)?;
if preference == Preference::Language && cfg!(not(any(target_os = "android", target_os = "ios"))) {
let dialog = ui.global::<crate::DialogBridge>();
wait(runtime, "saved language with restart prompt", |s| {
(s.settings.prefs["language"] == next && dialog.get_visible()).then_some(())
}).await?;
dialog.invoke_cancel();
}
let snapshot = ack(runtime, serial, "recent event preference saved", None).await?;
assert_eq!(snapshot.settings.prefs[preference.key()], expected);
assert_eq!(snapshot.catalog.language.code(), language);
wait(runtime, &format!("recent event with clock {clock}"), |_| {
(shell.get_title() == panel && shell.get_entries().iter().any(|entry| {
entry.id == row.id && entry.title == title && entry.subtitle == clock
})).then_some(())
}).await?;
assert_eq!(owner.notifications.lock().unwrap().event_log(&key).unwrap(), &canonical);
}
Ok(())
}).unwrap_or_else(|error| panic!("{language}: {error}"));
}
}
#[test]