Skip to content
Open
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions apps/website/src/components/home/HomeHubSection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { render, screen } from '@testing-library/vue'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { readonly, ref } from 'vue'
import type { Ref } from 'vue'

import { hubBannerContent } from '@/data/hubBanner'
import { discoveryProviders } from '@/data/modelDiscovery'
import { HUB_HOME_FLAG } from '@/lib/workshop/hub-section'
import { setPreviewSwitch } from '@/lib/workshop/preview-switches'
import {
useWorkshopAppsEnabled,
useWorkshopEnabled,
useWorkshopEnabledSettled,
useWorkshopFlag,
useWorkshopWorkflowsEnabled
} from '@/scripts/posthog'
import HomeHubSection from './HomeHubSection.vue'

vi.mock(import('@/scripts/posthog'))

let hubHome: Ref<boolean>

beforeEach(() => {
setPreviewSwitch('home-hub-pick-remix-run', false)
window.localStorage.clear()
hubHome = ref(false)
vi.mocked(useWorkshopFlag).mockImplementation((name) =>
readonly(name === HUB_HOME_FLAG ? hubHome : ref(false))
)
vi.mocked(useWorkshopEnabled).mockReturnValue(readonly(ref(true)))
vi.mocked(useWorkshopEnabledSettled).mockReturnValue(readonly(ref(true)))
vi.mocked(useWorkshopAppsEnabled).mockReturnValue(readonly(ref(true)))
vi.mocked(useWorkshopWorkflowsEnabled).mockReturnValue(readonly(ref(true)))
})

const renderSection = () =>
render(HomeHubSection, {
props: {
content: hubBannerContent,
providers: discoveryProviders,
workflows: []
}
})

describe('the Hub section on the home page', () => {
it('keeps the section that is published today while the flag is closed', async () => {
renderSection()

expect(await screen.findByTestId('model-discovery')).toBeTruthy()
expect(screen.queryByTestId('home-hub-banner')).toBeNull()
})

it('swaps in the new banner once the flag answers for this visitor', async () => {
hubHome.value = true
renderSection()

expect(await screen.findByTestId('home-hub-banner')).toBeTruthy()
expect(screen.queryByTestId('model-discovery')).toBeNull()
})
})
36 changes: 36 additions & 0 deletions apps/website/src/components/home/HomeHubSection.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<script setup lang="ts">
import { computed } from 'vue'
import { useMounted } from '@vueuse/core'

import type { HubBannerContent } from '@/data/hubBanner'
import type { Locale } from '@/i18n/translations'
import { HUB_HOME_FLAG } from '@/lib/workshop/hub-section'
import { useWorkshopFlag } from '@/scripts/posthog'
import type {
DiscoveryProvider,
DiscoveryWorkflow
} from '@/data/modelDiscovery'
import HubBannerSection from './HubBannerSection.vue'
import ModelDiscoverySection from './ModelDiscoverySection.vue'

const {
locale = 'en',
content,
providers,
workflows
} = defineProps<{
locale?: Locale
content: HubBannerContent
providers: readonly DiscoveryProvider[]
workflows: readonly DiscoveryWorkflow[]
}>()

const mounted = useMounted()
const hubHomeEnabled = useWorkshopFlag(HUB_HOME_FLAG)
const showBanner = computed(() => mounted.value && hubHomeEnabled.value)
</script>

<template>
<HubBannerSection v-if="showBanner" :locale :content />
<ModelDiscoverySection v-else :providers :workflows />
</template>
162 changes: 162 additions & 0 deletions apps/website/src/components/home/HubBannerSection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import { render, screen, within } from '@testing-library/vue'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { readonly, ref } from 'vue'

import { workshopModels } from '@/config/workshop-browse-content'
import { workflowModels } from '@/config/workshop-workflow-content'
import { hubBannerContent } from '@/data/hubBanner'
import { setPreviewSwitch } from '@/lib/workshop/preview-switches'
import {
useWorkshopAppsEnabled,
useWorkshopEnabled,
useWorkshopEnabledSettled,
useWorkshopFlag,
useWorkshopWorkflowsEnabled
} from '@/scripts/posthog'
import HubBannerSection from './HubBannerSection.vue'

vi.mock(import('@/scripts/posthog'))

const catalogueHrefs = new Set(
[...workflowModels, ...workshopModels].map((model) => model.href)
)

function flags({ apps = true, workflows = true } = {}) {
vi.mocked(useWorkshopEnabled).mockReturnValue(readonly(ref(true)))
vi.mocked(useWorkshopEnabledSettled).mockReturnValue(readonly(ref(true)))
vi.mocked(useWorkshopFlag).mockReturnValue(readonly(ref(false)))
vi.mocked(useWorkshopAppsEnabled).mockReturnValue(readonly(ref(apps)))
vi.mocked(useWorkshopWorkflowsEnabled).mockReturnValue(
readonly(ref(workflows))
)
}

beforeEach(() => {
setPreviewSwitch('home-hub-pick-remix-run', false)
window.localStorage.clear()
flags()
})

const renderBanner = (locale: 'en' | 'zh-CN' = 'en') =>
render(HubBannerSection, { props: { content: hubBannerContent, locale } })

