Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

test(video-download): align integration coverage with link queues and Reddit

Leggett30c66fbbcb13
diff --git a/apps/web/e2e/creator-presets.spec.ts b/apps/web/e2e/creator-presets.spec.ts
index 2bb510eb..8146fb35 100644
--- a/apps/web/e2e/creator-presets.spec.ts
+++ b/apps/web/e2e/creator-presets.spec.ts
@@ -12,6 +12,7 @@ import {
} from './fixtures/creator-presets.js';
import {
expect,
+ stubVideoDownloadProbe,
test,
type RuntimeFixture
} from './fixtures/runtime.js';
@@ -301,19 +302,18 @@ test('@AC-4 六模块解析严格默认值,工作台首帧预填并持久化
statePath: ['subtitleStyle', 'primaryColor'],
expectedPersistedValue: '#112233'
});
- await verifyWorkspaceEdit({
- page,
- runtime,
- module: 'video-download',
- job: jobs.get('video-download')!,
- heading: '视频下载',
- field: page.getByRole('textbox', { name: '待下载视频链接' }),
- initialValue: '',
- editedValue: 'https://www.youtube.com/watch?v=OpenCreatorPreset',
- statePath: ['sourceUrl'],
- expectedPersistedValue: 'https://www.youtube.com/watch?v=OpenCreatorPreset',
- preservedState: { mediaType: 'audio' }
- });
+ await stubVideoDownloadProbe(page, runtime);
+ const downloadJob = jobs.get('video-download')!;
+ const downloadUrl = 'https://www.youtube.com/watch?v=OpenCreatorPreset';
+ await openWorkspace(page, runtime, 'video-download', downloadJob.id);
+ const downloadInput = page.getByRole('textbox', { name: '视频链接', exact: true });
+ await expect(downloadInput).toHaveValue('');
+ await downloadInput.fill(downloadUrl);
+ await page.getByRole('button', { name: '添加并解析' }).click();
+ await expectJobState(runtime, downloadJob.id, ['sourceUrl'], downloadUrl);
+ expect((await getJob(runtime, downloadJob.id)).state).toMatchObject({ mediaType: 'audio' });
+ await page.reload();
+ await expect(page.getByRole('list', { name: '视频链接列表' })).toContainText(downloadUrl);
await verifyWorkspaceEdit({
page,
runtime,
diff --git a/apps/web/e2e/fixtures/runtime.ts b/apps/web/e2e/fixtures/runtime.ts
index f9406350..6a863ec5 100644
--- a/apps/web/e2e/fixtures/runtime.ts
+++ b/apps/web/e2e/fixtures/runtime.ts
@@ -1,4 +1,5 @@
import { expect, test as base, type Page } from '@playwright/test';
+import type { CreatorActionRequest, CreatorJob } from '@opencreator/protocol';
import { execFileSync, spawn, type ChildProcess } from 'node:child_process';
import {
copyFileSync,
@@ -471,6 +472,22 @@ export const test = base.extend<TestFixtures>({
export { expect };
+// Keep creation and persistence real while avoiding external video platforms.
+export async function stubVideoDownloadProbe(page: Page, runtime: RuntimeFixture): Promise<void> {
+ await page.route('**/creator/jobs/*/actions', async route => {
+ const request = route.request();
+ if (request.method() !== 'POST') return route.continue();
+ const action = request.postDataJSON() as CreatorActionRequest;
+ if (action.action !== 'run-stage' || action.input.stageId !== 'probe') return route.continue();
+ const jobId = new URL(request.url()).pathname.split('/').at(-2)!;
+ const { job } = await runtime.api<{ job: CreatorJob }>('GET', `/creator/jobs/${jobId}`);
+ await route.fulfill({ json: { job, receipt: {
+ actor: action.actor ?? 'user', action: action.action, summary: action.action,
+ affectedArtifacts: [], newRevision: job.revision, createdAt: job.updatedAt
+ } } });
+ });
+}
+
function isYtDlpStatusUrl(value: string): boolean {
try {
return new URL(value).pathname.endsWith('/creator/yt-dlp/status');
diff --git a/apps/web/e2e/video-download-layout.spec.ts b/apps/web/e2e/video-download-layout.spec.ts
index 0e748f53..33c14b1f 100644
--- a/apps/web/e2e/video-download-layout.spec.ts
+++ b/apps/web/e2e/video-download-layout.spec.ts
@@ -1,7 +1,7 @@
import type { CreatorJob } from '@opencreator/protocol';
import { expect, test } from './fixtures/runtime.js';
-test('video download platforms stay centered and wrap within the full workspace width', async ({ page, runtime }) => {
+test('video download platforms stay centered and wrap within the full workspace width', async ({ page, runtime }, testInfo) => {
const { job } = await runtime.api<{ job: CreatorJob }>('POST', '/creator/jobs', {
projectId: runtime.projectId,
templateId: 'video-download',
@@ -14,7 +14,10 @@ test('video download platforms stay centered and wrap within the full workspace
const stack = page.locator('.video-download-workspace-page .creator-tool-stack');
const platforms = page.getByRole('list', { name: '支持的平台' });
const items = platforms.locator('li');
- await expect(items).toHaveCount(9);
+ await expect(items).toHaveCount(10);
+
+ expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(true);
+ await page.screenshot({ path: testInfo.outputPath('video-download-layout.png'), fullPage: true });
await page.setViewportSize({ width: 1920, height: 1000 });
const wide = await platforms.evaluate(element => {
@@ -31,7 +34,8 @@ test('video download platforms stay centered and wrap within the full workspace
const style = getComputedStyle(element);
return element.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);
});
- expect(await stack.evaluate(element => element.getBoundingClientRect().width)).toBeCloseTo(contentWidth, 0);
+ // clientWidth excludes the scrollbar gutter and rounds fractional CSS pixels.
+ expect(Math.round(await stack.evaluate(element => element.getBoundingClientRect().width))).toBe(Math.round(contentWidth));
expect(wide.rowTops).toHaveLength(1);
expect(Math.abs(wide.itemsCenter - wide.listCenter)).toBeLessThan(2);
expect(wide.loadedIcons).toBe(true);
diff --git a/apps/web/e2e/video-translation-sources.spec.ts b/apps/web/e2e/video-translation-sources.spec.ts
index d66a0a99..b842e338 100644
--- a/apps/web/e2e/video-translation-sources.spec.ts
+++ b/apps/web/e2e/video-translation-sources.spec.ts
@@ -14,7 +14,7 @@ test('视频翻译显示全部下载来源并接受抖音分享文本', async ({
await runtime.openApp(page);
await page.goto(`${runtime.origin}/#/workbench?tool=video-translation&jobId=${encodeURIComponent(job.id)}`);
const platforms = page.getByRole('list', { name: '支持的平台' });
- await expect(platforms.locator('li')).toHaveCount(9);
+ await expect(platforms.locator('li')).toHaveCount(10);
await expect.poll(() => platforms.locator('img').evaluateAll(images => images.every(image => (
(image as HTMLImageElement).complete && (image as HTMLImageElement).naturalWidth > 0
)))).toBe(true);
diff --git a/apps/web/e2e/web-desktop-parity.spec.ts b/apps/web/e2e/web-desktop-parity.spec.ts
index d7581e54..171fae88 100644
--- a/apps/web/e2e/web-desktop-parity.spec.ts
+++ b/apps/web/e2e/web-desktop-parity.spec.ts
@@ -1,5 +1,5 @@
import { createDefaultCreatorServicesConfig, type CreatorRuntimeComponentsResponse, type CreatorServicesCapabilitiesResponse, type CreatorYtDlpStatusResponse, type YouTubeConnectionState } from '@opencreator/protocol';
-import { test, expect } from './fixtures/runtime.js';
+import { test, expect, stubVideoDownloadProbe } from './fixtures/runtime.js';
test('Windows YouTube 专用登录和完成在 Browser/Desktop 下保持一致', async ({ browser, runtime }, testInfo) => {
const results: unknown[] = [];
@@ -1266,9 +1266,17 @@ test('视频下载在 Browser/Desktop Bridge 下保持相同界面、请求和
const workspace = page.getByRole('region', { name: '视频下载 操作区' });
const panel = page.getByRole('complementary', { name: 'OpenCreator' });
- await expect(workspace.getByRole('textbox', { name: '待下载视频链接' }))
- .toHaveValue('https://www.youtube.com/watch?v=OpenCreatorParity');
+ const sources = workspace.getByRole('list', { name: '视频链接列表' });
+ await expect(sources).toContainText('https://www.youtube.com/watch?v=OpenCreatorParity');
await expect(panel).toContainText('YouTube · 待解析');
+ await expect(workspace.getByText('正在加载链接列表')).toHaveCount(0);
+ await sources.getByRole('button', { name: /^移除链接/ }).click();
+ await expect(sources).toHaveCount(0);
+ await workspace.getByRole('textbox', { name: '视频链接', exact: true })
+ .fill('https://www.youtube.com/watch?v=OpenCreatorParity');
+ await workspace.getByRole('button', { name: '添加并解析' }).click();
+ await expect(sources.getByRole('listitem')).toHaveCount(1);
+ await expect(workspace.getByRole('textbox', { name: '视频链接', exact: true })).toHaveCount(0);
const boxes: Record<
string,
@@ -1277,7 +1285,7 @@ test('视频下载在 Browser/Desktop Bridge 下保持相同界面、请求和
for (const [name, locator] of [
['workspace', workspace],
['panel', panel],
- ['source-input', workspace.getByRole('textbox', { name: '待下载视频链接' })]
+ ['source-list', sources]
] as const) {
const box = await locator.boundingBox();
expect(box, `${platform} 缺少 ${name} 尺寸目标`).not.toBeNull();
@@ -2106,6 +2114,7 @@ test('第三方组件设置在 Browser/Desktop Bridge 下保持相同状态、
});
test('工作台模块新建 Creator Job,刷新和最近项目精确恢复历史且不启动普通 Codex Run', async ({ page, runtime }) => {
+ await stubVideoDownloadProbe(page, runtime);
await page.route(
/^https:\/\/i\.ytimg\.com\/vi\/OpenCreator(?:Demo|Second)\/maxresdefault\.jpg$/,
route => route.fulfill({
@@ -2121,15 +2130,19 @@ test('工作台模块新建 Creator Job,刷新和最近项目精确恢复历
await expect(page.getByRole('heading', { name: '工作台' })).toBeVisible();
await page.getByRole('button', { name: /^视频下载/ }).click();
- const input = page.getByRole('textbox', { name: '待下载视频链接' });
+ const input = page.getByRole('textbox', { name: '视频链接', exact: true });
await expect(input).toBeVisible();
await input.fill('https://www.youtube.com/watch?v=OpenCreatorDemo');
+ await page.getByRole('button', { name: '添加并解析' }).click();
await expect(page).toHaveURL(/#\/workbench\?tool=video-download&jobId=creator_job_/);
const firstJobId = new URL(page.url()).hash.match(/jobId=([^&]+)/)?.[1];
expect(firstJobId).toBeTruthy();
+ const mobileAgentTab = page.getByRole('tab', { name: 'Agent', exact: true });
+ if (await mobileAgentTab.isVisible()) await mobileAgentTab.click();
await expect(page.getByRole('complementary', { name: 'OpenCreator' }))
.toContainText('YouTube');
+ if (await mobileAgentTab.isVisible()) await page.getByRole('tab', { name: '创作', exact: true }).click();
await expect.poll(async () => {
const listed = await runtime.api<{
jobs: Array<{ id: string; templateId: string; state: Record<string, unknown> }>;
@@ -2144,18 +2157,30 @@ test('工作台模块新建 Creator Job,刷新和最近项目精确恢复历
}).toBe(1);
expect(runtime.readInvocationCount()).toBe(0);
+ await page.getByRole('button', { name: '添加链接', exact: true }).click();
+ await input.fill('https://www.youtube.com/watch?v=OpenCreatorChild');
+ await page.getByRole('button', { name: '添加并解析' }).click();
+ await expect(page.getByRole('list', { name: '视频链接列表' }).getByRole('listitem')).toHaveCount(2);
+ const children = await runtime.api<{ jobs: Array<{ state: Record<string, unknown> }> }>(
+ 'GET', `/creator/jobs?projectId=${encodeURIComponent(runtime.projectId)}`
+ );
+ expect(children.jobs.find(job => job.state.sourceUrl === 'https://www.youtube.com/watch?v=OpenCreatorChild')?.state.downloadBatchId)
+ .toBe(decodeURIComponent(firstJobId!));
+
await page.reload();
await expect(page.getByRole('heading', { name: '视频下载' })).toBeVisible();
- await expect(page.getByRole('textbox', { name: '待下载视频链接' }))
- .toHaveValue('https://www.youtube.com/watch?v=OpenCreatorDemo');
+ await expect(page.getByRole('list', { name: '视频链接列表' }).getByRole('listitem')).toHaveCount(2);
+ await expect(page.getByRole('list', { name: '视频链接列表' }))
+ .toContainText('https://www.youtube.com/watch?v=OpenCreatorDemo');
await page.getByRole('region', { name: '视频下载 操作区' })
.getByRole('button', { name: '返回', exact: true })
.click();
await page.getByRole('button', { name: /^视频下载/ }).click();
- await expect(page.getByRole('textbox', { name: '待下载视频链接' })).toHaveValue('');
- await page.getByRole('textbox', { name: '待下载视频链接' })
+ await expect(page.getByRole('textbox', { name: '视频链接', exact: true })).toHaveValue('');
+ await page.getByRole('textbox', { name: '视频链接', exact: true })
.fill('https://www.youtube.com/watch?v=OpenCreatorSecond');
+ await page.getByRole('button', { name: '添加并解析' }).click();
await expect(page).toHaveURL(/#\/workbench\?tool=video-download&jobId=creator_job_/);
const secondJobId = new URL(page.url()).hash.match(/jobId=([^&]+)/)?.[1];
expect(secondJobId).toBeTruthy();
@@ -2165,13 +2190,14 @@ test('工作台模块新建 Creator Job,刷新和最近项目精确恢复历
jobs: Array<{ templateId: string }>;
}>('GET', `/creator/jobs?projectId=${encodeURIComponent(runtime.projectId)}`);
return listed.jobs.filter(job => job.templateId === 'video-download').length;
- }).toBe(2);
+ }).toBe(3);
await page.goto(`${runtime.origin}/#/projects`);
await page.getByRole('button', { name: '打开项目 youtube.com · OpenCreatorDemo' }).click();
await expect(page).toHaveURL(new RegExp(`jobId=${firstJobId}`));
- await expect(page.getByRole('textbox', { name: '待下载视频链接' }))
- .toHaveValue('https://www.youtube.com/watch?v=OpenCreatorDemo');
+ await expect(page.getByRole('list', { name: '视频链接列表' }).getByRole('listitem')).toHaveCount(2);
+ await expect(page.getByRole('list', { name: '视频链接列表' }))
+ .toContainText('https://www.youtube.com/watch?v=OpenCreatorDemo');
});
test('图像生成在桌面和移动视口创建、持久化并从项目中心恢复 Creator Job', async ({
diff --git a/apps/web/src/features/dashboard/DashboardPage.test.tsx b/apps/web/src/features/dashboard/DashboardPage.test.tsx
index 0e4d7d7b..c8f0bb43 100644
--- a/apps/web/src/features/dashboard/DashboardPage.test.tsx
+++ b/apps/web/src/features/dashboard/DashboardPage.test.tsx
@@ -987,7 +987,7 @@ describe('DashboardPage', () => {
expect(screen.getByRole('heading', { name: '视频翻译配音' })).toBeInTheDocument();
expect(screen.getByRole('complementary', { name: 'OpenCreator' })).toBeInTheDocument();
expect(screen.getByRole('heading', { name: '拖放视频到这里' })).toBeInTheDocument();
- expect(screen.getByRole('list', { name: '支持的平台' }).querySelectorAll('li')).toHaveLength(9);
+ expect(screen.getByRole('list', { name: '支持的平台' }).querySelectorAll('li')).toHaveLength(10);
fireEvent.change(screen.getByRole('textbox', { name: '视频链接' }), {
target: { value: 'https://www.youtube.com/watch?v=test' }
});
@@ -1140,18 +1140,22 @@ describe('DashboardPage', () => {
});
it('submits public video link analysis from the dashboard', async () => {
- render(<DashboardPage onSelectPrompt={vi.fn()} />);
+ const creatorService = createInMemoryCreatorService();
+ const applyAction = vi.spyOn(creatorService, 'applyAction');
+ render(<DashboardPage onSelectPrompt={vi.fn()} creatorService={creatorService} />);
openBlankWorkspace('视频下载', '空白视频下载');
expect(screen.getByRole('heading', { name: '视频下载' })).toBeInTheDocument();
- fireEvent.change(screen.getByRole('textbox', { name: '待下载视频链接' }), {
+ fireEvent.change(screen.getByRole('textbox', { name: '视频链接' }), {
target: { value: 'https://www.youtube.com/watch?v=download-test' }
});
- fireEvent.click(screen.getByRole('button', { name: '解析链接' }));
+ fireEvent.click(screen.getByRole('button', { name: '添加并解析' }));
- expect(await screen.findByText('解析任务已提交,真实规格返回后会自动显示'))
- .toBeInTheDocument();
- expect(screen.queryByRole('tab', { name: '下载规格' })).not.toBeInTheDocument();
+ await waitFor(() => expect(applyAction).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({
+ action: 'run-stage', input: { stageId: 'probe' }
+ })));
+ expect(await screen.findByRole('list', { name: '视频链接列表' })).toHaveTextContent('https://www.youtube.com/watch?v=download-test');
+ expect(screen.getByRole('tab', { name: '下载规格' })).toBeInTheDocument();
});
it('opens the runtime-backed stickman workspace from the dashboard', async () => {