media-has-caption-test.js
3.92 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
/* eslint-env jest */
/**
* @fileoverview <audio> and <video> elements must have a <track> for captions.
* @author Ethan Cohen
*/
// -----------------------------------------------------------------------------
// Requirements
// -----------------------------------------------------------------------------
import { RuleTester } from 'eslint';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
import rule from '../../../src/rules/media-has-caption';
// -----------------------------------------------------------------------------
// Tests
// -----------------------------------------------------------------------------
const ruleTester = new RuleTester();
const expectedError = {
message: 'Media elements such as <audio> and <video> must have a <track> for captions.',
type: 'JSXOpeningElement',
};
const customSchema = [
{
audio: ['Audio'],
video: ['Video'],
track: ['Track'],
},
];
ruleTester.run('media-has-caption', rule, {
valid: [
{ code: '<div />;' },
{ code: '<MyDiv />;' },
{ code: '<audio><track kind="captions" /></audio>' },
{ code: '<audio><track kind="Captions" /></audio>' },
{
code: '<audio><track kind="Captions" /><track kind="subtitles" /></audio>',
},
{ code: '<video><track kind="captions" /></video>' },
{ code: '<video><track kind="Captions" /></video>' },
{
code: '<video><track kind="Captions" /><track kind="subtitles" /></video>',
},
{
code: '<audio muted={true}></audio>',
},
{
code: '<video muted={true}></video>',
},
{
code: '<video muted></video>',
},
{
code: '<Audio><track kind="captions" /></Audio>',
options: customSchema,
},
{
code: '<audio><Track kind="captions" /></audio>',
options: customSchema,
},
{
code: '<Video><track kind="captions" /></Video>',
options: customSchema,
},
{
code: '<video><Track kind="captions" /></video>',
options: customSchema,
},
{
code: '<Audio><Track kind="captions" /></Audio>',
options: customSchema,
},
{
code: '<Video><Track kind="captions" /></Video>',
options: customSchema,
},
{
code: '<Video muted></Video>',
options: customSchema,
},
{
code: '<Video muted={true}></Video>',
options: customSchema,
},
{
code: '<Audio muted></Audio>',
options: customSchema,
},
{
code: '<Audio muted={true}></Audio>',
options: customSchema,
},
].map(parserOptionsMapper),
invalid: [
{ code: '<audio><track /></audio>', errors: [expectedError] },
{
code: '<audio><track kind="subtitles" /></audio>',
errors: [expectedError],
},
{ code: '<audio />', errors: [expectedError] },
{ code: '<video><track /></video>', errors: [expectedError] },
{
code: '<video><track kind="subtitles" /></video>',
errors: [expectedError],
},
{
code: '<Audio muted={false}></Audio>',
options: customSchema,
errors: [expectedError],
},
{
code: '<Video muted={false}></Video>',
options: customSchema,
errors: [expectedError],
},
{ code: '<video />', errors: [expectedError] },
{ code: '<audio>Foo</audio>', errors: [expectedError] },
{ code: '<video>Foo</video>', errors: [expectedError] },
{ code: '<Audio />', options: customSchema, errors: [expectedError] },
{ code: '<Video />', options: customSchema, errors: [expectedError] },
{ code: '<audio><Track /></audio>', options: customSchema, errors: [expectedError] },
{ code: '<video><Track /></video>', options: customSchema, errors: [expectedError] },
{
code: '<Audio><Track kind="subtitles" /></Audio>',
options: customSchema,
errors: [expectedError],
},
{
code: '<Video><Track kind="subtitles" /></Video>',
options: customSchema,
errors: [expectedError],
},
].map(parserOptionsMapper),
});