Commit 73011383 by polesye

Add js unit tests.

parent eeab7847
(function (requirejs, require, define) {
require(
['video/00_resizer.js'],
function (Resizer) {
describe('Resizer', function () {
var config, container, element;
beforeEach(function () {
var html = [
'<div class="rszr-wrapper" style="width:200px; height: 200px;">',
'<div class="rszr-el" style="width:100px; height: 150px;">',
'Content',
'</div>',
'</div>'
].join('');
setFixtures(html);
container = $('.rszr-wrapper');
element = $('.rszr-el');
config = {
container: container,
element: element
};
});
it('When Initialize without required parameters, log message is shown',
function () {
spyOn(console, 'log');
new Resizer({ });
expect(console.log).toHaveBeenCalled();
}
);
it('`alignByWidthOnly` works correctly', function () {
var resizer = new Resizer(config).alignByWidthOnly(),
expectedWidth = container.width(),
realWidth = element.width();
expect(realWidth).toBe(expectedWidth);
});
it('`alignByHeightOnly` works correctly', function () {
var resizer = new Resizer(config).alignByHeightOnly(),
expectedHeight = container.height(),
realHeight = element.height(),
realWidth;
expect(realHeight).toBe(expectedHeight);
});
it('`align` works correctly', function () {
var resizer = new Resizer(config).align(),
expectedHeight = container.height(),
realHeight = element.height(),
expectedWidth = 50;
// conatinerRatio >= elementRatio
expect(realHeight).toBe(expectedHeight);
// conatinerRatio < elementRatio
container.width(expectedWidth);
resizer.align();
realWidth = element.width();
expect(realWidth).toBe(expectedWidth);
});
it('`setMode` works correctly', function () {
var resizer = new Resizer(config).setMode('height'),
expectedHeight = container.height(),
realHeight = element.height(),
expectedWidth = 50;
// conatinerRatio >= elementRatio
expect(realHeight).toBe(expectedHeight);
// conatinerRatio < elementRatio
container.width(expectedWidth);
resizer.setMode('width');
realWidth = element.width();
expect(realWidth).toBe(expectedWidth);
});
});
});
}(RequireJS.requirejs, RequireJS.require, RequireJS.define));
......@@ -10,6 +10,8 @@
}
state = new Video('#example');
state.videoEl = $('video, iframe');
videoPlayer = state.videoPlayer;
player = videoPlayer.player;
videoControl = state.videoControl;
......@@ -17,6 +19,19 @@
videoProgressSlider = state.videoProgressSlider;
videoSpeedControl = state.videoSpeedControl;
videoVolumeControl = state.videoVolumeControl;
state.resizer = (function () {
var methods = [
'align', 'alignByWidthOnly', 'alignByHeightOnly', 'setParams', 'setMode'
],
obj = {};
$.each(methods, function(index, method) {
obj[method] = jasmine.createSpy(method).andReturn(obj);
});
return obj;
})();
}
function initializeYouTube() {
......@@ -557,6 +572,7 @@
it('tell VideoCaption to resize', function() {
expect(videoCaption.resize).toHaveBeenCalled();
expect(state.resizer.setMode).toHaveBeenCalled();
});
});
......@@ -583,6 +599,7 @@
it('tell VideoCaption to resize', function() {
expect(videoCaption.resize).toHaveBeenCalled();
expect(state.resizer.setMode).toHaveBeenCalledWith('width');
});
});
});
......
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