fix(download): M94 r2 —— 安装终态出口 + 分类真机过滤(复审 P1-1 / P2-1)

P1-1 安装一旦收尾就再也装不了第二个版本(终态面板没有出口)
- 页面侧:`Download::from_snapshot` 把 **Done / Cancelled** 当结束(`InstallView::finished`),
  面板让回列表 —— 装完一个版本可以直接选下一个继续装(图:r2-done / r2-done-next)。
  不清 `Failed`:失败态带着用户要的东西(停在哪个文件 + 去日志页)。
- 面板加真出口:失败态「Open logs」(实心)+「Dismiss」(文本 → `Message::CancelInstall`,
  host 侧对没在跑的任务是安全 no-op),修掉「失败后连重试都不可达」。
- 决策抽成纯函数 `install::panel_state()`(Hint / Ready / Install),`panel()` 只是它的画法,
  于是「能不能再装」可以被单测钉死,不用开图形环境。
- 两条新测试**不走 MockBackend**(它从不发 `InstallProgress`,终态永远跑不到 ⇒ 假绿):
  直接构造 `AppState` + `apply(CoreEvent::InstallProgress(..))`。

P2-1 分类 chip 在真 host 上是空控件
- `from_snapshot(state, category, catalog)` 收分类并按 `Category::matches` **本地过滤**
  (真 host 的 `ListVersions(_)` 丢掉分类参数、回全量清单);
- 分类不再从列表反推(`Category::of` 只留给演示首帧),`app/view.rs::model` 收分类、
  `refresh_view` 把上一份视图模型的分类带回去 ⇒ 事件回来 chip 不会跳回「全部」;
- `update.rs` 的 `SetCategory` 写分类后**立刻重建**(chip 与列表同一个谓词),再派真指令。

p3(顺带)
- 失败态与占位态共存:列表空/加载中时若安装还在跑,面板照样出现在底部(r2-installing-empty);
- 修 `install.rs` 的坏 rustdoc 链接;`install.rs` / `model.rs` 的测试模块外置到子文件守住 400 行。

测试文件:`pages/download/{model,install}/tests.rs`(新),`pages/download/tests.rs` 里的
`from_snapshot` 调用补分类参数。

实证(回退法):删掉 `.filter(|view| !view.finished())` → 两条终态测试红并点名
「Done 之后不许再占着安装面板」;删掉 `.filter(|category.matches(..))` → 两条分类测试红
(「只剩正式版」left=3 right=1)。放回修复 → 全绿。

门禁:fmt --check 干净、clippy -D warnings 干净、app-iced 280 + 集成 6 + i18n 23 全绿(-j 4)。
This commit is contained in:
tower authored and AskaEth committed 2026-11-02 21:36:28 +08:00
1 parent 9d6ee70301
commit 6453c76750
12 files changed
+432 -74

No files matched your search

+9 -9
View File
@@ -93,7 +93,7 @@ fn the_snapshot_becomes_the_page_model() {
},
))));
let model = Download::from_snapshot(&state, Lang::En.catalog());
let model = Download::from_snapshot(&state, Category::All, Lang::En.catalog());
assert_eq!(model.rows.len(), 2);
assert_eq!(model.rows[0].id, "1.21.9");
@@ -101,8 +101,8 @@ fn the_snapshot_becomes_the_page_model() {
assert!(!model.rows[0].installed);
assert_eq!(
model.category,
Category::Release,
"整份列表都是正式版 → 反推出正式版分类"
Category::All,
"分类是**调用方给的过滤条件**,不再从列表反推(反推正是 chip 跳回「全部」的来源)"
);
assert_eq!(
model.selected.as_deref(),
@@ -134,14 +134,14 @@ fn presenter_filters_still_apply() {
let installed_only = {
state.installed_only = true;
Download::from_snapshot(&state, Lang::En.catalog())
Download::from_snapshot(&state, Category::All, Lang::En.catalog())
};
assert_eq!(installed_only.rows.len(), 2, "仅已装");
let queried = {
state.installed_only = false;
state.download_query = " 1.21 ".to_string();
Download::from_snapshot(&state, Lang::En.catalog())
Download::from_snapshot(&state, Category::All, Lang::En.catalog())
};
assert_eq!(queried.rows.len(), 2, "版本号片段匹配两个");
assert!(queried.rows.iter().all(|row| row.id.starts_with("1.21")));
@@ -151,12 +151,12 @@ fn presenter_filters_still_apply() {
/// 抓不住:真机上卡在加载态多久(没有超时信号,见模块文档的缺口表)。
#[test]
fn loading_and_empty_are_different_states() {
let loading = Download::from_snapshot(&AppState::new(), Lang::En.catalog());
let loading = Download::from_snapshot(&AppState::new(), Category::All, Lang::En.catalog());
assert!(loading.is_loading() && !loading.is_empty());
let mut state = state_with(vec![version("1.21.9", VersionKind::Release, false)]);
state.download_query = "no-such-version".to_string();
let empty = Download::from_snapshot(&state, Lang::En.catalog());
let empty = Download::from_snapshot(&state, Category::All, Lang::En.catalog());
assert!(!empty.is_loading(), "列表拉到了,不是加载中");
assert!(empty.is_empty(), "过滤后没有行 = 空态");
}
@@ -252,8 +252,8 @@ fn the_model_speaks_the_catalog_language() {
let versions = vec![version("1.21.9", VersionKind::Release, false)];
let state = state_with(versions);
let en = Download::from_snapshot(&state, Lang::En.catalog());
let zh = Download::from_snapshot(&state, Lang::ZhCn.catalog());
let en = Download::from_snapshot(&state, Category::All, Lang::En.catalog());
let zh = Download::from_snapshot(&state, Category::All, Lang::ZhCn.catalog());
assert_eq!(en.rows[0].supporting, "Release · released 2026-09-20");
assert_eq!(zh.rows[0].supporting, "正式版 · 发布于 2026-09-20");