feat: add props system and refactor asset library architecture
This commit is contained in:
23
tests/unit/script-view/clip-asset-utils.test.ts
Normal file
23
tests/unit/script-view/clip-asset-utils.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { getAllClipsAssets, parseClipAssets } from '@/app/[locale]/workspace/[projectId]/modes/novel-promotion/components/script-view/clip-asset-utils'
|
||||
|
||||
describe('clip asset utils', () => {
|
||||
it('parses prop names from clip JSON payloads', () => {
|
||||
const parsed = parseClipAssets({
|
||||
characters: '[{"name":"小雨","appearance":"初始形象"}]',
|
||||
location: '天台',
|
||||
props: '["青铜匕首","录音笔"]',
|
||||
})
|
||||
|
||||
expect(Array.from(parsed.propNames)).toEqual(['青铜匕首', '录音笔'])
|
||||
})
|
||||
|
||||
it('aggregates prop names across clips', () => {
|
||||
const all = getAllClipsAssets([
|
||||
{ props: '["青铜匕首"]' },
|
||||
{ props: '["录音笔","红绳手链"]' },
|
||||
])
|
||||
|
||||
expect(Array.from(all.allPropNames)).toEqual(['青铜匕首', '录音笔', '红绳手链'])
|
||||
})
|
||||
})
|
||||
43
tests/unit/script-view/selection-sync.test.ts
Normal file
43
tests/unit/script-view/selection-sync.test.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
reuseStringArrayIfEqual,
|
||||
reuseStringSetIfEqual,
|
||||
} from '@/app/[locale]/workspace/[projectId]/modes/novel-promotion/components/script-view/selection-sync'
|
||||
|
||||
describe('script view selection sync', () => {
|
||||
it('reuses the previous array reference when ids are unchanged', () => {
|
||||
const previous = ['char-1', 'char-2']
|
||||
const next = ['char-1', 'char-2']
|
||||
|
||||
const result = reuseStringArrayIfEqual(previous, next)
|
||||
|
||||
expect(result).toBe(previous)
|
||||
})
|
||||
|
||||
it('returns the next array when ids changed', () => {
|
||||
const previous = ['char-1', 'char-2']
|
||||
const next = ['char-1', 'prop-1']
|
||||
|
||||
const result = reuseStringArrayIfEqual(previous, next)
|
||||
|
||||
expect(result).toBe(next)
|
||||
})
|
||||
|
||||
it('reuses the previous set reference when selected appearance keys are unchanged', () => {
|
||||
const previous = new Set(['char-1::Base', 'char-2::Alt'])
|
||||
const next = new Set(['char-2::Alt', 'char-1::Base'])
|
||||
|
||||
const result = reuseStringSetIfEqual(previous, next)
|
||||
|
||||
expect(result).toBe(previous)
|
||||
})
|
||||
|
||||
it('returns the next set when selected appearance keys changed', () => {
|
||||
const previous = new Set(['char-1::Base'])
|
||||
const next = new Set(['char-1::Base', 'char-2::Alt'])
|
||||
|
||||
const result = reuseStringSetIfEqual(previous, next)
|
||||
|
||||
expect(result).toBe(next)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user