Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
import { describe, expect, it, vi } from 'vitest';
import { fireEvent, render, screen } from '@testing-library/react';
import ModelDownloadBadge, { deriveSizeEstimate } from './ModelDownloadBadge.jsx';
describe('deriveSizeEstimate', () => {
it('preserves decimal and binary gigabyte labels', () => {
expect(deriveSizeEstimate('Example model (~8 GB)')).toBe('~8 GB');
expect(deriveSizeEstimate('Wan 2.2 (~16.9 GiB download)')).toBe('~16.9 GiB');
});
it('returns null when no estimate is embedded', () => {
expect(deriveSizeEstimate('Example model')).toBeNull();
expect(deriveSizeEstimate(null)).toBeNull();
});
});
describe('ModelDownloadBadge', () => {
it('disables a gated download and explains why', () => {
const onDownload = vi.fn();
render(<ModelDownloadBadge
status={{ repo: 'example/model', cached: false }}
onDownload={onDownload}
disabled
disabledReason="Accept the model terms first"
disabledReasonId="model-terms"
/>);
const button = screen.getByRole('button', { name: /Download/ });
expect(button).toBeDisabled();
expect(button).toHaveAttribute('title', 'Accept the model terms first');
expect(button).toHaveAttribute('aria-describedby', 'model-terms');
fireEvent.click(button);
expect(onDownload).not.toHaveBeenCalled();
});
it('does not treat a 1-file start as 100%', () => {
render(<ModelDownloadBadge
status={{
repo: 'example/encoder',
cached: false,
downloading: true,
progress: {
type: 'progress',
stage: 'download',
progress: 0,
step: 1,
total: 1,
file: 'qwen3vl_32b.safetensors',
},
}}
/>);
expect(screen.getByText('Downloading…')).toBeInTheDocument();
expect(screen.queryByText(/100%/)).not.toBeInTheDocument();
expect(screen.getByText('1/1 · qwen3vl_32b.safetensors')).toBeInTheDocument();
});
it('shows byte progress for a large single-file pull', () => {
render(<ModelDownloadBadge
status={{
repo: 'example/encoder',
cached: false,
downloading: true,
progress: {
type: 'progress',
stage: 'download',
progress: 0.5,
step: 1,
total: 1,
downloaded: 24 * 1024 * 1024 * 1024,
totalBytes: 48 * 1024 * 1024 * 1024,
file: 'qwen3vl_32b.safetensors',
},
}}
/>);
expect(screen.getByText('Downloading… 50%')).toBeInTheDocument();
expect(screen.getByText('24 GB / 48 GB')).toBeInTheDocument();
});
it('labels the post-transfer commit as verifying', () => {
render(<ModelDownloadBadge
status={{
repo: 'example/encoder',
cached: false,
downloading: true,
progress: {
type: 'progress',
stage: 'verify',
progress: 1,
step: 1,
total: 1,
file: 'qwen3vl_32b.safetensors',
},
}}
/>);
expect(screen.getByText('Verifying… 100%')).toBeInTheDocument();
});
});