diff --git a/apps/website/e2e/hub-navigation.spec.ts b/apps/website/e2e/hub-navigation.spec.ts index d0244787bc1..4777021ac92 100644 --- a/apps/website/e2e/hub-navigation.spec.ts +++ b/apps/website/e2e/hub-navigation.spec.ts @@ -31,7 +31,7 @@ for (const { from, to, copy, reducedMotion } of [ { from: 'apps', to: 'models', - copy: 'Try the latest AI models', + copy: 'Try models here, call them through the API', reducedMotion: 'no-preference' }, { diff --git a/apps/website/e2e/workshop-api-actions.spec.ts b/apps/website/e2e/workshop-api-actions.spec.ts index dc430af5b0a..bc0c4a1a992 100644 --- a/apps/website/e2e/workshop-api-actions.spec.ts +++ b/apps/website/e2e/workshop-api-actions.spec.ts @@ -34,8 +34,20 @@ async function allowWorkflows(context: BrowserContext) { test('the model API tab opens with the key action and what it needs beside the code', async ({ page }) => { - await page.goto(MODEL_PATH) - await page.getByTestId('tab-api').click() + await page.goto('/hub/models/') + await page + .getByRole('searchbox', { + name: 'Search models, providers, and categories' + }) + .fill('Flux 2 Max') + await page + .getByTestId('workshop-models-grid') + .locator(`a[href="${MODEL_PATH}#api"]`) + .click() + await expect(page.getByTestId('tab-api')).toHaveAttribute( + 'aria-selected', + 'true' + ) const facts = page.getByTestId('api-facts') await expect(facts).toContainText('POST /v2/models/bfl/flux-2-max') diff --git a/apps/website/e2e/workshop-workflows.spec.ts b/apps/website/e2e/workshop-workflows.spec.ts index e99e42fd8f0..ea4098e3e97 100644 --- a/apps/website/e2e/workshop-workflows.spec.ts +++ b/apps/website/e2e/workshop-workflows.spec.ts @@ -682,7 +682,9 @@ test('a workflow card spends the tag line on its name', async ({ // The heading above the row already names the kind, so the card does not // repeat it under a name that needed the room. - await expect(cards.getByTestId('model-card-task')).toHaveCount(0) + await expect(cards.locator('..').getByTestId('model-card-task')).toHaveCount( + 0 + ) // Searching takes the headings away, and with them the only other place the // kind is written, so there every card carries its tag again. @@ -690,7 +692,9 @@ test('a workflow card spends the tag line on its name', async ({ await expect(cards.first()).toBeVisible() const found = await cards.count() expect(found).toBeGreaterThan(0) - await expect(cards.getByTestId('model-card-task')).toHaveCount(found) + await expect(cards.locator('..').getByTestId('model-card-task')).toHaveCount( + found + ) }) test('every workflow card carries its whole name, not a shortened one', async ({ diff --git a/apps/website/e2e/workshop.spec.ts b/apps/website/e2e/workshop.spec.ts index 1c5079d501d..34298374bf3 100644 --- a/apps/website/e2e/workshop.spec.ts +++ b/apps/website/e2e/workshop.spec.ts @@ -561,8 +561,8 @@ test.describe('Models catalog', () => { .getByTestId('workshop-models-grid') .getByTestId('workshop-model-card') await expect(cards.first()).toBeVisible() - for (const card of await cards.all()) - await expect(card.getByTestId('tag-row')).toContainText(/premium/i) + await cards.and(page.locator(`a[href="${MODEL_PATH}"]`)).click() + await expect(page.getByTestId('model-tags')).toContainText(/premium/i) }) test('the hero medium deep-links into the catalog', async ({ page }) => { @@ -599,7 +599,7 @@ test.describe('Models catalog', () => { const card = row.getByTestId('workshop-model-card').first() await expect(card).toBeVisible() await card.hover() - const cardBox = await card.boundingBox() + const cardBox = await card.locator('..').boundingBox() const arrowBox = await row.getByTestId('card-row-next').boundingBox() if (!cardBox || !arrowBox) throw new Error('the row did not lay out') const middleOf = (box: { y: number; height: number }) => diff --git a/apps/website/src/components/hub/HubBrowse.test.ts b/apps/website/src/components/hub/HubBrowse.test.ts index 9a895656ad9..66bd99ecaf5 100644 --- a/apps/website/src/components/hub/HubBrowse.test.ts +++ b/apps/website/src/components/hub/HubBrowse.test.ts @@ -1,5 +1,5 @@ import userEvent from '@testing-library/user-event' -import { render, screen } from '@testing-library/vue' +import { render, screen, within } from '@testing-library/vue' import { afterEach, describe, expect, it } from 'vitest' import { useHubStore } from '@/composables/useHubStore' @@ -53,7 +53,16 @@ describe('HubBrowse', () => { await user.type(screen.getByTestId('workshop-search'), 'upscale') const cards = screen.getAllByTestId('workshop-model-card') expect(cards.length).toBeGreaterThan(0) - cards.forEach((card) => expect(card.textContent).toMatch(/Upscale/i)) + expect( + cards.map((card) => { + const model = workshopModels.find( + (candidate) => candidate.href === card.getAttribute('href') + ) + return /upscale/i.test( + [model?.name, ...(model?.capabilities ?? [])].join(' ') + ) + }) + ).not.toContain(false) }) it('does not show a duplicate search results panel', async () => { @@ -104,7 +113,9 @@ describe('HubBrowse', () => { ) ).map((family) => family.latest.href) expect(audioModelHrefs.length).toBeGreaterThan(0) - expect(audioModelHrefs).toContain(lead[0].getAttribute('href')) + expect(audioModelHrefs).toContain( + within(lead[0]).getByTestId('workshop-model-card').getAttribute('href') + ) expect(screen.getByTestId('hub-showing').textContent).toMatch( /of [1-9]\d*\b/ ) diff --git a/apps/website/src/components/workshop/FeaturedBanner.analytics.test.ts b/apps/website/src/components/workshop/FeaturedBanner.analytics.test.ts index 345a7c5dc51..51872f62163 100644 --- a/apps/website/src/components/workshop/FeaturedBanner.analytics.test.ts +++ b/apps/website/src/components/workshop/FeaturedBanner.analytics.test.ts @@ -36,7 +36,7 @@ describe('FeaturedBanner analytics', () => { props: { slides, autoplay: false } }) - await user.click(screen.getByRole('link', { name: 'Try now' })) + await user.click(screen.getByRole('link', { name: 'Try model' })) await user.click(screen.getByRole('button', { name: 'Kling' })) await user.click(screen.getByTestId('featured-slide-link')) diff --git a/apps/website/src/components/workshop/FeaturedBanner.test.ts b/apps/website/src/components/workshop/FeaturedBanner.test.ts index 5b76ce1f8db..f34c20c30b1 100644 --- a/apps/website/src/components/workshop/FeaturedBanner.test.ts +++ b/apps/website/src/components/workshop/FeaturedBanner.test.ts @@ -102,7 +102,7 @@ describe('FeaturedBanner', () => { ) }) - it('shows the docs button only when the provider has a docs section', async () => { + it('offers an API link even when the provider has no docs section', async () => { const user = userEvent.setup() const undocumented: WorkshopModel = { ...kling, @@ -117,13 +117,16 @@ describe('FeaturedBanner', () => { }) const docs = screen.getByTestId('featured-docs-link') - expect(docs.getAttribute('href')).toBe( - 'https://docs.comfy.org/development/comfy-router/models#black-forest-labs' - ) - expect(docs.getAttribute('target')).toBe('_blank') + expect(docs.getAttribute('href')).toBe('/models/flux/#api') + expect(docs.getAttribute('target')).toBeNull() + expect(docs).toHaveTextContent('Use API') + expect(docs).toHaveTextContent('⌘') await user.click(screen.getByRole('button', { name: 'Magnific' })) - expect(screen.queryByTestId('featured-docs-link')).toBeNull() + expect(screen.getByTestId('featured-docs-link')).toHaveAttribute( + 'href', + '/models/magnific/#api' + ) }) it('stays out of the way when the catalogue has nothing to feature', () => { diff --git a/apps/website/src/components/workshop/FeaturedBanner.vue b/apps/website/src/components/workshop/FeaturedBanner.vue index 2f19a1bca08..64fa4243b25 100644 --- a/apps/website/src/components/workshop/FeaturedBanner.vue +++ b/apps/website/src/components/workshop/FeaturedBanner.vue @@ -33,6 +33,7 @@ export interface FeaturedSlide { readonly summary: string | undefined readonly media: { url: string; kind: 'image' | 'video' } | undefined readonly docsHref: string | undefined + readonly apiHref?: string readonly cta?: string } @@ -58,6 +59,25 @@ const active = computed( () => slides[shownIndex.value] ) +const secondaryAction = computed(() => { + const slide = active.value + if (slide?.apiHref) + return { + href: slide.apiHref, + label: t('workshop.hub.useApi'), + target: undefined, + symbol: '⌘' + } + if (slide?.docsHref) + return { + href: slide.docsHref, + label: t('workshop.hub.docs'), + target: '_blank', + symbol: '' + } + return undefined +}) + function goTo(index: number) { activeIndex.value = (index + slides.length) % slides.length } @@ -211,16 +231,17 @@ const fill = computed(() => {{ active.cta ?? t('workshop.hub.tryNow') }} diff --git a/apps/website/src/components/workshop/ModelDetail.test.ts b/apps/website/src/components/workshop/ModelDetail.test.ts index 66b805c7fb4..26597e47808 100644 --- a/apps/website/src/components/workshop/ModelDetail.test.ts +++ b/apps/website/src/components/workshop/ModelDetail.test.ts @@ -260,6 +260,25 @@ describe('ModelDetail', () => { }) }) + it('opens the API tab from a catalogue deep link', async () => { + const previousUrl = location.href + history.replaceState(null, '', '#api') + onTestFinished(() => history.replaceState(null, '', previousUrl)) + await mountDetail({ model: runnable }) + expect(screen.getByTestId('tab-api')).toHaveAttribute( + 'aria-selected', + 'true' + ) + expect(runWorkshopRouter).not.toHaveBeenCalled() + history.replaceState(null, '', '#playground') + window.dispatchEvent(new Event('hashchange')) + await nextTick() + expect(screen.getByTestId('tab-playground')).toHaveAttribute( + 'aria-selected', + 'true' + ) + }) + // Ben's finding, pinned: whatever the flag says, a page that goes away takes // its run with it. Only the reader can choose otherwise, and only out loud. it.for([{ saving: '1' }, { saving: '0' }])( diff --git a/apps/website/src/components/workshop/ModelDetail.vue b/apps/website/src/components/workshop/ModelDetail.vue index 6c30716a54f..e0e48cb43f2 100644 --- a/apps/website/src/components/workshop/ModelDetail.vue +++ b/apps/website/src/components/workshop/ModelDetail.vue @@ -126,6 +126,13 @@ const sectionLabel: Record = { } const activeSection = ref
('playground') +function readSectionHash() { + if (window.location.hash === '#api') activeSection.value = 'api' + else if (window.location.hash === '#playground') + activeSection.value = 'playground' +} +onMounted(readSectionHash) +useEventListener('hashchange', readSectionHash) const { onKeydown: onTabKeydown } = useTablist( () => sections.value, activeSection diff --git a/apps/website/src/components/workshop/ModelsCatalogue.test.ts b/apps/website/src/components/workshop/ModelsCatalogue.test.ts index 8367fb50b46..e9b0d0239e5 100644 --- a/apps/website/src/components/workshop/ModelsCatalogue.test.ts +++ b/apps/website/src/components/workshop/ModelsCatalogue.test.ts @@ -99,7 +99,7 @@ describe('ModelsCatalogue', () => { locale: 'en', tab: 'models', subtitle: - 'Try the latest AI models with your own ideas, right in your browser.' + 'Try models here, call them through the API, or build them into a ComfyUI workflow.' }, { locale: 'en', @@ -116,7 +116,8 @@ describe('ModelsCatalogue', () => { { locale: 'zh-CN', tab: 'models', - subtitle: '用你自己的创意试用最新的 AI 模型,就在浏览器中。' + subtitle: + '在这里试用模型,通过 API 调用,或将它们集成到 ComfyUI 工作流中。' }, { locale: 'zh-CN', diff --git a/apps/website/src/components/workshop/WorkshopModelCard.test.ts b/apps/website/src/components/workshop/WorkshopModelCard.test.ts index d70eaeba904..5f4ca109880 100644 --- a/apps/website/src/components/workshop/WorkshopModelCard.test.ts +++ b/apps/website/src/components/workshop/WorkshopModelCard.test.ts @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/vue' +import { render, screen, within } from '@testing-library/vue' import { afterEach, describe, expect, it } from 'vitest' import { nextTick } from 'vue' @@ -37,6 +37,36 @@ describe('WorkshopModelCard', () => { Object.defineProperty(HTMLElement.prototype, name, descriptor) }) + it('offers separate playground and API links without nesting controls', () => { + render(WorkshopModelCard, { + props: { model: { ...base, capabilities: ['upscale'] } } + }) + expect(screen.getByTestId('model-card-task')).toHaveTextContent( + 'Image to image' + ) + expect(screen.queryByText('upscale')).toBeNull() + expect(screen.getByRole('link', { name: 'Use API' })).toHaveTextContent('⌘') + expect(screen.getByRole('link', { name: 'Try model' })).toHaveAttribute( + 'href', + base.href + ) + expect(screen.getByRole('link', { name: 'Use API' })).toHaveAttribute( + 'href', + base.href + '#api' + ) + expect( + within(screen.getByTestId('workshop-model-card')).queryByRole('link') + ).toBeNull() + }) + + it('does not offer model actions for a disabled model', () => { + render(WorkshopModelCard, { + props: { model: { ...base, href: undefined } } + }) + expect(screen.queryByRole('link', { name: 'Use API' })).toBeNull() + expect(screen.queryByRole('link', { name: 'Try model' })).toBeNull() + }) + it('links the name, provider badge and task to the model page', () => { render(WorkshopModelCard, { props: { model: base } }) const link = screen.getByTestId('workshop-model-card') @@ -45,14 +75,16 @@ describe('WorkshopModelCard', () => { expect(screen.getByTestId('model-card-provider')).toHaveTextContent( 'Black Forest Labs' ) - expect(screen.getByTestId('model-card-task').textContent).toBe( + expect(screen.getByTestId('model-card-task')).toHaveTextContent( 'Image to image' ) expect(screen.queryByText(/credits|\$/)).toBeNull() expect(screen.queryByTestId('model-incomplete-badge')).toBeNull() expect(screen.getByTestId('model-media-placeholder')).toBeTruthy() expect(screen.queryByRole('img', { name: 'Flux' })).toBeNull() - expect(screen.getAllByLabelText('Flux')).toEqual([screen.getByRole('link')]) + expect(screen.getAllByLabelText('Flux')).toEqual([ + screen.getByTestId('workshop-model-card') + ]) }) // The artwork is decorative: the mark says who made this and the heading @@ -66,7 +98,7 @@ describe('WorkshopModelCard', () => { } } }) - expect(screen.getByRole('link')).toHaveAccessibleName( + expect(screen.getByTestId('workshop-model-card')).toHaveAccessibleName( 'Black Forest Labs Flux Image to image' ) expect(screen.queryByRole('img', { name: 'Flux' })).toBeNull() @@ -83,13 +115,20 @@ describe('WorkshopModelCard', () => { }) render(WorkshopModelCard, { props: { - model: { ...base, capabilities: ['upscale', 'inpaint', 'controlnet'] } + model: { + ...base, + routerId: undefined, + type: 'CLOUD', + workflowId: 'workflows/flux', + href: '/models/flux/', + capabilities: ['upscale', 'inpaint', 'controlnet'] + } } }) await nextTick() await nextTick() expect(screen.getByTestId('tag-overflow')).toBeTruthy() - expect(screen.getByRole('link')).toHaveAccessibleName( + expect(screen.getByTestId('workshop-model-card')).toHaveAccessibleName( 'Black Forest Labs Flux Image to image' ) expect(screen.queryByRole('button')).toBeNull() @@ -97,7 +136,7 @@ describe('WorkshopModelCard', () => { it('names a hub card with its kind badge after the provider', () => { render(WorkshopModelCard, { props: { model: base, providerBadge: true } }) - expect(screen.getByRole('link')).toHaveAccessibleName( + expect(screen.getByTestId('workshop-model-card')).toHaveAccessibleName( 'Black Forest Labs Models Flux Image to image' ) }) @@ -154,7 +193,9 @@ describe('WorkshopModelCard', () => { 'href', base.href ) - expect(screen.getAllByLabelText('Flux')).toEqual([screen.getByRole('link')]) + expect(screen.getAllByLabelText('Flux')).toEqual([ + screen.getByTestId('workshop-model-card') + ]) }) // Artwork that repeats the name gives a screen reader the model twice. The @@ -180,7 +221,7 @@ describe('WorkshopModelCard', () => { screen.getByRole('link', { name: /Black Forest Labs/ }) ).toBeVisible() expect(screen.getAllByLabelText('Flux')).toEqual([ - screen.getByRole('link') + screen.getByTestId('workshop-model-card') ]) if (kind === 'video') expect(screen.getByTestId('model-card-media')).toHaveAttribute( diff --git a/apps/website/src/components/workshop/WorkshopModelCard.vue b/apps/website/src/components/workshop/WorkshopModelCard.vue index 0bad60bf7f1..d9fd53364b2 100644 --- a/apps/website/src/components/workshop/WorkshopModelCard.vue +++ b/apps/website/src/components/workshop/WorkshopModelCard.vue @@ -62,6 +62,7 @@ const thumbnailLabel = computed(() => ) const id = useId() +const hasModelActions = computed(() => Boolean(model.routerId && model.href)) const showsTask = computed(() => !workflow.value || !underHeading) // The tags stay visible inside the link but out of its name. const labelledBy = computed(() => @@ -81,83 +82,107 @@ const pillClass = diff --git a/apps/website/src/components/workshop/WorkshopModelsGrid.analytics.test.ts b/apps/website/src/components/workshop/WorkshopModelsGrid.analytics.test.ts index 0fe3560b3d2..921bc765b40 100644 --- a/apps/website/src/components/workshop/WorkshopModelsGrid.analytics.test.ts +++ b/apps/website/src/components/workshop/WorkshopModelsGrid.analytics.test.ts @@ -181,7 +181,9 @@ describe('WorkshopModelsGrid analytics', () => { await user.click(screen.getByRole('button', { name: 'Browse all models' })) await user.click( - within(screen.getByTestId('workshop-models-grid')).getAllByRole('link')[1] + within(screen.getByTestId('workshop-models-grid')).getAllByTestId( + 'workshop-model-card' + )[1] ) expect(events('hub_item_clicked')).toEqual([ @@ -204,7 +206,9 @@ describe('WorkshopModelsGrid analytics', () => { await user.type(await searchbox(), ' Flux {Enter}') await user.click( - within(screen.getByTestId('workshop-models-grid')).getByRole('link') + within(screen.getByTestId('workshop-models-grid')).getByTestId( + 'workshop-model-card' + ) ) expect(events('hub_item_clicked')).toEqual([ @@ -228,7 +232,9 @@ describe('WorkshopModelsGrid analytics', () => { await user.type(await searchbox(), 'Flux') await user.click( - within(screen.getByTestId('workshop-models-grid')).getByRole('link') + within(screen.getByTestId('workshop-models-grid')).getByTestId( + 'workshop-model-card' + ) ) unmount() vi.advanceTimersByTime(SEARCH_SETTLE_MS) diff --git a/apps/website/src/components/workshop/WorkshopModelsGrid.test.ts b/apps/website/src/components/workshop/WorkshopModelsGrid.test.ts index 4ddca0869c8..77d38b67104 100644 --- a/apps/website/src/components/workshop/WorkshopModelsGrid.test.ts +++ b/apps/website/src/components/workshop/WorkshopModelsGrid.test.ts @@ -44,7 +44,9 @@ const models: WorkshopModel[] = [ ] function cardNames() { - return screen.queryAllByRole('link').map((card) => card.textContent) + return screen + .queryAllByTestId('workshop-model-card') + .map((card) => card.textContent) } async function search() { @@ -126,6 +128,18 @@ describe('WorkshopModelsGrid', () => { scrollTo.mockRestore() }) + it('opens all models from the counted top button', async () => { + render(WorkshopModelsGrid, { props: { models } }) + await userEvent.click( + screen.getByRole('button', { name: 'View all models (3)' }) + ) + expect(screen.queryByTestId('browse-all-top')).toBeNull() + expect(cardNames()).toHaveLength(models.length) + expect( + screen.getAllByTestId('model-card-name').map((name) => name.textContent) + ).toEqual(['Kling AI', 'Flux', 'Mystery']) + }) + it('filters by use case from the filter menu', async () => { const user = userEvent.setup() render(WorkshopModelsGrid, { props: { models } }) diff --git a/apps/website/src/components/workshop/WorkshopModelsGrid.vue b/apps/website/src/components/workshop/WorkshopModelsGrid.vue index 17346ece473..a2459a4b9b6 100644 --- a/apps/website/src/components/workshop/WorkshopModelsGrid.vue +++ b/apps/website/src/components/workshop/WorkshopModelsGrid.vue @@ -316,15 +316,28 @@ watch(browseAll, (on) => on && resetFilters()) - -