mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 14:30:41 +00:00
test: add regression tests for workspace-dependent profile creation
Add unit tests covering the workspace context requirement for profile creation: missing sessionStorage, malformed JSON, missing workspace ID, creation without avatar, and cached state update after success. Add E2E test verifying the publish intro panel renders when switching to the publish tab with comfyHubUploadEnabled. Fix pre-existing import path aliases in shareWorkflowDialog.spec.ts.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import type { Page } from '@playwright/test'
|
||||
import { expect } from '@playwright/test'
|
||||
|
||||
import type { AssetInfo } from '../../../src/schemas/apiSchema'
|
||||
import { comfyPageFixture } from '../../fixtures/ComfyPage'
|
||||
import { TestIds } from '../../fixtures/selectors'
|
||||
import type { AssetInfo } from '@/schemas/apiSchema'
|
||||
import { comfyPageFixture } from '@e2e/fixtures/ComfyPage'
|
||||
import { TestIds } from '@e2e/fixtures/selectors'
|
||||
|
||||
interface PublishRecord {
|
||||
workflow_id: string
|
||||
@@ -330,6 +330,32 @@ test.describe('Share Workflow Dialog', { tag: '@cloud' }, () => {
|
||||
await expect(publishPanel).toBeHidden()
|
||||
})
|
||||
|
||||
test('should show publish intro panel when switching to publish tab', async ({
|
||||
comfyPage
|
||||
}) => {
|
||||
const { page } = comfyPage
|
||||
const workflowName = 'share-test-publish-intro'
|
||||
|
||||
await saveAndWait(comfyPage, workflowName)
|
||||
|
||||
await page.evaluate(() => {
|
||||
const api = window.app!.api
|
||||
api.serverFeatureFlags.value = {
|
||||
...api.serverFeatureFlags.value,
|
||||
comfyhub_upload_enabled: true
|
||||
}
|
||||
})
|
||||
|
||||
await mockPublishStatus(page, null)
|
||||
await mockShareableAssets(page)
|
||||
await openShareDialog(page)
|
||||
|
||||
const dialog = getShareDialog(page)
|
||||
await dialog.getByRole('tab', { name: /publish/i }).click()
|
||||
|
||||
await expect(dialog.getByTestId('publish-intro')).toBeVisible()
|
||||
})
|
||||
|
||||
test('should require acknowledgment before publishing private assets', async ({
|
||||
comfyPage
|
||||
}) => {
|
||||
|
||||
@@ -193,5 +193,65 @@ describe('useComfyHubProfileGate', () => {
|
||||
expect(requestCallOrder[0]).toBeLessThan(uploadCallOrder[0])
|
||||
expect(uploadCallOrder[0]).toBeLessThan(createCallOrder[0])
|
||||
})
|
||||
|
||||
it('throws when workspace context is missing from sessionStorage', async () => {
|
||||
sessionStorage.removeItem('Comfy.Workspace.Current')
|
||||
|
||||
await expect(
|
||||
gate.createProfile({ username: 'testuser' })
|
||||
).rejects.toThrow('Unable to determine current workspace')
|
||||
|
||||
expect(mockCreateProfile).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('throws when workspace JSON is malformed', async () => {
|
||||
sessionStorage.setItem('Comfy.Workspace.Current', '{invalid')
|
||||
|
||||
await expect(
|
||||
gate.createProfile({ username: 'testuser' })
|
||||
).rejects.toThrow('Unable to determine current workspace')
|
||||
|
||||
expect(mockCreateProfile).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('throws when workspace object has no id', async () => {
|
||||
sessionStorage.setItem(
|
||||
'Comfy.Workspace.Current',
|
||||
JSON.stringify({ type: 'personal', name: 'My Workspace' })
|
||||
)
|
||||
|
||||
await expect(
|
||||
gate.createProfile({ username: 'testuser' })
|
||||
).rejects.toThrow('Unable to determine current workspace')
|
||||
|
||||
expect(mockCreateProfile).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('creates profile without avatar when no picture provided', async () => {
|
||||
await gate.createProfile({
|
||||
username: 'testuser',
|
||||
name: 'Test User'
|
||||
})
|
||||
|
||||
expect(mockRequestAssetUploadUrl).not.toHaveBeenCalled()
|
||||
expect(mockUploadFileToPresignedUrl).not.toHaveBeenCalled()
|
||||
expect(mockCreateProfile).toHaveBeenCalledWith({
|
||||
workspaceId: 'workspace-1',
|
||||
username: 'testuser',
|
||||
displayName: 'Test User',
|
||||
description: undefined,
|
||||
avatarToken: undefined
|
||||
})
|
||||
})
|
||||
|
||||
it('updates cached state after successful creation', async () => {
|
||||
expect(gate.hasProfile.value).toBe(null)
|
||||
expect(gate.profile.value).toBe(null)
|
||||
|
||||
await gate.createProfile({ username: 'testuser' })
|
||||
|
||||
expect(gate.hasProfile.value).toBe(true)
|
||||
expect(gate.profile.value).toEqual(mockProfile)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user