162 lines
9.3 KiB
Rust
162 lines
9.3 KiB
Rust
use std::{sync::Arc, time::Duration};
|
|
use teamspeach_native::{
|
|
AppConfig, AppRuntime,
|
|
app::runtime::model::{BootstrapState, Snapshot},
|
|
services::{profile::ProfileServices, profile_import::initialize_native_root},
|
|
ui::{
|
|
i18n::{Catalog, Language},
|
|
settings::{self, Category, Intent, Navigation, Operation, Page, Presentation, Row, SettingsAction, SettingsSnapshot, ViewState},
|
|
shell::Destination,
|
|
},
|
|
};
|
|
|
|
async fn snapshot(runtime: &AppRuntime, ready: impl Fn(&Snapshot) -> bool) -> Arc<Snapshot> {
|
|
let mut updates = runtime.subscribe();
|
|
let state = tokio::time::timeout(Duration::from_secs(5), updates.wait_for(|state| {
|
|
state.bootstrap == BootstrapState::Failed || ready(state)
|
|
})).await.expect("isolated About runtime did not publish").unwrap().clone();
|
|
assert_ne!(state.bootstrap, BootstrapState::Failed, "{}", state.error);
|
|
assert_eq!(state.audio_input_starts, 0);
|
|
assert_eq!(state.audio_output_starts, 0);
|
|
state
|
|
}
|
|
|
|
async fn invoke(runtime: &AppRuntime, operation: Operation) -> Arc<Snapshot> {
|
|
let previous = runtime.snapshot().settings_completed;
|
|
runtime.dispatch_settings(SettingsAction::Invoke(operation)).unwrap();
|
|
snapshot(runtime, |state| state.settings_completed > previous).await
|
|
}
|
|
|
|
fn row<'a>(view: &'a Presentation, id: &str) -> &'a Row {
|
|
view.rows.iter().find(|row| row.id == id).unwrap_or_else(|| panic!("missing About row {id}"))
|
|
}
|
|
|
|
fn activation(row: &Row) -> Operation {
|
|
assert!(row.enabled, "About row {} is disabled", row.id);
|
|
let Intent::Invoke(op) = &row.intent else { panic!("About row {} is inert", row.id); };
|
|
op.clone()
|
|
}
|
|
|
|
fn present(state: &Snapshot, language: Language, page: Page) -> Presentation {
|
|
assert!(state.last_error.is_none(), "{}", state.error);
|
|
assert_eq!(state.destination, Destination::Settings);
|
|
assert_eq!(state.settings_view.category, Category::About);
|
|
assert_eq!(state.settings_view.page(), page);
|
|
settings::build(&state.settings, &state.settings_view, &Catalog::new(language))
|
|
}
|
|
|
|
#[tokio::test(flavor = "current_thread")]
|
|
async fn bundled_about_documents_and_diagnostics_through_public_runtime() {
|
|
let temp = tempfile::tempdir().unwrap();
|
|
let root = temp.path().join("profile");
|
|
initialize_native_root(&root).unwrap();
|
|
ProfileServices::open(&root).unwrap().identities.onboard("Isolated About").unwrap();
|
|
let runtime = AppRuntime::start(AppConfig::isolated(root.clone())).unwrap();
|
|
let ready = snapshot(&runtime, |state| state.settings.loaded).await;
|
|
let tabs: Vec<_> = ready.connections.connections.iter().map(|tab| tab.key.clone()).collect();
|
|
let back = Operation::Navigate(Navigation::Back);
|
|
|
|
let opened = invoke(&runtime, Operation::Navigate(Navigation::Category(Category::About))).await;
|
|
let about = present(&opened, Language::En, Page::Root);
|
|
assert!(about.show_slint);
|
|
assert_eq!(row(&about, "about-version").subtitle, env!("CARGO_PKG_VERSION"));
|
|
|
|
let opened = invoke(&runtime, activation(row(&about, "page:Licenses"))).await;
|
|
let licenses = present(&opened, Language::En, Page::Licenses);
|
|
assert_eq!(licenses.focus_row.as_deref(), Some("about-back"));
|
|
assert_eq!(row(&licenses, "license:native:0").title, "Slint");
|
|
assert!(licenses.rows.iter().any(|row| row.title.starts_with("tsclientlib ")));
|
|
assert!(!licenses.rows.iter().any(|row| row.title.starts_with("Chromium")));
|
|
|
|
let slint_row = row(&licenses, "license:native:0");
|
|
let opened = invoke(&runtime, activation(slint_row)).await;
|
|
let slint = present(&opened, Language::En, Page::License("native:0".into()));
|
|
assert!(slint.show_slint);
|
|
assert_eq!(row(&slint, "license-body").subtitle, include_str!("../resources/licenses/Slint-License-2.0.txt"));
|
|
let returned = invoke(&runtime, back.clone()).await;
|
|
let licenses = present(&returned, Language::En, Page::Licenses);
|
|
assert_eq!(licenses.focus_row.as_deref(), Some(slint_row.id.as_str()));
|
|
let opened = invoke(&runtime, activation(row(&licenses, "license:teamspeach:1"))).await;
|
|
let noto = present(&opened, Language::En, Page::License("teamspeach:1".into()));
|
|
assert!(!noto.show_slint);
|
|
assert_eq!(row(¬o, "license-body").subtitle, include_str!("../../LICENSES/NotoSans-OFL.txt"));
|
|
let returned = invoke(&runtime, back.clone()).await;
|
|
let licenses = present(&returned, Language::En, Page::Licenses);
|
|
assert_eq!(licenses.focus_row.as_deref(), Some("license:teamspeach:1"));
|
|
|
|
let unrelated_path = temp.path().join("unrelated-file");
|
|
std::fs::write(&unrelated_path, "not bundled").unwrap();
|
|
for (id, expected) in [(unrelated_path.to_string_lossy().into_owned(), "bad_request"), ("native:42".into(), "not_found")] {
|
|
let refused = invoke(&runtime, Operation::Navigate(Navigation::Page(Page::License(id)))).await;
|
|
assert_eq!(refused.last_error.as_ref().unwrap().code, expected);
|
|
assert_eq!(refused.settings_view.page(), Page::Licenses);
|
|
let unchanged = settings::build(&refused.settings, &refused.settings_view, &Catalog::new(Language::En));
|
|
assert_eq!(unchanged.focus_row.as_deref(), Some("license:teamspeach:1"));
|
|
assert_eq!(unchanged.error, refused.last_error.as_ref().unwrap().message);
|
|
assert!(!unchanged.rows.iter().any(|row| row.id == "license-body"));
|
|
}
|
|
|
|
let returned = invoke(&runtime, back.clone()).await;
|
|
let about = present(&returned, Language::Ru, Page::Root);
|
|
assert_eq!(about.focus_row.as_deref(), Some("page:Licenses"));
|
|
let opened = invoke(&runtime, activation(row(&about, "page:Changelog"))).await;
|
|
let changelog = present(&opened, Language::Ru, Page::Changelog);
|
|
assert_eq!(row(&changelog, "section:universal.changelog").title, "Журнал изменений");
|
|
assert_eq!(row(&changelog, "change:0").title, "Ещё не выпущено");
|
|
let release_row = changelog.rows.iter().find(|row| row.title == "Обновление 0.1.7").unwrap();
|
|
assert_eq!(release_row.subtitle, "2026-11-02");
|
|
let open_release = activation(release_row);
|
|
let Operation::Navigate(Navigation::Page(Page::Release(index))) = open_release else {
|
|
panic!("changelog row does not open a release detail");
|
|
};
|
|
let opened = invoke(&runtime, Operation::Navigate(Navigation::Page(Page::Release(index)))).await;
|
|
let release = present(&opened, Language::Ru, Page::Release(index));
|
|
assert_eq!(row(&release, "release-title").title, release_row.title);
|
|
assert!(row(&release, "release-change:0").subtitle.contains("Matched light-theme toolbar/header/composer icon colors"));
|
|
let returned = invoke(&runtime, back.clone()).await;
|
|
let changelog = present(&returned, Language::Ru, Page::Changelog);
|
|
assert_eq!(changelog.focus_row.as_deref(), Some(release_row.id.as_str()));
|
|
let returned = invoke(&runtime, back.clone()).await;
|
|
let about = present(&returned, Language::En, Page::Root);
|
|
assert_eq!(about.focus_row.as_deref(), Some("page:Changelog"));
|
|
|
|
let opened = invoke(&runtime, activation(row(&about, "page:Diagnostics"))).await;
|
|
let diagnostics = present(&opened, Language::En, Page::Diagnostics);
|
|
let value = |label| diagnostics.rows.iter().find(|row| row.title == label).unwrap().subtitle.as_str();
|
|
assert_eq!(value("Version"), env!("CARGO_PKG_VERSION"));
|
|
assert_eq!(value("Native Runtime"), "rust-slint");
|
|
assert_eq!(value("Build Target"), env!("TEAMSPEACH_BUILD_TARGET"));
|
|
assert_eq!(value("Operating System"), std::env::consts::OS);
|
|
assert_eq!(value("Architecture"), std::env::consts::ARCH);
|
|
assert_eq!(value("Profile Directory"), root.to_string_lossy());
|
|
assert_eq!(value("Log Directory"), root.join("logs").to_string_lossy());
|
|
assert_eq!(value("Network Access"), "Disabled");
|
|
assert_eq!(value("Operating System Actions"), "Disabled");
|
|
assert_eq!(row(&diagnostics, "logs-unavailable").title, "Opening the log directory is disabled in this session.");
|
|
assert!(!diagnostics.rows.iter().any(|row| row.title.contains("Chromium") || row.title.contains("Electron") || row.id == "logs"));
|
|
std::fs::create_dir_all(root.join("logs")).unwrap();
|
|
let denied = invoke(&runtime, Operation::OpenLogs).await;
|
|
assert_eq!(denied.last_error.as_ref().unwrap().code, "os_actions_disabled");
|
|
assert_eq!(denied.settings_view.page(), Page::Diagnostics);
|
|
let returned = invoke(&runtime, back).await;
|
|
let about = present(&returned, Language::En, Page::Root);
|
|
assert_eq!(about.focus_row.as_deref(), Some("page:Diagnostics"));
|
|
assert_eq!(returned.connections.connections.iter().map(|tab| tab.key.clone()).collect::<Vec<_>>(), tabs);
|
|
runtime.shutdown().await.unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn missing_changelog_is_not_an_empty_success_in_either_catalog() {
|
|
let mut view = ViewState::default();
|
|
view.navigate(&Navigation::Category(Category::About));
|
|
view.navigate(&Navigation::Page(Page::Changelog));
|
|
let snapshot = SettingsSnapshot { loaded: true, ..Default::default() };
|
|
for (language, message) in [(Language::En, "Not found in this installation"), (Language::Ru, "Не найдено в этой установке")] {
|
|
let result = settings::build(&snapshot, &view, &Catalog::new(language));
|
|
let error = row(&result, "about-missing:CHANGELOG.md");
|
|
assert!(error.subtitle.starts_with(message));
|
|
assert!(error.subtitle.ends_with("CHANGELOG.md"));
|
|
assert!(!result.rows.iter().any(|row| matches!(row.intent, Intent::Invoke(_))));
|
|
}
|
|
}
|