/
Webcam.test.js
93 lines (79 loc) · 2.83 KB
/
Webcam.test.js
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
import { describe, expect, it } from '@jest/globals'
import Uppy from '@uppy/core'
import Webcam from '../lib/index.js'
describe('Webcam', () => {
describe('_getMediaRecorderOptions', () => {
it('should not have a mimeType set if no preferences given', () => {
globalThis.MediaRecorder = {
isTypeSupported: () => true,
}
const uppy = new Uppy().use(Webcam)
expect(
uppy.getPlugin('Webcam').getMediaRecorderOptions().mimeType,
).not.toBeDefined()
})
it('should use preferredVideoMimeType', () => {
globalThis.MediaRecorder = {
isTypeSupported: (ty) => ty === 'video/webm',
}
const uppy = new Uppy().use(Webcam, { preferredVideoMimeType: 'video/webm' })
expect(
uppy.getPlugin('Webcam').getMediaRecorderOptions().mimeType,
).toEqual('video/webm')
})
it('should not use preferredVideoMimeType if it is not supported', () => {
globalThis.MediaRecorder = {
isTypeSupported: (ty) => ty === 'video/webm',
}
const uppy = new Uppy().use(Webcam, { preferredVideoMimeType: 'video/mp4' })
expect(
uppy.getPlugin('Webcam').getMediaRecorderOptions().mimeType,
).not.toBeDefined()
})
it('should pick type based on `allowedFileTypes`', () => {
globalThis.MediaRecorder = {
isTypeSupported: () => true,
}
const uppy = new Uppy({
restrictions: { allowedFileTypes: ['video/mp4', 'video/webm'] },
}).use(Webcam)
expect(
uppy.getPlugin('Webcam').getMediaRecorderOptions().mimeType,
).toEqual('video/mp4')
})
it('should use first supported type from allowedFileTypes', () => {
globalThis.MediaRecorder = {
isTypeSupported: (ty) => ty === 'video/webm',
}
const uppy = new Uppy({
restrictions: { allowedFileTypes: ['video/mp4', 'video/webm'] },
}).use(Webcam)
expect(
uppy.getPlugin('Webcam').getMediaRecorderOptions().mimeType,
).toEqual('video/webm')
})
it('should prefer preferredVideoMimeType over allowedFileTypes', () => {
globalThis.MediaRecorder = {
isTypeSupported: () => true,
}
const uppy = new Uppy({
restrictions: { allowedFileTypes: ['video/mp4', 'video/webm'] },
})
.use(Webcam, { preferredVideoMimeType: 'video/webm' })
expect(
uppy.getPlugin('Webcam').getMediaRecorderOptions().mimeType,
).toEqual('video/webm')
})
it('should not use allowedFileTypes if they are unsupported', () => {
globalThis.MediaRecorder = {
isTypeSupported: () => false,
}
const uppy = new Uppy({
restrictions: { allowedFileTypes: ['video/mp4', 'video/webm'] },
}).use(Webcam)
expect(
uppy.getPlugin('Webcam').getMediaRecorderOptions().mimeType,
).toEqual(undefined)
})
})
})