Skip to content
Merged
55 changes: 55 additions & 0 deletions e2e/home.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { test, expect } from '@playwright/test'
import { launchApp, type AppContext } from './launchApp'
import { expectChooserVisible } from './support/chooserHelpers'

const HOME_VIEW = '[data-testid="home-view"]'
const SIDEBAR_HOME = '[data-testid="app-sidebar-home"]'
const SIDEBAR_BUILDS = '[data-testid="app-sidebar-chooser"]'

let ctx: AppContext

test.describe.configure({ mode: 'serial' })

test.beforeAll(async () => {
ctx = await launchApp(
{ settings: { firstUseCompleted: true, telemetryEnabled: false } },
{ stayOnHome: true }
)
})

test.afterAll(async () => {
await ctx.cleanup()
})

function currentSidebarPage(selector: string): Promise<boolean> {
return ctx.panel.evaluate<boolean>(
`document.querySelector('${selector}')?.getAttribute('aria-current') === 'page'`
)
}

test('Desktop opens on Home with Comfy Cloud among its builds @windows @macos @linux', async () => {
await ctx.panel.waitForVisible(HOME_VIEW)
expect(await currentSidebarPage(SIDEBAR_HOME)).toBe(true)
expect(await ctx.panel.isVisible('.chooser-view')).toBe(false)

await ctx.panel.waitForVisible('[data-testid="home-build"]')
const builds = await ctx.panel.allText('[data-testid="home-build"]')
expect(builds.some((text) => text.includes('Comfy Cloud') && text.includes('RTX 6000 Pro'))).toBe(
true
)
})

test('All builds on Home goes to the Builds page @windows @macos @linux', async () => {
expect(await ctx.panel.click('[data-testid="home-all-builds"]')).toBe(true)

await expectChooserVisible(ctx.panel)
expect(await currentSidebarPage(SIDEBAR_BUILDS)).toBe(true)
expect(await ctx.panel.exists(HOME_VIEW)).toBe(false)
})

test('Home in the sidebar returns to Home @windows @macos @linux', async () => {
expect(await ctx.panel.click(SIDEBAR_HOME)).toBe(true)

await ctx.panel.waitForVisible(HOME_VIEW)
expect(await ctx.panel.isVisible('.chooser-view')).toBe(false)
})
16 changes: 15 additions & 1 deletion e2e/launchApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type WebContentsPage
} from './support/cdpPages'
import { evalWithRetry } from './support/evalRetry'
import { showBuildsPage } from './support/chooserHelpers'

