Skip to content

Commit

Permalink
test(testing): Added more tests
Browse files Browse the repository at this point in the history
Added mute, fullscreen and controls tests. Removed unused dependencies at VgControls.
  • Loading branch information
Elecash committed Feb 1, 2016
1 parent 952bdcb commit 9af01e7
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 7 deletions.
14 changes: 14 additions & 0 deletions src/vg-controls/vg-controls.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {it, describe, expect, beforeEach, inject} from 'angular2/testing';
import {VgControls} from "./vg-controls";

describe('Controls Bar', () => {
let controls:VgControls;

beforeEach(() => {
controls = new VgControls();
});

it('Should have been defined', () => {
expect(controls).toBeTruthy();
});
});
6 changes: 1 addition & 5 deletions src/vg-controls/vg-controls.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {Component} from 'angular2/core';

import {VgAPI} from '../services/vg-api';

@Component({
selector: 'vg-controls',
template: `<ng-content></ng-content>`,
Expand Down Expand Up @@ -35,7 +33,5 @@ import {VgAPI} from '../services/vg-api';
`]
})
export class VgControls {
constructor(public API:VgAPI) {

}
constructor() {}
}
4 changes: 2 additions & 2 deletions src/vg-controls/vg-fullscreen/vg-fullscreen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ describe('Videogular Player', () => {
spyOn(api, 'toggleFullscreen');
});

it('should call toggleFullscreen with null param if target is API', () => {
it('Should call toggleFullscreen with null param if target is API', () => {
fullscreen.target = api;

fullscreen.onClick();

expect(api.toggleFullscreen).toHaveBeenCalledWith(null);
});

it('should call toggleFullscreen with target param if target', () => {
it('Should call toggleFullscreen with target param if target', () => {
fullscreen.target = 'test';

fullscreen.onClick();
Expand Down
133 changes: 133 additions & 0 deletions src/vg-controls/vg-mute/vg-mute.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import {it, describe, expect, beforeEach, inject} from 'angular2/testing';
import {VgMute} from "./vg-mute";
import {VgAPI} from "../../services/vg-api";
import {ElementRef} from "angular2/core";

describe('Mute Button', () => {
let mute:VgMute;
let ref:ElementRef;
let api:VgAPI;

beforeEach(() => {
ref = {
nativeElement: {
getAttribute: (name) => {
return name;
}
}
};

api = new VgAPI();
api.medias = {
main: {
volume: 1
},
secondary: {
volume: 0.5
}
};


mute = new VgMute(ref, api);
});

it('Should get media by id on init', () => {
spyOn(mute.elem, 'getAttribute').and.callThrough();
spyOn(api, 'getMediaById').and.callFake(() => {
return {
volume: 1
};
});

mute.ngOnInit();

expect(mute.elem.getAttribute).toHaveBeenCalledWith('vg-for');
expect(api.getMediaById).toHaveBeenCalledWith('vg-for');
expect(mute.currentVolume).toBe(1);
});

it('Should get average volume between all media files', () => {
mute.target = api;

var volume = mute.getVolume();

expect(volume).toBe(0.75);
});

it('Should get volume for one media file', () => {
api.medias = {
main: {
volume: 1
}
};

mute.target = api;

var volume = mute.getVolume();

expect(volume).toBe(1);
});

describe('onClick (single media)', () => {
it('should mute volume if current volume is different than 0', () => {
api.medias = {
main: {
volume: 0.75
}
};

mute.target = api;

mute.onClick();

expect(mute.currentVolume).toBe(0.75);
expect(api.volume).toEqual(0);
});

it('should unmute volume if current volume is 0', () => {
api.medias = {
main: {
volume: 0
}
};

mute.target = api;

mute.currentVolume = 0.75;

mute.onClick();

expect(api.volume).toEqual(0.75);
});
});

describe('onClick (multiple medias)', () => {
it('should mute volume if current volume is different than 0', () => {
mute.target = api;

mute.onClick();

expect(mute.currentVolume).toBe(0.75);
expect(api.volume).toEqual({main: 0, secondary: 0});
});

it('should unmute volume if current volume is 0', () => {
api.medias = {
main: {
volume: 0
},
secondary: {
volume: 0
}
};

mute.target = api;

mute.currentVolume = 0.75;

mute.onClick();

expect(api.volume).toEqual({main: 0.75, secondary: 0.75});
});
});
});
1 change: 1 addition & 0 deletions src/vg-controls/vg-mute/vg-mute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class VgMute implements OnInit {
onClick() {
var volume = this.getVolume();

console.log('volume', volume);
if (volume === 0) {
this.target.volume = this.currentVolume;
}
Expand Down
122 changes: 122 additions & 0 deletions src/vg-controls/vg-play-pause/vg-play-pause.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import {it, describe, expect, beforeEach, inject} from 'angular2/testing';
import {VgPlayPause} from "./vg-play-pause";
import {VgAPI} from "../../services/vg-api";
import {ElementRef} from "angular2/core";

describe('Play/Pause Button', () => {
let playPause:VgPlayPause;
let ref:ElementRef;
let api:VgAPI;

beforeEach(() => {
ref = {
nativeElement: {
getAttribute: (name) => {
return name;
}
}
};

api = new VgAPI();
api.medias = {
main: {
state: 'play'
},
secondary: {
state: 'pause'
}
};


playPause = new VgPlayPause(ref, api);
});

it('Should get media by id on init', () => {
spyOn(playPause.elem, 'getAttribute').and.callThrough();
spyOn(api, 'getMediaById').and.callFake(() => {
return {
volume: 1
};
});

playPause.ngOnInit();

expect(playPause.elem.getAttribute).toHaveBeenCalledWith('vg-for');
expect(api.getMediaById).toHaveBeenCalledWith('vg-for');
});

it('Should get average state between all media files (play)', () => {
playPause.target = api;

var state = playPause.getState();

// If one media is on 'play' state we return 'play' as average state
expect(state).toBe('play');
});

it('Should get average state between all media files (pause)', () => {
api.medias = {
main: {
state: 'pause'
},
secondary: {
state: 'pause'
}
};

playPause.target = api;

var state = playPause.getState();

// If all medias are on 'pause' state we return 'pause' as average state
expect(state).toBe('pause');
});

it('Should get state for one media file', () => {
api.medias = {
main: {
state: 'play'
}
};

playPause.target = api;

var volume = playPause.getState();

expect(volume).toBe('play');
});

describe('onClick (single and multiple media)', () => {
it('should pause if current state is different play', () => {
spyOn(api, 'pause').and.callFake(() => {});

api.medias = {
main: {
state: 'play'
}
};

playPause.target = api;

playPause.onClick();

expect(api.pause).toHaveBeenCalled();
});

it('should play if current state is pause', () => {
spyOn(api, 'play').and.callFake(() => {});

api.medias = {
main: {
state: 'pause'
}
};

playPause.target = api;

playPause.onClick();

expect(api.play).toHaveBeenCalled();
});
});
});

0 comments on commit 9af01e7

Please sign in to comment.