mirror of
https://gitee.com/wanwujie/sub2api
synced 2026-04-22 23:54:45 +08:00
fix(admin/accounts): reset edit modal state on reopen
This commit is contained in:
@@ -1980,10 +1980,10 @@ const normalizePoolModeRetryCount = (value: number) => {
|
|||||||
return normalized
|
return normalized
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
const syncFormFromAccount = (newAccount: Account | null) => {
|
||||||
() => props.account,
|
if (!newAccount) {
|
||||||
(newAccount) => {
|
return
|
||||||
if (newAccount) {
|
}
|
||||||
antigravityMixedChannelConfirmed.value = false
|
antigravityMixedChannelConfirmed.value = false
|
||||||
showMixedChannelWarning.value = false
|
showMixedChannelWarning.value = false
|
||||||
mixedChannelWarningDetails.value = null
|
mixedChannelWarningDetails.value = null
|
||||||
@@ -2246,6 +2246,16 @@ watch(
|
|||||||
}
|
}
|
||||||
editApiKey.value = ''
|
editApiKey.value = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
[() => props.show, () => props.account],
|
||||||
|
([show, newAccount], [wasShow, previousAccount]) => {
|
||||||
|
if (!show || !newAccount) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!wasShow || newAccount !== previousAccount) {
|
||||||
|
syncFormFromAccount(newAccount)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,159 @@
|
|||||||
|
import { describe, expect, it, vi } from 'vitest'
|
||||||
|
import { defineComponent } from 'vue'
|
||||||
|
import { mount } from '@vue/test-utils'
|
||||||
|
|
||||||
|
const { updateAccountMock, checkMixedChannelRiskMock } = vi.hoisted(() => ({
|
||||||
|
updateAccountMock: vi.fn(),
|
||||||
|
checkMixedChannelRiskMock: vi.fn()
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock('@/stores/app', () => ({
|
||||||
|
useAppStore: () => ({
|
||||||
|
showError: vi.fn(),
|
||||||
|
showSuccess: vi.fn(),
|
||||||
|
showInfo: vi.fn()
|
||||||
|
})
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock('@/stores/auth', () => ({
|
||||||
|
useAuthStore: () => ({
|
||||||
|
isSimpleMode: true
|
||||||
|
})
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock('@/api/admin', () => ({
|
||||||
|
adminAPI: {
|
||||||
|
accounts: {
|
||||||
|
update: updateAccountMock,
|
||||||
|
checkMixedChannelRisk: checkMixedChannelRiskMock
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock('@/api/admin/accounts', () => ({
|
||||||
|
getAntigravityDefaultModelMapping: vi.fn()
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock('vue-i18n', async () => {
|
||||||
|
const actual = await vi.importActual<typeof import('vue-i18n')>('vue-i18n')
|
||||||
|
return {
|
||||||
|
...actual,
|
||||||
|
useI18n: () => ({
|
||||||
|
t: (key: string) => key
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
import EditAccountModal from '../EditAccountModal.vue'
|
||||||
|
|
||||||
|
const BaseDialogStub = defineComponent({
|
||||||
|
name: 'BaseDialog',
|
||||||
|
props: {
|
||||||
|
show: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
template: '<div v-if="show"><slot /><slot name="footer" /></div>'
|
||||||
|
})
|
||||||
|
|
||||||
|
const ModelWhitelistSelectorStub = defineComponent({
|
||||||
|
name: 'ModelWhitelistSelector',
|
||||||
|
props: {
|
||||||
|
modelValue: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: ['update:modelValue'],
|
||||||
|
template: `
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-testid="rewrite-to-snapshot"
|
||||||
|
@click="$emit('update:modelValue', ['gpt-5.2-2025-12-11'])"
|
||||||
|
>
|
||||||
|
rewrite
|
||||||
|
</button>
|
||||||
|
<span data-testid="model-whitelist-value">
|
||||||
|
{{ Array.isArray(modelValue) ? modelValue.join(',') : '' }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
})
|
||||||
|
|
||||||
|
function buildAccount() {
|
||||||
|
return {
|
||||||
|
id: 1,
|
||||||
|
name: 'OpenAI Key',
|
||||||
|
notes: '',
|
||||||
|
platform: 'openai',
|
||||||
|
type: 'apikey',
|
||||||
|
credentials: {
|
||||||
|
api_key: 'sk-test',
|
||||||
|
base_url: 'https://api.openai.com',
|
||||||
|
model_mapping: {
|
||||||
|
'gpt-5.2': 'gpt-5.2'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
extra: {},
|
||||||
|
proxy_id: null,
|
||||||
|
concurrency: 1,
|
||||||
|
priority: 1,
|
||||||
|
rate_multiplier: 1,
|
||||||
|
status: 'active',
|
||||||
|
group_ids: [],
|
||||||
|
expires_at: null,
|
||||||
|
auto_pause_on_expired: false
|
||||||
|
} as any
|
||||||
|
}
|
||||||
|
|
||||||
|
function mountModal(account = buildAccount()) {
|
||||||
|
return mount(EditAccountModal, {
|
||||||
|
props: {
|
||||||
|
show: true,
|
||||||
|
account,
|
||||||
|
proxies: [],
|
||||||
|
groups: []
|
||||||
|
},
|
||||||
|
global: {
|
||||||
|
stubs: {
|
||||||
|
BaseDialog: BaseDialogStub,
|
||||||
|
Select: true,
|
||||||
|
Icon: true,
|
||||||
|
ProxySelector: true,
|
||||||
|
GroupSelector: true,
|
||||||
|
ModelWhitelistSelector: ModelWhitelistSelectorStub
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('EditAccountModal', () => {
|
||||||
|
it('reopening the same account rehydrates the OpenAI whitelist from props', async () => {
|
||||||
|
const account = buildAccount()
|
||||||
|
updateAccountMock.mockReset()
|
||||||
|
checkMixedChannelRiskMock.mockReset()
|
||||||
|
checkMixedChannelRiskMock.mockResolvedValue({ has_risk: false })
|
||||||
|
updateAccountMock.mockResolvedValue(account)
|
||||||
|
|
||||||
|
const wrapper = mountModal(account)
|
||||||
|
|
||||||
|
expect(wrapper.get('[data-testid="model-whitelist-value"]').text()).toBe('gpt-5.2')
|
||||||
|
|
||||||
|
await wrapper.get('[data-testid="rewrite-to-snapshot"]').trigger('click')
|
||||||
|
expect(wrapper.get('[data-testid="model-whitelist-value"]').text()).toBe('gpt-5.2-2025-12-11')
|
||||||
|
|
||||||
|
await wrapper.setProps({ show: false })
|
||||||
|
await wrapper.setProps({ show: true })
|
||||||
|
|
||||||
|
expect(wrapper.get('[data-testid="model-whitelist-value"]').text()).toBe('gpt-5.2')
|
||||||
|
|
||||||
|
await wrapper.get('form#edit-account-form').trigger('submit.prevent')
|
||||||
|
|
||||||
|
expect(updateAccountMock).toHaveBeenCalledTimes(1)
|
||||||
|
expect(updateAccountMock.mock.calls[0]?.[1]?.credentials?.model_mapping).toEqual({
|
||||||
|
'gpt-5.2': 'gpt-5.2'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user