135 lines
5.0 KiB
TypeScript
135 lines
5.0 KiB
TypeScript
import fs from 'node:fs'
|
|
import os from 'node:os'
|
|
import path from 'node:path'
|
|
|
|
import { afterEach, describe, expect, it } from 'bun:test'
|
|
|
|
import { DesktopConfigStore } from '../src/main/config'
|
|
import {
|
|
buildCursorOverlayHtml,
|
|
buildRecordingFilename,
|
|
buildRecordingIndicatorHtml,
|
|
computeIndicatorBounds,
|
|
formatRecordingDuration,
|
|
pickSupportedRecordingMimeTypes,
|
|
resolveRecordingExtension,
|
|
} from '../src/main/recording-core'
|
|
|
|
const tempDirs: string[] = []
|
|
|
|
afterEach(() => {
|
|
while (tempDirs.length > 0) {
|
|
const dir = tempDirs.pop()!
|
|
fs.rmSync(dir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
|
|
describe('recording-core helpers & preference persistence', () => {
|
|
it('formats durations across zero, sub-minute, multi-minute, and multi-hour boundaries', () => {
|
|
expect(formatRecordingDuration(-500)).toBe('00:00')
|
|
expect(formatRecordingDuration(Number.NaN)).toBe('00:00')
|
|
expect(formatRecordingDuration(0)).toBe('00:00')
|
|
expect(formatRecordingDuration(59_900)).toBe('00:59')
|
|
expect(formatRecordingDuration(60_000)).toBe('01:00')
|
|
expect(formatRecordingDuration(3_661_000)).toBe('01:01:01')
|
|
})
|
|
|
|
it('builds collision-safe filenames and resolves mp4/webm extensions', () => {
|
|
const stamp = new Date(2026, 10, 30, 14, 35, 9)
|
|
expect(resolveRecordingExtension('video/mp4;codecs=avc1.42E01E')).toBe('mp4')
|
|
expect(resolveRecordingExtension('video/webm;codecs=vp9')).toBe('webm')
|
|
expect(resolveRecordingExtension(undefined)).toBe('webm')
|
|
|
|
expect(buildRecordingFilename(stamp, 'mp4')).toBe('Planet-Earth-20261130-143509.mp4')
|
|
expect(buildRecordingFilename(stamp, 'mp4', 1)).toBe('Planet-Earth-20261130-143509-2.mp4')
|
|
expect(buildRecordingFilename(stamp, 'webm', 0)).toBe('Planet-Earth-20261130-143509.webm')
|
|
})
|
|
|
|
it('prioritizes MP4 H.264 MIME candidates before WebM fallbacks', () => {
|
|
const silent = pickSupportedRecordingMimeTypes(false)
|
|
expect(silent[0]).toContain('video/mp4')
|
|
expect(silent.some((item) => item.includes('opus') || item.includes('mp4a'))).toBe(false)
|
|
|
|
const withAudio = pickSupportedRecordingMimeTypes(true)
|
|
expect(withAudio[0]).toContain('video/mp4')
|
|
expect(withAudio[0]).toContain('mp4a')
|
|
expect(withAudio.some((item) => item.includes('opus'))).toBe(true)
|
|
})
|
|
|
|
it('computes centered top indicator bounds inside contentBounds for landscape, portrait, and >1h timer', () => {
|
|
const landscape = computeIndicatorBounds({
|
|
contentBounds: { x: 100, y: 80, width: 1280, height: 800 },
|
|
elapsedMs: 12_000,
|
|
})
|
|
expect(landscape.width).toBe(120)
|
|
expect(landscape.height).toBe(36)
|
|
expect(landscape.x).toBe(680)
|
|
expect(landscape.y).toBe(136)
|
|
|
|
const longTimer = computeIndicatorBounds({
|
|
contentBounds: { x: 0, y: 0, width: 1000, height: 700 },
|
|
elapsedMs: 3_600_000,
|
|
})
|
|
expect(longTimer.width).toBe(136)
|
|
|
|
const tinyWindow = computeIndicatorBounds({
|
|
contentBounds: { x: 20, y: 30, width: 110, height: 80 },
|
|
elapsedMs: 5000,
|
|
})
|
|
expect(tinyWindow.x).toBeGreaterThanOrEqual(20)
|
|
expect(tinyWindow.x + tinyWindow.width).toBeLessThanOrEqual(130)
|
|
expect(tinyWindow.y).toBeGreaterThanOrEqual(30)
|
|
expect(tinyWindow.y + tinyWindow.height).toBeLessThanOrEqual(110)
|
|
})
|
|
|
|
it('renders transparent HUD pill HTML with blinking red dot, hover square stop morph, and click action', () => {
|
|
const html = buildRecordingIndicatorHtml()
|
|
expect(html).toContain('background: transparent')
|
|
expect(html).toContain('@keyframes recPulse')
|
|
expect(html).toContain('.rec-pill:hover .rec-glyph')
|
|
expect(html).toContain('border-radius: 2px')
|
|
expect(html).toContain('window.planetRecordingIndicator?.requestStop')
|
|
expect(html).toContain('Ctrl+Shift+F9')
|
|
expect(html).toContain('00:00')
|
|
})
|
|
|
|
it('renders click-through custom cursor overlay HTML supporting all cursor shapes', () => {
|
|
const html = buildCursorOverlayHtml()
|
|
expect(html).toContain('background: transparent')
|
|
expect(html).toContain('pointer-events: none')
|
|
expect(html).toContain('cursor-svg--default')
|
|
expect(html).toContain('cursor-svg--pointer')
|
|
expect(html).toContain('cursor-svg--grabbing')
|
|
expect(html).toContain('cursor-svg--text')
|
|
expect(html).toContain('window.planetRecordingCursor?.onUpdate')
|
|
})
|
|
|
|
it('persists recordAudio and recordHideCursor preferences defaulting to false', () => {
|
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'planet-rec-cfg-'))
|
|
tempDirs.push(tempDir)
|
|
|
|
const store1 = new DesktopConfigStore({
|
|
userDataDir: tempDir,
|
|
exeDir: tempDir,
|
|
argv: [],
|
|
env: {},
|
|
})
|
|
expect(store1.get().recordAudio).toBe(false)
|
|
expect(store1.get().recordHideCursor).toBe(false)
|
|
|
|
store1.updateRecordAudio(true)
|
|
store1.updateRecordHideCursor(true)
|
|
expect(store1.get().recordAudio).toBe(true)
|
|
expect(store1.get().recordHideCursor).toBe(true)
|
|
|
|
const store2 = new DesktopConfigStore({
|
|
userDataDir: tempDir,
|
|
exeDir: tempDir,
|
|
argv: [],
|
|
env: {},
|
|
})
|
|
expect(store2.get().recordAudio).toBe(true)
|
|
expect(store2.get().recordHideCursor).toBe(true)
|
|
})
|
|
})
|