-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathStatusItemControllerMenuTests.swift
More file actions
113 lines (95 loc) · 4.31 KB
/
StatusItemControllerMenuTests.swift
File metadata and controls
113 lines (95 loc) · 4.31 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import AppKit
import CodexBarCore
import Foundation
import Testing
@testable import CodexBar
struct StatusItemControllerMenuTests {
private func makeSnapshot(
primary: RateWindow?,
secondary: RateWindow?,
tertiary: RateWindow? = nil,
providerCost: ProviderCostSnapshot? = nil)
-> UsageSnapshot
{
UsageSnapshot(
primary: primary,
secondary: secondary,
tertiary: tertiary,
providerCost: providerCost,
updatedAt: Date())
}
@Test
func `cursor switcher falls back to on demand budget when plan exhausted and showing remaining`() {
let primary = RateWindow(usedPercent: 100, windowMinutes: nil, resetsAt: nil, resetDescription: nil)
let secondary = RateWindow(usedPercent: 36, windowMinutes: nil, resetsAt: nil, resetDescription: nil)
let providerCost = ProviderCostSnapshot(
used: 12,
limit: 200,
currencyCode: "USD",
updatedAt: Date())
let snapshot = self.makeSnapshot(primary: primary, secondary: secondary, providerCost: providerCost)
let percent = StatusItemController.switcherWeeklyMetricPercent(
for: .cursor,
snapshot: snapshot,
showUsed: false)
#expect(percent == 94)
}
@Test
func `cursor switcher uses primary when showing used`() {
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 `cursor switcher keeps primary when remaining is positive`() {
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)
}
@Test
func `cursor switcher does not treat auto lane as extra remaining quota`() {
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 == 0)
}
@Test
func `perplexity switcher falls back after recurring credits are exhausted`() {
let primary = RateWindow(usedPercent: 100, windowMinutes: nil, resetsAt: nil, resetDescription: nil)
let secondary = RateWindow(usedPercent: 100, windowMinutes: nil, resetsAt: nil, resetDescription: nil)
let tertiary = RateWindow(usedPercent: 24, windowMinutes: nil, resetsAt: nil, resetDescription: nil)
let snapshot = self.makeSnapshot(primary: primary, secondary: secondary, tertiary: tertiary)
let percent = StatusItemController.switcherWeeklyMetricPercent(
for: .perplexity,
snapshot: snapshot,
showUsed: false)
#expect(percent == 76)
}
@Test
@MainActor
func `menu card width stays at base width when menu accessories are present`() {
let shortcutMenu = NSMenu()
let refreshItem = NSMenuItem(title: "Refresh", action: nil, keyEquivalent: "r")
shortcutMenu.addItem(refreshItem)
#expect(ceil(shortcutMenu.size.width) < 310)
let submenuMenu = NSMenu()
let parentItem = NSMenuItem(title: "Session", action: nil, keyEquivalent: "")
parentItem.submenu = NSMenu(title: "Session")
submenuMenu.addItem(parentItem)
#expect(ceil(submenuMenu.size.width) < 310)
}
}