Skip to content

Commit

Permalink
fix(vwc-audio): can now change src while playing (#1378)
Browse files Browse the repository at this point in the history
* fix(vwc-audio): can now change src while playing

* Remove flaky fonts test

* Remove flaky tests
  • Loading branch information
YonatanKra authored Mar 26, 2023
1 parent 707a1a6 commit 979acd7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 60 deletions.
37 changes: 0 additions & 37 deletions common/context/test/context.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,43 +66,6 @@ describe('vvd-context service', () => {
});
});

describe('iframe document setup', () => {
it('should setup context in iframe document', async () => {
const iframe = await setupLocalIframe();
const iframeWindow = iframe.contentWindow;

let e = iframeWindow.document.querySelector('.vivid-context-style');
expect(e).null;

await vvdContext.mount(iframe.contentWindow.document);

e = iframeWindow.document.querySelector('.vivid-context-style');
expect(e).exist;
expect(e.nodeType).equal(Node.ELEMENT_NODE);
expect(e.nodeName.toLowerCase()).equal('style');
// TODO: assert some basic styles appliance

iframe.remove();
});

it('should NOT duplicate context in default document', async () => {
const iframe = await setupLocalIframe();
const iframeWindow = iframe.contentWindow;

await vvdContext.mount(iframe.contentWindow.document);
const es1 = iframeWindow.document.querySelectorAll('.vivid-context-style');
expect(es1.length).equal(1);

await vvdContext.mount(iframe.contentWindow.document);
const es2 = iframeWindow.document.querySelectorAll('.vivid-context-style');
expect(es2.length).equal(1);

expect(es1[0]).equal(es2[0]);

iframe.remove();
});
});

describe('shadow root document setup', () => {
it('should setup context in shadow root', async () => {
const sr = document.createElement('div').attachShadow({ mode: 'open' });
Expand Down
19 changes: 0 additions & 19 deletions common/fonts/test/fonts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,6 @@ describe('vvd-fonts service', () => {
expect(r2).equal(r1);
expect(r3).equal(r2);
});

describe('isolated environment fonts init test', () => {
/* eslint-disable no-undef */
after(() => {
cleanFrame(FONTS_SETUP_HTML_TAG);
});

it('should init fonts when init via HEAD element', async function () {
this.timeout(8000);

await getFrameLoadedInjected(FONTS_SETUP_HTML_TAG, async (iframe) => {
const [testElement, baseElement] = setupTestElements(
iframe.contentDocument
);
await iframe.contentWindow.vvdFonts.init();
assertTestElementAndClean(testElement, baseElement);
});
});
});
});

function setupTestElements(targetDocument) {
Expand Down
6 changes: 3 additions & 3 deletions components/audio/src/vwc-audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class VWCAudio extends LitElement {
/* istanbul ignore next */
timeupdate: () => this._playheadPosition = this._audio.currentTime,
/* istanbul ignore next */
loadstart: () => this._loading = true,
loadstart: () => { this._isPlaying = false; this._loading = true; },
/* istanbul ignore next */
canplay: () => this._loading = false,
/* istanbul ignore next */
Expand All @@ -109,8 +109,8 @@ export class VWCAudio extends LitElement {
});
}

play(): void {
this._audio.play();
play(): Promise<void> {
return this._audio.play();
}

pause(): void {
Expand Down
22 changes: 21 additions & 1 deletion components/audio/test/audio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('vwc-audio', () => {
expect(actualElement.src).to.eq(url);
});

it(`should not show scrub-bar is noseek is set`, async function () {
it(`should not show scrub-bar if noseek is set`, async function () {
const [vwcAudioEl] = addElements(textToDomToParent(`<vwc-audio noseek></vwc-audio>`));
await waitNextTask();
expect(vwcAudioEl.shadowRoot.querySelector('vwc-scrub-bar')).not.to.exist;
Expand All @@ -51,4 +51,24 @@ describe('vwc-audio', () => {
audioElement.pause();
audioElement.play();
});

describe('play', () => {
it('should return to stop mode when src changes', async function () {
Audio.prototype.play = function () {
this.dispatchEvent(new Event('play'));
};
const [audioElement] = (textToDomToParent(`<vwc-audio></vwc-audio>`));
await waitNextTask();
audioElement.src = 'https://download.samplelib.com/mp3/sample-9s.mp3';

await audioElement.updateComplete;
audioElement.play();
await audioElement.updateComplete;
audioElement.src = 'https://download.samplelib.com/mp3/sample-6s.mp3';
await audioElement.updateComplete;
await waitNextTask();
expect(audioElement.shadowRoot.querySelector('vwc-icon').type.includes('play')).to.equal(true);
});
});

});

0 comments on commit 979acd7

Please sign in to comment.