A full-featured download manager.
import '@testing-library/jest-dom/vitest'
import '@renderer/lib/i18n'
import {
type PlatformServices,
PlatformServicesProvider,
} from '@renderer/platform/services'
import { Queries } from '@shared/protocol/queries'
import { NatState } from '@shared/types/nat'
import { render, screen } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
vi.mock('@renderer/hooks/use-global-stats', () => ({
useGlobalStats: () => ({
stats: {
totalDownloadSpeed: 16_500_000,
totalUploadSpeed: 4_000_000,
activeTasks: 4,
waitingTasks: 0,
stoppedTasks: 42,
},
}),
}))
vi.mock('@renderer/lib/transport', () => ({
transport: {
invoke: vi.fn().mockImplementation((channel: string) => {
if (channel === Queries.GetEngineStatus) {
return Promise.resolve({ state: 'ready' })
}
if (channel === Queries.GetNatStatus) {
return Promise.resolve({
state: NatState.Active,
enabled: true,
activeMappings: [],
gatewayInfo: null,
lastError: null,
lastDiagnostic: null,
retryAttempt: 0,
maxRetries: 3,
})
}
return Promise.resolve(undefined)
}),
on: vi.fn(),
off: vi.fn(),
platform: 'darwin',
},
}))
import { GlobalStatsBar } from './global-stats-bar'
const testPlatformServices: PlatformServices = {
kind: 'electron',
pickSaveDir: vi.fn(async () => null),
closeHost: vi.fn(),
readClipboard: vi.fn(async () => ''),
openExternal: vi.fn(),
notify: vi.fn(),
}
describe('GlobalStatsBar', () => {
it('renders formatted speeds with engine and nat badges', async () => {
render(
<PlatformServicesProvider services={testPlatformServices}>
<GlobalStatsBar />
</PlatformServicesProvider>
)
const [upload, download] = screen.getAllByRole('definition')
expect(upload).toHaveTextContent('4.0 MB/s')
expect(download).toHaveTextContent('16.5 MB/s')
expect(await screen.findByText(/Engine ready/)).toBeInTheDocument()
expect(await screen.findByText(/NAT mapped/)).toBeInTheDocument()
})
})