test: 支持更新下载时展示图标

This commit is contained in:
2026-04-12 19:11:11 +08:00
parent 81cd00661c
commit 60628ff1fa
2 changed files with 50 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createUpdateCenterStore } from "@/modules/updateCenter";
import { downloads } from "@/global/downloadStatus";
const createSnapshot = (overrides = {}) => ({
items: [
@@ -33,6 +34,7 @@ describe("updateCenter store", () => {
start.mockReset();
onState.mockReset();
offState.mockReset();
downloads.value = [];
Object.defineProperty(window, "updateCenter", {
configurable: true,
@@ -97,6 +99,34 @@ describe("updateCenter store", () => {
expect(start).toHaveBeenCalledWith(["aptss:spark-weather"]);
});
it("uses remoteIcon when adding update tasks to the download queue", async () => {
const snapshot = createSnapshot({
items: [
{
taskKey: "aptss:spark-weather",
packageName: "spark-weather",
displayName: "Spark Weather",
currentVersion: "1.0.0",
newVersion: "2.0.0",
source: "aptss" as const,
ignored: false,
remoteIcon: "https://example.com/icons/spark-weather.png",
},
],
});
open.mockResolvedValue(snapshot);
const store = createUpdateCenterStore();
await store.open();
store.toggleSelection("aptss:spark-weather");
await store.startSelected();
expect(downloads.value).toHaveLength(1);
expect(downloads.value[0]?.icon).toBe(
"https://example.com/icons/spark-weather.png",
);
});
it("blocks close requests while the snapshot reports running tasks", () => {
const store = createUpdateCenterStore();
store.isOpen.value = true;

View File

@@ -155,18 +155,31 @@ export const createUpdateCenterStore = (): UpdateCenterStore => {
// 在前端创建下载项,这样用户能在下载列表中看到更新任务
const arch = window.apm_store.arch || "amd64";
let downloadIdCounter = downloads.value.length > 0 ? Math.max(...downloads.value.map(d => d.id)) + 1 : 1;
let downloadIdCounter =
downloads.value.length > 0
? Math.max(...downloads.value.map((d) => d.id)) + 1
: 1;
selectedItems.forEach((item) => {
// 检查任务是否已存在
if (!downloads.value.find(d => d.pkgname === item.packageName && d.origin === (item.source === "apm" ? "apm" : "spark"))) {
const finalArch = item.source === "apm" ? `${arch}-apm` : `${arch}-store`;
if (
!downloads.value.find(
(d) =>
d.pkgname === item.packageName &&
d.origin === (item.source === "apm" ? "apm" : "spark"),
)
) {
const finalArch =
item.source === "apm" ? `${arch}-apm` : `${arch}-store`;
const icon =
item.remoteIcon ||
`${APM_STORE_BASE_URL}/${finalArch}/unknown/${item.packageName}/icon.png`;
const download: DownloadItem = {
id: downloadIdCounter++,
name: item.displayName,
pkgname: item.packageName,
version: item.newVersion,
icon: `${APM_STORE_BASE_URL}/${finalArch}/unknown/${item.packageName}/icon.png`,
icon,
origin: item.source === "apm" ? "apm" : "spark",
status: "queued",
progress: 0,
@@ -180,7 +193,9 @@ export const createUpdateCenterStore = (): UpdateCenterStore => {
retry: false,
upgradeOnly: true,
filename: item.fileName,
metalinkUrl: item.downloadUrl ? `${item.downloadUrl}.metalink` : undefined,
metalinkUrl: item.downloadUrl
? `${item.downloadUrl}.metalink`
: undefined,
};
downloads.value.push(download);
}