mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-29 12:24:39 +00:00
feat(webui): add compare versions view for version stacks
Add a Compare Versions mode to the file detail page (authenticated and public share) that splits the viewer into two 50/50 panes showing two versions side by side. - Breadcrumb file menu gains a Compare Versions entry (version stacks with >=2 versions); the file segment is hidden in compare mode. - URL-driven state (compare/cmpLeft/cmpRight/cmpActive) on both file routes so the view is refresh/share-safe. - Per-side topbar with filename, version, version-switch dropdown, an active-side highlight, and an X exit button. - Shared control bar reflects the active pane; for same-type media it coordinates both panes (play/pause, seek, frame-step, zoom, pan sync), seekbar length matches the active side while the shorter side holds its last frame; only the active side plays audio; resolution/download apply to the active side; fullscreen covers the whole compare view. - Right sidebar (comments/fields) binds to the active side; comment selection seeks the active pane and annotations/comments can be created. - Reuses useFramePlayer + DrawingCanvas without modifying the existing single-file video player. - Unit tests for compare selection/clamp logic.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { kindOf, pickDefaultCompareVersions, clampFrame, isSameType } from './compare-utils'
|
||||
|
||||
describe('compare-utils', () => {
|
||||
describe('kindOf', () => {
|
||||
it('classifies image media types', () => {
|
||||
expect(kindOf('image/png')).toBe('image')
|
||||
expect(kindOf('image/webp')).toBe('image')
|
||||
})
|
||||
|
||||
it('classifies video media types', () => {
|
||||
expect(kindOf('video/mp4')).toBe('video')
|
||||
expect(kindOf('video/quicktime')).toBe('video')
|
||||
})
|
||||
|
||||
it('returns unsupported for missing or unknown types', () => {
|
||||
expect(kindOf(null)).toBe('unsupported')
|
||||
expect(kindOf(undefined)).toBe('unsupported')
|
||||
expect(kindOf('application/pdf')).toBe('unsupported')
|
||||
})
|
||||
})
|
||||
|
||||
describe('pickDefaultCompareVersions', () => {
|
||||
it('picks latest and latest-1 regardless of input order', () => {
|
||||
const versions = [
|
||||
{ id: 'a', version: 1 },
|
||||
{ id: 'c', version: 3 },
|
||||
{ id: 'b', version: 2 },
|
||||
]
|
||||
const pair = pickDefaultCompareVersions(versions)
|
||||
expect(pair).not.toBeNull()
|
||||
expect(pair!.left.id).toBe('c') // v3 (latest)
|
||||
expect(pair!.right.id).toBe('b') // v2 (latest - 1)
|
||||
})
|
||||
|
||||
it('returns null when fewer than two versions', () => {
|
||||
expect(pickDefaultCompareVersions([{ id: 'a', version: 1 }])).toBeNull()
|
||||
expect(pickDefaultCompareVersions([])).toBeNull()
|
||||
expect(pickDefaultCompareVersions(undefined)).toBeNull()
|
||||
expect(pickDefaultCompareVersions(null)).toBeNull()
|
||||
})
|
||||
|
||||
it('does not mutate the input array', () => {
|
||||
const versions = [
|
||||
{ id: 'a', version: 1 },
|
||||
{ id: 'b', version: 2 },
|
||||
]
|
||||
pickDefaultCompareVersions(versions)
|
||||
expect(versions.map((v) => v.id)).toEqual(['a', 'b'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('clampFrame', () => {
|
||||
it('clamps to the last frame when beyond total (shorter side holds last frame)', () => {
|
||||
expect(clampFrame(500, 100)).toBe(99)
|
||||
})
|
||||
|
||||
it('clamps negative frames to zero', () => {
|
||||
expect(clampFrame(-5, 100)).toBe(0)
|
||||
})
|
||||
|
||||
it('passes through in-range frames', () => {
|
||||
expect(clampFrame(42, 100)).toBe(42)
|
||||
})
|
||||
|
||||
it('handles zero-length safely', () => {
|
||||
expect(clampFrame(10, 0)).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isSameType', () => {
|
||||
it('true only for matching, supported kinds', () => {
|
||||
expect(isSameType('video', 'video')).toBe(true)
|
||||
expect(isSameType('image', 'image')).toBe(true)
|
||||
})
|
||||
|
||||
it('false for mismatched or unsupported kinds', () => {
|
||||
expect(isSameType('video', 'image')).toBe(false)
|
||||
expect(isSameType('unsupported', 'unsupported')).toBe(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user