mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 08:05:12 +00:00
fix(accounts): show proxy account counts in account dialogs
This commit is contained in:
1 parent
0f66714571
commit
0c7d3ff58c
9 files changed
+44
-12
No files matched your search
@@ -9,10 +9,11 @@ vi.mock('vue-i18n', () => ({ useI18n: () => ({ t: (key: string) => key }) }))
|
||||
enableAutoUnmount(afterEach)
|
||||
beforeEach(() => { vi.clearAllMocks() })
|
||||
|
||||
async function openSelector() {
|
||||
async function openSelector(accountCounts?: number[]) {
|
||||
const wrapper = mount(ProxySelector, {
|
||||
props: { modelValue: null, proxies: [1, 2].map(id => ({
|
||||
id, name: `Proxy ${id}`, host: 'localhost', port: 8080, protocol: 'http'
|
||||
id, name: `Proxy ${id}`, host: 'localhost', port: 8080, protocol: 'http',
|
||||
account_count: accountCounts?.[id - 1]
|
||||
} as Proxy)) },
|
||||
global: { stubs: { Icon: true } }
|
||||
})
|
||||
@@ -20,6 +21,22 @@ async function openSelector() {
|
||||
return wrapper
|
||||
}
|
||||
|
||||
describe('proxy account counts', () => {
|
||||
it('displays zero and nonzero counts in dropdown options', async () => {
|
||||
const wrapper = await openSelector([0, 7])
|
||||
const options = wrapper.findAll('.select-option').slice(1)
|
||||
|
||||
expect(options[0].get('.bg-gray-100').text()).toBe('0')
|
||||
expect(options[1].get('.bg-gray-100').text()).toBe('7')
|
||||
})
|
||||
|
||||
it('does not display a count when it is unavailable', async () => {
|
||||
const wrapper = await openSelector()
|
||||
|
||||
expect(wrapper.findAll('.select-option .bg-gray-100')).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('proxy connection tests', () => {
|
||||
it('does not restart an individual test when a batch is started', async () => {
|
||||
let finish!: (result: object) => void
|
||||
|
||||
@@ -2622,7 +2622,7 @@ onMounted(async () => {
|
||||
load()
|
||||
loadUpstreamBillingProbeGlobalState()
|
||||
const [proxiesResult, groupsResult] = await Promise.allSettled([
|
||||
adminAPI.proxies.getAll(),
|
||||
adminAPI.proxies.getAllWithCount(),
|
||||
adminAPI.groups.getAll()
|
||||
])
|
||||
if (proxiesResult.status === 'fulfilled') {
|
||||
|
||||
@@ -45,7 +45,7 @@ vi.mock('@/api/admin', () => ({
|
||||
toggleSchedulable: vi.fn()
|
||||
},
|
||||
proxies: {
|
||||
getAll: getAllProxies
|
||||
getAllWithCount: getAllProxies
|
||||
},
|
||||
groups: {
|
||||
getAll: getAllGroups
|
||||
|
||||
@@ -52,7 +52,7 @@ vi.mock('@/api/admin', () => ({
|
||||
previewUpstreamGroup,
|
||||
update: updateAccount
|
||||
},
|
||||
proxies: { getAll: getAllProxies },
|
||||
proxies: { getAllWithCount: getAllProxies },
|
||||
groups: { getAll: getAllGroups }
|
||||
}
|
||||
}))
|
||||
@@ -90,7 +90,7 @@ const AccountGroupsCellStub = defineComponent({
|
||||
})
|
||||
|
||||
const EditAccountModalStub = defineComponent({
|
||||
props: { show: Boolean, account: { type: Object, default: null } },
|
||||
props: { show: Boolean, account: { type: Object, default: null }, proxies: Array },
|
||||
template: '<div data-test="edit-account">{{ show ? account?.name : "" }}</div>'
|
||||
})
|
||||
|
||||
@@ -188,6 +188,21 @@ describe('admin AccountsView lite account list', () => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('loads proxies with account counts and passes them to create and edit modals', async () => {
|
||||
const proxies = [
|
||||
{ id: 1, name: 'Unused proxy', account_count: 0 },
|
||||
{ id: 2, name: 'Shared proxy', account_count: 7 }
|
||||
]
|
||||
getAllProxies.mockResolvedValue(proxies)
|
||||
const wrapper = mountView()
|
||||
await flushPromises()
|
||||
|
||||
expect(getAllProxies).toHaveBeenCalledTimes(1)
|
||||
expect(wrapper.findComponent({ name: 'CreateAccountModal' }).props('proxies')).toEqual(proxies)
|
||||
expect(wrapper.findComponent(EditAccountModalStub).props('proxies')).toEqual(proxies)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('syncs the selected row without clearing notes missing from the upstream', async () => {
|
||||
const account = { ...listRow, type: 'apikey', notes: 'local notes' }
|
||||
listAccounts.mockResolvedValue({ items: [account], total: 1, page: 1, page_size: 20, pages: 1 })
|
||||
|
||||
@@ -19,7 +19,7 @@ vi.mock('@/api/admin', () => ({
|
||||
batchRefresh: vi.fn(),
|
||||
toggleSchedulable: vi.fn()
|
||||
},
|
||||
proxies: { getAll: vi.fn().mockResolvedValue([]) },
|
||||
proxies: { getAllWithCount: vi.fn().mockResolvedValue([]) },
|
||||
groups: { getAll: vi.fn().mockResolvedValue([]) }
|
||||
}
|
||||
}))
|
||||
|
||||
@@ -30,7 +30,7 @@ vi.mock('@/api/admin', () => ({
|
||||
toggleSchedulable: vi.fn()
|
||||
},
|
||||
proxies: {
|
||||
getAll: getAllProxies
|
||||
getAllWithCount: getAllProxies
|
||||
},
|
||||
groups: {
|
||||
getAll: getAllGroups
|
||||
|
||||
@@ -36,7 +36,7 @@ vi.mock('@/api/admin', () => ({
|
||||
bulkUpdate: vi.fn()
|
||||
},
|
||||
proxies: {
|
||||
getAll: getAllProxies
|
||||
getAllWithCount: getAllProxies
|
||||
},
|
||||
groups: {
|
||||
getAll: getAllGroups
|
||||
|
||||
@@ -45,7 +45,7 @@ vi.mock('@/api/admin', () => ({
|
||||
batchRefresh: vi.fn(),
|
||||
toggleSchedulable: vi.fn()
|
||||
},
|
||||
proxies: { getAll: getAllProxies },
|
||||
proxies: { getAllWithCount: getAllProxies },
|
||||
groups: { getAll: getAllGroups }
|
||||
}
|
||||
}))
|
||||
@@ -341,7 +341,7 @@ describe('admin AccountsView — 账号行展示', () => {
|
||||
const tooltip = wrapper.findComponent(HelpTooltip)
|
||||
expect(tooltip.props('content')).toBe('https://relay.example.com')
|
||||
expect(tooltip.props('widthClass')).toBe('w-max max-w-sm break-all')
|
||||
expect(tooltip.classes()).toEqual(expect.arrayContaining(['self-start']))
|
||||
expect(tooltip.classes()).toEqual(expect.arrayContaining(['inline-flex', 'items-center', 'align-middle', '-ml-1']))
|
||||
expect(wrapper.text()).toContain('oauth-account')
|
||||
expect(wrapper.text()).toContain('invalid-url')
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ vi.mock('@/api/admin', () => ({
|
||||
toggleSchedulable: vi.fn()
|
||||
},
|
||||
proxies: {
|
||||
getAll: getAllProxies
|
||||
getAllWithCount: getAllProxies
|
||||
},
|
||||
groups: {
|
||||
getAll: getAllGroups
|
||||
|
||||
Reference in new issue
Block a user