forked from Wei-Shaw/sub2api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsageStatsCards.spec.ts
More file actions
67 lines (61 loc) · 1.72 KB
/
Copy pathUsageStatsCards.spec.ts
File metadata and controls
67 lines (61 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { describe, expect, it, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import UsageStatsCards from '../UsageStatsCards.vue'
const messages: Record<string, string> = {
'usage.totalRequests': 'Total Requests',
'usage.inSelectedRange': 'in selected range',
'usage.totalTokens': 'Total Tokens',
'usage.in': 'In',
'usage.out': 'Out',
'usage.cacheTotal': 'Cache',
'usage.cacheBreakdown': 'Cache Token Breakdown',
'usage.cacheCreationTokensLabel': 'Cache Creation',
'usage.cacheReadTokensLabel': 'Cache Read',
'usage.totalCost': 'Total Cost',
'usage.accountCost': 'Cost',
'usage.standardCost': 'Standard',
'usage.avgDuration': 'Avg Duration',
}
vi.mock('vue-i18n', async () => {
const actual = await vi.importActual<typeof import('vue-i18n')>('vue-i18n')
return {
...actual,
useI18n: () => ({
t: (key: string) => messages[key] ?? key,
}),
}
})
const stats = {
total_requests: 1,
total_input_tokens: 100,
total_output_tokens: 50,
total_cache_tokens: 34,
total_cache_creation_tokens: 12,
total_cache_read_tokens: 22,
total_tokens: 184,
total_cost: 0.001,
total_actual_cost: 0.001,
total_account_cost: 0.001,
average_duration_ms: 250,
}
describe('UsageStatsCards', () => {
it('shows cache token breakdown values', () => {
const wrapper = mount(UsageStatsCards, {
props: {
stats,
},
global: {
stubs: {
Icon: true,
},
},
})
const text = wrapper.text()
expect(text).toContain('Cache: 34')
expect(text).toContain('Cache Token Breakdown')
expect(text).toContain('Cache Creation')
expect(text).toContain('12')
expect(text).toContain('Cache Read')
expect(text).toContain('22')
})
})