From 4e42465c3870dfdc10bb7e7c7de98d5a647630e0 Mon Sep 17 00:00:00 2001 From: zhangxiang Date: Thu, 9 Apr 2026 19:20:15 +0800 Subject: [PATCH] feat(test): add test data factory for journey tests --- e2e/fixtures/test-data-factory.ts | 98 +++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 e2e/fixtures/test-data-factory.ts diff --git a/e2e/fixtures/test-data-factory.ts b/e2e/fixtures/test-data-factory.ts new file mode 100644 index 0000000..6d767bf --- /dev/null +++ b/e2e/fixtures/test-data-factory.ts @@ -0,0 +1,98 @@ +export interface ContentData { + type: 'news' | 'product' | 'service' | 'case'; + title: string; + slug: string; + excerpt?: string; + content?: string; + category?: string; + tags?: string[]; + status?: 'draft' | 'published' | 'archived'; +} + +export interface ContactFormData { + name: string; + email: string; + phone?: string; + company?: string; + message: string; +} + +export class TestDataFactory { + private static counter = 0; + + private static getTimestamp(): string { + return `${Date.now()}-${++this.counter}`; + } + + static createNews(overrides?: Partial): ContentData { + const timestamp = this.getTimestamp(); + return { + type: 'news', + title: `测试新闻-${timestamp}`, + slug: `test-news-${timestamp}`, + excerpt: '这是一条测试新闻的摘要内容', + content: '

这是测试新闻的正文内容

', + category: '公司新闻', + tags: ['测试', '自动化'], + status: 'published', + ...overrides, + }; + } + + static createProduct(overrides?: Partial): ContentData { + const timestamp = this.getTimestamp(); + return { + type: 'product', + title: `测试产品-${timestamp}`, + slug: `test-product-${timestamp}`, + excerpt: '这是一个测试产品的描述', + content: '

测试产品的详细介绍

', + category: '软件产品', + tags: ['产品', '测试'], + status: 'published', + ...overrides, + }; + } + + static createService(overrides?: Partial): ContentData { + const timestamp = this.getTimestamp(); + return { + type: 'service', + title: `测试服务-${timestamp}`, + slug: `test-service-${timestamp}`, + excerpt: '这是一个测试服务的描述', + content: '

测试服务的详细介绍

', + category: '软件开发', + tags: ['服务', '测试'], + status: 'published', + ...overrides, + }; + } + + static createCase(overrides?: Partial): ContentData { + const timestamp = this.getTimestamp(); + return { + type: 'case', + title: `测试案例-${timestamp}`, + slug: `test-case-${timestamp}`, + excerpt: '这是一个测试案例的描述', + content: '

测试案例的详细介绍

', + category: '企业服务', + tags: ['案例', '测试'], + status: 'published', + ...overrides, + }; + } + + static createContactForm(overrides?: Partial): ContactFormData { + const timestamp = this.getTimestamp(); + return { + name: `测试用户-${timestamp}`, + email: `test-${timestamp}@example.com`, + phone: '13800138000', + company: '测试公司', + message: '这是一条测试咨询留言', + ...overrides, + }; + } +}