codeburn/mac/Tests/CodeBurnMenubarTests/CapacityDockConnectionActionTests.swift
Aditya Vikram Singh 84fea9d550
feat(menubar): add native Capacity Dock (#1167)
* feat(menubar): add native capacity dock

* fix(menubar): harden dock interaction boundaries

* feat(menubar): polish native Capacity Dock for launch

- Flush top-edge docking via NSHostingView safe-area opt-out; shielding
  window level so the rail necks into the physical top like the system notch
- Liquid Glass legibility scrim so labels stay readable on light wallpapers
- Weekly-else-monthly headline window; unified severity colour bands
  (green <50 / yellow / orange / red) across rings and detail bars
- Squircle gauge + graphite theme defaults; auto-show connected
  subscriptions (up to 5) until the user edits the set, then respect it
- Capacity Dock Settings menu item; re-centre the settings window; info
  glyph for the About row
- Trim dead provider-credential override fields down to apiKey only
- Reconcile and extend tests for all of the above

---------

Co-authored-by: iamtoruk <hello@agentseal.org>
2026-08-29 00:37:30 -07:00

68 lines
2.4 KiB
Swift

import Foundation
import Testing
@testable import CodeBurnMenubar
@Suite("Capacity Dock connection action")
struct CapacityDockConnectionActionTests {
@Test("missing or disconnected quota offers a direct Connect action")
func connectAction() {
#expect(CapacityDockConnectionAction.resolve(quota: nil) == .connect)
#expect(CapacityDockConnectionAction.resolve(quota: summary(connection: .disconnected)) == .connect)
}
@Test("terminal provider failure offers Reconnect")
func reconnectAction() {
let quota = summary(connection: .terminalFailure(reason: "Sign in again."))
#expect(CapacityDockConnectionAction.resolve(quota: quota) == .reconnect)
}
@Test("API-only providers route the dock action to credential entry")
func apiCredentialActionTitle() {
let provider = CapacityDockProvider(rawValue: "clinepass")!
#expect(CapacityDockConnectionAction.reconnect.title(for: provider) == "Add API Key")
#expect(ProviderConnectionGuidance.dockInstruction(for: provider) ==
"Add an API key or token in Provider Settings.")
}
@Test("active and automatically recovering states do not offer a connection action")
func noActionWhileActive() {
let states: [QuotaSummary.Connection] = [
.connected,
.loading,
.stale,
.transientFailure,
]
for state in states {
#expect(CapacityDockConnectionAction.resolve(quota: summary(connection: state)) == nil)
}
}
@Test("an explicit Connect executes one user-initiated refresh operation")
func explicitConnectInteraction() async throws {
let counter = RefreshCounter()
let value = try await CapacityDockProviderRefreshInteraction.userInitiated {
await counter.increment()
return 42
}
let refreshCount = await counter.value
#expect(value == 42)
#expect(refreshCount == 1)
}
private func summary(connection: QuotaSummary.Connection) -> QuotaSummary {
QuotaSummary(
providerFilter: .codex,
connection: connection,
primary: nil,
details: [],
planLabel: nil,
footerLines: []
)
}
private actor RefreshCounter {
private(set) var value = 0
func increment() { value += 1 }
}
}