import { expect, test } from '@playwright/test'; const packageTemplate = { package_id: 'template-package', name: '标准到店服务', category: '通用服务', description: '顾客到店完成一次标准服务。', tags: ['到店', '标准服务'], service_modes: ['at_store'], price_mode: 'fixed', currency: 'CNY', price_unit: 'per_service', min_price: '200.00', max_price: '200.00', duration_minutes: 60, included_items: '一次标准服务', excluded_items: '额外耗材', preparation: '请提前说明需求', addons: [], travel_fee: { mode: 'included', amount: '0', per_km: '0', description: '无额外费用', }, service_radius_km: null, out_of_range_policy: '', source_type: 'template', }; test.beforeEach(async ({ page }) => { await page.route('https://telegram.org/js/telegram-web-app.js', (route) => route.fulfill({ contentType: 'application/javascript', body: ` window.Telegram = { WebApp: { initData: 'signed-test-init-data', ready() {}, expand() {}, close() {}, setHeaderColor() {}, setBackgroundColor() {} } }; `, }), ); await page.route('**/api/technician/v1/**', async (route) => { const headers = route.request().headers(); expect(headers['x-telegram-bot-id']).toBe('primary'); expect(headers['x-telegram-init-data']).toBe('signed-test-init-data'); const path = new URL(route.request().url()).pathname; if (path.endsWith('/bootstrap')) { return route.fulfill({ contentType: 'application/json', body: JSON.stringify({ data: { technician: { user_id: '700', display_name: '测试技师', username: 'technician700', eligibility: { ready: true, issues: [] }, service_profile: null, }, templates: [ { template_id: 'builtin_quick_at_store', version: 1, name: '快速到店服务', builtin: true, package: packageTemplate, }, ], limits: { max_packages: 5 }, }, }), }); } return route.fulfill({ contentType: 'application/json', body: JSON.stringify({ data: {} }), }); }); }); test('技师可从模板快速进入五项发布表单', async ({ page }) => { await page.goto('/admin/technician?bot_id=primary'); await expect(page.getByRole('heading', { name: '你好,测试技师' })).toBeVisible(); await expect(page.getByRole('button', { name: /快速到店服务/ })).toBeVisible(); await page.getByRole('button', { name: /快速到店服务/ }).click(); await expect(page.getByRole('heading', { name: '发布服务' })).toBeVisible(); await expect(page.getByText('约 30 秒')).toBeVisible(); await expect(page.getByLabel('服务名称')).toHaveValue('标准到店服务'); await expect(page.getByLabel('服务价格')).toHaveValue('CNY 200.00/次'); await expect(page.getByLabel('服务内容')).toHaveValue('顾客到店完成一次标准服务。'); await expect(page.getByLabel('额外费用说明')).toHaveValue('无额外费用'); await expect(page.getByLabel('大概服务区域')).toBeVisible(); await expect(page.getByText('per_service')).toHaveCount(0); await expect(page.getByRole('button', { name: /直接发布/ })).toBeVisible(); });