Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions desktop/src/renderer/src/lib/components/update/UpdatesPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,11 @@ onMount(async () => {
{#if installedVersion}
<span>Installed: v{installedVersion}</span>
{/if}
<span>{channelLabel(releaseChannel)} channel</span>
</div>
{:else if s.state === "available"}
<p class="text-sm font-medium">Devsy {s.availableVersion} is available</p>
<p class="text-xs text-muted-foreground">
Installed v{installedVersion || "unknown"} · {channelLabel(releaseChannel)} channel
Installed v{installedVersion || "unknown"}
</p>
{:else if s.state === "downloading"}
<p class="text-sm font-medium">Downloading Devsy {s.availableVersion}</p>
Expand All @@ -155,7 +154,6 @@ onMount(async () => {
{#if installedVersion}
<span>Version {installedVersion}</span>
{/if}
<span>{channelLabel(releaseChannel)} channel</span>
</div>
{:else if s.code === "dev-mode"}
<p class="text-sm font-medium">Updates run in packaged builds</p>
Expand All @@ -173,7 +171,6 @@ onMount(async () => {
{#if installedVersion}
<span>Installed: v{installedVersion}</span>
{/if}
<span>{channelLabel(releaseChannel)} channel</span>
{#if lastChecked}
<span>Last checked at {fmtTime(lastChecked)}</span>
{/if}
Expand All @@ -184,7 +181,6 @@ onMount(async () => {
{#if installedVersion}
<span>Version {installedVersion}</span>
{/if}
<span>{channelLabel(releaseChannel)} channel</span>
{#if lastChecked}
<span>Last checked at {fmtTime(lastChecked)}</span>
{/if}
Expand Down Expand Up @@ -235,7 +231,7 @@ onMount(async () => {

<section class="space-y-3">
<Label>Release channel</Label>
<div class="grid grid-cols-2 gap-3" role="radiogroup" aria-label="Release Channel">
<div class="grid grid-cols-2 gap-3" role="radiogroup" aria-label="Release channel">
{#each CHANNELS as c (c.value)}
<button
type="button"
Expand All @@ -252,31 +248,38 @@ onMount(async () => {
<CheckCircle2 class="h-3.5 w-3.5 text-primary" />
{/if}
</div>
<p class="mt-1 text-xs {c.unstable ? 'text-yellow-600 dark:text-yellow-400' : 'text-muted-foreground'}">{c.cadence}</p>
</button>
{/each}
</div>
</section>

<Separator />

<section class="space-y-3">
<Label>Update Behavior</Label>
<section>
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<div>
<p class="text-sm">Download updates automatically</p>
<p class="text-xs text-muted-foreground">
Updates download in the background; you choose when to restart.
<Label for="auto-download-updates">Automatically download updates</Label>
<p id="auto-download-updates-description" class="text-xs text-muted-foreground">
Restart Devsy when you're ready to install.
</p>
</div>
<Switch checked={$autoUpdate} onCheckedChange={(v) => setAutoUpdate(v)} />
<Switch
id="auto-download-updates"
aria-describedby="auto-download-updates-description"
checked={$autoUpdate}
onCheckedChange={(v) => setAutoUpdate(v)}
/>
</div>
</section>

<section class="flex items-center justify-between text-xs text-muted-foreground">
<span>Devsy {appVersion ? `v${appVersion}` : "version unavailable"}</span>
<span>{channelLabel(releaseChannel)} channel</span>
</section>
<Separator />

<dl class="text-sm">
<div class="flex items-center justify-between gap-4">
<dt class="text-muted-foreground">Current version</dt>
<dd class="font-medium">{appVersion ? `v${appVersion}` : "Unavailable"}</dd>
</div>
</dl>
</div>

<ConfirmDialog
Expand Down
177 changes: 172 additions & 5 deletions desktop/src/renderer/src/lib/components/update/UpdatesPanel.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { render } from "@testing-library/svelte"
import "@testing-library/jest-dom/vitest"
import { cleanup, render, screen, waitFor } from "@testing-library/svelte"
import { tick } from "svelte"
import { get } from "svelte/store"
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"

const getAppVersion = vi.fn()
Expand All @@ -8,6 +10,7 @@ const setReleaseChannel = vi.fn()
const checkForUpdates = vi.fn()
const downloadUpdate = vi.fn()
const installUpdate = vi.fn()
const setAutoDownload = vi.fn()

vi.mock("$lib/ipc/commands.js", () => ({
getAppVersion: (...a: unknown[]) => getAppVersion(...a),
Expand All @@ -16,6 +19,7 @@ vi.mock("$lib/ipc/commands.js", () => ({
checkForUpdates: (...a: unknown[]) => checkForUpdates(...a),
downloadUpdate: (...a: unknown[]) => downloadUpdate(...a),
installUpdate: (...a: unknown[]) => installUpdate(...a),
setAutoDownload: (...a: unknown[]) => setAutoDownload(...a),
}))

const toastSuccess = vi.fn()
Expand All @@ -34,6 +38,7 @@ vi.mock("$lib/ipc/events.js", async (importOriginal) => {
return { ...mod, onUpdateStatus: async () => () => {} }
})

import { autoUpdate } from "$lib/stores/settings.js"
import { __setForTest, initUpdateStore } from "$lib/stores/updates.svelte.js"
import UpdatesPanel from "./UpdatesPanel.svelte"

Expand All @@ -56,6 +61,11 @@ async function renderPanel(channel: "stable" | "beta") {
await tick()
await Promise.resolve()
await tick()
await waitFor(() => {
expect(
cardButton(channel === "beta" ? /Preview/ : /Stable/),
).toHaveAttribute("aria-checked", "true")
})
}

describe("UpdatesPanel channel switching", () => {
Expand All @@ -68,7 +78,7 @@ describe("UpdatesPanel channel switching", () => {
})

afterEach(() => {
document.body.innerHTML = ""
cleanup()
})

it("switches immediately and confirms via toast on a normal upgrade", async () => {
Expand Down Expand Up @@ -125,10 +135,10 @@ describe("UpdatesPanel status display", () => {
})

afterEach(() => {
document.body.innerHTML = ""
cleanup()
})

it("renders up-to-date state with installed version and channel", async () => {
it("renders up-to-date state with the installed version and current version row", async () => {
getAppVersion.mockResolvedValue("1.17.0")
getReleaseChannel.mockResolvedValue("stable")
await initUpdateStore()
Expand All @@ -140,7 +150,10 @@ describe("UpdatesPanel status display", () => {

expect(document.body.textContent).toMatch(/devsy is up to date/i)
expect(document.body.textContent).toMatch(/version 1\.17\.0/i)
expect(document.body.textContent).toMatch(/stable channel/i)
expect(document.body.textContent).not.toMatch(/stable channel/i)
expect(
screen.getByText("Current version").nextElementSibling,
).toHaveTextContent("v1.17.0")
})

it("renders available update with both installed and available versions", async () => {
Expand Down Expand Up @@ -234,6 +247,9 @@ describe("UpdatesPanel status display", () => {
expect(document.body.textContent).toMatch(
/no releases on this channel yet/i,
)
await waitFor(() =>
expect(document.body.textContent).toMatch(/preview channel/i),
)
})

it("renders error notice for malformed-version failures and does not claim up to date", async () => {
Expand Down Expand Up @@ -262,3 +278,154 @@ describe("UpdatesPanel status display", () => {
expect(retryBtn).toBeTruthy()
})
})

describe("UpdatesPanel preferences", () => {
beforeEach(() => {
getAppVersion.mockReset()
getReleaseChannel.mockReset()
setReleaseChannel.mockReset()
setAutoDownload.mockReset()
setAutoDownload.mockResolvedValue(undefined)
autoUpdate.set(true)
localStorage.setItem("devsy-auto-update", "true")
})

afterEach(() => {
cleanup()
})

it("renders compact, named release channel choices with selection state", async () => {
await renderPanel("beta")

expect(
screen.getByRole("radiogroup", { name: "Release channel" }),
).toBeTruthy()
expect(screen.getByRole("radio", { name: "Stable" })).toHaveAttribute(
"aria-checked",
"false",
)
expect(screen.getByRole("radio", { name: "Preview" })).toHaveAttribute(
"aria-checked",
"true",
)
expect(document.body.textContent).not.toMatch(
/released on a regular schedule|updated frequently/i,
)
})

it("names and describes automatic downloading and persists a toggle", async () => {
await renderPanel("stable")

const toggle = screen.getByRole("switch", {
name: "Automatically download updates",
})
expect(toggle).toHaveAccessibleDescription(
"Restart Devsy when you're ready to install.",
)
expect(toggle).toHaveAttribute("aria-checked", "true")
expect(document.body.textContent).not.toMatch(/update behavior/i)

toggle.click()
await tick()
await Promise.resolve()

expect(toggle).toHaveAttribute("aria-checked", "false")
expect(setAutoDownload).toHaveBeenCalledWith(false)
})

it("restores the automatic download preference when persistence fails", async () => {
await renderPanel("stable")
const failure = new Error("Unable to save auto-download preference")
setAutoDownload.mockRejectedValueOnce(failure)
const warning = vi.spyOn(console, "warn").mockImplementation(() => {})
const toggle = screen.getByRole("switch", {
name: "Automatically download updates",
})

try {
toggle.click()
await tick()
await waitFor(() => {
expect(warning).toHaveBeenCalledWith(
"[settings] setAutoDownload failed; rolled back:",
failure,
)
expect(toggle).toHaveAttribute("aria-checked", "true")
})

expect(setAutoDownload).toHaveBeenCalledWith(false)
expect(get(autoUpdate)).toBe(true)
expect(localStorage.getItem("devsy-auto-update")).toBe("true")
} finally {
warning.mockRestore()
}
})

it("shows the running app version even when a different update is available", async () => {
await renderPanel("stable")
__setForTest({
state: "available",
currentVersion: "1.2.3",
availableVersion: "2.0.0",
})
await tick()

const term = screen.getByText("Current version")
expect(term.tagName).toBe("DT")
expect(term.nextElementSibling?.tagName).toBe("DD")
expect(term.nextElementSibling).toHaveTextContent("v1.2.3")
})

it("shows Unavailable when the running app version cannot be loaded", async () => {
getAppVersion.mockRejectedValue(new Error("Version unavailable"))
getReleaseChannel.mockResolvedValue("stable")
await initUpdateStore()
__setForTest({
state: "available",
currentVersion: "1.2.3",
availableVersion: "2.0.0",
})
render(UpdatesPanel)
await tick()
await Promise.resolve()
await tick()

expect(
screen.getByText("Current version").nextElementSibling,
).toHaveTextContent("Unavailable")
})

it.each([
"checking",
"available",
"idle",
"not-eligible",
"up-to-date",
"not-available",
] as const)(
"omits redundant channel metadata from the %s status",
async (state) => {
await renderPanel("stable")
if (state === "available") {
__setForTest({
state,
currentVersion: "1.2.3",
availableVersion: "2.0.0",
})
} else if (state === "not-eligible") {
__setForTest({
state: "not-available",
currentVersion: "1.2.3",
code: "not-eligible",
})
} else {
__setForTest({ state, currentVersion: "1.2.3" })
}
await tick()

const status = screen.getByRole("region", { name: "Update status" })
expect(status.textContent).not.toMatch(/stable channel|preview channel/i)
expect(status.textContent).toMatch(/1\.2\.3/)
},
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ describe("channel labels", () => {
expect(CHANNELS.map((c) => c.value)).toEqual(["stable", "beta"])
})

it("flags Preview as unstable", () => {
expect(CHANNELS.find((c) => c.value === "beta")?.unstable).toBe(true)
expect(CHANNELS.find((c) => c.value === "stable")?.unstable).toBe(false)
it("exposes the channel choices without redundant presentation copy", () => {
expect(CHANNELS).toEqual([
{ value: "stable", label: "Stable" },
{ value: "beta", label: "Preview" },
])
})
})

Expand Down
9 changes: 0 additions & 9 deletions desktop/src/renderer/src/lib/components/update/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,16 @@ import type { ReleaseChannel } from "$lib/ipc/commands.js"
export interface ChannelMeta {
value: ReleaseChannel
label: string
cadence: string
description: string
unstable: boolean
}

export const CHANNELS: ChannelMeta[] = [
{
value: "stable",
label: "Stable",
cadence: "Released on a regular schedule",
description: "Production-ready builds, tested before release.",
unstable: false,
},
{
value: "beta",
label: "Preview",
cadence: "Updated frequently",
description: "Early access to new features. May be unstable.",
unstable: true,
},
]

Expand Down
Loading
Loading