Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/website/e2e/hub-navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
{
Expand Down
16 changes: 14 additions & 2 deletions apps/website/e2e/workshop-api-actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
8 changes: 6 additions & 2 deletions apps/website/e2e/workshop-workflows.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,15 +682,19 @@ 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.
await page.goto('/hub/workflows/?q=video')
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 ({
Expand Down
6 changes: 3 additions & 3 deletions apps/website/e2e/workshop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
})

test('the hero medium deep-links into the catalog', async ({ page }) => {
Expand Down Expand Up @@ -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 }) =>
Expand Down
17 changes: 14 additions & 3 deletions apps/website/src/components/hub/HubBrowse.test.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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/
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down
15 changes: 9 additions & 6 deletions apps/website/src/components/workshop/FeaturedBanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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', () => {
Expand Down
29 changes: 25 additions & 4 deletions apps/website/src/components/workshop/FeaturedBanner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -58,6 +59,25 @@ const active = computed<FeaturedSlide | undefined>(
() => 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
}
Expand Down Expand Up @@ -211,16 +231,17 @@ const fill = computed(() =>
{{ active.cta ?? t('workshop.hub.tryNow') }}
</Button>
<Button
v-if="active.docsHref"
v-if="secondaryAction"
as="a"
variant="outline"
:href="active.docsHref"
target="_blank"
:href="secondaryAction.href"
:target="secondaryAction.target"
rel="noopener noreferrer"
class="w-fit"
data-testid="featured-docs-link"
>
{{ t('workshop.hub.docs') }}
{{ secondaryAction.label }}
<span aria-hidden="true">{{ secondaryAction.symbol }}</span>
</Button>
</div>
</div>
Expand Down
19 changes: 19 additions & 0 deletions apps/website/src/components/workshop/ModelDetail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
})

Comment thread
RKhur marked this conversation as resolved.
Resolved
// 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' }])(
Expand Down
7 changes: 7 additions & 0 deletions apps/website/src/components/workshop/ModelDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ const sectionLabel: Record<Section, TranslationKey> = {
}

const activeSection = ref<Section>('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
Expand Down
5 changes: 3 additions & 2 deletions apps/website/src/components/workshop/ModelsCatalogue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -116,7 +116,8 @@ describe('ModelsCatalogue', () => {
{
locale: 'zh-CN',
tab: 'models',
subtitle: '用你自己的创意试用最新的 AI 模型,就在浏览器中。'
subtitle:
'在这里试用模型,通过 API 调用,或将它们集成到 ComfyUI 工作流中。'
},
{
locale: 'zh-CN',
Expand Down
59 changes: 50 additions & 9 deletions apps/website/src/components/workshop/WorkshopModelCard.test.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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')
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -83,21 +115,28 @@ describe('WorkshopModelCard', () => {
})
render(WorkshopModelCard, {
props: {
model: { ...base, capabilities: ['upscale', 'inpaint', 'controlnet'] }
model: {
...base,
routerId: undefined,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
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()
})

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'
)
})
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down
Loading
Loading