Commit 27d00673 by jmclaus

Bug fixes, mainly in tests

parent 2fb6c02b
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
$('.subtitles li[data-index]').each(function(index, link) { $('.subtitles li[data-index]').each(function(index, link) {
expect($(link)).toHaveData('index', index); expect($(link)).toHaveData('index', index);
expect($(link)).toHaveData('start', captionsData.start[index]); expect($(link)).toHaveData('start', captionsData.start[index]);
expect($(link)).toHaveData('tabindex', 0); expect($(link)).toHaveAttr('tabindex', 0);
expect($(link)).toHaveText(captionsData.text[index]); expect($(link)).toHaveText(captionsData.text[index]);
}); });
}); });
...@@ -285,7 +285,7 @@ ...@@ -285,7 +285,7 @@
$('.subtitles li[data-index]').each(function(index, link) { $('.subtitles li[data-index]').each(function(index, link) {
expect($(link)).toHaveData('index', index); expect($(link)).toHaveData('index', index);
expect($(link)).toHaveData('start', captionsData.start[index]); expect($(link)).toHaveData('start', captionsData.start[index]);
expect($(link)).toHaveData('tabindex', 0); expect($(link)).toHaveAttr('tabindex', 0);
expect($(link)).toHaveText(captionsData.text[index]); expect($(link)).toHaveText(captionsData.text[index]);
}); });
}); });
...@@ -580,83 +580,84 @@ ...@@ -580,83 +580,84 @@
describe('when getting focus through TAB key', function() { describe('when getting focus through TAB key', function() {
beforeEach(function() { beforeEach(function() {
$('.subtitles li:first').trigger(jQuery.Event('focus'); videoCaption.isMouseFocus = false;
$('.subtitles li[data-index=0]').trigger(jQuery.Event('focus'));
}); });
it('shows an outline around the caption', function() { it('shows an outline around the caption', function() {
expect($('.subtitles li:first')).not.toHaveClass('unfocused'); expect($('.subtitles li[data-index=0]')).toHaveClass('focused');
expect($('.subtitles li:first')).toHaveClass('focused');
}); });
it('has automatic scrolling disabled', function() { it('has automatic scrolling disabled', function() {
expect(videoCaption.autoScrolling).toBe(false)); expect(videoCaption.autoScrolling).toBe(false);
}); });
}); });
describe('when loosing focus through TAB key', function() { describe('when loosing focus through TAB key', function() {
beforeEach(function() { beforeEach(function() {
$('.subtitles li:first').trigger(jQuery.Event('blur'); $('.subtitles li[data-index=0]').trigger(jQuery.Event('blur'));
}); });
it('does not show an outline around the caption', function() { it('does not show an outline around the caption', function() {
expect($('.subtitles li:first')).not.toHaveClass('focused'); expect($('.subtitles li[data-index=0]')).not.toHaveClass('focused');
expect($('.subtitles li:first')).toHaveClass('unfocused');
}); });
it('has automatic scrolling enabled', function() { it('has automatic scrolling enabled', function() {
expect(videoCaption.autoScrolling).toBe(true)); expect(videoCaption.autoScrolling).toBe(true);
}); });
}); });
describe('when same caption gets the focus through mouse after having describe('when same caption gets the focus through mouse after having focus through TAB key', function() {
focus through TAB key', function() {
beforeEach(function() { beforeEach(function() {
$('.subtitles li:first').trigger(jQuery.Event('focus'); videoCaption.isMouseFocus = false;
$('.subtitles li:first').trigger(jQuery.Event('mouseclick'); $('.subtitles li[data-index=0]').trigger(jQuery.Event('focus'));
$('.subtitles li[data-index=0]').trigger(jQuery.Event('mousedown'));
}); });
it('does not show an outline around it', function() { it('does not show an outline around it', function() {
expect($('.subtitles li:first')).not.toHaveClass('focused'); expect($('.subtitles li[data-index=0]')).not.toHaveClass('focused');
expect($('.subtitles li:first')).toHaveClass('unfocused');
}); });
it('has automatic scrolling enabled', function() { it('has automatic scrolling enabled', function() {
expect(videoCaption.autoScrolling).toBe(true)); expect(videoCaption.autoScrolling).toBe(true);
}); });
}); });
describe('when a second caption gets focus through mouse after first had describe('when a second caption gets focus through mouse after first had focus through TAB key', function() {
focus through TAB key', function() {
beforeEach(function() { beforeEach(function() {
$('.subtitles li:first').trigger(jQuery.Event('focus'); videoCaption.isMouseFocus = false;
$('.subtitles li:last').trigger(jQuery.Event('mouseclick'); $('.subtitles li[data-index=0]').trigger(jQuery.Event('focus'));
$('.subtitles li[data-index=0]').trigger(jQuery.Event('blur'));
videoCaption.isMouseFocus = true;
$('.subtitles li[data-index=1]').trigger(jQuery.Event('mousedown'));
}); });
it('does not show an outline around the first', function() { it('does not show an outline around the first', function() {
expect($('.subtitles li:first')).not.toHaveClass('focused'); expect($('.subtitles li[data-index=0]')).not.toHaveClass('focused');
expect($('.subtitles li:first')).toHaveClass('unfocused');
}); });
it('shows an outline around the second', function() { it('does not show an outline around the second', function() {
expect($('.subtitles li:last')).not.toHaveClass('unfocused'); expect($('.subtitles li[data-index=1]')).not.toHaveClass('focused');
expect($('.subtitles li:last')).toHaveClass('focused');
}); });
it('has automatic scrolling enabled', function() { it('has automatic scrolling enabled', function() {
expect(videoCaption.autoScrolling).toBe(true)); expect(videoCaption.autoScrolling).toBe(true);
}); });
}); });
describe('when enter key is pressed on a caption', function() { describe('when enter key is pressed on a caption', function() {
beforeEach(function() { beforeEach(function() {
var e = $.Event('keypress'); var e;
spyOn(videoCaption, 'seekPlayer').andCallThrough();
videoCaption.isMouseFocus = false;
$('.subtitles li[data-index=0]').trigger(jQuery.Event('focus'));
e = jQuery.Event('keydown');
e.which = 13; // ENTER key e.which = 13; // ENTER key
$('.subtitles li:first').trigger(e); $('.subtitles li[data-index=0]').trigger(e);
}); });
it('shows an outline around it', function() { it('shows an outline around it', function() {
expect($('.subtitles li:first')).not.toHaveClass('unfocused'); expect($('.subtitles li[data-index=0]')).toHaveClass('focused');
expect($('.subtitles li:first')).toHaveClass('focused');
}); });
it('calls seekPlayer', function() { it('calls seekPlayer', function() {
......
...@@ -376,8 +376,9 @@ function () { ...@@ -376,8 +376,9 @@ function () {
function captionMouseDown(event) { function captionMouseDown(event) {
var caption = $(event.target); var caption = $(event.target);
this.videoCaption.isMouseFocus = true; this.videoCaption.isMouseFocus = true;
caption.removeClass('focused').addClass('unfocused');
this.videoCaption.autoScrolling = true; this.videoCaption.autoScrolling = true;
caption.removeClass('focused').addClass('unfocused');
this.videoCaption.currentCaptionIndex = -1;
} }
function captionClick(event) { function captionClick(event) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment