| @@ -34,9 +34,15 @@ async function countGeneratorRatioRows(page: Page) { | |||
| async function fetchModelPricing( | |||
| request: APIRequestContext, | |||
| model: string, | |||
| userId: number, | |||
| ): Promise<ModelPricingConfig> { | |||
| const response = await request.get( | |||
| `/api/option/model_pricing/${encodeURIComponent(model)}`, | |||
| { | |||
| headers: { | |||
| 'New-API-User': String(userId), | |||
| }, | |||
| }, | |||
| ); | |||
| expect(response.ok()).toBeTruthy(); | |||
| return (await response.json()) as ModelPricingConfig; | |||
| @@ -70,9 +76,9 @@ test.describe.serial('Model Pricing E2E', () => { | |||
| await fillByTestId(page, 'generator-base-price', '0.2'); | |||
| const generator = page.getByTestId('model-pricing-generator'); | |||
| await generator.locator('input[value="replace_all"]').check({ force: true }); | |||
| await generator.getByTestId('generator-strategy-replace-all').click(); | |||
| const qualityRowIndex = (await countGeneratorRatioRows(page)) - 1; | |||
| await fillByTestId(page, `generator-ratio-value-${qualityRowIndex}`, 'standard'); | |||
| await fillByTestId(page, `generator-ratio-value-${qualityRowIndex}`, '2'); | |||
| await fillByTestId(page, `generator-ratio-ratio-${qualityRowIndex}`, '1.5'); | |||
| await expect(page.getByTestId('generator-apply')).toBeEnabled(); | |||
| await page.getByTestId('generator-apply').click(); | |||
| @@ -99,7 +105,13 @@ test.describe.serial('Model Pricing E2E', () => { | |||
| await page.getByTestId(`model-pricing-edit-${model}`).click(); | |||
| await expect(page.getByTestId('model-pricing-editor')).toBeVisible(); | |||
| const data = await fetchModelPricing(request, model); | |||
| const rootUserId = await page.evaluate(() => { | |||
| const user = window.localStorage.getItem('user'); | |||
| return user ? JSON.parse(user).id : null; | |||
| }); | |||
| expect(typeof rootUserId).toBe('number'); | |||
| const data = await fetchModelPricing(request, model, rootUserId as number); | |||
| expect(data.success).toBe(true); | |||
| expect(data.data.schema_version).toBe(1); | |||
| expect(data.data.scope).toBe('model'); | |||
| @@ -2,6 +2,8 @@ import { defineConfig } from '@playwright/test'; | |||
| import path from 'node:path'; | |||
| import { cnBaseURL, playwrightArtifactRoot } from './e2e/fixtures/cluster'; | |||
| const chromiumExecutablePath = process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH; | |||
| export default defineConfig({ | |||
| testDir: './e2e', | |||
| testMatch: ['**/*.spec.ts', '**/*.spec.js'], | |||
| @@ -27,6 +29,11 @@ export default defineConfig({ | |||
| use: { | |||
| baseURL: cnBaseURL, | |||
| headless: true, | |||
| launchOptions: chromiumExecutablePath | |||
| ? { | |||
| executablePath: chromiumExecutablePath, | |||
| } | |||
| : undefined, | |||
| screenshot: 'only-on-failure', | |||
| trace: 'retain-on-failure', | |||
| video: 'retain-on-failure', | |||
| @@ -118,7 +118,6 @@ export default function GeneratorModal({ visible, dimensions, billingUnit, exist | |||
| return ( | |||
| <Modal | |||
| visible={visible} | |||
| data-testid='model-pricing-generator' | |||
| title={t('生成价格表')} | |||
| onCancel={onCancel} | |||
| width={920} | |||
| @@ -131,7 +130,7 @@ export default function GeneratorModal({ visible, dimensions, billingUnit, exist | |||
| </Space> | |||
| } | |||
| > | |||
| <Space vertical align='start' style={{ width: '100%' }}> | |||
| <Space vertical align='start' style={{ width: '100%' }} data-testid='model-pricing-generator'> | |||
| <Typography.Text> | |||
| {t('基础价格是所有倍率计算的起点,当前单位为 {{unitLabel}}。最终价格 = 基础价格 × 各维度倍率。', { unitLabel })} | |||
| </Typography.Text> | |||
| @@ -152,8 +151,12 @@ export default function GeneratorModal({ visible, dimensions, billingUnit, exist | |||
| data-testid='generator-base-price' | |||
| /> | |||
| <Radio.Group value={strategy} onChange={(event) => setStrategy(event.target.value)}> | |||
| <Radio value='preserve_manual'>{t('保留手动行')}</Radio> | |||
| <Radio value='replace_all'>{t('全部替换')}</Radio> | |||
| <Radio value='preserve_manual' data-testid='generator-strategy-preserve-manual'> | |||
| {t('保留手动行')} | |||
| </Radio> | |||
| <Radio value='replace_all' data-testid='generator-strategy-replace-all'> | |||
| {t('全部替换')} | |||
| </Radio> | |||
| </Radio.Group> | |||
| </Space> | |||
| <Table columns={ratioColumns} dataSource={ratioEntries} pagination={false} rowKey={(_, index) => `${index}`} /> | |||