public
Created

  • Download Gist
sound_player_view_spec.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
describe('Ember.SoundPlayerView', function() {
var player;
beforeEach(function() {
player = Ember.SoundPlayerView.create({ url: '/__spec__/fixtures/song.mp3' });
waitForReady();
});
afterEach(function() {
player.get('sound').stop();
player.get('sound').destruct();
});
describe('with a sound url', function() {
describe('sound is loaded', function() {
it('is stopped', function() {
expect(player.get('isStopped')).toBe(true);
});
it('plays', function() {
var sound = player.get('sound');
spyOn(sound, 'play');
player.play();
expect(sound.play).toHaveBeenCalled();
expect(player.get('isPlaying')).toBe(true);
});
it('toggles playback', function() {
var sound = player.get('sound');
spyOn(sound, 'play');
spyOn(sound, 'pause');
player.toggle();
expect(sound.play).toHaveBeenCalled();
expect(player.get('isPlaying')).toBe(true);
player.toggle();
expect(sound.pause).toHaveBeenCalled();
expect(player.get('isPlaying')).toBe(false);
player.toggle();
expect(sound.play).toHaveBeenCalled();
expect(player.get('isPlaying')).toBe(true);
});
describe('when it is playing', function() {
beforeEach(function() {
player.play();
expect(player.get('isPlaying')).toBe(true);
});
it('tracks the progress', function() {
waitForPlaying();
waits(50);
runs(function() {
expect(player.get('position')).toBeGreaterThan(0);
});
});
it('knows the total duration', function() {
expect(player.get('position')).toBe(0);
expect(player.get('duration')).toBe(731);
});
it('pauses', function() {
var sound = player.get('sound');
spyOn(sound, 'pause');
player.pause();
expect(sound.pause).toHaveBeenCalled();
expect(player.get('isPlaying')).toBe(false);
});
it('finishes', function() {
waitForPlaying();
waits(player.get('duration') + 50);
runs(function() {
expect(player.get('isStopped')).toBe(true);
expect(player.get('position')).toBe(0);
});
});
describe('when it is paused', function() {
beforeEach(function() {
player.pause();
});
it('resumes', function() {
var sound = player.get('sound');
spyOn(sound, 'resume');
player.play();
expect(sound.resume).toHaveBeenCalled();
expect(player.get('isPlaying')).toBe(true);
});
});
it('stops', function() {
var sound = player.get('sound');
spyOn(sound, 'stop');
player.set('position', 1);
player.stop();
expect(sound.stop).toHaveBeenCalled();
expect(player.get('isStopped')).toBe(true);
expect(player.get('position')).toBe(0);
});
});
});
});
function waitForReady() {
waits(10);
runs(function() {
if (player.get('stateManager.currentState.name') !== 'stopped') {
waitForReady();
}
});
}
function waitForPlaying() {
waits(10);
runs(function() {
if (!player.get('sound').position) {
waitForPlaying();
}
});
}
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.