Skip to content
149 changes: 55 additions & 94 deletions e2e/update-pills.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { test, expect, type ElectronApplication } from '@playwright/test'
import { test, expect } from '@playwright/test'
import { launchApp, type AppContext } from './launchApp'
import { findWebContentsId } from './support/cdpPages'
import { evalWithRetry } from './support/evalRetry'
import { setAppUpdateState, setInstallUpdate, type AppUpdateStateLike } from './support/devHooks'
import { byTestId, TID } from './support/testIds'

let ctx: AppContext

Expand All @@ -17,115 +16,77 @@ test.afterAll(async () => {
})

test.beforeEach(async () => {
await closeSystemModalIfOpen(ctx.app)
await closePanelModalIfOpen()
await setAppUpdateState(ctx.app, IDLE_APP_UPDATE)
await setInstallUpdate(ctx.app, { available: false })
})

const IDLE_APP_UPDATE: AppUpdateStateLike = { kind: null, version: null, autoUpdate: true }
const SIDEBAR_UPDATE = '[data-testid="app-sidebar-desktop-update"]'

test('desktop-update pill is hidden when state is idle @windows @macos @linux', async () => {
expect(await ctx.titleBar.exists('.title-update-pill.is-app-update')).toBe(false)
function sidebarUpdateIn(kind: NonNullable<AppUpdateStateLike['kind']>): string {
return `${SIDEBAR_UPDATE}[data-state="${kind}"]`
}

async function expectSidebarUpdate(kind: NonNullable<AppUpdateStateLike['kind']>): Promise<void> {
await ctx.panel.waitForVisible(sidebarUpdateIn(kind), { timeout: 5_000 })
}

async function closePanelModalIfOpen(): Promise<void> {
if (!(await ctx.panel.isVisible(byTestId(TID.modalCancel)))) return
expect(await ctx.panel.click(byTestId(TID.modalCancel))).toBe(true)
await ctx.panel.waitFor(async () => !(await ctx.panel.isVisible(byTestId(TID.modalConfirm))), {
timeout: 3_000,
message: 'panel confirm modal did not close'
})
}

test('desktop update is hidden in the sidebar and the title bar when state is idle @windows @macos @linux', async () => {
await ctx.panel.waitFor(async () => !(await ctx.panel.exists(SIDEBAR_UPDATE)), {
timeout: 5_000,
message: 'sidebar desktop update stayed visible while idle'
})
expect(await ctx.titleBar.exists('.title-update-pill')).toBe(false)
})

test('desktop-update pill renders for state=available @windows @macos @linux', async () => {
test('desktop update shows in the sidebar for state=available @windows @macos @linux', async () => {
await setAppUpdateState(ctx.app, { kind: 'available', version: '1.2.3', autoUpdate: false })
await expect
.poll(() => ctx.titleBar.exists('.title-update-pill.is-app-update'), {
timeout: 5_000,
intervals: [100, 200]
})
.toBe(true)
const label = await ctx.titleBar.textOf(
'.title-update-pill.is-app-update .title-update-pill-label'
)
expect(label?.toLowerCase()).toContain('update')
expect(await ctx.titleBar.exists('.title-update-pill.is-app-update.is-ready')).toBe(false)
expect(await ctx.titleBar.exists('.title-update-pill.is-app-update.is-downloading')).toBe(false)
await expectSidebarUpdate('available')
expect(await ctx.titleBar.exists('.title-update-pill')).toBe(false)
})

test('desktop-update pill renders for state=downloading @windows @macos @linux', async () => {
test('desktop update shows in the sidebar for state=downloading @windows @macos @linux', async () => {
await setAppUpdateState(ctx.app, { kind: 'downloading', version: '1.2.3', autoUpdate: true })
await expect
.poll(() => ctx.titleBar.exists('.title-update-pill.is-app-update.is-downloading'), {
timeout: 5_000,
intervals: [100, 200]
})
.toBe(true)
await expectSidebarUpdate('downloading')
})

test('desktop-update pill renders for state=ready @windows @macos @linux', async () => {
test('desktop update shows in the sidebar for state=ready @windows @macos @linux', async () => {
await setAppUpdateState(ctx.app, { kind: 'ready', version: '1.2.3', autoUpdate: true })
await expect
.poll(() => ctx.titleBar.exists('.title-update-pill.is-app-update.is-ready'), {
timeout: 5_000,
intervals: [100, 200]
})
.toBe(true)
await expectSidebarUpdate('ready')
})

test('clicking the ready desktop-update pill opens the embedded system-modal restart prompt @windows @macos @linux', async () => {
await setAppUpdateState(ctx.app, { kind: 'ready', version: '1.2.3', autoUpdate: true })
await expect
.poll(() => ctx.titleBar.exists('.title-update-pill.is-app-update.is-ready'), {
timeout: 5_000,
intervals: [100, 200]
})
.toBe(true)

const ok = await ctx.titleBar.click('.title-update-pill.is-app-update')
expect(ok, 'desktop-update pill click dispatched').toBe(true)

await expect
.poll(() => isSystemModalVisible(ctx.app), {
timeout: 5_000,
intervals: [100, 200]
})
.toBe(true)
test('clicking the available sidebar desktop update asks to download in the panel @windows @macos @linux', async () => {
await setAppUpdateState(ctx.app, { kind: 'available', version: '1.2.3', autoUpdate: false })
await expectSidebarUpdate('available')

expect(await ctx.panel.click(SIDEBAR_UPDATE), 'sidebar desktop update click dispatched').toBe(
true
)

await ctx.panel.waitForVisible(byTestId(TID.modalConfirm), { timeout: 5_000 })
expect(await ctx.panel.textOf(byTestId(TID.modalConfirm))).toContain('Download')
await closePanelModalIfOpen()
})

async function isSystemModalVisible(app: ElectronApplication): Promise<boolean> {
try {
return await evalWithRetry(() =>
app.evaluate(({ BrowserWindow, WebContentsView }) => {
for (const win of BrowserWindow.getAllWindows()) {
for (const child of win.contentView.children) {
if (!(child instanceof WebContentsView)) continue
if (!child.webContents.getURL().includes('comfySystemModal.html')) continue
if (!child.getVisible()) return false
const b = child.getBounds()
return b.width > 0 && b.height > 0
}
}
return false
})
)
} catch {
return false
}
}
test('clicking the ready sidebar desktop update asks to restart in the panel @windows @macos @linux', async () => {
await setAppUpdateState(ctx.app, { kind: 'ready', version: '1.2.3', autoUpdate: true })
await expectSidebarUpdate('ready')

async function closeSystemModalIfOpen(app: ElectronApplication): Promise<void> {
const id = await findWebContentsId(app, 'comfySystemModal.html')
if (id === null) return
if (!(await isSystemModalVisible(app))) return
await evalWithRetry(() =>
app.evaluate(({ webContents }) => {
const wc = webContents
.getAllWebContents()
.find((w) => w.getURL().includes('comfySystemModal.html'))
if (!wc) return
return wc
.executeJavaScript(
`(() => {
const ev = new KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true })
document.dispatchEvent(ev)
})()`
)
.catch(() => {})
})
expect(await ctx.panel.click(SIDEBAR_UPDATE), 'sidebar desktop update click dispatched').toBe(
true
)
await expect
.poll(() => isSystemModalVisible(app), { timeout: 3_000, intervals: [100, 200] })
.toBe(false)
}

await ctx.panel.waitForVisible(byTestId(TID.modalConfirm), { timeout: 5_000 })
expect(await ctx.panel.textOf(byTestId(TID.modalConfirm))).toContain('Restart & Update')
await closePanelModalIfOpen()
})
170 changes: 3 additions & 167 deletions src/renderer/src/comfyTitleBar/TitleBarApp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,86 +628,12 @@ describe('TitleBarApp', () => {
expect(bridgeState.refreshInstanceClicks).toBe(1)
})

it('hides both status pills by default (no update available, no install update)', async () => {
it('leaves the Desktop update to the sidebar and shows no update pill in the title bar', async () => {
const { default: TitleBarApp } = await import('./TitleBarApp.vue')
const wrapper = mount(TitleBarApp)
await flushPromises()
expect(wrapper.find('.title-update-pill.is-app-update').exists()).toBe(false)
expect(wrapper.find('.title-update-pill.is-install-update').exists()).toBe(false)
})

it('renders the app-update pill with "Desktop Update" copy when state.kind=available (auto-updates OFF)', async () => {
const { default: TitleBarApp } = await import('./TitleBarApp.vue')
const wrapper = mount(TitleBarApp)
await flushPromises()
bridgeState.appUpdateStateCallbacks.forEach((cb) =>
cb({ kind: 'available', version: '2.3.4', autoUpdate: false })
)
await flushPromises()
const pill = wrapper.find('.title-update-pill.is-app-update')
expect(pill.exists()).toBe(true)
expect(pill.classes()).not.toContain('is-ready')
expect(pill.text()).toContain('Desktop Update')
expect(pill.attributes('title')).toBe('Desktop Update (v2.3.4)')
expect(pill.attributes('aria-label')).toBe('Desktop Update (v2.3.4)')
})

it('renders the app-update pill with "Desktop Update Ready" copy when state.kind=ready (auto-updates OFF)', async () => {
const { default: TitleBarApp } = await import('./TitleBarApp.vue')
const wrapper = mount(TitleBarApp)
await flushPromises()
bridgeState.appUpdateStateCallbacks.forEach((cb) =>
cb({ kind: 'ready', version: '2.3.4', autoUpdate: false })
)
await flushPromises()
const pill = wrapper.find('.title-update-pill.is-app-update')
expect(pill.exists()).toBe(true)
expect(pill.classes()).toContain('is-ready')
expect(pill.text()).toContain('Desktop Update Ready')
expect(pill.attributes('title')).toBe('Desktop Update Ready (v2.3.4)')
})

it('renders the app-update pill with "Desktop Update Ready" copy when state.kind=ready (auto-updates ON)', async () => {
const { default: TitleBarApp } = await import('./TitleBarApp.vue')
const wrapper = mount(TitleBarApp)
await flushPromises()
bridgeState.appUpdateStateCallbacks.forEach((cb) =>
cb({ kind: 'ready', version: '2.3.4', autoUpdate: true })
)
await flushPromises()
const pill = wrapper.find('.title-update-pill.is-app-update')
expect(pill.exists()).toBe(true)
expect(pill.classes()).toContain('is-ready')
expect(pill.text()).toContain('Desktop Update Ready')
})

it('forwards app-update pill clicks through the bridge', async () => {
const { default: TitleBarApp } = await import('./TitleBarApp.vue')
const wrapper = mount(TitleBarApp, { attachTo: document.body })
await flushPromises()
bridgeState.appUpdateStateCallbacks.forEach((cb) =>
cb({ kind: 'available', version: '1.0.0', autoUpdate: false })
)
await flushPromises()
await wrapper.find('.title-update-pill.is-app-update').trigger('click')
expect(bridgeState.appUpdatePillClicks).toBe(1)
wrapper.unmount()
})

it('hides the app-update pill when state transitions back to kind=null', async () => {
const { default: TitleBarApp } = await import('./TitleBarApp.vue')
const wrapper = mount(TitleBarApp)
await flushPromises()
bridgeState.appUpdateStateCallbacks.forEach((cb) =>
cb({ kind: 'ready', version: '2.0.0', autoUpdate: false })
)
await flushPromises()
expect(wrapper.find('.title-update-pill.is-app-update').exists()).toBe(true)
bridgeState.appUpdateStateCallbacks.forEach((cb) =>
cb({ kind: null, version: null, autoUpdate: true })
)
await flushPromises()
expect(wrapper.find('.title-update-pill.is-app-update').exists()).toBe(false)
expect(bridgeState.appUpdateStateCallbacks).toHaveLength(0)
expect(wrapper.find('.title-update-pill').exists()).toBe(false)
})

it('renders the downloads tray with no badge in the empty steady state', async () => {
Expand Down Expand Up @@ -1077,96 +1003,6 @@ describe('TitleBarApp', () => {
}
})

describe('fitting the right side next to Home', () => {
const rect = (left: number, width: number): DOMRect =>
({
left,
right: left + width,
width,
top: 0,
bottom: 32,
height: 32,
x: left,
y: 0
}) as DOMRect

let resizeCallbacks: ResizeObserverCallback[] = []

beforeEach(() => {
resizeCallbacks = []
vi.stubGlobal(
'ResizeObserver',
class {
constructor(cb: ResizeObserverCallback) {
resizeCallbacks.push(cb)
}
observe(): void {}
unobserve(): void {}
disconnect(): void {}
}
)
})

afterEach(() => {
vi.unstubAllGlobals()
vi.restoreAllMocks()
})

async function mountWithTrailingAt(trailingLeft: number) {
vi.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(function (
this: Element
) {
if (this.matches('header')) return rect(0, 800)
if (this.closest('.title-trailing')) return rect(trailingLeft, 788 - trailingLeft)
return rect(12, 88)
})
const { default: TitleBarApp } = await import('./TitleBarApp.vue')
const wrapper = mount(TitleBarApp, { attachTo: document.body })
const header = wrapper.find('header').element as HTMLElement
header.style.columnGap = '12px'
await flushPromises()
resizeCallbacks.forEach((cb) => cb([], {} as ResizeObserver))
await new Promise((resolve) => requestAnimationFrame(resolve))
await flushPromises()
return wrapper
}

it('collapses once only the two grid gutters are left between Home and the right side', async () => {
const wrapper = await mountWithTrailingAt(124)
expect(wrapper.find('header').classes()).toContain('is-collapsed-feedback')
wrapper.unmount()
})

it('stays expanded while the empty middle still has room', async () => {
const wrapper = await mountWithTrailingAt(200)
expect(wrapper.find('header').classes()).not.toContain('is-collapsed-feedback')
wrapper.unmount()
})
})

describe('without ResizeObserver', () => {
let originalResizeObserver: typeof globalThis.ResizeObserver | undefined

beforeEach(() => {
originalResizeObserver = (globalThis as { ResizeObserver?: typeof globalThis.ResizeObserver })
.ResizeObserver
delete (globalThis as { ResizeObserver?: typeof globalThis.ResizeObserver }).ResizeObserver
})

afterEach(() => {
;(globalThis as { ResizeObserver?: typeof globalThis.ResizeObserver }).ResizeObserver =
originalResizeObserver
})

it('still mounts and renders the title bar', async () => {
const mod = await import('./TitleBarApp.vue')
const wrapper = mount(mod.default, { attachTo: document.body })
await flushPromises()
expect(wrapper.find('.title-trailing').exists()).toBe(true)
wrapper.unmount()
})
})

describe('core beta activation notice', () => {
let getPendingBetaNotice: ReturnType<typeof vi.fn>
let acknowledgeBetaNotice: ReturnType<typeof vi.fn>
Expand Down
Loading
Loading