diff --git a/apps/website/e2e/nvidia-vfx.spec.ts b/apps/website/e2e/nvidia-vfx.spec.ts new file mode 100644 index 00000000000..d609240568e --- /dev/null +++ b/apps/website/e2e/nvidia-vfx.spec.ts @@ -0,0 +1,63 @@ +import { expect } from '@playwright/test' + +import { test } from './fixtures/blockExternalMedia' + +test.describe('Nvidia VFX Nodes launch page @smoke', () => { + test.beforeEach(async ({ page }) => { + await page.goto('/nvidia-vfx') + }) + + test('introduces the nodes and opens the Cloud template', async ({ + page + }) => { + await expect( + page.getByRole('heading', { level: 1, name: 'Nvidia VFX Nodes' }) + ).toBeVisible() + await expect( + page.getByRole('link', { name: 'TRY ON COMFY CLOUD' }) + ).toHaveAttribute('href', /template=utility_nvidia_rtx_video_enhance/) + }) + + test('switches the before and after clips with the tabs', async ({ + page + }) => { + await page + .getByRole('heading', { level: 2, name: 'One clip, two states.' }) + .scrollIntoViewIfNeeded() + const before = page.getByTestId('video-compare-before') + const after = page.getByTestId('video-compare-after') + + await expect(before).toHaveAttribute('src', /super-resolution-before\.mp4$/) + + await page.getByRole('tab', { name: 'Frame Generation' }).click() + + await expect(before).toHaveAttribute('src', /frame-generation-before\.mp4$/) + await expect(after).toHaveAttribute('src', /frame-generation-after\.mp4$/) + await expect( + page.getByText( + 'Multiply frame rate up to 16× with Frame Generation for smooth slow motion.', + { exact: true } + ) + ).toBeVisible() + }) + + test('opens the workflow screenshot full screen and closes it on Escape', async ({ + page + }) => { + const tile = page.getByTestId('gallery-card-media') + await tile.scrollIntoViewIfNeeded() + const dialog = page.getByRole('dialog') + + await expect(async () => { + await tile.getByRole('button', { name: 'Fullscreen' }).click() + await expect(dialog).toBeVisible({ timeout: 1000 }) + }).toPass() + await expect( + dialog.getByRole('img', { name: /chained in one ComfyUI workflow/ }) + ).toBeVisible() + + await page.keyboard.press('Escape') + + await expect(dialog).toBeHidden() + }) +}) diff --git a/apps/website/public/images/models/nvidia-vfx-hero-poster.jpg b/apps/website/public/images/models/nvidia-vfx-hero-poster.jpg new file mode 100644 index 00000000000..b3a0c276d15 Binary files /dev/null and b/apps/website/public/images/models/nvidia-vfx-hero-poster.jpg differ diff --git a/apps/website/public/images/models/nvidia-vfx-pipeline.jpg b/apps/website/public/images/models/nvidia-vfx-pipeline.jpg new file mode 100644 index 00000000000..c3449a0b809 Binary files /dev/null and b/apps/website/public/images/models/nvidia-vfx-pipeline.jpg differ diff --git a/apps/website/public/llms.txt b/apps/website/public/llms.txt index 2e09203e33e..b8646c7d4a4 100644 --- a/apps/website/public/llms.txt +++ b/apps/website/public/llms.txt @@ -100,6 +100,7 @@ Languages: comfy.org is published in English and Simplified Chinese, with a Japa - [Models Overview](https://comfy.org/hub/models/): Hosted models you can run in the browser and call through Comfy Router, one page per model. Markdown version at https://comfy.org/hub/models.md. For open-weight model files you run locally, see Supported Models above. - [ChatGPT Images 2.5 (OpenAI, image model)](https://comfy.org/chatgpt-image-2.5/): Generate new images, edit existing visuals, and direct results with reference images in repeatable ComfyUI workflows through Partner Nodes. - [Qwen-Image 2.1 (Alibaba Qwen, image model)](https://comfy.org/qwen-image-2.1/): Open-weights 7B image model that generates and edits in one checkpoint, with native 2K output, RGBA transparency, and accurate English and Chinese text rendering. +- [Nvidia VFX Nodes (NVIDIA, custom nodes)](https://comfy.org/nvidia-vfx/): Three ComfyUI custom nodes powered by Nvidia's RTX technology for ultra fast video super resolution, frame generation and SDR-to-HDR conversion, running locally on RTX GPUs or on Comfy Cloud. - [Flux 3 (Black Forest Labs, video model)](https://comfy.org/flux-3/): Multimodal model: video with native audio, up to 20 seconds per generation, from text, image, video, or keyframes. - [Gemini Omni 1.1 Flash (Google, video model)](https://comfy.org/gemini-omni/): One node covers text to video, image to video, reference to video, editing, and scene extension, with output up to 4K and audio on every clip. - [LTX 2.5 (Lightricks, video model)](https://comfy.org/ltx-2.5/): Open weights: free to run on your own GPU, or on Comfy Cloud alongside every other model. diff --git a/apps/website/src/components/common/VideoCompareSlider.test.ts b/apps/website/src/components/common/VideoCompareSlider.test.ts new file mode 100644 index 00000000000..71eb59267c4 --- /dev/null +++ b/apps/website/src/components/common/VideoCompareSlider.test.ts @@ -0,0 +1,140 @@ +import userEvent from '@testing-library/user-event' +import { render, screen, waitFor } from '@testing-library/vue' +import { describe, expect, it, vi } from 'vitest' +import { createSSRApp, h } from 'vue' +import { renderToString } from 'vue/server-renderer' + +import VideoCompareSlider from './VideoCompareSlider.vue' + +const props = { + beforeSrc: 'before.webm', + afterSrc: 'after.webm', + beforeLabel: 'Before', + afterLabel: 'After', + sliderLabel: 'Comparison slider' +} + +async function renderSlider() { + render(VideoCompareSlider, { props }) + const slider = screen.getByRole('slider', { name: 'Comparison slider' }) + const surface = screen.getByTestId('video-compare-surface') + const beforeVideo = screen.getByTestId( + 'video-compare-before' + ) + const afterVideo = screen.getByTestId('video-compare-after') + await waitFor(() => expect(beforeVideo).toHaveAttribute('src', 'before.webm')) + return { slider, surface, beforeVideo, afterVideo } +} + +async function pressAt( + user: ReturnType, + surface: HTMLElement, + clientX: number, + keys = '[MouseLeft>]' +) { + vi.spyOn(surface, 'getBoundingClientRect').mockReturnValue( + new DOMRect(100, 0, 400, 225) + ) + await user.pointer([{ keys, target: surface, coords: { clientX } }]) +} + +describe('VideoCompareSlider', () => { + it('renders no clip sources on the server', async () => { + const html = await renderToString( + createSSRApp({ render: () => h(VideoCompareSlider, props) }) + ) + + expect(html).toContain('role="slider"') + expect(html).not.toContain('before.webm') + expect(html).not.toContain('after.webm') + }) + + it('starts at the midpoint with the after clip revealed on the right', async () => { + const { slider, afterVideo } = await renderSlider() + + expect(afterVideo).toHaveAttribute('src', 'after.webm') + expect(slider).toHaveAttribute('aria-valuenow', '50') + expect(afterVideo.style.clipPath).toBe('inset(0 0 0 50%)') + expect(screen.getByText('Before')).toBeVisible() + expect(screen.getByText('After')).toBeVisible() + }) + + it('moves with the keyboard and clips the after clip to match', async () => { + const user = userEvent.setup() + const { slider, afterVideo } = await renderSlider() + + slider.focus() + await user.keyboard('{Shift>}{ArrowRight}{/Shift}') + expect(slider).toHaveAttribute('aria-valuenow', '60') + expect(afterVideo.style.clipPath).toBe('inset(0 0 0 60%)') + + await user.keyboard('{Home}') + expect(slider).toHaveAttribute('aria-valuenow', '0') + }) + + it('jumps to the pressed point and follows the pointer while held', async () => { + const user = userEvent.setup() + const { slider, surface } = await renderSlider() + + await pressAt(user, surface, 200) + expect(slider).toHaveAttribute('aria-valuenow', '25') + + await user.pointer([{ coords: { clientX: 400 } }]) + expect(slider).toHaveAttribute('aria-valuenow', '75') + }) + + it('ignores presses from other buttons', async () => { + const user = userEvent.setup() + const { slider, surface } = await renderSlider() + + await pressAt(user, surface, 200, '[MouseRight>]') + await user.pointer([{ coords: { clientX: 400 } }]) + + expect(slider).toHaveAttribute('aria-valuenow', '50') + }) + + it.for([ + { release: 'pointerup', event: () => new Event('pointerup') }, + { release: 'pointercancel', event: () => new Event('pointercancel') }, + { + release: 'a move with no button held', + event: () => new PointerEvent('pointermove', { clientX: 400, buttons: 0 }) + } + ])('stops following the pointer after $release', async ({ event }) => { + const user = userEvent.setup() + const { slider, surface } = await renderSlider() + await pressAt(user, surface, 200) + + window.dispatchEvent(event()) + await user.pointer([{ coords: { clientX: 400 } }]) + + expect(slider).toHaveAttribute('aria-valuenow', '25') + }) + + it.for([ + { before: 4, after: 1, expected: 4 }, + { before: 4, after: 3.9, expected: 3.9 } + ])( + 'puts the after clip at $expected when it is at $after and the before clip is at $before', + async ({ before, after, expected }) => { + const { beforeVideo, afterVideo } = await renderSlider() + + beforeVideo.currentTime = before + afterVideo.currentTime = after + beforeVideo.dispatchEvent(new Event('timeupdate')) + + expect(afterVideo.currentTime).toBe(expected) + } + ) + + it('resumes the after clip when it has paused while the before clip plays', async () => { + const { beforeVideo, afterVideo } = await renderSlider() + vi.spyOn(beforeVideo, 'paused', 'get').mockReturnValue(false) + vi.spyOn(afterVideo, 'paused', 'get').mockReturnValue(true) + const play = vi.spyOn(afterVideo, 'play').mockResolvedValue() + + beforeVideo.dispatchEvent(new Event('timeupdate')) + + expect(play).toHaveBeenCalledOnce() + }) +}) diff --git a/apps/website/src/components/common/VideoCompareSlider.vue b/apps/website/src/components/common/VideoCompareSlider.vue new file mode 100644 index 00000000000..7897086e6d0 --- /dev/null +++ b/apps/website/src/components/common/VideoCompareSlider.vue @@ -0,0 +1,162 @@ + + + diff --git a/apps/website/src/components/common/videoCompare.test.ts b/apps/website/src/components/common/videoCompare.test.ts new file mode 100644 index 00000000000..38d618510fa --- /dev/null +++ b/apps/website/src/components/common/videoCompare.test.ts @@ -0,0 +1,39 @@ +import { describe, expect, it } from 'vitest' + +import { positionFromPointer, stepPosition } from './videoCompare' + +describe('positionFromPointer', () => { + it.for([ + { clientX: 150, left: 100, width: 200, expected: 25 }, + { clientX: 100, left: 100, width: 200, expected: 0 }, + { clientX: 300, left: 100, width: 200, expected: 100 }, + { clientX: 20, left: 100, width: 200, expected: 0 }, + { clientX: 900, left: 100, width: 200, expected: 100 }, + { clientX: 50, left: 0, width: 0, expected: 0 } + ])( + 'maps clientX $clientX in [$left, +$width] to $expected%', + ({ clientX, left, width, expected }) => { + expect(positionFromPointer(clientX, { left, width })).toBe(expected) + } + ) +}) + +describe('stepPosition', () => { + it.for([ + { current: 50, key: 'ArrowRight', shift: false, expected: 52 }, + { current: 50, key: 'ArrowUp', shift: false, expected: 52 }, + { current: 50, key: 'ArrowLeft', shift: false, expected: 48 }, + { current: 50, key: 'ArrowDown', shift: false, expected: 48 }, + { current: 50, key: 'ArrowRight', shift: true, expected: 60 }, + { current: 99, key: 'ArrowRight', shift: false, expected: 100 }, + { current: 1, key: 'ArrowLeft', shift: true, expected: 0 }, + { current: 50, key: 'Home', shift: false, expected: 0 }, + { current: 50, key: 'End', shift: false, expected: 100 }, + { current: 50, key: 'Enter', shift: false, expected: undefined } + ])( + '$key (shift=$shift) from $current gives $expected', + ({ current, key, shift, expected }) => { + expect(stepPosition(current, key, shift)).toBe(expected) + } + ) +}) diff --git a/apps/website/src/components/common/videoCompare.ts b/apps/website/src/components/common/videoCompare.ts new file mode 100644 index 00000000000..ca678122866 --- /dev/null +++ b/apps/website/src/components/common/videoCompare.ts @@ -0,0 +1,38 @@ +export const COMPARE_MIN = 0 +export const COMPARE_MAX = 100 +const KEY_STEP = 2 +const KEY_LARGE_STEP = 10 + +function clampPercent(value: number): number { + return Math.min(COMPARE_MAX, Math.max(COMPARE_MIN, value)) +} + +export function positionFromPointer( + clientX: number, + bounds: { left: number; width: number } +): number { + if (bounds.width <= 0) return COMPARE_MIN + return clampPercent(((clientX - bounds.left) / bounds.width) * COMPARE_MAX) +} + +export function stepPosition( + current: number, + key: string, + shift = false +): number | undefined { + const step = shift ? KEY_LARGE_STEP : KEY_STEP + switch (key) { + case 'ArrowLeft': + case 'ArrowDown': + return clampPercent(current - step) + case 'ArrowRight': + case 'ArrowUp': + return clampPercent(current + step) + case 'Home': + return COMPARE_MIN + case 'End': + return COMPARE_MAX + default: + return undefined + } +} diff --git a/apps/website/src/components/ui/scroll-carousel/ScrollCarousel.test.ts b/apps/website/src/components/ui/scroll-carousel/ScrollCarousel.test.ts new file mode 100644 index 00000000000..8de1b4abe4f --- /dev/null +++ b/apps/website/src/components/ui/scroll-carousel/ScrollCarousel.test.ts @@ -0,0 +1,94 @@ +import { render, screen } from '@testing-library/vue' +import { beforeEach, describe, expect, it, vi } from 'vitest' + +import { prefersReducedMotion } from '@/composables/useReducedMotion' +import { + setAllIntersecting, + stubIntersectionObserver +} from '@/test/fakeIntersectionObserver' +import ScrollCarousel from './ScrollCarousel.vue' + +vi.mock(import('@/composables/useReducedMotion'), () => ({ + prefersReducedMotion: vi.fn() +})) + +function renderCarousel(props: { autoplayMs?: number } = {}) { + render(ScrollCarousel, { + props, + slots: { default: '
a
b
' } + }) + const track = screen.getByTestId('scroll-carousel-track') + Object.defineProperty(track, 'clientWidth', { value: 100 }) + Object.defineProperty(track, 'scrollWidth', { value: 200 }) + track.scrollBy = vi.fn() + track.scrollTo = vi.fn() + return track +} + +describe('ScrollCarousel autoplay', () => { + beforeEach(() => { + vi.useFakeTimers() + stubIntersectionObserver() + vi.mocked(prefersReducedMotion).mockReturnValue(false) + }) + + it('advances one viewport after autoplayMs and wraps to the start at the end', async () => { + const track = renderCarousel({ autoplayMs: 4000 }) + await setAllIntersecting(true) + + await vi.advanceTimersByTimeAsync(4000) + expect(track.scrollBy).toHaveBeenCalledWith({ + left: 100, + behavior: 'smooth' + }) + + track.scrollLeft = 100 + track.dispatchEvent(new Event('scroll')) + await vi.advanceTimersByTimeAsync(4000) + expect(track.scrollTo).toHaveBeenCalledWith({ left: 0, behavior: 'smooth' }) + }) + + it('stays put when autoplayMs is not set', async () => { + const track = renderCarousel() + await setAllIntersecting(true) + + await vi.advanceTimersByTimeAsync(10000) + + expect(track.scrollBy).not.toHaveBeenCalled() + expect(track.scrollTo).not.toHaveBeenCalled() + }) + + it.for([ + { + gate: 'reduced motion is preferred', + reducedMotion: true, + intersecting: true, + hovered: false + }, + { + gate: 'the carousel is off screen', + reducedMotion: false, + intersecting: false, + hovered: false + }, + { + gate: 'the pointer is over the track', + reducedMotion: false, + intersecting: true, + hovered: true + } + ])( + 'does not advance while $gate', + async ({ reducedMotion, intersecting, hovered }) => { + vi.mocked(prefersReducedMotion).mockReturnValue(reducedMotion) + const track = renderCarousel({ autoplayMs: 4000 }) + await setAllIntersecting(intersecting) + track.dispatchEvent(new MouseEvent(hovered ? 'mouseenter' : 'mouseleave')) + + await vi.advanceTimersByTimeAsync(10000) + + expect(track.scrollBy).not.toHaveBeenCalled() + expect(track.scrollTo).not.toHaveBeenCalled() + } + ) +}) diff --git a/apps/website/src/components/ui/scroll-carousel/ScrollCarousel.vue b/apps/website/src/components/ui/scroll-carousel/ScrollCarousel.vue index 22e7f79371a..29a9f18169b 100644 --- a/apps/website/src/components/ui/scroll-carousel/ScrollCarousel.vue +++ b/apps/website/src/components/ui/scroll-carousel/ScrollCarousel.vue @@ -1,19 +1,27 @@ @@ -43,6 +76,7 @@ const progressPercent = computed(() => `${progress.value * 100}%`) >
diff --git a/apps/website/src/pages/zh-CN/nvidia-vfx.astro b/apps/website/src/pages/zh-CN/nvidia-vfx.astro new file mode 100644 index 00000000000..3e8815e15bf --- /dev/null +++ b/apps/website/src/pages/zh-CN/nvidia-vfx.astro @@ -0,0 +1,6 @@ +--- +import ModelLaunchPage from '@/templates/model-launch/ModelLaunchPage.astro' +import { nvidiaRtxPage } from '@/data/nvidiaRtx' +--- + + diff --git a/apps/website/src/templates/model-launch/ModelLaunchBeforeAfterSection.test.ts b/apps/website/src/templates/model-launch/ModelLaunchBeforeAfterSection.test.ts new file mode 100644 index 00000000000..6237a4f7f06 --- /dev/null +++ b/apps/website/src/templates/model-launch/ModelLaunchBeforeAfterSection.test.ts @@ -0,0 +1,112 @@ +import userEvent from '@testing-library/user-event' +import { render, screen, waitFor } from '@testing-library/vue' +import { describe, expect, it } from 'vitest' + +import type { ModelLaunchBeforeAfter } from './types' + +import ModelLaunchBeforeAfterSection from './ModelLaunchBeforeAfterSection.vue' + +function beforeAfterWith(chinese: boolean): ModelLaunchBeforeAfter { + return { + headingKey: 'modelLaunch.beforeAfter.tabsLabel', + tabs: [ + { + id: 'sharpen', + label: { en: 'Sharpen', 'zh-CN': chinese ? '锐化' : '' }, + caption: { + en: 'Soft in, sharp out.', + 'zh-CN': chinese ? '输入柔和,输出锐利。' : '' + }, + beforeSrc: 'https://media.comfy.org/a-before.webm', + afterSrc: 'https://media.comfy.org/a-after.webm' + }, + { + id: 'denoise', + label: { en: 'Denoise', 'zh-CN': chinese ? '降噪' : '' }, + caption: { + en: 'Grain in, clean out.', + 'zh-CN': chinese ? '输入噪点,输出干净。' : '' + }, + beforeSrc: 'https://media.comfy.org/b-before.webm', + afterSrc: 'https://media.comfy.org/b-after.webm' + } + ] + } +} + +const beforeAfter = beforeAfterWith(true) + +function videoSources(): (string | null)[] { + return [ + screen.getByTestId('video-compare-before').getAttribute('src'), + screen.getByTestId('video-compare-after').getAttribute('src') + ] +} + +describe('ModelLaunchBeforeAfterSection', () => { + it('opens on the first tab with its clip pair and caption', async () => { + render(ModelLaunchBeforeAfterSection, { props: { beforeAfter } }) + + expect( + screen.getByRole('tab', { name: 'Sharpen', selected: true }) + ).toBeVisible() + expect(screen.getByText('Soft in, sharp out.')).toBeVisible() + expect( + screen.getByRole('slider', { name: 'Comparison slider' }) + ).toBeVisible() + await waitFor(() => + expect(videoSources()).toEqual([ + 'https://media.comfy.org/a-before.webm', + 'https://media.comfy.org/a-after.webm' + ]) + ) + }) + + it('swaps the clip pair and caption when another tab is clicked', async () => { + const user = userEvent.setup() + render(ModelLaunchBeforeAfterSection, { props: { beforeAfter } }) + + await user.click(screen.getByRole('tab', { name: 'Denoise' })) + await screen.findByText('Grain in, clean out.') + + expect(screen.getByRole('tab', { name: 'Denoise' })).toHaveAttribute( + 'aria-selected', + 'true' + ) + expect(screen.queryByText('Soft in, sharp out.')).toBeNull() + await waitFor(() => + expect(videoSources()).toEqual([ + 'https://media.comfy.org/b-before.webm', + 'https://media.comfy.org/b-after.webm' + ]) + ) + }) + + it.for([ + { + copy: 'Chinese copy', + chinese: true, + tab: '锐化', + caption: '输入柔和,输出锐利。' + }, + { + copy: 'English fallback', + chinese: false, + tab: 'Sharpen', + caption: 'Soft in, sharp out.' + } + ])( + 'renders $copy for the zh-CN locale with translated slider labels', + ({ chinese, tab, caption }) => { + render(ModelLaunchBeforeAfterSection, { + props: { beforeAfter: beforeAfterWith(chinese), locale: 'zh-CN' } + }) + + expect(screen.getByRole('tab', { name: tab })).toBeVisible() + expect(screen.getByText(caption)).toBeVisible() + expect(screen.getByText('处理前')).toBeVisible() + expect(screen.getByText('处理后')).toBeVisible() + expect(screen.getByRole('slider', { name: '对比滑块' })).toBeVisible() + } + ) +}) diff --git a/apps/website/src/templates/model-launch/ModelLaunchBeforeAfterSection.vue b/apps/website/src/templates/model-launch/ModelLaunchBeforeAfterSection.vue new file mode 100644 index 00000000000..a8c63ba85a9 --- /dev/null +++ b/apps/website/src/templates/model-launch/ModelLaunchBeforeAfterSection.vue @@ -0,0 +1,87 @@ + + + diff --git a/apps/website/src/templates/model-launch/ModelLaunchGalleryCard.vue b/apps/website/src/templates/model-launch/ModelLaunchGalleryCard.vue new file mode 100644 index 00000000000..56f79cc7c60 --- /dev/null +++ b/apps/website/src/templates/model-launch/ModelLaunchGalleryCard.vue @@ -0,0 +1,111 @@ + + + diff --git a/apps/website/src/templates/model-launch/ModelLaunchGalleryCardMedia.vue b/apps/website/src/templates/model-launch/ModelLaunchGalleryCardMedia.vue new file mode 100644 index 00000000000..301d18a8747 --- /dev/null +++ b/apps/website/src/templates/model-launch/ModelLaunchGalleryCardMedia.vue @@ -0,0 +1,125 @@ + + + diff --git a/apps/website/src/templates/model-launch/ModelLaunchGallerySection.test.ts b/apps/website/src/templates/model-launch/ModelLaunchGallerySection.test.ts new file mode 100644 index 00000000000..eaf0268947c --- /dev/null +++ b/apps/website/src/templates/model-launch/ModelLaunchGallerySection.test.ts @@ -0,0 +1,123 @@ +import userEvent from '@testing-library/user-event' +import { render, screen, waitFor, within } from '@testing-library/vue' +import { beforeEach, describe, expect, it } from 'vitest' + +import type { ModelLaunchGallery } from './types' + +import { stubIntersectionObserver } from '@/test/fakeIntersectionObserver' +import ModelLaunchGallerySection from './ModelLaunchGallerySection.vue' + +const gallery: ModelLaunchGallery = { + headingKey: 'nvidiaRtx.gallery.heading', + cards: [ + { + id: 'one', + name: { en: 'First render', 'zh-CN': '第一幅' }, + tier: 'free', + note: { en: 'Runs locally', 'zh-CN': '本地运行' }, + description: { en: 'One.', 'zh-CN': '一。' }, + media: { kind: 'image', src: '/one.webp' }, + href: 'https://comfy.org/download/' + }, + { + id: 'two', + name: { en: 'Second render', 'zh-CN': '第二幅' }, + tier: 'free', + note: { en: 'Runs locally', 'zh-CN': '本地运行' }, + description: { en: 'Two.', 'zh-CN': '二。' }, + media: { kind: 'image', src: '/two.webp' }, + href: 'https://comfy.org/download/' + } + ] +} + +describe('ModelLaunchGallerySection', () => { + beforeEach(() => { + stubIntersectionObserver() + }) + + it.for([ + { ctaVariant: undefined, cardMeta: undefined, links: 2, notes: 2 }, + { ctaVariant: 'accent' as const, cardMeta: undefined, links: 2, notes: 2 }, + { ctaVariant: 'none' as const, cardMeta: undefined, links: 0, notes: 2 }, + { ctaVariant: undefined, cardMeta: 'none' as const, links: 2, notes: 0 }, + { + ctaVariant: 'none' as const, + cardMeta: 'none' as const, + links: 0, + notes: 0 + } + ])( + 'renders $links card links and $notes notes for ctaVariant=$ctaVariant cardMeta=$cardMeta', + ({ ctaVariant, cardMeta, links, notes }) => { + render(ModelLaunchGallerySection, { + props: { gallery: { ...gallery, ctaVariant, cardMeta } } + }) + + expect(screen.queryAllByRole('link')).toHaveLength(links) + expect(screen.queryAllByText('Runs locally')).toHaveLength(notes) + expect(screen.queryAllByText('Free')).toHaveLength(notes) + expect(screen.getByText('One.')).toBeVisible() + } + ) + + it.for([ + { captionPlacement: undefined, insideTile: 0 }, + { captionPlacement: 'overlay' as const, insideTile: 1 } + ])( + 'renders the caption once, $insideTile time(s) inside the tile, for captionPlacement=$captionPlacement', + ({ captionPlacement, insideTile }) => { + render(ModelLaunchGallerySection, { + props: { gallery: { ...gallery, captionPlacement } } + }) + const [tile] = screen.getAllByTestId('gallery-card-media') + + expect(screen.getAllByText('One.')).toHaveLength(1) + expect(within(tile).queryAllByText('One.')).toHaveLength(insideTile) + } + ) + + it('opens an expandable image full screen and closes it on Escape', async () => { + const user = userEvent.setup() + const [first, second] = gallery.cards + render(ModelLaunchGallerySection, { + props: { + gallery: { ...gallery, cards: [first, { ...second, expandable: true }] } + } + }) + + expect(screen.queryByRole('dialog')).toBeNull() + + await user.click(screen.getByRole('button', { name: 'Fullscreen' })) + + expect( + within(screen.getByRole('dialog')).getByRole('img', { + name: 'Second render' + }) + ).toBeVisible() + + await user.keyboard('{Escape}') + + await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()) + }) + + it('offers no full screen button for an expandable video card', () => { + const [first] = gallery.cards + render(ModelLaunchGallerySection, { + props: { + gallery: { + ...gallery, + cards: [ + { + ...first, + expandable: true, + media: { kind: 'video', src: '/one.mp4' } + } + ] + } + } + }) + + expect(screen.queryByRole('button', { name: 'Fullscreen' })).toBeNull() + }) +}) diff --git a/apps/website/src/templates/model-launch/ModelLaunchGallerySection.vue b/apps/website/src/templates/model-launch/ModelLaunchGallerySection.vue index 6b075536d29..b12b73acd0a 100644 --- a/apps/website/src/templates/model-launch/ModelLaunchGallerySection.vue +++ b/apps/website/src/templates/model-launch/ModelLaunchGallerySection.vue @@ -1,16 +1,19 @@