Commit 38163cf9 by polesye

BLD-410: Add tests.

parent 957f3184
...@@ -79,19 +79,13 @@ Feature: CMS.Video Component ...@@ -79,19 +79,13 @@ Feature: CMS.Video Component
And I see caption line with data-index "0" has class "focused" And I see caption line with data-index "0" has class "focused"
# 11 # 11
# Disabled until we come up with a more solid test, as this one is brittle. Scenario: When start end end times are specified, a range on slider is shown
# Scenario: When start end end times are specified, a range on slider is shown Given I have created a Video component
# Given I have created a Video component And Make sure captions are closed
# And Make sure captions are closed And I edit the component
# And I edit the component And I open tab "Advanced"
# And I open tab "Advanced" And I set value "00:00:12" to the field "Start Time"
# And I set value "12" to the field "Start Time" And I set value "00:00:24" to the field "End Time"
# And I set value "24" to the field "End Time" And I save changes
# And I save changes And I click video button "play"
# And I click video button "Play" Then I see a range on slider
# The below line is a bit flaky. Numbers 73 and 73 were determined rather
# accidentally. They might change in the future as Video player gets CSS
# updates. If this test starts failing, 99.9% cause of failure is the line
# below.
# Then I see a range on slider with styles "left" set to 73 px and "width" set to 73 px
...@@ -8,7 +8,8 @@ from selenium.webdriver.common.keys import Keys ...@@ -8,7 +8,8 @@ from selenium.webdriver.common.keys import Keys
VIDEO_BUTTONS = { VIDEO_BUTTONS = {
'CC': '.hide-subtitles', 'CC': '.hide-subtitles',
'volume': '.volume', 'volume': '.volume',
'Play': '.video_control.play', 'play': '.video_control.play',
'pause': '.video_control.pause',
} }
SELECTORS = { SELECTORS = {
...@@ -183,17 +184,11 @@ def caption_line_has_class(_step, index, className): ...@@ -183,17 +184,11 @@ def caption_line_has_class(_step, index, className):
world.css_has_class(SELECTOR, className.strip()) world.css_has_class(SELECTOR, className.strip())
@step('I see a range on slider with styles "left" set to (.+) px and "width" set to (.+) px$') @step('I see a range on slider$')
def see_a_range_slider_with_proper_range(_step, left, width): def see_a_range_slider_with_proper_range(_step):
left = int(left.strip()) world.wait_for_visible(VIDEO_BUTTONS['pause'])
width = int(width.strip())
world.wait_for_visible(".slider-range") assert world.css_visible(".slider-range")
world.wait(4)
slider_range = world.browser.driver.find_element_by_css_selector(".slider-range")
assert int(round(float(slider_range.value_of_css_property("left")[:-2]))) == left
assert int(round(float(slider_range.value_of_css_property("width")[:-2]))) == width
@step('I click video button "([^"]*)"$') @step('I click video button "([^"]*)"$')
......
...@@ -248,6 +248,43 @@ ...@@ -248,6 +248,43 @@
}); });
}); });
}); });
it('getRangeParams' , function() {
var testCases = [
{
startTime: 10,
endTime: 20,
duration: 150
},
{
startTime: 90,
endTime: 100,
duration: 100
},
{
startTime: 0,
endTime: 200,
duration: 200
}
];
initialize();
$.each(testCases, function(index, testCase) {
var step = 100/testCase.duration,
left = testCase.startTime*step,
width = testCase.endTime*step - left,
expectedParams = {
left: left + '%',
width: width + '%'
},
params = videoProgressSlider.getRangeParams(
testCase.startTime, testCase.endTime, testCase.duration
);
expect(params).toEqual(expectedParams);
});
});
}); });
}).call(this); }).call(this);
...@@ -37,6 +37,7 @@ function () { ...@@ -37,6 +37,7 @@ function () {
function _makeFunctionsPublic(state) { function _makeFunctionsPublic(state) {
var methodsDict = { var methodsDict = {
buildSlider: buildSlider, buildSlider: buildSlider,
getRangeParams: getRangeParams,
onSlide: onSlide, onSlide: onSlide,
onStop: onStop, onStop: onStop,
updatePlayTime: updatePlayTime, updatePlayTime: updatePlayTime,
...@@ -100,7 +101,7 @@ function () { ...@@ -100,7 +101,7 @@ function () {
} }
function updateStartEndTimeRegion(params) { function updateStartEndTimeRegion(params) {
var left, width, start, end, step, duration; var left, width, start, end, duration, rangeParams;
// We must have a duration in order to determine the area of range. // We must have a duration in order to determine the area of range.
// It also must be non-zero. // It also must be non-zero.
...@@ -128,9 +129,8 @@ function () { ...@@ -128,9 +129,8 @@ function () {
// //
// This will ensure that visually, the start-end range aligns nicely // This will ensure that visually, the start-end range aligns nicely
// with actual starting and ending point of the video. // with actual starting and ending point of the video.
step = 100.0 / duration;
left = start * step; rangeParams = getRangeParams(start, end, duration);
width = end * step - left;
if (!this.videoProgressSlider.sliderRange) { if (!this.videoProgressSlider.sliderRange) {
this.videoProgressSlider.sliderRange = $('<div />', { this.videoProgressSlider.sliderRange = $('<div />', {
...@@ -139,8 +139,8 @@ function () { ...@@ -139,8 +139,8 @@ function () {
'ui-corner-all ' + 'ui-corner-all ' +
'slider-range' 'slider-range'
}).css({ }).css({
left: left + '%', left: rangeParams.left,
width: width + '%' width: rangeParams.width
}); });
this.videoProgressSlider.sliderProgress this.videoProgressSlider.sliderProgress
...@@ -148,12 +148,23 @@ function () { ...@@ -148,12 +148,23 @@ function () {
} else { } else {
this.videoProgressSlider.sliderRange this.videoProgressSlider.sliderRange
.css({ .css({
left: left + '%', left: rangeParams.left,
width: width + '%' width: rangeParams.width
}); });
} }
} }
function getRangeParams(startTime, endTime, duration) {
var step = 100 / duration,
left = startTime * step,
width = endTime * step - left;
return {
left: left + '%',
width: width + '%'
};
}
function onSlide(event, ui) { function onSlide(event, ui) {
this.videoProgressSlider.frozen = true; this.videoProgressSlider.frozen = true;
......
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