feat: 前端集成 Prettier 代码格式化
This commit is contained in:
@@ -27,9 +27,7 @@ export interface SeedStatsInput {
|
||||
date: string
|
||||
}
|
||||
|
||||
export async function clearDatabase(
|
||||
request: import('@playwright/test').APIRequestContext,
|
||||
) {
|
||||
export async function clearDatabase(request: import('@playwright/test').APIRequestContext) {
|
||||
const providers = await request.get(`${API_BASE}/api/providers`)
|
||||
if (providers.ok()) {
|
||||
const data = await providers.json()
|
||||
@@ -39,10 +37,7 @@ export async function clearDatabase(
|
||||
}
|
||||
}
|
||||
|
||||
export async function seedProvider(
|
||||
request: import('@playwright/test').APIRequestContext,
|
||||
data: SeedProviderInput,
|
||||
) {
|
||||
export async function seedProvider(request: import('@playwright/test').APIRequestContext, data: SeedProviderInput) {
|
||||
const resp = await request.post(`${API_BASE}/api/providers`, {
|
||||
data: {
|
||||
id: data.id,
|
||||
@@ -59,10 +54,7 @@ export async function seedProvider(
|
||||
return resp.json()
|
||||
}
|
||||
|
||||
export async function seedModel(
|
||||
request: import('@playwright/test').APIRequestContext,
|
||||
data: SeedModelInput,
|
||||
) {
|
||||
export async function seedModel(request: import('@playwright/test').APIRequestContext, data: SeedModelInput) {
|
||||
const resp = await request.post(`${API_BASE}/api/models`, {
|
||||
data: {
|
||||
provider_id: data.providerId,
|
||||
@@ -80,20 +72,22 @@ export async function seedUsageStats(statsData: SeedStatsInput[]) {
|
||||
const tempDir = path.join(os.tmpdir(), 'nex-e2e')
|
||||
|
||||
const dbPath = path.join(tempDir, 'test.db')
|
||||
|
||||
|
||||
if (!fs.existsSync(dbPath)) {
|
||||
throw new Error(`Database file not found at ${dbPath}. Backend may not have created it yet.`)
|
||||
}
|
||||
|
||||
|
||||
const SQL = await initSqlite()
|
||||
const buf = fs.readFileSync(dbPath)
|
||||
const db = new SQL.Database(buf)
|
||||
|
||||
for (const row of statsData) {
|
||||
db.run(
|
||||
'INSERT OR REPLACE INTO usage_stats (provider_id, model_name, request_count, date) VALUES (?, ?, ?, ?)',
|
||||
[row.providerId, row.modelName, row.requestCount, row.date],
|
||||
)
|
||||
db.run('INSERT OR REPLACE INTO usage_stats (provider_id, model_name, request_count, date) VALUES (?, ?, ?, ?)', [
|
||||
row.providerId,
|
||||
row.modelName,
|
||||
row.requestCount,
|
||||
row.date,
|
||||
])
|
||||
}
|
||||
|
||||
const data = db.export()
|
||||
|
||||
@@ -47,18 +47,25 @@ test.describe('模型管理', () => {
|
||||
await page.locator('.t-table__expand-box').first().click()
|
||||
await expect(page.locator('.t-table__expanded-row').first()).toBeVisible()
|
||||
|
||||
await page.locator('.t-dialog:visible').waitFor({ state: 'hidden', timeout: 3000 }).catch(() => {})
|
||||
|
||||
await page
|
||||
.locator('.t-dialog:visible')
|
||||
.waitFor({ state: 'hidden', timeout: 3000 })
|
||||
.catch(() => {})
|
||||
|
||||
await page.locator('.t-table__expanded-row button:has-text("添加模型")').first().click()
|
||||
await expect(page.locator('.t-dialog:visible')).toBeVisible()
|
||||
|
||||
const inputs = modelFormInputs(page)
|
||||
await inputs.modelName.fill('gpt_4_turbo')
|
||||
|
||||
const responsePromise = page.waitForResponse(resp => resp.url().includes('/api/models') && resp.request().method() === 'POST')
|
||||
|
||||
const responsePromise = page.waitForResponse(
|
||||
(resp) => resp.url().includes('/api/models') && resp.request().method() === 'POST'
|
||||
)
|
||||
await inputs.saveBtn.click()
|
||||
await responsePromise
|
||||
await expect(page.locator('.t-table__expanded-row').getByText('gpt_4_turbo', { exact: true })).toBeVisible({ timeout: 5000 })
|
||||
await expect(page.locator('.t-table__expanded-row').getByText('gpt_4_turbo', { exact: true })).toBeVisible({
|
||||
timeout: 5000,
|
||||
})
|
||||
})
|
||||
|
||||
test('应显示统一模型 ID', async ({ page, request }) => {
|
||||
@@ -100,11 +107,15 @@ test.describe('模型管理', () => {
|
||||
const inputs = modelFormInputs(page)
|
||||
await inputs.modelName.clear()
|
||||
await inputs.modelName.fill('gpt_4o')
|
||||
|
||||
const responsePromise = page.waitForResponse(resp => resp.url().includes('/api/models') && resp.request().method() === 'PUT')
|
||||
|
||||
const responsePromise = page.waitForResponse(
|
||||
(resp) => resp.url().includes('/api/models') && resp.request().method() === 'PUT'
|
||||
)
|
||||
await inputs.saveBtn.click()
|
||||
await responsePromise
|
||||
await expect(page.locator('.t-table__expanded-row').getByText('gpt_4o', { exact: true })).toBeVisible({ timeout: 5000 })
|
||||
await expect(page.locator('.t-table__expanded-row').getByText('gpt_4o', { exact: true })).toBeVisible({
|
||||
timeout: 5000,
|
||||
})
|
||||
})
|
||||
|
||||
test('应能删除模型', async ({ page, request }) => {
|
||||
@@ -126,6 +137,8 @@ test.describe('模型管理', () => {
|
||||
await page.locator('.t-table__expanded-row button:has-text("删除")').first().click()
|
||||
await expect(page.getByText(/确定要删除/)).toBeVisible()
|
||||
await page.locator('.t-popconfirm').getByRole('button', { name: '确定' }).click()
|
||||
await expect(page.locator('.t-table__expanded-row').getByText('to_delete_model', { exact: true })).not.toBeVisible({ timeout: 5000 })
|
||||
await expect(page.locator('.t-table__expanded-row').getByText('to_delete_model', { exact: true })).not.toBeVisible({
|
||||
timeout: 5000,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -43,7 +43,7 @@ test.describe('供应商管理', () => {
|
||||
await page.waitForSelector('.t-select__dropdown', { state: 'hidden', timeout: 3000 })
|
||||
|
||||
await inputs.saveBtn.click()
|
||||
|
||||
|
||||
await expect(page.locator('.t-table__body').getByText('Test Provider')).toBeVisible({ timeout: 10000 })
|
||||
})
|
||||
|
||||
@@ -60,8 +60,10 @@ test.describe('供应商管理', () => {
|
||||
await page.waitForSelector('.t-select__dropdown', { timeout: 3000 })
|
||||
await page.locator('.t-select__dropdown .t-select-option').first().click()
|
||||
await page.waitForSelector('.t-select__dropdown', { state: 'hidden', timeout: 3000 })
|
||||
|
||||
const responsePromise = page.waitForResponse(resp => resp.url().includes('/api/providers') && resp.request().method() === 'POST')
|
||||
|
||||
const responsePromise = page.waitForResponse(
|
||||
(resp) => resp.url().includes('/api/providers') && resp.request().method() === 'POST'
|
||||
)
|
||||
await inputs.saveBtn.click()
|
||||
await responsePromise
|
||||
await expect(page.locator('.t-table__body').getByText('Before Edit')).toBeVisible({ timeout: 5000 })
|
||||
@@ -72,8 +74,10 @@ test.describe('供应商管理', () => {
|
||||
const editInputs = formInputs(page)
|
||||
await editInputs.name.clear()
|
||||
await editInputs.name.fill('After Edit')
|
||||
|
||||
const updateResponsePromise = page.waitForResponse(resp => resp.url().includes('/api/providers') && resp.request().method() === 'PUT')
|
||||
|
||||
const updateResponsePromise = page.waitForResponse(
|
||||
(resp) => resp.url().includes('/api/providers') && resp.request().method() === 'PUT'
|
||||
)
|
||||
await editInputs.saveBtn.click()
|
||||
await updateResponsePromise
|
||||
await expect(page.locator('.t-table__body').getByText('After Edit')).toBeVisible({ timeout: 5000 })
|
||||
|
||||
Reference in New Issue
Block a user