diff --git a/src/vg-controls/vg-controls.spec.ts b/src/vg-controls/vg-controls.spec.ts new file mode 100644 index 00000000..734f1430 --- /dev/null +++ b/src/vg-controls/vg-controls.spec.ts @@ -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(); + }); +}); diff --git a/src/vg-controls/vg-controls.ts b/src/vg-controls/vg-controls.ts index 8af12920..7d1a1cb4 100644 --- a/src/vg-controls/vg-controls.ts +++ b/src/vg-controls/vg-controls.ts @@ -1,7 +1,5 @@ import {Component} from 'angular2/core'; -import {VgAPI} from '../services/vg-api'; - @Component({ selector: 'vg-controls', template: ``, @@ -35,7 +33,5 @@ import {VgAPI} from '../services/vg-api'; `] }) export class VgControls { - constructor(public API:VgAPI) { - - } + constructor() {} } diff --git a/src/vg-controls/vg-fullscreen/vg-fullscreen.spec.ts b/src/vg-controls/vg-fullscreen/vg-fullscreen.spec.ts index 4f961afb..eee1859f 100644 --- a/src/vg-controls/vg-fullscreen/vg-fullscreen.spec.ts +++ b/src/vg-controls/vg-fullscreen/vg-fullscreen.spec.ts @@ -36,7 +36,7 @@ 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(); @@ -44,7 +44,7 @@ describe('Videogular Player', () => { 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(); diff --git a/src/vg-controls/vg-mute/vg-mute.spec.ts b/src/vg-controls/vg-mute/vg-mute.spec.ts new file mode 100644 index 00000000..eb98e462 --- /dev/null +++ b/src/vg-controls/vg-mute/vg-mute.spec.ts @@ -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}); + }); + }); +}); diff --git a/src/vg-controls/vg-mute/vg-mute.ts b/src/vg-controls/vg-mute/vg-mute.ts index ec4ab2c1..12678712 100644 --- a/src/vg-controls/vg-mute/vg-mute.ts +++ b/src/vg-controls/vg-mute/vg-mute.ts @@ -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; } diff --git a/src/vg-controls/vg-play-pause/vg-play-pause.spec.ts b/src/vg-controls/vg-play-pause/vg-play-pause.spec.ts new file mode 100644 index 00000000..5b0caeff --- /dev/null +++ b/src/vg-controls/vg-play-pause/vg-play-pause.spec.ts @@ -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(); + }); + }); +});