fix(grok): 对齐模型编辑布局与响应式展示

This commit is contained in:
Aomsir committed 2026-10-25 18:00:25 +08:00
1 parent 21b5b49d0a
commit 7f18239be2
4 files changed
+397 -48

No files matched your search

@@ -251,7 +251,11 @@
</div>
<!-- Model Restriction Section (不适用于 Antigravity) -->
<div v-if="account.platform !== 'antigravity'" class="border-t border-gray-200 pt-4 dark:border-dark-600">
<div
v-if="account.platform !== 'antigravity'"
class="border-t border-gray-200 pt-4 dark:border-dark-600"
:data-testid="account.platform === 'grok' ? 'grok-model-settings' : undefined"
>
<label class="input-label">{{ t('admin.accounts.modelRestriction') }}</label>
<div
@@ -265,18 +269,32 @@
<template v-else>
<!-- Mode Toggle -->
<div class="mb-4 flex gap-2">
<div
:data-testid="account.platform === 'grok' ? 'grok-model-mode-tabs' : undefined"
:class="account.platform === 'grok'
? 'mb-4 flex gap-1 rounded-xl bg-gray-100 p-1 dark:bg-dark-900'
: 'mb-4 flex gap-2'"
>
<button
type="button"
@click="modelRestrictionMode = 'whitelist'"
:class="[
'flex-1 rounded-lg px-4 py-2 text-sm font-medium transition-all',
modelRestrictionMode === 'whitelist'
? 'bg-primary-100 text-primary-700 dark:bg-primary-900/30 dark:text-primary-400'
: 'bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-dark-600 dark:text-gray-400 dark:hover:bg-dark-500'
]"
:aria-pressed="account.platform === 'grok' ? modelRestrictionMode === 'whitelist' : undefined"
:class="account.platform === 'grok'
? [
'rounded-lg px-3 py-2 text-sm',
modelRestrictionMode === 'whitelist'
? 'bg-white text-cyan-700 shadow-sm dark:bg-dark-800 dark:text-cyan-300'
: 'text-gray-600 hover:text-gray-900 dark:text-gray-300 dark:hover:text-gray-100'
]
: [
'flex-1 rounded-lg px-4 py-2 text-sm font-medium transition-all',
modelRestrictionMode === 'whitelist'
? 'bg-primary-100 text-primary-700 dark:bg-primary-900/30 dark:text-primary-400'
: 'bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-dark-600 dark:text-gray-400 dark:hover:bg-dark-500'
]"
>
<svg
v-if="account.platform !== 'grok'"
class="mr-1.5 inline h-4 w-4"
fill="none"
viewBox="0 0 24 24"
@@ -294,14 +312,23 @@
<button
type="button"
@click="modelRestrictionMode = 'mapping'"
:class="[
'flex-1 rounded-lg px-4 py-2 text-sm font-medium transition-all',
modelRestrictionMode === 'mapping'
? 'bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400'
: 'bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-dark-600 dark:text-gray-400 dark:hover:bg-dark-500'
]"
:aria-pressed="account.platform === 'grok' ? modelRestrictionMode === 'mapping' : undefined"
:class="account.platform === 'grok'
? [
'rounded-lg px-3 py-2 text-sm',
modelRestrictionMode === 'mapping'
? 'bg-white text-purple-700 shadow-sm dark:bg-dark-800 dark:text-purple-300'
: 'text-gray-600 hover:text-gray-900 dark:text-gray-300 dark:hover:text-gray-100'
]
: [
'flex-1 rounded-lg px-4 py-2 text-sm font-medium transition-all',
modelRestrictionMode === 'mapping'
? 'bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400'
: 'bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-dark-600 dark:text-gray-400 dark:hover:bg-dark-500'
]"
>
<svg
v-if="account.platform !== 'grok'"
class="mr-1.5 inline h-4 w-4"
fill="none"
viewBox="0 0 24 24"
@@ -352,10 +379,11 @@
</div>
<!-- Mapping Mode -->
<div v-else>
<div class="mb-3 rounded-lg bg-purple-50 p-3 dark:bg-purple-900/20">
<p class="text-xs text-purple-700 dark:text-purple-400">
<div v-else :data-testid="account.platform === 'grok' ? 'grok-model-mapping-editor' : undefined">
<div :class="account.platform === 'grok' ? 'mb-3' : 'mb-3 rounded-lg bg-purple-50 p-3 dark:bg-purple-900/20'">
<p :class="account.platform === 'grok' ? 'text-xs text-gray-500 dark:text-dark-400' : 'text-xs text-purple-700 dark:text-purple-400'">
<svg
v-if="account.platform !== 'grok'"
class="mr-1 inline h-4 w-4"
fill="none"
viewBox="0 0 24 24"
@@ -372,20 +400,41 @@
</p>
</div>
<div
v-if="account.platform === 'grok'"
class="mb-1.5 grid grid-cols-[minmax(0,1fr)_1rem_minmax(0,1.2fr)_2rem] gap-1.5 text-xs text-gray-500 dark:text-dark-400 sm:gap-2"
>
<span>{{ t('admin.accounts.grokModelDiagnostics.requestColumn') }}</span>
<span></span>
<span>{{ t('admin.accounts.grokModelDiagnostics.targetColumn') }}</span>
</div>
<!-- Model Mapping List -->
<div v-if="modelMappings.length > 0" class="mb-3 space-y-2">
<div
v-for="(mapping, index) in modelMappings"
:key="getModelMappingKey(mapping)"
class="flex items-center gap-2"
:data-testid="account.platform === 'grok' ? 'grok-model-mapping-row' : undefined"
:class="account.platform === 'grok'
? 'grid grid-cols-[minmax(0,1fr)_1rem_minmax(0,1.2fr)_2rem] items-center gap-1.5 sm:gap-2'
: 'flex items-center gap-2'"
>
<input
v-model="mapping.from"
type="text"
class="input flex-1"
:aria-label="account.platform === 'grok' ? t('admin.accounts.grokModelDiagnostics.mappingFromAria', { index: index + 1 }) : undefined"
:class="account.platform === 'grok' ? 'input min-w-0 w-full font-mono text-xs' : 'input flex-1'"
:placeholder="t('admin.accounts.requestModel')"
/>
<Icon
v-if="account.platform === 'grok'"
name="arrowRight"
size="sm"
aria-hidden="true"
class="w-4 shrink-0 text-gray-400"
/>
<svg
v-else
class="h-4 w-4 flex-shrink-0 text-gray-400"
fill="none"
viewBox="0 0 24 24"
@@ -401,15 +450,20 @@
<input
v-model="mapping.to"
type="text"
class="input flex-1"
:aria-label="account.platform === 'grok' ? t('admin.accounts.grokModelDiagnostics.mappingTargetAria', { index: index + 1 }) : undefined"
:class="account.platform === 'grok' ? 'input min-w-0 w-full font-mono text-xs' : 'input flex-1'"
:placeholder="t('admin.accounts.actualModel')"
/>
<button
type="button"
@click="removeModelMapping(index)"
class="rounded-lg p-2 text-red-500 transition-colors hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-900/20"
:aria-label="account.platform === 'grok' ? t('admin.accounts.grokModelDiagnostics.removeMappingAria', { index: index + 1 }) : undefined"
:class="account.platform === 'grok'
? 'rounded-lg p-1.5 text-gray-400 hover:bg-gray-100 focus-visible:ring-2 focus-visible:ring-primary-500 dark:hover:bg-dark-700'
: 'rounded-lg p-2 text-red-500 transition-colors hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-900/20'"
>
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<Icon v-if="account.platform === 'grok'" name="trash" size="sm" aria-hidden="true" />
<svg v-else class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
stroke-linecap="round"
stroke-linejoin="round"
@@ -424,7 +478,10 @@
<button
type="button"
@click="addModelMapping"
class="mb-3 w-full rounded-lg border-2 border-dashed border-gray-300 px-4 py-2 text-gray-600 transition-colors hover:border-gray-400 hover:text-gray-700 dark:border-dark-500 dark:text-gray-400 dark:hover:border-dark-400 dark:hover:text-gray-300"
:data-testid="account.platform === 'grok' ? 'grok-model-mapping-add' : undefined"
:class="account.platform === 'grok'
? 'mb-3 inline-flex items-center gap-1 py-2 text-xs text-primary-700 dark:text-primary-300'
: 'mb-3 w-full rounded-lg border-2 border-dashed border-gray-300 px-4 py-2 text-gray-600 transition-colors hover:border-gray-400 hover:text-gray-700 dark:border-dark-500 dark:text-gray-400 dark:hover:border-dark-400 dark:hover:text-gray-300'"
>
<svg
class="mr-1 inline h-4 w-4"
@@ -821,6 +878,7 @@
<div
v-if="(account.platform === 'openai' || account.platform === 'grok') && account.type === 'oauth'"
class="border-t border-gray-200 pt-4 dark:border-dark-600"
:data-testid="account.platform === 'grok' ? 'grok-model-settings' : undefined"
>
<label class="input-label">{{ t('admin.accounts.modelRestriction') }}</label>
@@ -835,28 +893,49 @@
<template v-else>
<!-- Mode Toggle -->
<div class="mb-4 flex gap-2">
<div
:data-testid="account.platform === 'grok' ? 'grok-model-mode-tabs' : undefined"
:class="account.platform === 'grok'
? 'mb-4 flex gap-1 rounded-xl bg-gray-100 p-1 dark:bg-dark-900'
: 'mb-4 flex gap-2'"
>
<button
type="button"
@click="modelRestrictionMode = 'whitelist'"
:class="[
'flex-1 rounded-lg px-4 py-2 text-sm font-medium transition-all',
modelRestrictionMode === 'whitelist'
? 'bg-primary-100 text-primary-700 dark:bg-primary-900/30 dark:text-primary-400'
: 'bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-dark-600 dark:text-gray-400 dark:hover:bg-dark-500'
]"
:aria-pressed="account.platform === 'grok' ? modelRestrictionMode === 'whitelist' : undefined"
:class="account.platform === 'grok'
? [
'rounded-lg px-3 py-2 text-sm',
modelRestrictionMode === 'whitelist'
? 'bg-white text-cyan-700 shadow-sm dark:bg-dark-800 dark:text-cyan-300'
: 'text-gray-600 hover:text-gray-900 dark:text-gray-300 dark:hover:text-gray-100'
]
: [
'flex-1 rounded-lg px-4 py-2 text-sm font-medium transition-all',
modelRestrictionMode === 'whitelist'
? 'bg-primary-100 text-primary-700 dark:bg-primary-900/30 dark:text-primary-400'
: 'bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-dark-600 dark:text-gray-400 dark:hover:bg-dark-500'
]"
>
{{ t('admin.accounts.modelWhitelist') }}
</button>
<button
type="button"
@click="modelRestrictionMode = 'mapping'"
:class="[
'flex-1 rounded-lg px-4 py-2 text-sm font-medium transition-all',
modelRestrictionMode === 'mapping'
? 'bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400'
: 'bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-dark-600 dark:text-gray-400 dark:hover:bg-dark-500'
]"
:aria-pressed="account.platform === 'grok' ? modelRestrictionMode === 'mapping' : undefined"
:class="account.platform === 'grok'
? [
'rounded-lg px-3 py-2 text-sm',
modelRestrictionMode === 'mapping'
? 'bg-white text-purple-700 shadow-sm dark:bg-dark-800 dark:text-purple-300'
: 'text-gray-600 hover:text-gray-900 dark:text-gray-300 dark:hover:text-gray-100'
]
: [
'flex-1 rounded-lg px-4 py-2 text-sm font-medium transition-all',
modelRestrictionMode === 'mapping'
? 'bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400'
: 'bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-dark-600 dark:text-gray-400 dark:hover:bg-dark-500'
]"
>
{{ t('admin.accounts.modelMapping') }}
</button>
@@ -896,26 +975,47 @@
</div>
<!-- Mapping Mode -->
<div v-else>
<div class="mb-3 rounded-lg bg-purple-50 p-3 dark:bg-purple-900/20">
<p class="text-xs text-purple-700 dark:text-purple-400">
<div v-else :data-testid="account.platform === 'grok' ? 'grok-model-mapping-editor' : undefined">
<div :class="account.platform === 'grok' ? 'mb-3' : 'mb-3 rounded-lg bg-purple-50 p-3 dark:bg-purple-900/20'">
<p :class="account.platform === 'grok' ? 'text-xs text-gray-500 dark:text-dark-400' : 'text-xs text-purple-700 dark:text-purple-400'">
{{ t('admin.accounts.mapRequestModels') }}
</p>
</div>
<div
v-if="account.platform === 'grok'"
class="mb-1.5 grid grid-cols-[minmax(0,1fr)_1rem_minmax(0,1.2fr)_2rem] gap-1.5 text-xs text-gray-500 dark:text-dark-400 sm:gap-2"
>
<span>{{ t('admin.accounts.grokModelDiagnostics.requestColumn') }}</span>
<span></span>
<span>{{ t('admin.accounts.grokModelDiagnostics.targetColumn') }}</span>
</div>
<div v-if="modelMappings.length > 0" class="mb-3 space-y-2">
<div
v-for="(mapping, index) in modelMappings"
:key="'oauth-' + getModelMappingKey(mapping)"
class="flex items-center gap-2"
:data-testid="account.platform === 'grok' ? 'grok-model-mapping-row' : undefined"
:class="account.platform === 'grok'
? 'grid grid-cols-[minmax(0,1fr)_1rem_minmax(0,1.2fr)_2rem] items-center gap-1.5 sm:gap-2'
: 'flex items-center gap-2'"
>
<input
v-model="mapping.from"
type="text"
class="input flex-1"
:aria-label="account.platform === 'grok' ? t('admin.accounts.grokModelDiagnostics.mappingFromAria', { index: index + 1 }) : undefined"
:class="account.platform === 'grok' ? 'input min-w-0 w-full font-mono text-xs' : 'input flex-1'"
:placeholder="t('admin.accounts.requestModel')"
/>
<Icon
v-if="account.platform === 'grok'"
name="arrowRight"
size="sm"
aria-hidden="true"
class="w-4 shrink-0 text-gray-400"
/>
<svg
v-else
class="h-4 w-4 flex-shrink-0 text-gray-400"
fill="none"
viewBox="0 0 24 24"
@@ -931,15 +1031,20 @@
<input
v-model="mapping.to"
type="text"
class="input flex-1"
:aria-label="account.platform === 'grok' ? t('admin.accounts.grokModelDiagnostics.mappingTargetAria', { index: index + 1 }) : undefined"
:class="account.platform === 'grok' ? 'input min-w-0 w-full font-mono text-xs' : 'input flex-1'"
:placeholder="t('admin.accounts.actualModel')"
/>
<button
type="button"
@click="removeModelMapping(index)"
class="rounded-lg p-2 text-red-500 transition-colors hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-900/20"
:aria-label="account.platform === 'grok' ? t('admin.accounts.grokModelDiagnostics.removeMappingAria', { index: index + 1 }) : undefined"
:class="account.platform === 'grok'
? 'rounded-lg p-1.5 text-gray-400 hover:bg-gray-100 focus-visible:ring-2 focus-visible:ring-primary-500 dark:hover:bg-dark-700'
: 'rounded-lg p-2 text-red-500 transition-colors hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-900/20'"
>
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<Icon v-if="account.platform === 'grok'" name="trash" size="sm" aria-hidden="true" />
<svg v-else class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
stroke-linecap="round"
stroke-linejoin="round"
@@ -954,7 +1059,10 @@
<button
type="button"
@click="addModelMapping"
class="mb-3 w-full rounded-lg border-2 border-dashed border-gray-300 px-4 py-2 text-gray-600 transition-colors hover:border-gray-400 hover:text-gray-700 dark:border-dark-500 dark:text-gray-400 dark:hover:border-dark-400 dark:hover:text-gray-300"
:data-testid="account.platform === 'grok' ? 'grok-model-mapping-add' : undefined"
:class="account.platform === 'grok'
? 'mb-3 inline-flex items-center gap-1 py-2 text-xs text-primary-700 dark:text-primary-300'
: 'mb-3 w-full rounded-lg border-2 border-dashed border-gray-300 px-4 py-2 text-gray-600 transition-colors hover:border-gray-400 hover:text-gray-700 dark:border-dark-500 dark:text-gray-400 dark:hover:border-dark-400 dark:hover:text-gray-300'"
>
+ {{ t('admin.accounts.addMapping') }}
</button>
@@ -27,7 +27,8 @@ const {
showWarningMock,
showSuccessMock,
showErrorMock,
authIsSimpleMode
authIsSimpleMode,
translateMock
} = vi.hoisted(() => ({
updateAccountMock: vi.fn(),
checkMixedChannelRiskMock: vi.fn(),
@@ -36,7 +37,15 @@ const {
showWarningMock: vi.fn(),
showSuccessMock: vi.fn(),
showErrorMock: vi.fn(),
authIsSimpleMode: { value: true }
authIsSimpleMode: { value: true },
translateMock: vi.fn((key: string, params?: Record<string, unknown>) => {
if (!params) return key
let text = key
for (const [name, value] of Object.entries(params)) {
text = text.split(`{${name}}`).join(value == null ? '' : String(value))
}
return text
})
}))
vi.mock('@/stores/app', () => ({
@@ -87,7 +96,7 @@ vi.mock('vue-i18n', async () => {
return {
...actual,
useI18n: () => ({
t: (key: string) => key
t: translateMock
})
}
})
@@ -238,6 +247,7 @@ describe('EditAccountModal Grok OAuth upstream config', () => {
showWarningMock.mockReset()
showSuccessMock.mockReset()
showErrorMock.mockReset()
translateMock.mockClear()
})
afterEach(() => {
@@ -1229,4 +1239,229 @@ describe('EditAccountModal Grok OAuth upstream config', () => {
expect(wrapper.get('[data-testid="grok-diagnostics-details-toggle"]').attributes('aria-expanded')).toBe('false')
expect((wrapper.get('[data-testid="grok-diagnostics-sync"]').element as HTMLButtonElement).disabled).toBe(false)
})
it.each(['oauth', 'apikey'])('keeps the redesigned editor scoped to Grok %s', async type => {
const account = { ...buildGrokOAuthAccount({ model_mapping: { friendly: 'grok-4.7' } }), type }
const wrapper = mountLiveSelectorModal(account)
await flushPromises()
expect(wrapper.find('[data-testid="grok-model-settings"]').exists()).toBe(true)
const editor = wrapper.get('[data-testid="grok-model-mapping-editor"]')
expect(editor.text()).toContain('admin.accounts.grokModelDiagnostics.requestColumn')
expect(editor.text()).toContain('admin.accounts.grokModelDiagnostics.targetColumn')
const from = editor.get('input[placeholder="admin.accounts.requestModel"]')
const to = editor.get('input[placeholder="admin.accounts.actualModel"]')
expect(from.attributes('aria-label')).toBeTruthy()
expect(to.attributes('aria-label')).toBeTruthy()
expect(from.attributes('maxlength')).toBeUndefined()
expect(to.attributes('maxlength')).toBeUndefined()
expect(translateMock).toHaveBeenCalledWith('admin.accounts.grokModelDiagnostics.mappingFromAria', { index: 1 })
expect(translateMock).toHaveBeenCalledWith('admin.accounts.grokModelDiagnostics.mappingTargetAria', { index: 1 })
expect(translateMock).toHaveBeenCalledWith('admin.accounts.grokModelDiagnostics.removeMappingAria', { index: 1 })
await wrapper.get('[data-testid="grok-model-mapping-add"]').trigger('click')
expect(wrapper.findAll('[data-testid="grok-model-mapping-row"]')).toHaveLength(2)
expect(translateMock).toHaveBeenCalledWith('admin.accounts.grokModelDiagnostics.mappingFromAria', { index: 2 })
})
it.each(['oauth', 'apikey'])('leaves non-grok %s model controls unchanged', async type => {
getByIdMock.mockClear()
const wrapper = mountLiveSelectorModal({
...buildGrokOAuthAccount({ model_mapping: { friendly: 'grok-4.7' } }),
platform: 'openai',
type
})
await flushPromises()
for (const id of [
'grok-model-settings',
'grok-model-mode-tabs',
'grok-model-mapping-editor',
'grok-model-mapping-row',
'grok-model-mapping-add',
'grok-model-diagnostics'
]) {
expect(wrapper.find(`[data-testid="${id}"]`).exists()).toBe(false)
}
expect(wrapper.text()).not.toContain('admin.accounts.grokModelDiagnostics.requestColumn')
expect(wrapper.text()).not.toContain('admin.accounts.grokModelDiagnostics.targetColumn')
expect(wrapper.text()).toContain('admin.accounts.mapRequestModels')
const from = wrapper.get('input[placeholder="admin.accounts.requestModel"]')
const to = wrapper.get('input[placeholder="admin.accounts.actualModel"]')
expect(from.attributes('aria-label')).toBeUndefined()
expect(to.attributes('aria-label')).toBeUndefined()
const remove = from.element.parentElement?.querySelector('button')
expect(remove?.getAttribute('aria-label')).toBeNull()
const mode = wrapper.findAll('button').find(button => button.text().includes('admin.accounts.modelMapping'))
expect(mode?.attributes('aria-pressed')).toBeUndefined()
expect(mode?.classes()).toContain('flex-1')
const add = wrapper.findAll('button').find(button =>
button.text().includes('admin.accounts.addMapping') && button.classes().includes('border-dashed')
)
expect(add).toBeTruthy()
expect(add?.classes()).toEqual(expect.arrayContaining(['w-full', 'border-dashed']))
expect(wrapper.find('[data-testid="sync-upstream-models"]').exists()).toBe(true)
expect(getByIdMock).not.toHaveBeenCalled()
const before = wrapper.findAll('input[placeholder="admin.accounts.requestModel"]').length
await add?.trigger('click')
expect(wrapper.findAll('input[placeholder="admin.accounts.requestModel"]')).toHaveLength(before + 1)
})
it.each(['oauth', 'apikey'])(
'saves Grok %s mapping edits, deletions, presets and full long ids',
async type => {
const longTarget = `grok-${'upstream'.repeat(12)}-target`
const account = {
...buildGrokOAuthAccount({
model_mapping: { friendly: 'grok-4.7', 'drop-me': 'grok-4.6' }
}),
type,
...(type === 'apikey' ? { credentials_status: { has_api_key: true } } : {})
}
updateAccountMock.mockResolvedValue(account)
const wrapper = mountLiveSelectorModal(account)
await flushPromises()
const rows = () => wrapper.findAll('[data-testid="grok-model-mapping-row"]')
expect(rows()).toHaveLength(2)
const friendly = rows().find(row =>
(row.get('input[placeholder="admin.accounts.requestModel"]').element as HTMLInputElement).value === 'friendly'
)
expect(friendly).toBeTruthy()
const target = friendly!.get('input[placeholder="admin.accounts.actualModel"]')
await target.setValue(longTarget)
expect((target.element as HTMLInputElement).value).toBe(longTarget)
const drop = rows().find(row =>
(row.get('input[placeholder="admin.accounts.requestModel"]').element as HTMLInputElement).value === 'drop-me'
)
await drop!.get('button').trigger('click')
expect(rows()).toHaveLength(1)
expect((rows()[0].get('input[placeholder="admin.accounts.actualModel"]').element as HTMLInputElement).value).toBe(longTarget)
const preset = wrapper.findAll('button').find(button => button.text() === '+ Grok Latest')
expect(preset).toBeTruthy()
await preset!.trigger('click')
expect(rows()).toHaveLength(2)
await wrapper.get('form#edit-account-form').trigger('submit.prevent')
await vi.waitFor(() => expect(updateAccountMock).toHaveBeenCalledTimes(1))
expect(updateAccountMock.mock.calls[0]?.[1]?.credentials?.model_mapping).toEqual({
friendly: longTarget,
'grok-latest': 'grok-4.5'
})
expect(updateAccountMock.mock.calls[0]?.[1]?.credentials?.grok_model_diagnostics).toBeUndefined()
}
)
it('edits and deletes duplicate Grok mapping rows without reusing their values as keys', async () => {
const wrapper = mountLiveSelectorModal(buildGrokOAuthAccount({ model_mapping: { friendly: 'grok-4.7' } }))
await flushPromises()
await wrapper.get('[data-testid="grok-model-mapping-add"]').trigger('click')
await wrapper.get('[data-testid="grok-model-mapping-add"]').trigger('click')
const rows = () => wrapper.findAll('[data-testid="grok-model-mapping-row"]')
expect(rows()).toHaveLength(3)
const firstAdded = rows()[1].element
const secondAdded = rows()[2].element
await rows()[1].get('input[placeholder="admin.accounts.requestModel"]').setValue('same-request')
await rows()[1].get('input[placeholder="admin.accounts.actualModel"]').setValue('same-target')
await rows()[2].get('input[placeholder="admin.accounts.requestModel"]').setValue('same-request')
await rows()[2].get('input[placeholder="admin.accounts.actualModel"]').setValue('same-target')
expect(rows()[1].element).toBe(firstAdded)
expect(rows()[2].element).toBe(secondAdded)
await rows()[1].get('input[placeholder="admin.accounts.actualModel"]').setValue('only-first')
expect((rows()[2].get('input[placeholder="admin.accounts.actualModel"]').element as HTMLInputElement).value).toBe('same-target')
expect((rows()[2].get('input[placeholder="admin.accounts.requestModel"]').element as HTMLInputElement).value).toBe('same-request')
await rows()[1].get('button').trigger('click')
expect(rows()).toHaveLength(2)
expect(rows()[1].element).toBe(secondAdded)
expect((rows()[1].get('input[placeholder="admin.accounts.actualModel"]').element as HTMLInputElement).value).toBe('same-target')
})
it.each(['oauth', 'apikey'])(
'keeps Grok %s diagnostics between the mode tabs and the active editor',
async type => {
const account = { ...buildGrokOAuthAccount({ model_mapping: { friendly: 'grok-4.7' } }), type }
const wrapper = mountLiveSelectorModal(account)
await flushPromises()
const settings = wrapper.get('[data-testid="grok-model-settings"]')
const tabs = settings.get('[data-testid="grok-model-mode-tabs"]')
const panel = settings.get('[data-testid="grok-model-diagnostics"]')
const editor = settings.get('[data-testid="grok-model-mapping-editor"]')
expect(tabs.element.compareDocumentPosition(panel.element) & Node.DOCUMENT_POSITION_FOLLOWING).toBe(
Node.DOCUMENT_POSITION_FOLLOWING
)
expect(panel.element.compareDocumentPosition(editor.element) & Node.DOCUMENT_POSITION_FOLLOWING).toBe(
Node.DOCUMENT_POSITION_FOLLOWING
)
const mapping = tabs.findAll('button').find(button => button.text().includes('admin.accounts.modelMapping'))
const whitelist = tabs.findAll('button').find(button => button.text().includes('admin.accounts.modelWhitelist'))
expect(mapping?.attributes('aria-pressed')).toBe('true')
expect(whitelist?.attributes('aria-pressed')).toBe('false')
expect(wrapper.findAll('[data-testid="grok-diagnostics-sync"]')).toHaveLength(1)
expect(wrapper.find('[data-testid="sync-upstream-models"]').exists()).toBe(false)
await editor.get('input[placeholder="admin.accounts.actualModel"]').setValue('grok-edited')
const dirty = settings.get('[data-testid="grok-diagnostics-dirty"]')
expect(wrapper.findAll('[data-testid="grok-diagnostics-dirty"]')).toHaveLength(1)
expect(panel.element.contains(dirty.element)).toBe(true)
expect(dirty.element.compareDocumentPosition(editor.element) & Node.DOCUMENT_POSITION_FOLLOWING).toBe(
Node.DOCUMENT_POSITION_FOLLOWING
)
await whitelist!.trigger('click')
expect(settings.get('[data-testid="grok-model-diagnostics"]').exists()).toBe(true)
expect(settings.find('[data-testid="grok-model-mapping-editor"]').exists()).toBe(false)
expect(wrapper.findAll('[data-testid="grok-diagnostics-sync"]')).toHaveLength(1)
expect(wrapper.find('[data-testid="sync-upstream-models"]').exists()).toBe(false)
expect(whitelist?.attributes('aria-pressed')).toBe('true')
expect(mapping?.attributes('aria-pressed')).toBe('false')
const fill = settings.findAll('button').find(button => button.text().includes('admin.accounts.fillRelatedModels'))
expect(fill).toBeTruthy()
expect(panel.element.compareDocumentPosition(fill!.element) & Node.DOCUMENT_POSITION_FOLLOWING).toBe(
Node.DOCUMENT_POSITION_FOLLOWING
)
}
)
it.each(['oauth', 'apikey'])(
'keeps Grok %s whitelist fill, clear and custom models with saved mapping priority',
async type => {
const custom = `manual-${'m'.repeat(80)}`
const account = {
...buildGrokOAuthAccount({
model_mapping: { 'listed-model': 'listed-model', friendly: 'grok-4.7' }
}),
type,
...(type === 'apikey' ? { credentials_status: { has_api_key: true } } : {})
}
updateAccountMock.mockResolvedValue(account)
const wrapper = mountLiveSelectorModal(account)
await flushPromises()
expect(wrapper.find('[data-testid="grok-model-mapping-editor"]').exists()).toBe(false)
const selector = wrapper.getComponent({ name: 'ModelWhitelistSelector' })
expect(selector.props('modelValue')).toEqual(['listed-model'])
await wrapper.findAll('button').find(button => button.text().includes('admin.accounts.fillRelatedModels'))!.trigger('click')
const filled = selector.props('modelValue') as string[]
expect(filled).toContain('listed-model')
expect(filled.length).toBeGreaterThan(1)
await wrapper.findAll('button').find(button => button.text().includes('admin.accounts.clearAllModels'))!.trigger('click')
expect(selector.props('modelValue')).toEqual([])
await wrapper.get('input[placeholder="admin.accounts.enterCustomModelName"]').setValue(custom)
await wrapper.findAll('button').find(button => button.text() === 'admin.accounts.addModel')!.trigger('click')
expect(selector.props('modelValue')).toEqual([custom])
const tabs = wrapper.get('[data-testid="grok-model-mode-tabs"]')
await tabs.findAll('button').find(button => button.text().includes('admin.accounts.modelMapping'))!.trigger('click')
const editor = wrapper.get('[data-testid="grok-model-mapping-editor"]')
expect((editor.get('input[placeholder="admin.accounts.requestModel"]').element as HTMLInputElement).value).toBe('friendly')
await editor.get('input[placeholder="admin.accounts.actualModel"]').setValue('grok-4.7-kept')
expect(wrapper.find('[data-testid="grok-model-diagnostics"]').exists()).toBe(true)
expect(wrapper.findAll('[data-testid="grok-diagnostics-sync"]')).toHaveLength(1)
await wrapper.get('form#edit-account-form').trigger('submit.prevent')
await vi.waitFor(() => expect(updateAccountMock).toHaveBeenCalledTimes(1))
expect(updateAccountMock.mock.calls[0]?.[1]?.credentials?.model_mapping).toEqual({
[custom]: custom,
friendly: 'grok-4.7-kept'
})
}
)
})
@@ -957,6 +957,9 @@ export default {
savedConfigHint: 'Diagnostics use the saved configuration. Save your changes, then sync again.',
requestColumn: 'Requested model',
targetColumn: 'Forwarded target',
mappingFromAria: 'Requested model {index}',
mappingTargetAria: 'Forwarded target {index}',
removeMappingAria: 'Remove mapping {index}',
errorConfiguration: 'Upstream configuration is unavailable',
errorHTTP: 'The upstream request failed',
errorTransport: 'Could not connect to the upstream',
@@ -1059,6 +1059,9 @@ export default {
savedConfigHint: '诊断基于已保存配置。当前修改尚未保存,保存后请重新同步。',
requestColumn: '请求模型',
targetColumn: '转发至',
mappingFromAria: '第 {index} 项请求模型',
mappingTargetAria: '第 {index} 项转发目标',
removeMappingAria: '移除第 {index} 项映射',
errorConfiguration: '上游配置不可用',
errorHTTP: '上游请求失败',
errorTransport: '连接上游失败',