f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric LuceYUI.add('slider-tests', function(Y) {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce// copied this from event-key-test.js to add tests for changing value by keyboard
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas GustafssonY.Node.prototype.key = function (keyCode, charCode, mods, type) {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var simulate = Y.Event.simulate,
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce el = this._node,
841179549b6433e782c164a562eb3422f603533dAndreas Gustafsson config = Y.merge(mods || {});
fcc9f7f86c2fa2ceb8a5c16dc934fea7fa6887f2Andreas Gustafsson
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce if (type) {
fcc9f7f86c2fa2ceb8a5c16dc934fea7fa6887f2Andreas Gustafsson if (type === 'keypress') {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce config.charCode = config.keyCode = config.which = charCode || keyCode;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce } else {
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson config.keyCode = config.which = keyCode;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce }
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce simulate(el, type, config);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce } else {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce config.keyCode = config.which = keyCode;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce simulate(el, 'keydown', config);
fcc9f7f86c2fa2ceb8a5c16dc934fea7fa6887f2Andreas Gustafsson simulate(el, 'keyup', config);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce config.charCode = config.keyCode = config.which = charCode || keyCode;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce simulate(el, 'keypress', config);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce }
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce};
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce// END copied this from event-key-test.js to add tests for changing value by keyboard
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric LuceY.Node.prototype.simulate = function (type, config) {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var simulate = Y.Event.simulate,
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce args = [this._node, type].concat(Y.Array(arguments, 1, true));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce if(type) {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce simulate.apply(Y.Event, args);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce }
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce};
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Lucevar suite = new Y.Test.Suite("Y.Slider");
fcc9f7f86c2fa2ceb8a5c16dc934fea7fa6887f2Andreas Gustafsson
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Lucesuite.add( new Y.Test.Case({
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce name: "Lifecycle",
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce setUp: function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.one("body").append('<div id="testbed"></div>');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce tearDown: function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.one("#testbed").remove(true);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "test default construction": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.isInstanceOf( Y.Slider, new Y.Slider() );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "test SliderBase construction": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.isInstanceOf( Y.SliderBase, new Y.SliderBase() );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "test render(selector)": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.one("#testbed").setContent(
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "<div></div>" + // block element
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce '<div class="floated" style="float:left"></div>' + // float
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "<p></p>" + // limited block element
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "<span></span>"); // inline element
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce (new Y.Slider().render("#testbed > div"));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce (new Y.Slider().render("#testbed > div.floated"));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce (new Y.Slider().render("#testbed > p"));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce (new Y.Slider().render("#testbed > span"));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var div = Y.one("#testbed > div"),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce fl = Y.one("#testbed > div.floated"),
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson p = Y.one("#testbed > p"),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce span = Y.one("#testbed > span");
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.assert( (div.get("offsetHeight") > 0) );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.assert( (fl.get("offsetHeight") > 0) );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.assert( (p.get("offsetHeight") > 0) );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.assert( (span.get("offsetHeight") > 0) );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.assert( (fl.get("offsetWidth") > 0) );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.assert( (span.get("offsetWidth") > 0) );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.Assert.areEqual( 8, div.all("span,img").size() );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.Assert.areEqual( 8, fl.all("span,img").size() );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.Assert.areEqual( 8, p.all("span,img").size() );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.Assert.areEqual( 8, span.all("span,img").size() );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "test render( node )": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.one("#testbed").setContent(
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "<div></div>" + // block element
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson '<div class="floated" style="float:left"></div>' + // float
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "<p></p>" + // limited block element
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "<span></span>"); // inline element
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var div = Y.one("#testbed > div"),
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson fl = Y.one("#testbed > div.floated"),
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington p = Y.one("#testbed > p"),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce span = Y.one("#testbed > span");
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce (new Y.Slider().render(div));
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson (new Y.Slider().render(fl));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce (new Y.Slider().render(p));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce (new Y.Slider().render(span));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.assert( (div.get("offsetHeight") > 0) );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.assert( (fl.get("offsetHeight") > 0) );
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington Y.assert( (p.get("offsetHeight") > 0) );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.assert( (span.get("offsetHeight") > 0) );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.assert( (fl.get("offsetWidth") > 0) );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.assert( (span.get("offsetWidth") > 0) );
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 8, div.all("span,img").size() );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 8, fl.all("span,img").size() );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 8, p.all("span,img").size() );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.Assert.areEqual( 8, span.all("span,img").size() );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "test render: selector attrib in constructor": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.one("#testbed").setContent(
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson "<div></div>" + // block element
6383d77950149e7a94bf59d84f3e51e1aa4b3d95Brian Wellington '<div class="floated" style="float:left"></div>' + // float
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "<p></p>" + // limited block element
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "<span></span>"); // inline element
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce (new Y.Slider({ render: "#testbed > div" }));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce (new Y.Slider({ render: "#testbed > div.floated" }));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce (new Y.Slider({ render: "#testbed > p" }));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce (new Y.Slider({ render: "#testbed > span" }));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var div = Y.one("#testbed > div"),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce fl = Y.one("#testbed > div.floated"),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce p = Y.one("#testbed > p"),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce span = Y.one("#testbed > span");
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.assert( (div.get("offsetHeight") > 0) );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.assert( (fl.get("offsetHeight") > 0) );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.assert( (p.get("offsetHeight") > 0) );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.assert( (span.get("offsetHeight") > 0) );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.assert( (fl.get("offsetWidth") > 0) );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.assert( (span.get("offsetWidth") > 0) );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.Assert.areEqual( 8, div.all("span,img").size() );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.Assert.areEqual( 8, fl.all("span,img").size() );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.Assert.areEqual( 8, p.all("span,img").size() );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.Assert.areEqual( 8, span.all("span,img").size() );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson },
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson "test render: node attrib in constructor": function () {
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.one("#testbed").setContent(
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson "<div></div>" + // block element
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson '<div class="floated" style="float:left"></div>' + // float
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson "<p></p>" + // limited block element
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson "<span></span>"); // inline element
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson var div = Y.one("#testbed > div"),
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson fl = Y.one("#testbed > div.floated"),
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson p = Y.one("#testbed > p"),
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson span = Y.one("#testbed > span");
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson (new Y.Slider({ render: div }));
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson (new Y.Slider({ render: fl }));
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson (new Y.Slider({ render: p }));
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson (new Y.Slider({ render: span }));
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.assert( (div.get("offsetHeight") > 0) );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.assert( (fl.get("offsetHeight") > 0) );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.assert( (p.get("offsetHeight") > 0) );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.assert( (span.get("offsetHeight") > 0) );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.assert( (fl.get("offsetWidth") > 0) );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.assert( (span.get("offsetWidth") > 0) );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.Assert.areEqual( 8, div.all("span,img").size() );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.Assert.areEqual( 8, fl.all("span,img").size() );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.Assert.areEqual( 8, p.all("span,img").size() );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.Assert.areEqual( 8, span.all("span,img").size() );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson },
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson "test render off DOM": function () {
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson var container = Y.Node.create("<div></div>");
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson (new Y.Slider().render(container));
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 8, container.all("span,img").size() );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "test destroy() before render": function () {
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson var slider = new Y.Slider();
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.isTrue( slider.get("destroyed") );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "test destroy() after render off DOM": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var container = Y.Node.create("<div></div>"),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider = new Y.Slider();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.render( container );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.isTrue( slider.get("destroyed") );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.isNull( container.get("firstChild") );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson "test destroy() after render to DOM": function () {
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson var slider = new Y.Slider();
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.render( "#testbed" );
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson slider.destroy();
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson Y.Assert.isTrue( slider.get("destroyed") );
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson Y.Assert.isNull( Y.one("#testbed").get("firstChild") );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson }
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson}));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafssonsuite.add( new Y.Test.Case({
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson name: "API",
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson setUp: function () {
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson Y.one('body').append('<div id="testbed"></div>');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce this.slider = new Y.Slider();
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson },
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson tearDown: function () {
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson this.slider.destroy();
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson Y.one('#testbed').remove(true);
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson },
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson "test getValue() and setValue(v) before render": function () {
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson var s = this.slider;
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson Y.Assert.areEqual( 0, s.getValue() );
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson s.setValue(50);
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson Y.Assert.areEqual( 50, s.getValue() );
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson s.setValue(3.3333);
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson Y.Assert.areEqual( 3, s.getValue() );
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson // out of range constrained by setter
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson s.setValue(-10);
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson Y.Assert.areEqual( 0, s.getValue() );
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson s.setValue(110);
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson Y.Assert.areEqual( 100, s.getValue() );
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson Y.Assert.areEqual( s.get('value'), s.getValue() );
eadfcf9cf79376eaae5e3010882ba4f41a7c9b89Andreas Gustafsson
eadfcf9cf79376eaae5e3010882ba4f41a7c9b89Andreas Gustafsson s.set('value', 6.66666);
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington Y.Assert.areEqual( 7, s.getValue() );
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington Y.Assert.areEqual( s.get('value'), s.getValue() );
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington },
eadfcf9cf79376eaae5e3010882ba4f41a7c9b89Andreas Gustafsson
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington "test getValue() and setValue(v) after render() to hidden container": function () {
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington var container = Y.Node.create('<div></div>'),
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington s = this.slider;
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington s.render( container );
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington Y.Assert.areEqual( 0, s.getValue() );
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington
eadfcf9cf79376eaae5e3010882ba4f41a7c9b89Andreas Gustafsson s.setValue(50);
eadfcf9cf79376eaae5e3010882ba4f41a7c9b89Andreas Gustafsson Y.Assert.areEqual( 50, s.getValue() );
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington s.setValue(3.3333);
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington Y.Assert.areEqual( 3, s.getValue() );
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington s.setValue(-10);
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington Y.Assert.areEqual( 0, s.getValue() );
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington s.setValue(110);
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington Y.Assert.areEqual( 100, s.getValue() );
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington Y.Assert.areEqual( s.get('value'), s.getValue() );
eadfcf9cf79376eaae5e3010882ba4f41a7c9b89Andreas Gustafsson
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington s.set('value', 6.66666);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 7, s.getValue() );
f37eb9482057adf62de35e634bfd574e59676950Andreas Gustafsson Y.Assert.areEqual( s.get('value'), s.getValue() );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "test getValue() and setValue(v) after render() to DOM": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var s = this.slider;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce s.render('#testbed');
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 0, s.getValue() );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce s.setValue(50);
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson Y.Assert.areEqual( 50, s.getValue() );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson s.setValue(3.3333);
fafd1d771905532e8dc3efa2ce90ce4c9e74af61Eric Luce Y.Assert.areEqual( 3, s.getValue() );
fcc9f7f86c2fa2ceb8a5c16dc934fea7fa6887f2Andreas Gustafsson
116dd27475e0521a033139ad5ac2355cf4b3e29bBrian Wellington s.setValue(-10);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 0, s.getValue() );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce s.setValue(110);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 100, s.getValue() );
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson Y.Assert.areEqual( s.get('value'), s.getValue() );
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce s.set('value', 6.66666);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 7, s.getValue() );
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson Y.Assert.areEqual( s.get('value'), s.getValue() );
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson },
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson "setValue(v) then render() should position thumb": function () {
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson var s = this.slider;
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson s.setValue(20);
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson s.render("#testbed");
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson Y.Assert.areEqual( 27, parseInt(s.thumb.getStyle("left"),10) );
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson },
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson "setValue(v) after render() should move the thumb": function () {
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson var s = this.slider;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce s.render('#testbed');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 0, parseInt(s.thumb.getStyle('left'),10) );
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson
7fca810d8735063703afff4208c8e92cf6b5ca6aAndreas Gustafsson s.setValue(20);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 27, parseInt(s.thumb.getStyle('left'),10) );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce s.setValue(0);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 0, s.getValue() );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 0, parseInt(s.thumb.getStyle('left'),10) );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce s.setValue(100);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 100, s.getValue() );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 135, parseInt(s.thumb.getStyle('left'),10) );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "setValue(v) when hidden should still move the thumb": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var s = this.slider;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.one('#testbed').setStyle('display','none');
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson s.render('#testbed');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 0, parseInt(s.thumb.getStyle('left'),10) );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce s.setValue(20);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 27, parseInt(s.thumb.getStyle('left'),10) );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.one('#testbed').setStyle('display','');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 27, parseInt(s.thumb.getStyle('left'),10) );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce }
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce}));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Lucesuite.add( new Y.Test.Case({
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce name: "Attributes",
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce _should: {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce fail: {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce // TODO This is a bug. invalid construction value should fallback
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce // to specified attribute default
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "axis should only accept 'x', 'X', 'y', and 'Y'": true
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce }
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce setUp: function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.one('body').append('<span id="testbed"></span>');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce tearDown: function () {
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.one('#testbed').remove(true);
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson },
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson "test axis": function () {
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson var testbed = Y.one('#testbed'),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider = new Y.Slider({ axis: 'x' }).render( testbed ),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce bb = testbed.get("firstChild");
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.assert( (bb.get("offsetWidth") > 100), "offsetWidth > 100" );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.assert( (bb.get("offsetHeight") < 50), "offsetHeight < 50" );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider = new Y.Slider({ axis: 'y' }).render( testbed );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce bb = testbed.get("firstChild");
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.assert( (bb.get("offsetHeight") > 100), "offsetHeight > 100" );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.assert( (bb.get("offsetWidth") < 50), "offsetWidth < 50" );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "axis should be writeOnce": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var slider = new Y.Slider();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual("x", slider.get("axis"));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.set('axis', 'y');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual("x", slider.get("axis"));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider = new Y.Slider({ axis: 'y' });
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual("y", slider.get("axis"));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.set('axis', 'x');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual("y", slider.get("axis"));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "axis should only accept 'x', 'X', 'y', and 'Y'": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var attempts = "a b c 1 2 3 yx yy YX YY vertical vert eks".split(/ /);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.each( attempts, function ( axis ) {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var slider = new Y.Slider({ axis: axis });
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual("x", slider.get("axis"));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce });
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce attempts = ['y', 'Y'];
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.each( attempts, function ( axis ) {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var slider = new Y.Slider({ axis: axis });
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual("y", slider.get("axis"));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce });
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "test length": function () {
56f1285ca5d97d3205b74c32dc4de1ea7b69fea1Michael Sawyer Y.one('#testbed').append('<div id="slider"></div><div id="ref"></div>');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
56f1285ca5d97d3205b74c32dc4de1ea7b69fea1Michael Sawyer var testbed = Y.one("#slider"),
56f1285ca5d97d3205b74c32dc4de1ea7b69fea1Michael Sawyer ref = Y.one("#ref"),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider, delta, bb;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider = new Y.Slider().render( testbed );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson bb = testbed.get('firstChild');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce delta = bb.get('offsetWidth') - parseInt(slider.get('length'), 10);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider = new Y.Slider({ length: 50 }).render( testbed );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce bb = testbed.get('firstChild');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( (50 + delta), bb.get('offsetWidth') );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.set('length', 300);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( (300 + delta), bb.get('offsetWidth') );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.set('length', "-140px");
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( (300 + delta), bb.get('offsetWidth') );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce ref.setStyle("width", "23.5em");
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.set('length', '23.5em');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( (ref.get('offsetWidth') + delta), bb.get('offsetWidth') );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider = new Y.Slider({ axis: 'y' }).render( testbed );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce bb = testbed.get('firstChild');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce delta = bb.get('offsetHeight') - parseInt(slider.get('length'), 10);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider = new Y.Slider({ axis: 'y', length: 50 }).render( testbed );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce bb = testbed.get('firstChild');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( (50 + delta), bb.get('offsetHeight') );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.set('length', 300);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( (300 + delta), bb.get('offsetHeight') );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.set('length', "-140px");
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( (300 + delta), bb.get('offsetHeight') );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce ref.setStyle("height", "23.5em");
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.set('length', '23.5em');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( (ref.get('offsetHeight') + delta), bb.get('offsetHeight') );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "thumbUrl should default at render()": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var slider = new Y.Slider();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.isNull( slider.get('thumbUrl') );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.render('#testbed');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.isString( slider.get('thumbUrl') );
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "thumbUrl should default to sam skin": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var slider = new Y.Slider().render("#testbed");
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( Y.config.base + 'slider-base/assets/skins/sam/thumb-x.png', slider.get('thumbUrl') );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "thumbUrl should default from the current skin": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var testbed = Y.one("#testbed"),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider = new Y.Slider();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce testbed.addClass("yui3-skin-foo");
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.render( testbed );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( Y.config.base + 'slider-base/assets/skins/foo/thumb-x.png', slider.get('thumbUrl') );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson "test clickableRail": function () {
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson var slider = new Y.Slider({
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce width : '300px',
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson clickableRail: true
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson }),
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson railRegion, where, fired;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.on('railMouseDown', function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce fired = true;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce });
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson slider.render('#testbed');
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce railRegion = slider.rail.get('region');
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson where = {
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson clientX: railRegion.left + Math.floor(railRegion.width / 2),
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson clientY: railRegion.top + Math.floor(railRegion.height / 2)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce };
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.on('railMouseDown', function (e) {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce fired = true;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce });
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.rail.simulate('mousedown', where);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.rail.simulate('mouseup', where);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.rail.simulate('click', where);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.isTrue(fired, "railMouseDown didn't fire for clickableRail: true");
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce fired = false;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.one('#testbed').empty();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson slider = new Y.Slider({
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson width : '300px',
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson clickableRail: false
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce });
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson slider.on('railMouseDown', function () {
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson fired = true;
56f1285ca5d97d3205b74c32dc4de1ea7b69fea1Michael Sawyer });
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.render('#testbed');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson slider.rail.simulate('mousedown', where);
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson slider.rail.simulate('mouseup', where);
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson slider.rail.simulate('click', where);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson Y.Assert.isFalse(fired, "railMouseDown fired for clickableRail: false");
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafsson slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "test min": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var slider = new Y.Slider({ min: -100 });
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areSame(-100, slider.get('min'));
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.set('min', 0);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areSame(0, slider.get('min'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce "test max": function () {
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce var slider = new Y.Slider({ max: 33 });
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areSame(33, slider.get('max'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.set('max', 80);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce Y.Assert.areSame(80, slider.get('max'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
8e245ec21beee31a780de9b89ba1e8bb2b9f4c9aAndreas Gustafsson "test value": function () {
8e245ec21beee31a780de9b89ba1e8bb2b9f4c9aAndreas Gustafsson var slider = new Y.Slider({ min: 0, max: 100, value: 50 });
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areSame(50, slider.get('value'));
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce slider.set('value', 0);
8e245ec21beee31a780de9b89ba1e8bb2b9f4c9aAndreas Gustafsson
8e245ec21beee31a780de9b89ba1e8bb2b9f4c9aAndreas Gustafsson Y.Assert.areSame(0, slider.get('value'));
8e245ec21beee31a780de9b89ba1e8bb2b9f4c9aAndreas Gustafsson
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce "setting the value outside the min or max should constrain it": function () {
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson var slider = new Y.Slider({ min: 0, max: 100, value: 50 });
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areSame(50, slider.get('value'));
8e245ec21beee31a780de9b89ba1e8bb2b9f4c9aAndreas Gustafsson
8e245ec21beee31a780de9b89ba1e8bb2b9f4c9aAndreas Gustafsson slider.set('value', -10);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areSame(0, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce slider.set('value', 110);
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areSame(100, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "setting the min or max should update the value if necessary": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var slider = new Y.Slider({ min: 0, max: 100, value: 50 });
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.render('#testbed');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areSame(50, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.set('min', 60);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areSame(60, slider.get('value'));
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.set('min', 0);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areSame(60, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.set('max', 50);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areSame(50, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce }
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce}));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Lucesuite.add( new Y.Test.Case({
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce name: "Mouse",
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce setUp: function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.one("body").append('<div id="testbed"></div>');
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce tearDown: function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.one("#testbed").remove(true);
8e245ec21beee31a780de9b89ba1e8bb2b9f4c9aAndreas Gustafsson },
8e245ec21beee31a780de9b89ba1e8bb2b9f4c9aAndreas Gustafsson
8e245ec21beee31a780de9b89ba1e8bb2b9f4c9aAndreas Gustafsson "clicking on the rail should move the thumb": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var slider = new Y.Slider({
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce length: '350px',
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce min : 0,
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce max : 100,
8e245ec21beee31a780de9b89ba1e8bb2b9f4c9aAndreas Gustafsson value : 50
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce }),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce position, fired, railRegion, where;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce function thumbPosition() {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce return parseInt(slider.thumb.getStyle('left'), 10);
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce }
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.render( "#testbed" );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce railRegion = slider.rail.get('region');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce where = {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce clientX: railRegion.left + Math.floor(railRegion.width / 2),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce clientY: railRegion.top + Math.floor(railRegion.height / 2)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce };
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areNotSame(0, thumbPosition());
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.set('value', 0);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areSame(0, thumbPosition());
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.on('railMouseDown', function (e) {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce fired = true;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce });
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.rail.simulate('mousedown', where);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.rail.simulate('mouseup', where);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.rail.simulate('click', where);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.isTrue(fired);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.isTrue( (thumbPosition() > 0) );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce }
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce}));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafssonsuite.add( new Y.Test.Case({
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce name: "Keyboard",
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce setUp: function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.one("body").append('<div id="testbed"></div>');
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce tearDown: function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.one("#testbed").remove(true);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "test keyboard input": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var slider = new Y.Slider({
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce length: '350px',
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce min : 0,
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce max : 100,
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce value : 50
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce });
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.render( "#testbed" );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 50, slider.get('value') );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var thumb = slider.thumb;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(33); // pageUp // .key() method is at top of this file
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(60, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(38); // up
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(61, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(39); // right
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(62, slider.get('value'));
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson thumb.key(33); // pageUp
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson Y.Assert.areEqual(72, slider.get('value'));
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson thumb.key(40); // down
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(71, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(34); // pageDown
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(61, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(37); // left
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(37); // left
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(59, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(36); // home
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(0, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(35); // end
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(100, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce // beyond max
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(33); // pageUp
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(100, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(38); // up
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(100, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(39); // right
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington Y.Assert.areEqual(100, slider.get('value'));
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce // min and beyond
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.set('value', 0);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(34); // pageDown
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(0, slider.get('value'), "= pageDown at min");
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(40); // down
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(0, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(37); // left
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(0, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "test focus on thumb by click": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var slider = new Y.Slider({
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce length: '350px',
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington min : 0,
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson max : 100,
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce value : 50,
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce majorStep : 34
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce });
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.render( "#testbed" );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 50, slider.get('value') );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var thumb = slider.thumb;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.on('focus', function(){
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce // 33 is pageUp. Increase value = init value + majorStep
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce // .key() method is at top of this file
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(33);
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce });
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.simulate('click'); // Should set focus on thumb
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(84, slider.get('value'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce /*
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce * This tests changing the value by one unit
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce * that would not move the slider a full pixel
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce * and because of ticket #2531498, was
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce * changing the value back to previous value
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce * to match the thumb position
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce */
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "test keyboard input and resultant value change, when Slider length is less than max - min": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var slider = new Y.Slider({
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce length: '30px', // length less than max - min
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce min : 0,
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce max : 100,
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce value : 0
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce });
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.render( "#testbed" );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 0, slider.get('value') );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var thumb = slider.thumb;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(38); // up // .key() method is at top of this file
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(1, slider.get('value'), "** init at 0, then keyUp");
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson },
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce "test ARIA attributes while values change by keyboard input": function () {
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var slider = new Y.Slider({
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce length: '300px', // length less than max - min
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce min : 0,
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce max : 100,
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce value : 50
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce });
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.render( "#testbed" );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual( 50, slider.get('value') );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce var thumb = slider.thumb;
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(0, thumb.getAttribute('aria-valuemin'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(100, thumb.getAttribute('aria-valuemax'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(38); // up // .key() method is at top of this file
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(51, thumb.getAttribute('aria-valuenow'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(51, thumb.getAttribute('aria-valuetext'));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce thumb.key(33); // pageUp
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce Y.Assert.areEqual(61, thumb.getAttribute('aria-valuenow'));
a9f5be43488d374aeb222e8870d6b522f07530bbBrian Wellington Y.Assert.areEqual(61, thumb.getAttribute('aria-valuetext'));
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce slider.destroy();
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce }
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce}));
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric LuceY.Test.Runner.add( suite );
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce}, '@VERSION@' ,{requires:['slider', 'test']});
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce