Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 50 additions & 15 deletions tests/e2e/features/model-limits/pages/model-limits.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ import { expect } from '../../../core/fixtures/base.fixture'
import { BasePage } from '../../../core/pages/base.page'
import { fillSelect, waitForNetworkIdle } from '../../../core/utils/test-helpers'

const resetPeriodLabels: Record<string, string> = {
'1m': 'Every Minute',
'5m': 'Every 5 Minutes',
'15m': 'Every 15 Minutes',
'30m': 'Every 30 Minutes',
'1h': 'Hourly',
'6h': 'Every 6 Hours',
'1d': 'Daily',
'1w': 'Weekly',
'1M': 'Monthly',
}

export interface ModelLimitConfig {
provider: string
modelName: string
Expand All @@ -17,6 +29,10 @@ function toTestIdPart(value: string): string {
return value.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '')
}

function escapeRegex(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
}

export class ModelLimitsPage extends BasePage {
readonly createBtn: Locator
readonly table: Locator
Expand Down Expand Up @@ -72,6 +88,31 @@ export class ModelLimitsPage extends BasePage {
.catch(() => {})
}

private async setBudget(config?: { maxLimit: number; resetDuration?: string }): Promise<void> {
if (!config) return

const budgetLines = this.page.locator('[data-testid^="model-limit-budget-lines-line-"]')
const existingCount = await budgetLines.count()
if (existingCount === 0) {
await this.page.getByTestId('model-limit-budget-lines-add-btn').click()
}

const budgetInput = this.page.getByTestId('model-limit-budget-lines-amount-0')
await budgetInput.click()
await budgetInput.fill('')
await budgetInput.pressSequentially(String(config.maxLimit))

if (config.resetDuration) {
const resetPeriodLabel = resetPeriodLabels[config.resetDuration]
if (!resetPeriodLabel) {
throw new Error(`unsupported resetDuration: ${config.resetDuration}`)
}
const budgetLine = this.page.getByTestId('model-limit-budget-lines-line-0')
await budgetLine.getByRole('combobox').click()
await this.page.getByRole('option', { name: resetPeriodLabel }).click()
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

/**
* Create a model limit via the sheet: selects provider, selects the requested
* model (config.modelName) in the search dropdown, fills budget and rate
Expand All @@ -89,20 +130,18 @@ export class ModelLimitsPage extends BasePage {
config.provider === 'all' ? 'All Providers' : config.provider
)

// Model multiselect - search and select requested model deterministically
// Model select - type and pick the requested model from the results
const modelSelectContainer = this.sheet.getByTestId('model-limit-model-select')
const modelInput = modelSelectContainer.locator('input')
await modelInput.fill(config.modelName)
await this.page.waitForSelector('[role="option"]', { timeout: 10000 })
const targetOption = this.page.getByRole('option', { name: config.modelName, exact: true })
const modelInput = modelSelectContainer.getByRole('combobox')
await modelInput.click()
await modelInput.pressSequentially(config.modelName)
const targetOption = this.page.getByRole('option', { name: config.modelName, exact: true }).first()
await expect(targetOption).toBeVisible({ timeout: 10000 })
await targetOption.click()
await this.page.keyboard.press('Tab')
const selectedModelName = config.modelName

Comment thread
coderabbitai[bot] marked this conversation as resolved.
if (config.budget?.maxLimit !== undefined) {
const budgetInput = this.page.locator('#modelBudgetMaxLimit')
await budgetInput.fill(String(config.budget.maxLimit))
}
await this.setBudget(config.budget)

if (config.rateLimit?.tokenMaxLimit !== undefined) {
await this.page.locator('#modelTokenMaxLimit').fill(String(config.rateLimit.tokenMaxLimit))
Expand All @@ -127,11 +166,7 @@ export class ModelLimitsPage extends BasePage {
await expect(this.sheet).toBeVisible({ timeout: 5000 })
await this.waitForSheetAnimation()

if (updates.budget?.maxLimit !== undefined) {
const budgetInput = this.page.locator('#modelBudgetMaxLimit')
await budgetInput.clear()
await budgetInput.fill(String(updates.budget.maxLimit))
}
await this.setBudget(updates.budget)

if (updates.rateLimit?.tokenMaxLimit !== undefined) {
const tokenInput = this.page.locator('#modelTokenMaxLimit')
Expand Down Expand Up @@ -171,4 +206,4 @@ export class ModelLimitsPage extends BasePage {
await expect(this.sheet).not.toBeVisible({ timeout: 5000 }).catch(() => {})
}
}
}
}
Loading