mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-24 22:58:08 +00:00
## Summary
Centralize template route mocking by mirroring the existing
`AssetHelper` fixture pattern, so tests no longer hand-roll
`page.route('**/templates/index.json', ...)` and
`page.route('**/templates/**.webp', ...)` blocks.
## Changes
- **What**:
- Expand `browser_tests/fixtures/data/templateFixtures.ts` with stable
distribution exports (`STABLE_CLOUD_TEMPLATE`,
`STABLE_DESKTOP_TEMPLATE`, `STABLE_LOCAL_TEMPLATE`,
`STABLE_UNRESTRICTED_TEMPLATE`), an `ALL_DISTRIBUTION_TEMPLATES` set,
and a `generateTemplates(count, distribution?)` bulk generator.
`makeTemplate` and `mockTemplateIndex` are preserved.
- Add `browser_tests/fixtures/helpers/TemplateHelper.ts` modeled on
`AssetHelper`: an immutable `TemplateConfig` driven by composable
operators (`withTemplates`, `withTemplate`, `withCloudTemplates`,
`withDesktopTemplates`, `withLocalTemplates`,
`withUnrestrictedTemplates`, `withRawIndex`), a `TemplateHelper` class
with `mock()` / `mockIndex()` / `mockThumbnails()` / `clearMocks()`, and
a `createTemplateHelper(page, ...operators)` factory.
- Add `browser_tests/fixtures/templateApiFixture.ts` exposing
`templateApi: TemplateHelper` as a Playwright fixture with automatic
`clearMocks()` teardown (mirrors `assetApiFixture`).
- Migrate `browser_tests/tests/templateFilteringCount.spec.ts` to
`mergeTests(comfyPageFixture, templateApiFixture)` and
`templateApi.configure(withTemplates(...))` + `templateApi.mockIndex()`.
The webp thumbnail mock moves into the helper.
- **Breaking**: None. `makeTemplate` and `mockTemplateIndex` exports
remain.
## Review Focus
- `TemplateHelper.mock()` is split into `mockIndex()` and
`mockThumbnails()` so the spec can install the thumbnail handler in
`beforeEach` (where it has no per-test data) and the index handler
per-test (after `configure(...)`). Both still register through
`routeHandlers` so `clearMocks()` unroutes everything.
- Operators are pure (`(config) => config`) and the helper deep-copies
the resulting `templates` array, matching the AssetHelper immutability
pattern.
- The thumbnail route is `**/templates/**.webp` and serves
`browser_tests/assets/example.webp` — identical to the previous inline
behavior.
Fixes #11431
┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-11837-refactor-browser-tests-centralize-template-mocking-via-TemplateHelper-3546d73d365081beac00d80c2ab5ea1c)
by [Unito](https://www.unito.io)
64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
import type {
|
|
TemplateInfo,
|
|
WorkflowTemplates
|
|
} from '@/platform/workflow/templates/types/template'
|
|
import { TemplateIncludeOnDistributionEnum } from '@/platform/workflow/templates/types/template'
|
|
|
|
const Cloud = TemplateIncludeOnDistributionEnum.Cloud
|
|
const Desktop = TemplateIncludeOnDistributionEnum.Desktop
|
|
const Local = TemplateIncludeOnDistributionEnum.Local
|
|
|
|
export function makeTemplate(
|
|
overrides: Partial<TemplateInfo> & Pick<TemplateInfo, 'name'>
|
|
): TemplateInfo {
|
|
return {
|
|
description: overrides.name,
|
|
mediaType: 'image',
|
|
mediaSubtype: 'webp',
|
|
...overrides
|
|
}
|
|
}
|
|
|
|
export function mockTemplateIndex(
|
|
templates: TemplateInfo[]
|
|
): WorkflowTemplates[] {
|
|
return [
|
|
{
|
|
moduleName: 'default',
|
|
title: 'Test Templates',
|
|
type: 'image',
|
|
templates
|
|
}
|
|
]
|
|
}
|
|
|
|
export const STABLE_CLOUD_TEMPLATE: TemplateInfo = makeTemplate({
|
|
name: 'cloud-stable',
|
|
title: 'Cloud Stable',
|
|
includeOnDistributions: [Cloud]
|
|
})
|
|
|
|
export const STABLE_DESKTOP_TEMPLATE: TemplateInfo = makeTemplate({
|
|
name: 'desktop-stable',
|
|
title: 'Desktop Stable',
|
|
includeOnDistributions: [Desktop]
|
|
})
|
|
|
|
export const STABLE_LOCAL_TEMPLATE: TemplateInfo = makeTemplate({
|
|
name: 'local-stable',
|
|
title: 'Local Stable',
|
|
includeOnDistributions: [Local]
|
|
})
|
|
|
|
export const STABLE_UNRESTRICTED_TEMPLATE: TemplateInfo = makeTemplate({
|
|
name: 'unrestricted-stable',
|
|
title: 'Unrestricted Stable'
|
|
})
|
|
|
|
export const ALL_DISTRIBUTION_TEMPLATES: TemplateInfo[] = [
|
|
STABLE_CLOUD_TEMPLATE,
|
|
STABLE_DESKTOP_TEMPLATE,
|
|
STABLE_LOCAL_TEMPLATE,
|
|
STABLE_UNRESTRICTED_TEMPLATE
|
|
]
|