-
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.
test(vgPlaybackButton): Raise coverage. Initial unit tests
#1 Raise coverage to 100%
- Loading branch information
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
src/vg-controls/vg-playback-button/vg-playback-button.spec.ts
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,96 @@ | ||
import {it, describe, expect, beforeEach, inject} from 'angular2/testing'; | ||
import {VgPlaybackButton} from "./vg-playback-button"; | ||
import {VgAPI} from "../../services/vg-api"; | ||
import {ElementRef} from "angular2/core"; | ||
|
||
describe('Play/Pause Button', () => { | ||
let playbackButton:VgPlaybackButton; | ||
let ref:ElementRef; | ||
let api:VgAPI; | ||
|
||
beforeEach(() => { | ||
ref = { | ||
nativeElement: { | ||
getAttribute: (name) => { | ||
return name; | ||
} | ||
} | ||
}; | ||
|
||
api = new VgAPI(); | ||
api.medias = { | ||
main: { | ||
state: 'play' | ||
}, | ||
secondary: { | ||
state: 'pause' | ||
} | ||
}; | ||
|
||
|
||
playbackButton = new VgPlaybackButton(ref, api); | ||
}); | ||
|
||
it('Should set playbackIndex default value to 1', () => { | ||
expect(playbackButton.playbackIndex).toEqual(1); | ||
}); | ||
|
||
it('Should get media by id on init', () => { | ||
spyOn(playbackButton.elem, 'getAttribute').and.callThrough(); | ||
spyOn(api, 'getMediaById').and.callFake(() => { | ||
return { | ||
volume: 1 | ||
}; | ||
}); | ||
|
||
playbackButton.ngOnInit(); | ||
|
||
expect(playbackButton.elem.getAttribute).toHaveBeenCalledWith('vg-for'); | ||
expect(api.getMediaById).toHaveBeenCalledWith('vg-for'); | ||
}); | ||
|
||
describe('onClick (single and multiple media)', () => { | ||
it('should increase playbackIndex', () => { | ||
api.medias = { | ||
main: { | ||
state: 'play' | ||
} | ||
}; | ||
|
||
playbackButton.target = api; | ||
|
||
playbackButton.onClick(); | ||
|
||
expect(playbackButton.playbackIndex).toEqual(2); | ||
}); | ||
|
||
it('should set playbackRate to target media', () => { | ||
api.medias = { | ||
main: { | ||
state: 'play' | ||
} | ||
}; | ||
|
||
playbackButton.target = api; | ||
|
||
playbackButton.onClick(); | ||
|
||
expect(playbackButton.target.playbackRate).toEqual('1.5'); | ||
}); | ||
|
||
it('should set playbackRate to target media', () => { | ||
let media = { | ||
playbackRate: { | ||
test: '1' | ||
} | ||
}; | ||
|
||
playbackButton.target = media; | ||
playbackButton.vgFor = 'test'; | ||
|
||
playbackButton.onClick(); | ||
|
||
expect(playbackButton.target.playbackRate.test).toEqual('1.5'); | ||
}); | ||
}); | ||
}); |