Skip to content

Commit

Permalink
chore: additional format and lint cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjpillsbury committed May 30, 2024
1 parent fb12090 commit 917f412
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 56 deletions.
3 changes: 1 addition & 2 deletions src/js/media-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,7 @@ class MediaContainer extends globalThis.HTMLElement {
/**
* @param {HTMLMediaElement} media
*/
mediaUnsetCallback(media) {
// eslint-disable-line
mediaUnsetCallback(media /* eslint-disable-line no-unused-vars */) {
this.#currentMedia = null;
}

Expand Down
6 changes: 3 additions & 3 deletions src/js/utils/server-safe-globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const documentShim = {
* @param {Event} event
* @returns {boolean}
*/
dispatchEvent(event) {
dispatchEvent(event /* eslint-disable-line no-unused-vars */) {
return false;
}, // eslint-disable-line no-unused-vars
},
};

const globalThisShim = {
Expand All @@ -49,7 +49,7 @@ const globalThisShim = {
* @param {string} key
* @returns {string|null}
*/
getItem(key) {
getItem(key /* eslint-disable-line no-unused-vars */) {
return null;
}, // eslint-disable-line no-unused-vars
/**
Expand Down
7 changes: 4 additions & 3 deletions test/unit/media-captions-listbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('<media-captions-listbox>', () => {
let listbox;

beforeEach(async () => {
mediaController = await fixture(/*html*/`
mediaController = await fixture(/*html*/ `
<media-controller>
<video
slot="media"
Expand Down Expand Up @@ -36,11 +36,12 @@ describe('<media-captions-listbox>', () => {
it('listbox is populated', async function () {
this.timeout(5000);

await new Promise(resolve => mediaController.media.textTracks.addEventListener('addtrack', resolve));
await new Promise((resolve) =>
mediaController.media.textTracks.addEventListener('addtrack', resolve)
);

assert.equal(mediaController.media.textTracks.length, 10);
assert.equal(listbox.options.length, 11); // includes Off option
// assert.equal(listbox.value, 'cc:en:English'); fails on Firefox and Safari
});

});
7 changes: 4 additions & 3 deletions test/unit/media-captions-selectmenu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('<media-captions-selectmenu>', () => {
let listbox;

beforeEach(async () => {
mediaController = await fixture(/*html*/`
mediaController = await fixture(/*html*/ `
<media-controller>
<video
slot="media"
Expand Down Expand Up @@ -38,11 +38,12 @@ describe('<media-captions-selectmenu>', () => {
it('selectmenu is populated', async function () {
this.timeout(5000);

await new Promise(resolve => mediaController.media.textTracks.addEventListener('addtrack', resolve));
await new Promise((resolve) =>
mediaController.media.textTracks.addEventListener('addtrack', resolve)
);

assert.equal(mediaController.media.textTracks.length, 10);
assert.equal(listbox.options.length, 11); // includes Off option
// assert.equal(listbox.value, 'cc:en:English'); fails on Firefox and Safari
});

});
1 change: 0 additions & 1 deletion test/unit/media-container.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ describe('<media-container>', () => {
video.remove();
assert.equal(mediaContainer.media, null);
});

});
6 changes: 4 additions & 2 deletions test/unit/media-controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ describe('state propagation behaviors', () => {
it(`should propagate ${propName} via attrs to a media state receiver if ${attrName} is listed in ${MediaStateReceiverAttributes.MEDIA_CHROME_ATTRIBUTES}`, () => {
mediaController.registerMediaStateReceiver(div);
/** @TODO Should we still propagate true boolean attrs so the value is explicitly '' if it was previously set to some other value? (CJP) */
const propIsTrue = mediaController.mediaStore.getState()[propName] === true;
const propIsTrue =
mediaController.mediaStore.getState()[propName] === true;
if (!propIsTrue) {
assert.notEqual(div.getAttribute(attrName), INITIAL_VALUE);
} else {
Expand Down Expand Up @@ -549,7 +550,8 @@ describe('state propagation behaviors', () => {

it(`should propagate ${propName} via attrs to a web component media state receiver if ${attrName} is an observed attr`, () => {
mediaController.registerMediaStateReceiver(wc);
const propIsTrue = mediaController.mediaStore.getState()[propName] === true;
const propIsTrue =
mediaController.mediaStore.getState()[propName] === true;
if (!propIsTrue) {
assert.notEqual(wc.getAttribute(attrName), INITIAL_VALUE);
} else {
Expand Down
3 changes: 1 addition & 2 deletions test/unit/media-playback-rate-listbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('<media-playback-rate-listbox>', () => {
let listbox;

beforeEach(async () => {
mediaController = await fixture(/*html*/`
mediaController = await fixture(/*html*/ `
<media-controller>
<video
slot="media"
Expand All @@ -24,5 +24,4 @@ describe('<media-playback-rate-listbox>', () => {
assert.equal(listbox.options.length, 5);
assert.equal(listbox.value, 1);
});

});
11 changes: 7 additions & 4 deletions test/unit/media-playback-rate-selectmenu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('<media-playback-rate-selectmenu>', () => {
let listbox;

beforeEach(async () => {
mediaController = await fixture(/*html*/`
mediaController = await fixture(/*html*/ `
<media-controller>
<video
slot="media"
Expand All @@ -18,13 +18,16 @@ describe('<media-playback-rate-selectmenu>', () => {
<media-playback-rate-selectmenu></media-playback-rate-selectmenu>
</media-controller>
`);
selectmenu = mediaController.querySelector('media-playback-rate-selectmenu');
listbox = selectmenu.shadowRoot.querySelector('media-playback-rate-listbox');
selectmenu = mediaController.querySelector(
'media-playback-rate-selectmenu'
);
listbox = selectmenu.shadowRoot.querySelector(
'media-playback-rate-listbox'
);
});

it('selectmenu is populated', async function () {
assert.equal(listbox.options.length, 5);
assert.equal(listbox.value, 1);
});

});
10 changes: 7 additions & 3 deletions test/unit/media-rendition-listbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('<media-rendition-listbox>', () => {
let listbox;

beforeEach(async () => {
mediaController = await fixture(/*html*/`
mediaController = await fixture(/*html*/ `
<media-controller>
<hls-video
slot="media"
Expand All @@ -24,10 +24,14 @@ describe('<media-rendition-listbox>', () => {
});

it('listbox is populated', async function () {
await new Promise(resolve => mediaController.media.videoRenditions.addEventListener('addrendition', resolve));
await new Promise((resolve) =>
mediaController.media.videoRenditions.addEventListener(
'addrendition',
resolve
)
);

assert.equal(listbox.options.length, 6);
assert.equal(listbox.value, 'auto');
});

});
10 changes: 7 additions & 3 deletions test/unit/media-rendition-selectmenu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('<media-rendition-selectmenu>', () => {
let listbox;

beforeEach(async () => {
mediaController = await fixture(/*html*/`
mediaController = await fixture(/*html*/ `
<media-controller>
<hls-video
slot="media"
Expand All @@ -26,10 +26,14 @@ describe('<media-rendition-selectmenu>', () => {
});

it('selectmenu is populated', async function () {
await new Promise(resolve => mediaController.media.videoRenditions.addEventListener('addrendition', resolve));
await new Promise((resolve) =>
mediaController.media.videoRenditions.addEventListener(
'addrendition',
resolve
)
);

assert.equal(listbox.options.length, 6);
assert.equal(listbox.value, 'auto');
});

});
41 changes: 31 additions & 10 deletions test/unit/media-theme.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { MediaUIAttributes } from '../../src/js/constants.js';

describe('<media-theme>', () => {
it(`<media-theme> with template attribute works w/ delayed document append`, async () => {

const template = document.createElement('template');
template.id = 'not-yet';
template.innerHTML = /*html*/`
template.innerHTML = /*html*/ `
<media-controller>
<slot name="media" slot="media"></slot>
<media-control-bar>
Expand All @@ -22,16 +21,25 @@ describe('<media-theme>', () => {

document.body.append(template, theme);

assert(theme.shadowRoot.innerHTML.includes('media-play-button'), 'shadow root contains a play button');
assert(
theme.shadowRoot.innerHTML.includes('media-play-button'),
'shadow root contains a play button'
);
});

it(`<media-theme> w/ template HTML file URL doesn't duplicate fetch/render `, async function() {
it(`<media-theme> w/ template HTML file URL doesn't duplicate fetch/render `, async function () {
this.timeout(5000);

const theme = document.createElement('media-theme');
theme.setAttribute('template', 'https://gist.githubusercontent.com/luwes/5812c419830fee000d3463c496d18e19/raw/c295dad03a33ea8ad93870fa55de40a3308c8f45/media-theme-micro.html');
theme.setAttribute(
'template',
'https://gist.githubusercontent.com/luwes/5812c419830fee000d3463c496d18e19/raw/c295dad03a33ea8ad93870fa55de40a3308c8f45/media-theme-micro.html'
);

await waitUntil(() => theme.shadowRoot.querySelector('media-controller'), 5000);
await waitUntil(
() => theme.shadowRoot.querySelector('media-controller'),
5000
);
const mediaController = theme.shadowRoot.querySelector('media-controller');

document.body.append(theme);
Expand Down Expand Up @@ -125,7 +133,11 @@ describe('<media-theme>', () => {
await Promise.resolve();

assert.equal(h1.textContent, 'Hello world');
assert.equal(h1, theme1.shadowRoot.querySelector('h1'), 'h1 is the same element');
assert.equal(
h1,
theme1.shadowRoot.querySelector('h1'),
'h1 is the same element'
);
assert(
theme1.shadowRoot.querySelector('hello-world'),
'caused a re-render and <hello-world> is available'
Expand All @@ -152,12 +164,21 @@ describe('<media-theme>', () => {

// Also includes the media-gesture-receiver by default
assert.equal(mediaController.mediaStateReceivers.length, 3);
assert(mediaController.mediaStateReceivers.includes(mediaController), 'registers itself');
assert(mediaController.mediaStateReceivers.includes(playButton), 'registers play button');
assert(
mediaController.mediaStateReceivers.includes(mediaController),
'registers itself'
);
assert(
mediaController.mediaStateReceivers.includes(playButton),
'registers play button'
);

playButton.remove();

assert.equal(mediaController.mediaStateReceivers.length, 2);
assert(!mediaController.mediaStateReceivers.includes(playButton), 'unregisters play button');
assert(
!mediaController.mediaStateReceivers.includes(playButton),
'unregisters play button'
);
});
});
2 changes: 1 addition & 1 deletion test/unit/scripts/react/common/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('module: scripts/react/common/utils', () => {

const actual = toNativeProps(props);

expect(actual).to.deep.equal({ 'camelcase': 'foo', nocamelcase: 'bar' });
expect(actual).to.deep.equal({ camelcase: 'foo', nocamelcase: 'bar' });
});

it('should appropriately translate special React props to their DOM equivalent names, even for camelCase', async () => {
Expand Down
6 changes: 5 additions & 1 deletion test/unit/template-parts.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/* Adapted from https://github.com/dy/template-parts - ISC - Dmitry Iv. */

import { assert } from '@open-wc/testing';
import { TemplateInstance, AttrPart, AttrPartList } from '../../src/js/utils/template-parts.js';
import {
TemplateInstance,
AttrPart,
AttrPartList,
} from '../../src/js/utils/template-parts.js';

const test = it;
const is = assert.deepEqual;
Expand Down
8 changes: 5 additions & 3 deletions test/unit/template-processor.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { assert } from '@open-wc/testing';
import { evaluateExpression, getParamValue, processor } from '../../src/js/utils/template-processor.js';
import {
evaluateExpression,
getParamValue,
processor,
} from '../../src/js/utils/template-processor.js';
import { TemplateInstance } from '../../src/js/utils/template-parts.js';

describe('evaluateExpression', () => {
Expand Down Expand Up @@ -74,7 +78,6 @@ describe('getParamValue', () => {
});

describe('processor', () => {

it('InnerTemplatePart: simple truthy if condition', async () => {
const template = document.createElement('template');
template.innerHTML = `<div>hello<template if="x"> world</template>!</div>`;
Expand Down Expand Up @@ -113,5 +116,4 @@ describe('processor', () => {
instance.update({ x: 1, loud: true });
assert.equal(instance.children[0].textContent.trim(), 'hello world!');
});

});
Loading

0 comments on commit 917f412

Please sign in to comment.