Skip to content

Commit

Permalink
test(vgPlaybackButton): Raise coverage. Initial unit tests
Browse files Browse the repository at this point in the history
#1 Raise coverage to 100%
  • Loading branch information
Bernhelm committed Feb 2, 2016
1 parent 9af01e7 commit 93564c7
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions src/vg-controls/vg-playback-button/vg-playback-button.spec.ts
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');
});
});
});

0 comments on commit 93564c7

Please sign in to comment.