-
Notifications
You must be signed in to change notification settings - Fork 673
Expand file tree
/
Copy pathVideoEditPanel.test.ts
More file actions
175 lines (148 loc) · 5.18 KB
/
Copy pathVideoEditPanel.test.ts
File metadata and controls
175 lines (148 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import userEvent from '@testing-library/user-event'
import { render, screen } from '@testing-library/vue'
import { describe, expect, it } from 'vitest'
import { defineComponent, h } from 'vue'
import { createI18n } from 'vue-i18n'
import type { ComponentProps } from 'vue-component-type-helpers'
import VideoEditPanel from './VideoEditPanel.vue'
const i18n = createI18n({
legacy: false,
locale: 'en',
messages: {
en: {
videoEdit: {
trimVideo: 'Trim Video',
cropVideo: 'Crop Video',
startFrame: 'Start Frame',
endFrame: 'End Frame',
duration: 'Duration',
frames: 'Number of Frames',
fileSize: 'File Size',
resolution: '{width} × {height}',
loadingVideo: 'Loading video preview',
setStartFrame: 'Reset start frame',
setEndFrame: 'Reset end frame',
durationZero: '0s',
durationSeconds: '{count}s',
selectedOfTotal: '{selected} / {total}',
fileSizeUnknown: '—',
fileSizeBytes: '{count} B',
fileSizeKilobytes: '{count} KB',
fileSizeMegabytes: '{count} MB',
noVideoSource: 'Select or connect a video to preview and edit'
},
imageCrop: {
ratio: 'Ratio',
custom: 'Custom',
lockRatio: 'Lock ratio',
unlockRatio: 'Unlock ratio'
}
}
}
})
function stub(testId: string) {
return defineComponent({
setup: () => () => h('div', { 'data-testid': testId })
})
}
const ToggleStub = defineComponent({
props: {
widget: { type: Object, required: true },
modelValue: { type: Boolean, default: false }
},
emits: ['update:modelValue'],
setup(props, { emit }) {
return () =>
h('button', {
'data-testid': `toggle-${props.widget.name}`,
onClick: () => emit('update:modelValue', !props.modelValue)
})
}
})
type PanelProps = ComponentProps<typeof VideoEditPanel>
function renderPanel(props: Partial<PanelProps> = {}) {
return render(VideoEditPanel, {
props: {
features: ['trim', 'crop'],
videoUrl: '/api/view?filename=clip.mp4',
thumbnails: ['data:image/jpeg;base64,one'],
totalFrames: 100,
duration: 10,
fps: 10,
fileSize: 2048,
width: 1920,
height: 1080,
loading: false,
...props
} as PanelProps,
global: {
plugins: [i18n],
directives: { tooltip: {} },
stubs: {
VideoFilmstripTrim: stub('stub-filmstrip'),
VideoCropOverlay: stub('stub-crop-overlay'),
WidgetInputNumberInput: stub('stub-number-input'),
WidgetBoundingBox: stub('stub-bounding-box'),
WidgetToggleSwitch: ToggleStub,
Loader: stub('stub-loader'),
Select: stub('stub-select'),
SelectTrigger: stub('stub-select-trigger'),
SelectValue: stub('stub-select-value'),
SelectContent: stub('stub-select-content'),
SelectItem: stub('stub-select-item'),
Button: stub('stub-lock-button')
}
}
})
}
describe('VideoEditPanel', () => {
it('shows an empty state without a video source', () => {
renderPanel({ videoUrl: undefined })
expect(screen.getByTestId('video-edit-empty')).toBeTruthy()
expect(screen.queryByTestId('video-preview')).toBeNull()
expect(screen.queryByTestId('toggle-trim_enabled')).toBeNull()
})
it('renders only the toggles of the enabled features', () => {
renderPanel({ features: ['trim'] })
expect(screen.getByTestId('toggle-trim_enabled')).toBeTruthy()
expect(screen.queryByTestId('toggle-crop_enabled')).toBeNull()
})
it('keeps the filmstrip visible but collapses trim controls until enabled', async () => {
renderPanel({ features: ['trim'] })
expect(screen.getByTestId('stub-filmstrip')).toBeTruthy()
expect(screen.queryByTestId('stub-number-input')).toBeNull()
await userEvent.click(screen.getByTestId('toggle-trim_enabled'))
expect(screen.getAllByTestId('stub-number-input')).toHaveLength(2)
})
it('expands the crop editor when the crop toggle is enabled', async () => {
renderPanel({ features: ['crop'] })
expect(screen.queryByTestId('stub-crop-overlay')).toBeNull()
expect(screen.queryByTestId('stub-bounding-box')).toBeNull()
await userEvent.click(screen.getByTestId('toggle-crop_enabled'))
expect(screen.getByTestId('stub-crop-overlay')).toBeTruthy()
expect(screen.getByTestId('stub-bounding-box')).toBeTruthy()
})
it('shows a loading overlay while the filmstrip loads', () => {
renderPanel({ loading: true })
expect(screen.getByTestId('video-preview-loading')).toBeTruthy()
})
it('shows selected/total metadata when trim is a feature', () => {
renderPanel({
features: ['trim'],
startFrame: 0,
endFrame: 99
})
expect(screen.getByText('10s / 10s')).toBeTruthy()
expect(screen.getByText('100 / 100')).toBeTruthy()
expect(screen.getByText('2 KB')).toBeTruthy()
})
it('shows plain totals when trim is not a feature', () => {
renderPanel({ features: ['crop'] })
expect(screen.getByText('10s')).toBeTruthy()
expect(screen.getByText('100')).toBeTruthy()
})
it('renders the source resolution', () => {
renderPanel()
expect(screen.getByText('1920 × 1080')).toBeTruthy()
})
})