-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added mute, fullscreen and controls tests. Removed unused dependencies at VgControls.
- Loading branch information
Showing
6 changed files
with
273 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |