Skip to content

Commit

Permalink
feat(player): Added unit tests for recent changes in load, play a…
Browse files Browse the repository at this point in the history
…nd `loadAd` methods; removed unnecessary files and added helper for all unit tests to ensure proper handle on failures; fixes #283
  • Loading branch information
rafa8626 committed Oct 3, 2021
1 parent c109bb9 commit c8ba2db
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 164 deletions.
25 changes: 0 additions & 25 deletions .nycrc

This file was deleted.

9 changes: 4 additions & 5 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ module.exports = config => {
{
pattern: 'src/css/**/*.svg', watched: false, included: false, served: true
},
'src/css/*.css',
{ pattern: 'node_modules/expect.js/index.js' },
{ pattern: 'test/player.html', type: 'dom', watched: false },
'src/css/*.css',
'src/js/**/*.ts',
'test/utils/*.ts',
'test/controls/volume.ts',
'test/controls/*.ts',
'test/player.ts',
'test/**/*.ts',
],
preprocessors: {
'src/js/**/*.ts': ['karma-typescript', 'coverage'],
Expand Down Expand Up @@ -60,6 +57,8 @@ module.exports = config => {
client: {
mocha: {
asyncOnly: true,
forbidOnly: true,
bail: true
}
},
});
Expand Down
4 changes: 3 additions & 1 deletion test/controls/fullscreen.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import OpenPlayerJS from '../../src/js/player';
import '../helper';

describe('controls/fullscreen', () => {
let player = null;

afterEach(() => {
afterEach(done => {
if (OpenPlayerJS.instances.video) {
OpenPlayerJS.instances.video.destroy();
}
Expand All @@ -12,6 +13,7 @@ describe('controls/fullscreen', () => {
}

player = null;
done();
});

it('displays a Fullscreen button in the control bar to the right by default', async () => {
Expand Down
9 changes: 6 additions & 3 deletions test/controls/play.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import OpenPlayerJS from '../../src/js/player';
import '../helper';

describe('controls/play', () => {
let player = null;

afterEach(() => {
afterEach(done => {
player.pause();

if (OpenPlayerJS.instances.video) {
Expand All @@ -14,6 +15,7 @@ describe('controls/play', () => {
}

player = null;
done();
});

it('displays a Play button in the control bar to the left by default', async () => {
Expand Down Expand Up @@ -51,7 +53,7 @@ describe('controls/play', () => {
startVolume: 0,
});
await player.init();
return new Promise((resolve, reject) => {
return new Promise(resolve => {
const events = {
ended: () => {
const play = player.getControls().getContainer()
Expand All @@ -63,6 +65,7 @@ describe('controls/play', () => {
Object.keys(events).forEach(event => {
player.getElement().removeEventListener(event, events[event]);
});
player.getElement().currentTime = 0;
resolve();
},
play: () => {
Expand All @@ -89,7 +92,7 @@ describe('controls/play', () => {
try {
player.play();
} catch (err) {
reject();
throw new Error('error');
}
});
});
Expand Down
29 changes: 3 additions & 26 deletions test/controls/time.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import OpenPlayerJS from '../../src/js/player';
import { formatTime } from '../../src/js/utils/time';
import '../helper';

describe('controls/time', () => {
let player = null;

afterEach(() => {
player.activeElement().muted = true;
afterEach(done => {
player.destroy();
player = null;
done();
});

it('displays the current time and duration in the control bar to the left by default', async () => {
Expand Down Expand Up @@ -86,28 +87,4 @@ describe('controls/time', () => {
expect(duration).to.not.be(null);
expect(duration.textContent).to.equal(formatTime(50));
});

it('hides the duration and delimiter when dealing with live media', async () => {
const media = document.getElementById('video') as HTMLMediaElement;
media.setAttribute('op-live__enabled', 'true');

player = new OpenPlayerJS('video', {
progress: {
duration: Infinity,
},
});
await player.init();

const current = player.getControls().getContainer().querySelector('.op-controls__current') as HTMLInputElement;
expect(current).to.not.be(null);

const delimiter = player.getControls().getContainer().querySelector('.op-controls__time-delimiter') as HTMLElement;
expect(delimiter).to.not.be(null);
expect(delimiter.getAttribute('aria-hidden')).to.equal('true');

const duration = player.getControls().getContainer().querySelector('.op-controls__duration') as HTMLInputElement;
expect(duration).to.not.be(null);
expect(duration.getAttribute('aria-hidden')).to.equal('true');
media.removeAttribute('op-live__enabled');
});
});
4 changes: 3 additions & 1 deletion test/controls/volume.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import OpenPlayerJS from '../../src/js/player';
import '../helper';

describe('controls/volume', () => {
let player = null;

afterEach(() => {
afterEach(done => {
player.activeElement().muted = true;
player.activeElement().volume = 0;
player.destroy();
player = null;
done();
});

it('displays a Volume button and slider in the control bar to the left by default', async () => {
Expand Down
6 changes: 6 additions & 0 deletions test/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function onUncaught(err: string) {
console.error(err);
process.exit(1);
}

process.on('unhandledRejection', onUncaught);
Loading

0 comments on commit c8ba2db

Please sign in to comment.