codeburn/app/renderer/sections/WindowsCompanionCard.test.tsx
Resham Joshi ea78d36ccf
Some checks are pending
Tests / desktop (push) Waiting to run
Tests / test (22) (push) Waiting to run
Tests / test (22.13.0) (push) Waiting to run
CI / semgrep (push) Waiting to run
Tests / test (24) (push) Waiting to run
Tests / test (26) (push) Waiting to run
Tests / test-platforms (macos-latest) (push) Waiting to run
Tests / test-platforms (windows-latest) (push) Waiting to run
Windows menu bar and Capacity Dock as a Plugins card, plus desktop fixes (#1507)
* feat(windows): configure the menu bar and Capacity Dock as a Plugins card

Windows now configures its tray companion from a card on the Plugins page, the
same place macOS does, instead of two switches in the sidebar corner.

- WindowsCompanionCard mirrors the macOS MenuBarCard: Install/Reinstall,
  Update, Open (show the tray popover), Settings (opens the desktop Menu bar
  settings pane), Quit (stop without uninstalling), Uninstall, plus the
  Capacity Dock toggle, a Running dot, the version, and an info popup.
- MenubarCompanion.status() now reports installed/running/version/outdated/
  canInstall, and new discrete install/open/quit/uninstall actions back the
  card. uninstall only forgets the tray once the CLI removal succeeds, and a
  cancelled elevation prompt is treated as a no-op rather than a failure.
- isNewerVersion sorts a dev build below any release, so a staged release still
  lights Update and a dev build never does.
- codeburn menubar --uninstall reads the product code from the install marker
  or the uninstall registry and runs msiexec /x.
- Remove the bespoke sidebar CompanionSwitches and their dead CSS.
- A dev-only CODEBURN_MENUBAR_RESOURCES override lets the tray install run
  without packaging; the CLI still validates the staged path in full.

* feat(desktop): fold the Capacity Dock settings into the Menu bar pane

One tray rail entry instead of two: MenuBarPane and CapacityDockPane render
together in the Menu bar pane with a clear gap between the two cards, so the
card's Settings button opens both. Drops the now-unreachable 'dock' pane value.

* fix(desktop): stop the Spend cost-flow Sankey from re-rendering forever

The label-fit effect measured the already-truncated text, so a capped label
read as short, un-capped, overflowed the cap, and re-capped without end
(Maximum update depth exceeded). It now estimates each label from its full
name via data-name, and caps only tighten per layout, so the measure, cap and
remeasure cycle is guaranteed to settle instead of oscillating.

* feat(desktop): bundle Inter and JetBrains Mono for one UI on every OS

The app used each platform's system font (SF Pro on macOS, Segoe UI on
Windows), so the two looked different. Bundle Inter for text and JetBrains
Mono for figures and lead the --sans and --mono stacks with them, keeping the
per-locale CJK fallbacks, so Windows and macOS render the same faces.

* desktop: gate tray installed state on support; drop strings and channels the sidebar switches left behind
2026-09-19 18:43:27 -07:00

148 lines
6.2 KiB
TypeScript

