import CodexBarCoreimport Foundationimport Testing@testable import CodexBar @Suitestruct StatusItemControllerMenuTests { private func makeSnapshot(primary: RateWindow?, secondary: RateWindow?) -> UsageSnapshot { UsageSnapshot(primary: primary, secondary: secondary, updatedAt: Date()) } @Test func cursorSwitcherFallsBackToSecondaryWhenPlanExhaustedAndShowingRemaining() { let primary = RateWindow(usedPercent: 100, windowMinutes: nil, resetsAt: nil, resetDescription: nil) let secondary = RateWindow(usedPercent: 36, windowMinutes: nil, resetsAt: nil, resetDescription: nil) let snapshot = self.makeSnapshot(primary: primary, secondary: secondary) let percent = StatusItemController.switcherWeeklyMetricPercent( for: .cursor, snapshot: snapshot, showUsed: false) #expect(percent == 64) } @Test func cursorSwitcherUsesPrimaryWhenShowingUsed() { let primary = RateWindow(usedPercent: 100, windowMinutes: nil, resetsAt: nil, resetDescription: nil) let secondary = RateWindow(usedPercent: 36, windowMinutes: nil, resetsAt: nil, resetDescription: nil) let snapshot = self.makeSnapshot(primary: primary, secondary: secondary) let percent = StatusItemController.switcherWeeklyMetricPercent( for: .cursor, snapshot: snapshot, showUsed: true) #expect(percent == 100) } @Test func cursorSwitcherKeepsPrimaryWhenRemainingIsPositive() { let primary = RateWindow(usedPercent: 20, windowMinutes: nil, resetsAt: nil, resetDescription: nil) let secondary = RateWindow(usedPercent: 40, windowMinutes: nil, resetsAt: nil, resetDescription: nil) let snapshot = self.makeSnapshot(primary: primary, secondary: secondary) let percent = StatusItemController.switcherWeeklyMetricPercent( for: .cursor, snapshot: snapshot, showUsed: false) #expect(percent == 80) }}
import CodexBarCore
import Foundation
import Testing
@testable import CodexBar
@Suite
struct StatusItemControllerMenuTests {
private func makeSnapshot(primary: RateWindow?, secondary: RateWindow?) -> UsageSnapshot {
UsageSnapshot(primary: primary, secondary: secondary, updatedAt: Date())
}
@Test
func cursorSwitcherFallsBackToSecondaryWhenPlanExhaustedAndShowingRemaining() {
let primary = RateWindow(usedPercent: 100, windowMinutes: nil, resetsAt: nil, resetDescription: nil)
let secondary = RateWindow(usedPercent: 36, windowMinutes: nil, resetsAt: nil, resetDescription: nil)
let snapshot = self.makeSnapshot(primary: primary, secondary: secondary)
let percent = StatusItemController.switcherWeeklyMetricPercent(
for: .cursor,
snapshot: snapshot,
showUsed: false)
#expect(percent == 64)
}
@Test
func cursorSwitcherUsesPrimaryWhenShowingUsed() {
let primary = RateWindow(usedPercent: 100, windowMinutes: nil, resetsAt: nil, resetDescription: nil)
let secondary = RateWindow(usedPercent: 36, windowMinutes: nil, resetsAt: nil, resetDescription: nil)
let snapshot = self.makeSnapshot(primary: primary, secondary: secondary)
let percent = StatusItemController.switcherWeeklyMetricPercent(
for: .cursor,
snapshot: snapshot,
showUsed: true)
#expect(percent == 100)
}
@Test
func cursorSwitcherKeepsPrimaryWhenRemainingIsPositive() {
let primary = RateWindow(usedPercent: 20, windowMinutes: nil, resetsAt: nil, resetDescription: nil)
let secondary = RateWindow(usedPercent: 40, windowMinutes: nil, resetsAt: nil, resetDescription: nil)
let snapshot = self.makeSnapshot(primary: primary, secondary: secondary)
let percent = StatusItemController.switcherWeeklyMetricPercent(
for: .cursor,
snapshot: snapshot,
showUsed: false)
#expect(percent == 80)
}
}