async function waitForChooserWebContents(
app: ElectronApplication,
Expand Down Expand Up @@ -39,7 +40,16 @@ export interface AppContext {
cleanup: () => Promise<void>
}

export async function launchApp(options?: SeedOptions): Promise<AppContext> {
export interface LaunchOptions {
stayOnHome?: boolean
}

const HOME_VIEW = '[data-testid="home-view"]'

export async function launchApp(
options?: SeedOptions,
launchOptions: LaunchOptions = {}
): Promise<AppContext> {
const { application, homeDir, cleanup: cleanupHarness } = await launchLauncherApp(options)

await waitForChooserWebContents(application)
Expand All @@ -54,6 +64,10 @@ export async function launchApp(options?: SeedOptions): Promise<AppContext> {
await panel.waitForSelector('.chooser-view, .panel-chooser, .start-hero', { timeout: 15_000 })
await titleBar.waitForSelector('.title-bar', { timeout: 15_000 })

if (!launchOptions.stayOnHome && (await panel.isVisible(HOME_VIEW))) {
await showBuildsPage(panel)
}

return {
app: application,
panel,
Expand Down
2 changes: 1 addition & 1 deletion e2e/lifecycle-first-use-skip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test('ToS + Local + Continue surfaces the waffle menu; Skip Onboarding reveals t
await popup.waitForVisible('li.item', { timeout: 10_000 })
expect(await popup.clickByText('li.item', 'Skip Onboarding')).toBe(true)

await ctx.panel.waitForVisible('.chooser-view', { timeout: 10_000 })
await ctx.panel.waitForVisible('[data-testid="home-view"]', { timeout: 10_000 })

await expect
.poll(
Expand Down
12 changes: 12 additions & 0 deletions e2e/support/chooserHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@ import {
} from './cdpPages'
import { byTestId, TID } from './testIds'

const HOME_VIEW = '[data-testid="home-view"]'
const SIDEBAR_BUILDS = '[data-testid="app-sidebar-chooser"]'

export async function showBuildsPage(panel: WebContentsPage): Promise<void> {
expect(await panel.click(SIDEBAR_BUILDS), 'Builds picked in the sidebar').toBe(true)
await panel.waitForVisible('.chooser-view')
}

export async function expectChooserVisible(panel: WebContentsPage): Promise<void> {
await panel.waitFor(
async () => (await panel.isVisible('.chooser-view')) || (await panel.isVisible(HOME_VIEW))
)
if (await panel.isVisible(HOME_VIEW)) await showBuildsPage(panel)
await panel.waitForVisible('.chooser-view')
}

Expand Down
16 changes: 16 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@
"signInTitle": "Log in to Comfy",
"signInBody": "Sync your work and run it on Comfy Cloud."
},
"home": {
"title": "Welcome. Let's create!",
"openComfyUI": "Open ComfyUI",
"allBuilds": "All builds",
"buildRunning": "Running",
"buildStarting": "Starting",
"buildReady": "Ready",
"buildAlwaysOn": "Always on",
"cloudHardware": "RTX 6000 Pro · 96 GB",
"exampleWorkflows": "Example workflows",
"seeAllWorkflows": "See all workflows",
"showWorkflow": "Show {title}",
"openWorkflow": "Open {title} on Comfy Hub",
"workflowsUnavailable": "Example workflows couldn't be loaded. Check your connection and try again.",
"retry": "Try again"
},
"installType": {
"standalone": "Standalone",
"cloud": "Cloud",
Expand Down
16 changes: 16 additions & 0 deletions locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@
"signInTitle": "登录 Comfy",
"signInBody": "同步你的作品,并在 Comfy Cloud 上运行。"
},
"home": {
"title": "欢迎。开始创作吧!",
"openComfyUI": "打开 ComfyUI",
"allBuilds": "全部构建",
"buildRunning": "运行中",
"buildStarting": "启动中",
"buildReady": "就绪",
"buildAlwaysOn": "始终在线",
"cloudHardware": "RTX 6000 Pro · 96 GB",
"exampleWorkflows": "示例工作流",
"seeAllWorkflows": "查看全部工作流",
"showWorkflow": "显示 {title}",
"openWorkflow": "在 Comfy Hub 打开 {title}",
"workflowsUnavailable": "无法加载示例工作流。请检查网络连接后重试。",
"retry": "重试"
},
"installType": {
"standalone": "独立版",
"cloud": "云端",
Expand Down
210 changes: 210 additions & 0 deletions src/main/catalog/workflows.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'

vi.mock('../lib/fetch', () => ({ fetchJSON: vi.fn() }))

import { fetchJSON } from '../lib/fetch'
import {
HOME_WORKFLOW_LIMIT,
_resetCatalogWorkflowsForTest,
hubUrlForListedWorkflow,
listHomeWorkflows
} from './workflows'

const mockedFetchJSON = vi.mocked(fetchJSON)

function catalogItem(over: {
uid?: string
slug?: unknown
data?: Record<string, unknown>
}): Record<string, unknown> {
const uid = over.uid ?? 'upscale-uid'
return {
uid,
slug: 'slug' in over ? over.slug : `/hub/workflows/${uid}`,
data: {
title: 'Upscale and restore detail',
description: 'Enlarge an image and restore fine detail.',
website_media: { '$.static_thumb': `/catalog-media/${uid}/v1` },
website_media_types: { '$.static_thumb': 'image/webp' },
translations: {
'zh-CN': { title: '放大图像并修复细节', description: '放大图像并修复精细细节。' }
},
...over.data
}
}
}

function serveCatalog(pages: { desktop: unknown[]; everything: unknown[] }): void {
mockedFetchJSON.mockImplementation(async (url) => {
const surface = new URL(url).searchParams.get('surface')
return { items: surface === 'desktop_starters' ? pages.desktop : pages.everything }
})
}

beforeEach(() => {
vi.clearAllMocks()
_resetCatalogWorkflowsForTest()
})

describe('Home example workflows from the Comfy content catalog', () => {
it('shows the workflows the catalog marks for Desktop', async () => {
serveCatalog({
desktop: [catalogItem({ uid: 'picked-for-desktop' })],
everything: [catalogItem({ uid: 'hub-only' })]
})

expect(await listHomeWorkflows('en')).toEqual([
{
id: 'picked-for-desktop',
title: 'Upscale and restore detail',
description: 'Enlarge an image and restore fine detail.',
thumbnailUrl: 'https://comfy.org/catalog-media/picked-for-desktop/v1'
}
])
})

it("falls back to the catalog's own order while no workflow is marked for Desktop", async () => {
serveCatalog({
desktop: [],
everything: [catalogItem({ uid: 'first' }), catalogItem({ uid: 'second' })]
})

const workflows = await listHomeWorkflows('en')

expect(workflows.map((workflow) => workflow.id)).toEqual(['first', 'second'])
})

it('never shows more cards than the Home row holds', async () => {
serveCatalog({
desktop: Array.from({ length: HOME_WORKFLOW_LIMIT + 5 }, (_, index) =>
catalogItem({ uid: `workflow-${index}` })
),
everything: []
})

expect(await listHomeWorkflows('en')).toHaveLength(HOME_WORKFLOW_LIMIT)
})

it('shows the title and description in the app language when the catalog has them', async () => {
serveCatalog({ desktop: [catalogItem({})], everything: [] })

const [workflow] = await listHomeWorkflows('zh')

expect(workflow).toMatchObject({
title: '放大图像并修复细节',
description: '放大图像并修复精细细节。'
})
})

it('leaves out records that have no title or no Comfy Hub page to open', async () => {
serveCatalog({
desktop: [
catalogItem({ uid: 'untitled', data: { title: ' ' } }),
catalogItem({ uid: 'elsewhere', slug: 'https://example.com/hub/workflows/elsewhere' }),
catalogItem({ uid: 'not-a-workflow-page', slug: '/hub/apps/not-a-workflow-page' }),
catalogItem({ uid: 'missing-slug', slug: undefined }),
'not-a-record',
catalogItem({ uid: 'good' })
],
everything: []
})

const workflows = await listHomeWorkflows('en')

expect(workflows.map((workflow) => workflow.id)).toEqual(['good'])
})

it('shows a card without a picture when the catalog only has a video or an off-site image', async () => {
serveCatalog({
desktop: [
catalogItem({
uid: 'video-only',
data: {
website_media: { '$.thumbnail': '/catalog-media/video-only/v1' },
website_media_types: { '$.thumbnail': 'video/mp4' }
}
}),
catalogItem({
uid: 'off-site',
data: {
website_media: { '$.static_thumb': 'https://example.com/tracker.png' },
website_media_types: { '$.static_thumb': 'image/png' }
}
})
],
everything: []
})

const workflows = await listHomeWorkflows('en')

expect(workflows.map((workflow) => workflow.thumbnailUrl)).toEqual([null, null])
})

it('keeps showing the last list when the catalog stops answering', async () => {
vi.useFakeTimers()
try {
serveCatalog({ desktop: [catalogItem({ uid: 'loaded-earlier' })], everything: [] })
await listHomeWorkflows('en')

vi.advanceTimersByTime(60 * 60 * 1000)
mockedFetchJSON.mockRejectedValue(new Error('offline'))

const workflows = await listHomeWorkflows('en')

expect(workflows.map((workflow) => workflow.id)).toEqual(['loaded-earlier'])
} finally {
vi.useRealTimers()
}
})

it('reports a failure when the catalog has never answered', async () => {
mockedFetchJSON.mockRejectedValue(new Error('offline'))

await expect(listHomeWorkflows('en')).rejects.toThrow('offline')
})

it('reports a failure when the catalog answers with something that is not a list', async () => {
mockedFetchJSON.mockResolvedValue({ code: 'invalid', message: 'invalid catalog query' })

await expect(listHomeWorkflows('en')).rejects.toThrow()
})

it('asks the catalog once while several pages wait for the same list', async () => {
serveCatalog({ desktop: [catalogItem({})], everything: [] })

await Promise.all([listHomeWorkflows('en'), listHomeWorkflows('en'), listHomeWorkflows('en')])
await listHomeWorkflows('en')

expect(mockedFetchJSON).toHaveBeenCalledTimes(1)
})
})

describe('opening an example workflow', () => {
it('opens the Comfy Hub page of a workflow that Home is showing', async () => {
serveCatalog({ desktop: [catalogItem({ uid: 'shown' })], everything: [] })
await listHomeWorkflows('en')

expect(hubUrlForListedWorkflow('shown')).toBe('https://comfy.org/hub/workflows/shown')
})

it('drops query strings and fragments the catalog put on a Hub page address', async () => {
serveCatalog({
desktop: [catalogItem({ uid: 'tagged', slug: '/hub/workflows/tagged?next=evil#frag' })],
everything: []
})
await listHomeWorkflows('en')

expect(hubUrlForListedWorkflow('tagged')).toBe('https://comfy.org/hub/workflows/tagged')
})

it('opens nothing for an id Home is not showing', async () => {
serveCatalog({ desktop: [catalogItem({ uid: 'shown' })], everything: [] })
await listHomeWorkflows('en')

expect(hubUrlForListedWorkflow('https://example.com')).toBeNull()
})

it('opens nothing before Home has loaded the list', () => {
expect(hubUrlForListedWorkflow('shown')).toBeNull()
})
})
Loading
Loading