// @vitest-environment jsdom
import { afterEach, describe, expect, it, vi } from 'vitest'
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
import type { CompanionStatus } from '../lib/types'
const bridge = vi.hoisted(() => ({
companionStatus: vi.fn(),
companionInstall: vi.fn(),
companionOpen: vi.fn(),
companionQuit: vi.fn(),
companionUninstall: vi.fn(),
companionSetDock: vi.fn(),
}))
vi.mock('../lib/ipc', () => ({ codeburn: bridge, normalizeCliError: (err: unknown) => err }))
const { WindowsCompanionCard } = await import('./WindowsCompanionCard')
function status(patch: Partial<CompanionStatus> = {}): CompanionStatus {
return {
supported: true, menuBar: true, sidebar: true, store: false,
canInstall: true, installed: true, running: true, version: '0.9.24', outdated: false,
...patch,
}
}
afterEach(() => { vi.clearAllMocks() })
function renderCard(s: CompanionStatus = status(), onOpenSettings?: () => void) {
bridge.companionStatus.mockResolvedValue(s)
render(<WindowsCompanionCard onOpenSettings={onOpenSettings} />)
}
describe('WindowsCompanionCard', () => {
it('renders nothing where the main process reports no bundled tray app', async () => {
renderCard(status({ supported: false }))
await waitFor(() => expect(bridge.companionStatus).toHaveBeenCalled())
expect(screen.queryByText('Menu bar')).toBeNull()
})
it('offers Install when supported but nothing is installed', async () => {
renderCard(status({ installed: false, running: false, version: null }))
const install = await screen.findByRole('button', { name: 'Install' })
bridge.companionInstall.mockResolvedValue({ ok: true, error: null, status: status() })
fireEvent.click(install)
await waitFor(() => expect(bridge.companionInstall).toHaveBeenCalled())
})
it('shows the website line where the tray app cannot be installed from here (Store)', async () => {
renderCard(status({ installed: false, running: false, canInstall: false, version: null }))
expect(await screen.findByText('Get the menu bar from the website')).toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Install' })).toBeNull()
})
it('shows Running and the version while it is up', async () => {
renderCard()
expect(await screen.findByText('Running')).toBeInTheDocument()
expect(screen.getByText('v0.9.24')).toBeInTheDocument()
})
it('while running, offers Settings, Quit, Uninstall and an enabled dock toggle, but not Open', async () => {
const onOpenSettings = vi.fn()
renderCard(status(), onOpenSettings)
expect(await screen.findByRole('button', { name: 'Settings' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Quit' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Uninstall' })).toBeInTheDocument()
expect(screen.getByRole('switch', { name: 'Capacity Dock' })).toBeEnabled()
expect(screen.queryByRole('button', { name: 'Open' })).toBeNull()
fireEvent.click(screen.getByRole('button', { name: 'Settings' }))
expect(onOpenSettings).toHaveBeenCalledTimes(1)
})
it('while down, offers Open and Uninstall, and the dock toggle is disabled', async () => {
renderCard(status({ running: false }))
expect(await screen.findByRole('button', { name: 'Open' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Uninstall' })).toBeInTheDocument()
expect(screen.getByRole('switch', { name: 'Capacity Dock' })).toBeDisabled()
expect(screen.queryByRole('button', { name: 'Quit' })).toBeNull()
bridge.companionOpen.mockResolvedValue(status())
fireEvent.click(screen.getByRole('button', { name: 'Open' }))
await waitFor(() => expect(bridge.companionOpen).toHaveBeenCalled())
})
it('offers Update when a newer tray app is staged', async () => {
renderCard(status({ outdated: true }))
const update = await screen.findByRole('button', { name: 'Update' })
bridge.companionInstall.mockResolvedValue({ ok: true, error: null, status: status({ outdated: false }) })
fireEvent.click(update)
await waitFor(() => expect(bridge.companionInstall).toHaveBeenCalled())
})
it('toggling the Capacity Dock sends the opposite of what is set', async () => {
renderCard(status({ sidebar: true }))
const dock = await screen.findByRole('switch', { name: 'Capacity Dock' })
bridge.companionSetDock.mockResolvedValue(status({ sidebar: false }))
fireEvent.click(dock)
expect(bridge.companionSetDock).toHaveBeenCalledWith(false)
})
it('quits only on a second click, and calls the quit action then', async () => {
renderCard()
const quit = await screen.findByRole('button', { name: 'Quit' })
fireEvent.click(quit)
expect(bridge.companionQuit).not.toHaveBeenCalled()
bridge.companionQuit.mockResolvedValue({ ok: true, error: null, status: status({ running: false }) })
fireEvent.click(screen.getByRole('button', { name: 'Confirm quit' }))
await waitFor(() => expect(bridge.companionQuit).toHaveBeenCalled())
})
it('uninstalls only on a second click', async () => {
renderCard()
const uninstall = await screen.findByRole('button', { name: 'Uninstall' })
fireEvent.click(uninstall)
expect(bridge.companionUninstall).not.toHaveBeenCalled()
bridge.companionUninstall.mockResolvedValue({ ok: true, error: null, status: status({ installed: false, running: false }) })
fireEvent.click(screen.getByRole('button', { name: 'Confirm uninstall' }))
await waitFor(() => expect(bridge.companionUninstall).toHaveBeenCalled())
})
it('opens the info popup from the info dot', async () => {
renderCard()
fireEvent.click(await screen.findByRole('button', { name: 'What the menu bar app does' }))
expect(await screen.findByRole('dialog')).toBeInTheDocument()
})
it('shows the returned error when an action fails', async () => {
renderCard(status({ installed: false, running: false, version: null }))
const install = await screen.findByRole('button', { name: 'Install' })
bridge.companionInstall.mockResolvedValue({ ok: false, error: 'msiexec exited with 1603', status: status({ installed: false }) })
fireEvent.click(install)
expect(await screen.findByText('msiexec exited with 1603')).toBeInTheDocument()
})
})