Files
shumai/apps/web/e2e/tests/team/provider-model-refresh.spec.ts
T

104 lines
3.5 KiB
TypeScript
Raw Normal View History

import type { RefreshedProviderModel } from '@shumai/dtos'
import { expect, test } from '../../fixtures'
test('provider cards show credential status and open a scrollable preview for the selected provider', async ({
owner,
prisma,
}) => {
const { page, teamId } = owner
const provider = await prisma.provider.create({
data: {
teamId,
name: 'OpenAI production',
config: {
api: 'openai-responses',
baseUrl: 'https://api.openai.com/v1',
apiKey: 'saved-test-key',
},
},
})
const missing = await prisma.provider.create({
data: {
teamId,
name: 'Anthropic staging',
config: {
api: 'anthropic-messages',
baseUrl: 'https://api.anthropic.com',
apiKey: 'UNSET_E2E_ANTHROPIC_KEY',
},
},
})
const models = Array.from({ length: 48 }, (_, index): RefreshedProviderModel => ({
modelId: `test-model-${index + 1}`,
name: `Test Model ${index + 1}`,
selectionToken: `preview-token-${index + 1}`,
config: {
reasoning: false,
input: ['text'],
contextWindow: 128000,
maxTokens: 4096,
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
},
}))
const releasePreview = Promise.withResolvers<void>()
await page.route(
`**/api/teams/${teamId}/providers/${provider.id}/models/refresh`,
async (route) => {
await releasePreview.promise
await route.fulfill({ json: { status: 'ready', models } })
},
)
await page.goto(`/teams/${teamId}/settings#providers`)
const cards = page.locator('main [data-slot="card"]')
const openai = cards.filter({ hasText: provider.name })
const anthropic = cards.filter({ hasText: missing.name })
const refresh = openai.getByRole('button', { name: /Refresh models for OpenAI production/ })
await expect(cards.first()).toContainText(provider.name)
await expect(openai.getByText('Configured', { exact: true })).toBeVisible()
await expect(anthropic.getByText('Set an API key to refresh models.')).toBeVisible()
await expect(anthropic.getByRole('button', { name: /Refresh models/ })).toBeDisabled()
await refresh.focus()
await page.keyboard.press('Enter')
await expect(refresh).toHaveAttribute('aria-busy', 'true')
await expect(anthropic.getByRole('button', { name: /Refresh models/ })).toHaveAttribute(
'aria-busy',
'false',
)
releasePreview.resolve()
const dialog = page.getByRole('dialog', { name: 'New models for OpenAI production' })
await expect(dialog).toBeVisible()
await expect(dialog.getByRole('checkbox', { name: 'Test Model 1 test-model-1' })).toBeVisible()
for (const viewport of [
{ width: 1280, height: 800 },
{ width: 390, height: 640 },
]) {
await page.setViewportSize(viewport)
await expect
.poll(() =>
dialog.locator('[data-slot="scroll-area-viewport"]').evaluate((element) => {
const scrollAreaBounds = element.getBoundingClientRect()
const dialogBounds = element.closest('[role="dialog"]')?.getBoundingClientRect()
return (
dialogBounds !== undefined &&
dialogBounds.left >= 0 &&
dialogBounds.right <= window.innerWidth &&
dialogBounds.top >= 0 &&
dialogBounds.bottom <= window.innerHeight &&
scrollAreaBounds.bottom < dialogBounds.bottom &&
element.scrollHeight > element.clientHeight
)
}),
)
.toBe(true)
}
await dialog.getByRole('button', { name: 'Cancel' }).click()
await expect(dialog).toBeHidden()
await expect(refresh).toBeFocused()
})