this repo has no description
1import CodexBarCore
2import Foundation
3import Testing
4@testable import CodexBar
5
6@Suite
7struct MenuCardModelTests {
8 @Test
9 func buildsMetricsUsingRemainingPercent() {
10 let now = Date()
11 let snapshot = UsageSnapshot(
12 primary: RateWindow(
13 usedPercent: 22,
14 windowMinutes: 300,
15 resetsAt: now.addingTimeInterval(3000),
16 resetDescription: nil),
17 secondary: RateWindow(
18 usedPercent: 40,
19 windowMinutes: 10080,
20 resetsAt: now.addingTimeInterval(6000),
21 resetDescription: nil),
22 updatedAt: now,
23 accountEmail: "codex@example.com",
24 loginMethod: "Plus Plan")
25 let metadata = ProviderDefaults.metadata[.codex]!
26 let updatedSnap = UsageSnapshot(
27 primary: snapshot.primary,
28 secondary: RateWindow(
29 usedPercent: snapshot.secondary.usedPercent,
30 windowMinutes: snapshot.secondary.windowMinutes,
31 resetsAt: now.addingTimeInterval(3600),
32 resetDescription: nil),
33 tertiary: snapshot.tertiary,
34 updatedAt: now,
35 accountEmail: snapshot.accountEmail,
36 accountOrganization: snapshot.accountOrganization,
37 loginMethod: snapshot.loginMethod)
38
39 let model = UsageMenuCardView.Model.make(.init(
40 provider: .codex,
41 metadata: metadata,
42 snapshot: updatedSnap,
43 credits: CreditsSnapshot(remaining: 12, events: [], updatedAt: now),
44 creditsError: nil,
45 account: AccountInfo(email: "codex@example.com", plan: "Plus Plan"),
46 isRefreshing: false,
47 lastError: nil))
48
49 #expect(model.providerName == "Codex")
50 #expect(model.metrics.count == 2)
51 #expect(model.metrics.first?.percentLeft == 78)
52 #expect(model.planText == "Plus")
53 #expect(model.subtitleText.hasPrefix("Updated"))
54 #expect(model.progressColor != .clear)
55 #expect(model.metrics[1].resetText?.isEmpty == false)
56 }
57
58 @Test
59 func showsErrorSubtitleWhenPresent() {
60 let metadata = ProviderDefaults.metadata[.codex]!
61 let model = UsageMenuCardView.Model.make(.init(
62 provider: .codex,
63 metadata: metadata,
64 snapshot: nil,
65 credits: nil,
66 creditsError: nil,
67 account: AccountInfo(email: nil, plan: nil),
68 isRefreshing: false,
69 lastError: "Probe failed for Codex"))
70
71 #expect(model.subtitleStyle == .error)
72 #expect(model.subtitleText.contains("Probe failed"))
73 #expect(model.placeholder == nil)
74 }
75
76 @Test
77 func claudeModelDoesNotLeakCodexPlan() {
78 let metadata = ProviderDefaults.metadata[.claude]!
79 let model = UsageMenuCardView.Model.make(.init(
80 provider: .claude,
81 metadata: metadata,
82 snapshot: nil,
83 credits: nil,
84 creditsError: nil,
85 account: AccountInfo(email: "codex@example.com", plan: "plus"),
86 isRefreshing: false,
87 lastError: nil))
88
89 #expect(model.planText == nil)
90 #expect(model.email.isEmpty)
91 }
92}