improve(updates): close update center after component updates

This commit is contained in:
zipg authored and GitHub committed 2026-09-20 00:50:25 +08:00
1 parent f9b984da68
commit fff07eff00
4 files changed
+52 -2

No files matched your search

@@ -1,7 +1,7 @@
// @vitest-environment happy-dom
import { beforeEach, describe, expect, it, vi } from "vitest";
import { clearPendingComponentUpdatesAfterAppUpdate, markPendingComponentUpdatesAfterAppUpdate, resolveUpdateAllAction, runPendingComponentUpdatePlan, takePendingComponentUpdatesAfterAppRestart } from "@/lib/updates/componentUpdateOrchestration";
import { clearPendingComponentUpdatesAfterAppUpdate, markPendingComponentUpdatesAfterAppUpdate, resolveUpdateAllAction, runPendingComponentUpdatePlan, shouldCloseUpdateCenterAfterComponentUpdate, takePendingComponentUpdatesAfterAppRestart } from "@/lib/updates/componentUpdateOrchestration";
describe("component update orchestration", () => {
beforeEach(() => {
@@ -88,6 +88,29 @@ describe("component update orchestration", () => {
expect(resolveUpdateAllAction({ hasAppUpdate: false, appUpdateCanInstall: true, appUpdatePrepared: false, hasComponentUpdates: false })).toBe("none");
});
it("closes the update center after a successful component-only update with nothing left to install", () => {
expect(
shouldCloseUpdateCenterAfterComponentUpdate({
failedCount: 0,
skippedDriverCount: 0,
hasAppUpdate: false,
remainingComponentUpdateCount: 0,
}),
).toBe(true);
});
it("keeps the update center open when an update failed or a driver update was skipped", () => {
const base = { hasAppUpdate: false, remainingComponentUpdateCount: 0 };
expect(shouldCloseUpdateCenterAfterComponentUpdate({ ...base, failedCount: 1, skippedDriverCount: 0 })).toBe(false);
expect(shouldCloseUpdateCenterAfterComponentUpdate({ ...base, failedCount: 0, skippedDriverCount: 1 })).toBe(false);
});
it("keeps the update center open while the app or another component still needs an update", () => {
const base = { failedCount: 0, skippedDriverCount: 0 };
expect(shouldCloseUpdateCenterAfterComponentUpdate({ ...base, hasAppUpdate: true, remainingComponentUpdateCount: 0 })).toBe(false);
expect(shouldCloseUpdateCenterAfterComponentUpdate({ ...base, hasAppUpdate: false, remainingComponentUpdateCount: 1 })).toBe(false);
});
it("can explicitly clear pending state", () => {
markPendingComponentUpdatesAfterAppUpdate("0.6.16", "0.6.17");
clearPendingComponentUpdatesAfterAppUpdate();
@@ -96,6 +96,10 @@ export function resolveUpdateAllAction(options: { hasAppUpdate: boolean; appUpda
return options.appUpdatePrepared ? "defer-components" : "download-app";
}
export function shouldCloseUpdateCenterAfterComponentUpdate(options: { failedCount: number; skippedDriverCount: number; hasAppUpdate: boolean; remainingComponentUpdateCount: number }): boolean {
return options.failedCount === 0 && options.skippedDriverCount === 0 && !options.hasAppUpdate && options.remainingComponentUpdateCount === 0;
}
export function runPendingComponentUpdatePlan<T>(pending: PendingComponentUpdates, updates: { installCategories: (categories: ComponentUpdateCategory[]) => Promise<T>; autoUpdateEnabledComponents: () => Promise<T> }): Promise<T> {
return pending.plan.kind === "manual" ? updates.installCategories(pending.plan.categories) : updates.autoUpdateEnabledComponents();
}