返回 oh-my-ppt
animation-preferences-inherit.test.ts
根目录 / tests / unit / generation / animation-preferences-inherit.test.ts
1 import { describe, expect, it } from 'vitest'
2 import {
3 resolveInheritedAnimationPreferences,
4 type AnimationPreferenceSourceRun
5 } from '../../../src/shared/generation'
6
7 describe('resolveInheritedAnimationPreferences', () => {
8 it('returns null when there is no source run', () => {
9 expect(resolveInheritedAnimationPreferences(null, 's1')).toBeNull()
10 expect(resolveInheritedAnimationPreferences(undefined, 's1')).toBeNull()
11 })
12
13 it('returns null when the source run belongs to another session', () => {
14 const run: AnimationPreferenceSourceRun = {
15 session_id: 'other',
16 animation_preferences: JSON.stringify({ ids: ['fade-up'] })
17 }
18 expect(resolveInheritedAnimationPreferences(run, 's1')).toBeNull()
19 })
20
21 it('inherits normalized preferences from a session-owned run', () => {
22 const run: AnimationPreferenceSourceRun = {
23 session_id: 's1',
24 animation_preferences: JSON.stringify({ ids: ['fade-up', 'fade-up', 'wipe'] })
25 }
26 expect(resolveInheritedAnimationPreferences(run, 's1')).toEqual({
27 ids: ['fade-up', 'wipe']
28 })
29 })
30
31 it('returns null when the session-owned run has no stored preferences', () => {
32 const run: AnimationPreferenceSourceRun = {
33 session_id: 's1',
34 animation_preferences: null
35 }
36 expect(resolveInheritedAnimationPreferences(run, 's1')).toBeNull()
37 })
38
39 it('returns null on malformed stored preferences instead of throwing', () => {
40 const run: AnimationPreferenceSourceRun = {
41 session_id: 's1',
42 animation_preferences: '{not json'
43 }
44 expect(() => resolveInheritedAnimationPreferences(run, 's1')).not.toThrow()
45 expect(resolveInheritedAnimationPreferences(run, 's1')).toBeNull()
46 })
47 })
48
48 lines TYPESCRIPT