Show today stats for Vertex usage window

This commit is contained in:
Oliver
2026-04-25 19:46:32 -04:00
parent 496469ac4e
commit 489a4d934e
2 changed files with 87 additions and 0 deletions

View File

@@ -332,6 +332,37 @@
<!-- Usage data or unlimited flow -->
<div class="space-y-1">
<div
v-if="showGeminiTodayStats && todayStats"
class="mb-0.5 flex items-center"
>
<div class="flex items-center gap-1.5 text-[9px] text-gray-500 dark:text-gray-400">
<span class="rounded bg-gray-100 px-1.5 py-0.5 dark:bg-gray-800">
{{ formatKeyRequests }} req
</span>
<span class="rounded bg-gray-100 px-1.5 py-0.5 dark:bg-gray-800">
{{ formatKeyTokens }}
</span>
<span class="rounded bg-gray-100 px-1.5 py-0.5 dark:bg-gray-800" :title="t('usage.accountBilled')">
A ${{ formatKeyCost }}
</span>
<span
v-if="todayStats.user_cost != null"
class="rounded bg-gray-100 px-1.5 py-0.5 dark:bg-gray-800"
:title="t('usage.userBilled')"
>
U ${{ formatKeyUserCost }}
</span>
</div>
</div>
<div
v-else-if="showGeminiTodayStats && todayStatsLoading"
class="mb-0.5 flex items-center gap-1"
>
<div class="h-3 w-10 animate-pulse rounded bg-gray-200 dark:bg-gray-700"></div>
<div class="h-3 w-8 animate-pulse rounded bg-gray-200 dark:bg-gray-700"></div>
<div class="h-3 w-12 animate-pulse rounded bg-gray-200 dark:bg-gray-700"></div>
</div>
<div v-if="loading" class="space-y-1">
<div class="flex items-center gap-1">
<div class="h-3 w-[32px] animate-pulse rounded bg-gray-200 dark:bg-gray-700"></div>
@@ -512,6 +543,10 @@ const shouldFetchUsage = computed(() => {
return false
})
const showGeminiTodayStats = computed(() => {
return props.account.platform === 'gemini' && props.account.type === 'service_account'
})
const geminiUsageAvailable = computed(() => {
return (
!!usageInfo.value?.gemini_shared_daily ||

View File

@@ -57,6 +57,19 @@ function makeAccount(overrides: Partial<Account>): Account {
describe('AccountUsageCell', () => {
beforeEach(() => {
getUsage.mockReset()
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation(() => ({
matches: true,
media: '(min-width: 768px)',
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
}))
})
})
it('Antigravity 图片用量会聚合新旧 image 模型', async () => {
@@ -603,4 +616,43 @@ describe('AccountUsageCell', () => {
expect(wrapper.text().trim()).toBe('-')
})
it('Vertex 账号会在 Gemini 用量窗口里展示 today stats 徽章', async () => {
const wrapper = mount(AccountUsageCell, {
props: {
account: makeAccount({
id: 4001,
platform: 'gemini',
type: 'service_account',
credentials: {
tier_id: 'vertex',
project_id: 'vertex-proj',
client_email: 'svc@vertex-proj.iam.gserviceaccount.com',
location: 'global'
},
extra: {}
}),
todayStats: {
requests: 0,
tokens: 0,
cost: 0,
standard_cost: 0,
user_cost: 0
}
},
global: {
stubs: {
UsageProgressBar: true,
AccountQuotaInfo: true
}
}
})
await flushPromises()
expect(wrapper.text()).toContain('0 req')
expect(wrapper.text()).toContain('0')
expect(wrapper.text()).toContain('A $0.00')
expect(wrapper.text()).toContain('U $0.00')
})
})