const sectionLinks = () =>
within(screen.getByRole('navigation', { name: 'Hub sections' }))
.getAllByRole('link')
.map((link) => [link.textContent.trim(), link.getAttribute('href')])

describe('HubBannerSection', () => {
it('leads with three entries into the open Hub sections by default', async () => {
renderBanner()

expect(
await screen.findByRole('heading', {
name: 'Everything you need to make it'
})
).toBeVisible()
expect(screen.getByTestId('home-hub-banner')).toHaveAttribute(
'data-design',
'entries'
)
expect(
screen.getByRole('link', { name: 'Explore the Hub' })
).toHaveAttribute('href', '/hub/')
expect(sectionLinks()).toEqual([
[
'AppsUpload, click, done. No nodes, no setup.See all apps',
'/hub/apps/'
],
[
'WorkflowsRun it in Comfy Cloud, then change any step.See all workflows',
'/hub/workflows/'
],
[
'ModelsCall the latest models through one API.See all models',
'/hub/models/'
]
])
})

it('shows each entry with an image from its own catalogue', async () => {
renderBanner()

await screen.findByTestId('home-hub-banner')
for (const [id, tiles] of [
['apps', hubBannerContent.apps],
['workflows', hubBannerContent.workflows],
['models', hubBannerContent.models]
] as const)
expect(
within(screen.getByTestId(`home-hub-entry-${id}`)).getByTestId(
'home-hub-entry-image'
)
).toHaveAttribute('src', tiles[0]?.imageUrl)
})

it('leaves out the entries whose sections are closed', async () => {
flags({ apps: false, workflows: false })
renderBanner()

await screen.findByTestId('home-hub-banner')
expect(sectionLinks().map(([, href]) => href)).toEqual(['/hub/models/'])
})

it('switches to Pick · Remix · Run when the preview switch is on', async () => {
setPreviewSwitch('home-hub-pick-remix-run', true)
renderBanner()

expect(await screen.findByTestId('home-hub-banner')).toHaveAttribute(
'data-design',
'pick-remix-run'
)
expect(sectionLinks()).toEqual([
['PICKApps', '/hub/apps/'],
['REMIXWorkflows', '/hub/workflows/'],
['RUNPartner models', '/hub/models/']
])
expect(
screen.getByRole('link', { name: 'Explore the Hub' })
).toHaveAttribute('href', '/hub/')
})

it('links every Pick · Remix · Run tile to a real workflow or model page', async () => {
setPreviewSwitch('home-hub-pick-remix-run', true)
renderBanner()

const showcase = await screen.findByRole('region', {
name: 'Workflows and models in the Hub'
})
const tiles = within(showcase).getAllByRole('link')
expect(tiles.length).toBeGreaterThan(0)
for (const tile of tiles) {
expect(catalogueHrefs.has(tile.getAttribute('href') ?? '')).toBe(true)
expect(tile).toHaveAccessibleName(/\S.*(Workflow|Model) · \S/)
}
})

it('keeps closed sections as plain words without a link or tiles', async () => {
flags({ apps: false, workflows: false })
setPreviewSwitch('home-hub-pick-remix-run', true)
renderBanner()

await screen.findByTestId('home-hub-banner')
expect(sectionLinks()).toEqual([['RUNPartner models', '/hub/models/']])
expect(screen.getByTestId('home-hub-lane-apps').tagName).toBe('SPAN')
const tileHrefs = screen
.getAllByTestId('home-hub-tile')
.map((tile) => tile.getAttribute('href'))
expect(tileHrefs.every((href) => href?.startsWith('/hub/models/'))).toBe(
true
)
})

it('speaks Chinese on the zh-CN homepage', async () => {
setPreviewSwitch('home-hub-pick-remix-run', true)
renderBanner('zh-CN')

expect(
await screen.findByRole('link', { name: '探索 Hub' })
).toHaveAttribute('href', '/hub/')
expect(screen.getByText('挑选')).toBeVisible()
})
})
35 changes: 35 additions & 0 deletions apps/website/src/components/home/HubBannerSection.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<script setup lang="ts">
import { computed } from 'vue'

import WorkshopGate from '@/components/workshop/WorkshopGate.vue'
import type { HubBannerContent } from '@/data/hubBanner'
import type { Locale } from '@/i18n/translations'
import { usePreviewSwitch } from '@/lib/workshop/preview-switches'
import { useWorkshopWorkflowsEnabled } from '@/scripts/posthog'
import HubEntriesBanner from './HubEntriesBanner.vue'
import HubPickRemixRun from './HubPickRemixRun.vue'

const { locale = 'en', content } = defineProps<{
locale?: Locale
content: HubBannerContent
}>()

const pickRemixRun = usePreviewSwitch('home-hub-pick-remix-run')
const workflowsEnabled = useWorkshopWorkflowsEnabled()
const workflows = computed(() =>
workflowsEnabled.value ? content.workflows : []
)

const marqueeRows = computed(() => {
if (workflows.value.length) return [workflows.value, content.models]
const half = Math.ceil(content.models.length / 2)
return [content.models.slice(0, half), content.models.slice(half)]
})
</script>

<template>
<WorkshopGate>
<HubPickRemixRun v-if="pickRemixRun" :locale :rows="marqueeRows" />
<HubEntriesBanner v-else :locale :content />
</WorkshopGate>
</template>
Loading
Loading