@@ -67,6 +67,198 @@ struct MenuCardModelCodexProjectionTests {
6767 #expect( weekly. detailRightText == " Lasts until reset" )
6868 }
6969
70+ @Test
71+ func `codex weekly lane includes workday markers when workDaysPerWeek is set`() throws {
72+ let now = Date ( timeIntervalSince1970: 1_800_000_000 )
73+ let metadata = try #require( ProviderDefaults . metadata [ . codex] )
74+ let identity = ProviderIdentitySnapshot (
75+ providerID: . codex,
76+ accountEmail
: " [email protected] " , 77+ accountOrganization: nil ,
78+ loginMethod: " Pro " )
79+ let snapshot = UsageSnapshot (
80+ primary: RateWindow (
81+ usedPercent: 2 ,
82+ windowMinutes: 300 ,
83+ resetsAt: now. addingTimeInterval ( 4 * 60 * 60 ) ,
84+ resetDescription: nil ) ,
85+ secondary: RateWindow (
86+ usedPercent: 4 ,
87+ windowMinutes: 10080 ,
88+ resetsAt: now. addingTimeInterval ( 6 * 24 * 60 * 60 ) ,
89+ resetDescription: nil ) ,
90+ tertiary: nil ,
91+ updatedAt: now,
92+ identity: identity)
93+ let projection = CodexConsumerProjection . make (
94+ surface: . liveCard,
95+ context: CodexConsumerProjection . Context (
96+ snapshot: snapshot,
97+ rawUsageError: nil ,
98+ liveCredits: nil ,
99+ rawCreditsError: nil ,
100+ liveDashboard: nil ,
101+ rawDashboardError: nil ,
102+ dashboardAttachmentAuthorized: false ,
103+ dashboardRequiresLogin: false ,
104+ now: now) )
105+
106+ let model = UsageMenuCardView . Model. make ( . init(
107+ provider: . codex,
108+ metadata: metadata,
109+ snapshot: snapshot,
110+ codexProjection: projection,
111+ credits: nil ,
112+ creditsError: nil ,
113+ dashboard: nil ,
114+ dashboardError: nil ,
115+ tokenSnapshot: nil ,
116+ tokenError: nil ,
117+ account
: AccountInfo ( email
: " [email protected] " , plan
: " Pro " ) , 118+ isRefreshing: false ,
119+ lastError: nil ,
120+ usageBarsShowUsed: false ,
121+ resetTimeDisplayStyle: . countdown,
122+ tokenCostUsageEnabled: false ,
123+ showOptionalCreditsAndExtraUsage: true ,
124+ hidePersonalInfo: false ,
125+ quotaWarningThresholds: [ . session: [ ] , . weekly: [ ] ] ,
126+ workDaysPerWeek: 5 ,
127+ now: now) )
128+
129+ let weekly = try #require( model. metrics. first { $0. id == " secondary " } )
130+ #expect( weekly. warningMarkerPercents == [ 20.0 , 40.0 , 60.0 , 80.0 ] )
131+
132+ let session = try #require( model. metrics. first { $0. id == " primary " } )
133+ #expect( session. warningMarkerPercents. isEmpty)
134+ }
135+
136+ @Test
137+ func `codex weekly lane workday markers merge with quota warning markers`() throws {
138+ let now = Date ( timeIntervalSince1970: 1_800_000_000 )
139+ let metadata = try #require( ProviderDefaults . metadata [ . codex] )
140+ let identity = ProviderIdentitySnapshot (
141+ providerID: . codex,
142+ accountEmail
: " [email protected] " , 143+ accountOrganization: nil ,
144+ loginMethod: " Pro " )
145+ let snapshot = UsageSnapshot (
146+ primary: RateWindow (
147+ usedPercent: 2 ,
148+ windowMinutes: 300 ,
149+ resetsAt: now. addingTimeInterval ( 4 * 60 * 60 ) ,
150+ resetDescription: nil ) ,
151+ secondary: RateWindow (
152+ usedPercent: 4 ,
153+ windowMinutes: 10080 ,
154+ resetsAt: now. addingTimeInterval ( 6 * 24 * 60 * 60 ) ,
155+ resetDescription: nil ) ,
156+ tertiary: nil ,
157+ updatedAt: now,
158+ identity: identity)
159+ let projection = CodexConsumerProjection . make (
160+ surface: . liveCard,
161+ context: CodexConsumerProjection . Context (
162+ snapshot: snapshot,
163+ rawUsageError: nil ,
164+ liveCredits: nil ,
165+ rawCreditsError: nil ,
166+ liveDashboard: nil ,
167+ rawDashboardError: nil ,
168+ dashboardAttachmentAuthorized: false ,
169+ dashboardRequiresLogin: false ,
170+ now: now) )
171+
172+ let model = UsageMenuCardView . Model. make ( . init(
173+ provider: . codex,
174+ metadata: metadata,
175+ snapshot: snapshot,
176+ codexProjection: projection,
177+ credits: nil ,
178+ creditsError: nil ,
179+ dashboard: nil ,
180+ dashboardError: nil ,
181+ tokenSnapshot: nil ,
182+ tokenError: nil ,
183+ account
: AccountInfo ( email
: " [email protected] " , plan
: " Pro " ) , 184+ isRefreshing: false ,
185+ lastError: nil ,
186+ usageBarsShowUsed: false ,
187+ resetTimeDisplayStyle: . countdown,
188+ tokenCostUsageEnabled: false ,
189+ showOptionalCreditsAndExtraUsage: true ,
190+ hidePersonalInfo: false ,
191+ quotaWarningThresholds: [ . session: [ ] , . weekly: [ 50 ] ] ,
192+ workDaysPerWeek: 5 ,
193+ now: now) )
194+
195+ let weekly = try #require( model. metrics. first { $0. id == " secondary " } )
196+ #expect( weekly. warningMarkerPercents == [ 20.0 , 40.0 , 50.0 , 60.0 , 80.0 ] )
197+ }
198+
199+ @Test
200+ func `codex weekly lane workday markers not inverted by usageBarsShowUsed`() throws {
201+ let now = Date ( timeIntervalSince1970: 1_800_000_000 )
202+ let metadata = try #require( ProviderDefaults . metadata [ . codex] )
203+ let identity = ProviderIdentitySnapshot (
204+ providerID: . codex,
205+ accountEmail
: " [email protected] " , 206+ accountOrganization: nil ,
207+ loginMethod: " Pro " )
208+ let snapshot = UsageSnapshot (
209+ primary: RateWindow (
210+ usedPercent: 2 ,
211+ windowMinutes: 300 ,
212+ resetsAt: now. addingTimeInterval ( 4 * 60 * 60 ) ,
213+ resetDescription: nil ) ,
214+ secondary: RateWindow (
215+ usedPercent: 4 ,
216+ windowMinutes: 10080 ,
217+ resetsAt: now. addingTimeInterval ( 6 * 24 * 60 * 60 ) ,
218+ resetDescription: nil ) ,
219+ tertiary: nil ,
220+ updatedAt: now,
221+ identity: identity)
222+ let projection = CodexConsumerProjection . make (
223+ surface: . liveCard,
224+ context: CodexConsumerProjection . Context (
225+ snapshot: snapshot,
226+ rawUsageError: nil ,
227+ liveCredits: nil ,
228+ rawCreditsError: nil ,
229+ liveDashboard: nil ,
230+ rawDashboardError: nil ,
231+ dashboardAttachmentAuthorized: false ,
232+ dashboardRequiresLogin: false ,
233+ now: now) )
234+
235+ let model = UsageMenuCardView . Model. make ( . init(
236+ provider: . codex,
237+ metadata: metadata,
238+ snapshot: snapshot,
239+ codexProjection: projection,
240+ credits: nil ,
241+ creditsError: nil ,
242+ dashboard: nil ,
243+ dashboardError: nil ,
244+ tokenSnapshot: nil ,
245+ tokenError: nil ,
246+ account
: AccountInfo ( email
: " [email protected] " , plan
: " Pro " ) , 247+ isRefreshing: false ,
248+ lastError: nil ,
249+ usageBarsShowUsed: true ,
250+ resetTimeDisplayStyle: . countdown,
251+ tokenCostUsageEnabled: false ,
252+ showOptionalCreditsAndExtraUsage: true ,
253+ hidePersonalInfo: false ,
254+ quotaWarningThresholds: [ . session: [ ] , . weekly: [ ] ] ,
255+ workDaysPerWeek: 5 ,
256+ now: now) )
257+
258+ let weekly = try #require( model. metrics. first { $0. id == " secondary " } )
259+ #expect( weekly. warningMarkerPercents == [ 20.0 , 40.0 , 60.0 , 80.0 ] )
260+ }
261+
70262 @Test
71263 func `codex plan only snapshot shows limits unavailable placeholder`() throws {
72264 let now = Date ( )
0 commit comments