mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
fix(curriculum): add test to ensure typeAttr matches srcAttr media type (#62512)
Co-authored-by: Ilenia <26656284+ilenia-magoni@users.noreply.github.com> Co-authored-by: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com>
This commit is contained in:
co-authored by
Ilenia
Huyen Nguyen
parent
836134b327
commit
76984837ea
+19
@@ -112,6 +112,25 @@ const typeAttr = source.getAttribute('type');
|
||||
assert.isNotEmpty(typeAttr);
|
||||
```
|
||||
|
||||
The `type` attribute should match the media type of the file extension of the `src` attribute.
|
||||
|
||||
```js
|
||||
const section = document.querySelector('section');
|
||||
const source = section?.querySelector('h2 + video > source');
|
||||
const typeAttr = source.getAttribute('type');
|
||||
const srcAttr = source.getAttribute('src');
|
||||
const srcFileExt = srcAttr.match(/[^\.]+$/g)[0];
|
||||
const fileExtToMediaTypes = {
|
||||
mp4: ['video/mp4'],
|
||||
webm: ['video/webm'],
|
||||
ogg: ['video/ogg'],
|
||||
avi: ['video/avi', 'video/vnd.avi', 'video/msvideo', 'video/x-msvideo'],
|
||||
mov: ['video/quicktime']
|
||||
};
|
||||
const srcMediaTypes = fileExtToMediaTypes[srcFileExt];
|
||||
assert.oneOf(typeAttr, srcMediaTypes);
|
||||
```
|
||||
|
||||
Inside the second `section` element, you should have an `h2` element for the title of the song playing.
|
||||
|
||||
```js
|
||||
|
||||
Reference in New Issue
Block a user