Kaynağa Gözat

test: stabilize model pricing e2e runtime

master
fengsilin 3 hafta önce
ebeveyn
işleme
99168a9660
3 değiştirilmiş dosya ile 29 ekleme ve 7 silme
  1. +15
    -3
      web/e2e/model-pricing.spec.ts
  2. +7
    -0
      web/playwright.config.ts
  3. +7
    -4
      web/src/pages/Setting/Operation/ModelPricing/GeneratorModal.jsx

+ 15
- 3
web/e2e/model-pricing.spec.ts Dosyayı Görüntüle

@@ -34,9 +34,15 @@ async function countGeneratorRatioRows(page: Page) {
async function fetchModelPricing( async function fetchModelPricing(
request: APIRequestContext, request: APIRequestContext,
model: string, model: string,
userId: number,
): Promise<ModelPricingConfig> { ): Promise<ModelPricingConfig> {
const response = await request.get( const response = await request.get(
`/api/option/model_pricing/${encodeURIComponent(model)}`, `/api/option/model_pricing/${encodeURIComponent(model)}`,
{
headers: {
'New-API-User': String(userId),
},
},
); );
expect(response.ok()).toBeTruthy(); expect(response.ok()).toBeTruthy();
return (await response.json()) as ModelPricingConfig; return (await response.json()) as ModelPricingConfig;
@@ -70,9 +76,9 @@ test.describe.serial('Model Pricing E2E', () => {
await fillByTestId(page, 'generator-base-price', '0.2'); await fillByTestId(page, 'generator-base-price', '0.2');


const generator = page.getByTestId('model-pricing-generator'); 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; 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 fillByTestId(page, `generator-ratio-ratio-${qualityRowIndex}`, '1.5');
await expect(page.getByTestId('generator-apply')).toBeEnabled(); await expect(page.getByTestId('generator-apply')).toBeEnabled();
await page.getByTestId('generator-apply').click(); 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 page.getByTestId(`model-pricing-edit-${model}`).click();
await expect(page.getByTestId('model-pricing-editor')).toBeVisible(); 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.success).toBe(true);
expect(data.data.schema_version).toBe(1); expect(data.data.schema_version).toBe(1);
expect(data.data.scope).toBe('model'); expect(data.data.scope).toBe('model');


+ 7
- 0
web/playwright.config.ts Dosyayı Görüntüle

@@ -2,6 +2,8 @@ import { defineConfig } from '@playwright/test';
import path from 'node:path'; import path from 'node:path';
import { cnBaseURL, playwrightArtifactRoot } from './e2e/fixtures/cluster'; import { cnBaseURL, playwrightArtifactRoot } from './e2e/fixtures/cluster';


const chromiumExecutablePath = process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH;

export default defineConfig({ export default defineConfig({
testDir: './e2e', testDir: './e2e',
testMatch: ['**/*.spec.ts', '**/*.spec.js'], testMatch: ['**/*.spec.ts', '**/*.spec.js'],
@@ -27,6 +29,11 @@ export default defineConfig({
use: { use: {
baseURL: cnBaseURL, baseURL: cnBaseURL,
headless: true, headless: true,
launchOptions: chromiumExecutablePath
? {
executablePath: chromiumExecutablePath,
}
: undefined,
screenshot: 'only-on-failure', screenshot: 'only-on-failure',
trace: 'retain-on-failure', trace: 'retain-on-failure',
video: 'retain-on-failure', video: 'retain-on-failure',


+ 7
- 4
web/src/pages/Setting/Operation/ModelPricing/GeneratorModal.jsx Dosyayı Görüntüle

@@ -118,7 +118,6 @@ export default function GeneratorModal({ visible, dimensions, billingUnit, exist
return ( return (
<Modal <Modal
visible={visible} visible={visible}
data-testid='model-pricing-generator'
title={t('生成价格表')} title={t('生成价格表')}
onCancel={onCancel} onCancel={onCancel}
width={920} width={920}
@@ -131,7 +130,7 @@ export default function GeneratorModal({ visible, dimensions, billingUnit, exist
</Space> </Space>
} }
> >
<Space vertical align='start' style={{ width: '100%' }}>
<Space vertical align='start' style={{ width: '100%' }} data-testid='model-pricing-generator'>
<Typography.Text> <Typography.Text>
{t('基础价格是所有倍率计算的起点,当前单位为 {{unitLabel}}。最终价格 = 基础价格 × 各维度倍率。', { unitLabel })} {t('基础价格是所有倍率计算的起点,当前单位为 {{unitLabel}}。最终价格 = 基础价格 × 各维度倍率。', { unitLabel })}
</Typography.Text> </Typography.Text>
@@ -152,8 +151,12 @@ export default function GeneratorModal({ visible, dimensions, billingUnit, exist
data-testid='generator-base-price' data-testid='generator-base-price'
/> />
<Radio.Group value={strategy} onChange={(event) => setStrategy(event.target.value)}> <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> </Radio.Group>
</Space> </Space>
<Table columns={ratioColumns} dataSource={ratioEntries} pagination={false} rowKey={(_, index) => `${index}`} /> <Table columns={ratioColumns} dataSource={ratioEntries} pagination={false} rowKey={(_, index) => `${index}`} />


Yükleniyor…
İptal
Kaydet