228 lines
6.5 KiB
TypeScript
228 lines
6.5 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { flushPromises, mount } from '@vue/test-utils'
|
|
|
|
import AccountsView from '../AccountsView.vue'
|
|
|
|
const {
|
|
listAccounts,
|
|
listWithEtag,
|
|
getBatchTodayStats,
|
|
getAllProxies,
|
|
getAllGroups
|
|
} = vi.hoisted(() => ({
|
|
listAccounts: vi.fn(),
|
|
listWithEtag: vi.fn(),
|
|
getBatchTodayStats: vi.fn(),
|
|
getAllProxies: vi.fn(),
|
|
getAllGroups: vi.fn()
|
|
}))
|
|
|
|
vi.mock('@/api/admin', () => ({
|
|
adminAPI: {
|
|
accounts: {
|
|
list: listAccounts,
|
|
listWithEtag,
|
|
getBatchTodayStats,
|
|
delete: vi.fn(),
|
|
batchClearError: vi.fn(),
|
|
batchRefresh: vi.fn(),
|
|
toggleSchedulable: vi.fn()
|
|
},
|
|
proxies: {
|
|
getAll: getAllProxies
|
|
},
|
|
groups: {
|
|
getAll: getAllGroups
|
|
}
|
|
}
|
|
}))
|
|
|
|
vi.mock('@/stores/app', () => ({
|
|
useAppStore: () => ({
|
|
showError: vi.fn(),
|
|
showSuccess: vi.fn(),
|
|
showInfo: vi.fn()
|
|
})
|
|
}))
|
|
|
|
vi.mock('@/stores/auth', () => ({
|
|
useAuthStore: () => ({
|
|
token: 'test-token'
|
|
})
|
|
}))
|
|
|
|
vi.mock('vue-i18n', async () => {
|
|
const actual = await vi.importActual<typeof import('vue-i18n')>('vue-i18n')
|
|
return {
|
|
...actual,
|
|
useI18n: () => ({
|
|
t: (key: string) => key
|
|
})
|
|
}
|
|
})
|
|
|
|
const DataTableStub = {
|
|
props: ['columns', 'data'],
|
|
template: `
|
|
<div data-test="data-table">
|
|
<span v-for="column in columns" :key="column.key" data-test="column-key">{{ column.key }}</span>
|
|
<div v-for="row in data" :key="row.id">
|
|
<slot name="cell-created_at" :value="row.created_at" :row="row" />
|
|
</div>
|
|
</div>
|
|
`
|
|
}
|
|
|
|
const AccountBulkActionsBarStub = {
|
|
props: ['selectedIds'],
|
|
emits: ['edit-filtered'],
|
|
template: '<button data-test="edit-filtered" @click="$emit(\'edit-filtered\')">edit filtered</button>'
|
|
}
|
|
|
|
const BulkEditAccountModalStub = {
|
|
props: ['show', 'target'],
|
|
template: '<div data-test="bulk-edit-modal" :data-show="String(show)" :data-target-mode="target?.mode ?? \'\'"></div>'
|
|
}
|
|
|
|
describe('admin AccountsView bulk edit scope', () => {
|
|
beforeEach(() => {
|
|
localStorage.clear()
|
|
|
|
listAccounts.mockReset()
|
|
listWithEtag.mockReset()
|
|
getBatchTodayStats.mockReset()
|
|
getAllProxies.mockReset()
|
|
getAllGroups.mockReset()
|
|
|
|
listAccounts.mockResolvedValue({
|
|
items: [],
|
|
total: 0,
|
|
page: 1,
|
|
page_size: 20,
|
|
pages: 0
|
|
})
|
|
listWithEtag.mockResolvedValue({
|
|
notModified: true,
|
|
etag: null,
|
|
data: null
|
|
})
|
|
getBatchTodayStats.mockResolvedValue({ stats: {} })
|
|
getAllProxies.mockResolvedValue([])
|
|
getAllGroups.mockResolvedValue([])
|
|
})
|
|
|
|
it('opens bulk edit in filtered-results mode from the bulk actions dropdown', async () => {
|
|
const wrapper = mount(AccountsView, {
|
|
global: {
|
|
stubs: {
|
|
AppLayout: { template: '<div><slot /></div>' },
|
|
TablePageLayout: {
|
|
template: '<div><slot name="filters" /><slot name="table" /><slot name="pagination" /></div>'
|
|
},
|
|
DataTable: DataTableStub,
|
|
Pagination: true,
|
|
ConfirmDialog: true,
|
|
AccountTableActions: { template: '<div><slot name="beforeCreate" /><slot name="after" /></div>' },
|
|
AccountTableFilters: { template: '<div></div>' },
|
|
AccountBulkActionsBar: AccountBulkActionsBarStub,
|
|
AccountActionMenu: true,
|
|
ImportDataModal: true,
|
|
ReAuthAccountModal: true,
|
|
AccountTestModal: true,
|
|
AccountStatsModal: true,
|
|
ScheduledTestsPanel: true,
|
|
SyncFromCrsModal: true,
|
|
TempUnschedStatusModal: true,
|
|
ErrorPassthroughRulesModal: true,
|
|
TLSFingerprintProfilesModal: true,
|
|
CreateAccountModal: true,
|
|
EditAccountModal: true,
|
|
BulkEditAccountModal: BulkEditAccountModalStub,
|
|
PlatformTypeBadge: true,
|
|
AccountCapacityCell: true,
|
|
AccountStatusIndicator: true,
|
|
AccountTodayStatsCell: true,
|
|
AccountGroupsCell: true,
|
|
AccountUsageCell: true,
|
|
Icon: true
|
|
}
|
|
}
|
|
})
|
|
|
|
await flushPromises()
|
|
await wrapper.get('[data-test="edit-filtered"]').trigger('click')
|
|
await flushPromises()
|
|
|
|
expect(wrapper.get('[data-test="bulk-edit-modal"]').attributes('data-show')).toBe('true')
|
|
expect(wrapper.get('[data-test="bulk-edit-modal"]').attributes('data-target-mode')).toBe('filtered')
|
|
})
|
|
|
|
it('renders the created_at column by default', async () => {
|
|
listAccounts.mockResolvedValue({
|
|
items: [
|
|
{
|
|
id: 1,
|
|
name: 'test-account',
|
|
platform: 'anthropic',
|
|
type: 'oauth',
|
|
status: 'active',
|
|
schedulable: true,
|
|
created_at: '2026-03-07T10:00:00Z',
|
|
updated_at: '2026-03-07T10:00:00Z'
|
|
}
|
|
],
|
|
total: 1,
|
|
page: 1,
|
|
page_size: 20,
|
|
pages: 1
|
|
})
|
|
|
|
const wrapper = mount(AccountsView, {
|
|
global: {
|
|
stubs: {
|
|
AppLayout: { template: '<div><slot /></div>' },
|
|
TablePageLayout: {
|
|
template: '<div><slot name="filters" /><slot name="table" /><slot name="pagination" /></div>'
|
|
},
|
|
DataTable: DataTableStub,
|
|
Pagination: true,
|
|
ConfirmDialog: true,
|
|
AccountTableActions: { template: '<div><slot name="beforeCreate" /><slot name="after" /></div>' },
|
|
AccountTableFilters: { template: '<div></div>' },
|
|
AccountBulkActionsBar: AccountBulkActionsBarStub,
|
|
AccountActionMenu: true,
|
|
ImportDataModal: true,
|
|
ReAuthAccountModal: true,
|
|
AccountTestModal: true,
|
|
AccountStatsModal: true,
|
|
ScheduledTestsPanel: true,
|
|
SyncFromCrsModal: true,
|
|
TempUnschedStatusModal: true,
|
|
ErrorPassthroughRulesModal: true,
|
|
TLSFingerprintProfilesModal: true,
|
|
CreateAccountModal: true,
|
|
EditAccountModal: true,
|
|
BulkEditAccountModal: BulkEditAccountModalStub,
|
|
PlatformTypeBadge: true,
|
|
AccountCapacityCell: true,
|
|
AccountStatusIndicator: true,
|
|
AccountTodayStatsCell: true,
|
|
AccountGroupsCell: true,
|
|
AccountUsageCell: true,
|
|
Icon: true
|
|
}
|
|
}
|
|
})
|
|
|
|
await flushPromises()
|
|
|
|
const columnKeys = wrapper.findAll('[data-test="column-key"]').map(node => node.text())
|
|
expect(columnKeys).toContain('created_at')
|
|
const columns = wrapper.getComponent(DataTableStub).props('columns') as Array<{ key: string; label: string; sortable: boolean }>
|
|
expect(columns.find(column => column.key === 'created_at')).toMatchObject({
|
|
label: 'admin.accounts.columns.createdAt',
|
|
sortable: true
|
|
})
|
|
})
|
|
})
|