[76] | 1 | /*! |
---|
| 2 | * Ext JS Library 3.4.0 |
---|
| 3 | * Copyright(c) 2006-2011 Sencha Inc. |
---|
| 4 | * licensing@sencha.com |
---|
| 5 | * http://www.sencha.com/license |
---|
| 6 | */ |
---|
| 7 | /** |
---|
| 8 | * Tests Ext.data.Store functionality |
---|
| 9 | * @author Ed Spencer |
---|
| 10 | */ |
---|
| 11 | (function() { |
---|
| 12 | var suite = Ext.test.session.getSuite('Ext.Slider'), |
---|
| 13 | assert = Y.Assert; |
---|
| 14 | |
---|
| 15 | suite.add(new Y.Test.Case({ |
---|
| 16 | name: 'constructor and initComponent', |
---|
| 17 | |
---|
| 18 | setUp: function() { |
---|
| 19 | this.slider = new Ext.Slider(); |
---|
| 20 | }, |
---|
| 21 | |
---|
| 22 | testDefaultValues: function() { |
---|
| 23 | assert.areEqual(0, this.slider.minValue); |
---|
| 24 | assert.areEqual(0, this.slider.value); |
---|
| 25 | assert.areEqual(100, this.slider.maxValue); |
---|
| 26 | }, |
---|
| 27 | |
---|
| 28 | testDefaultValueSet: function() { |
---|
| 29 | var slider = new Ext.Slider({minValue: 50}); |
---|
| 30 | |
---|
| 31 | assert.areEqual(50, slider.value); |
---|
| 32 | } |
---|
| 33 | })); |
---|
| 34 | |
---|
| 35 | suite.add(new Y.Test.Case({ |
---|
| 36 | name: 'Changing value', |
---|
| 37 | |
---|
| 38 | setUp: function() { |
---|
| 39 | this.slider = new Ext.Slider({ |
---|
| 40 | minValue: 30, |
---|
| 41 | values : [50, 70], |
---|
| 42 | maxValue: 90, |
---|
| 43 | renderTo: Ext.getBody() |
---|
| 44 | }); |
---|
| 45 | |
---|
| 46 | this.slider.render(); |
---|
| 47 | }, |
---|
| 48 | |
---|
| 49 | tearDown: function() { |
---|
| 50 | this.slider.destroy(); |
---|
| 51 | }, |
---|
| 52 | |
---|
| 53 | testValueChanged: function() { |
---|
| 54 | this.slider.setValue(0, 60); |
---|
| 55 | |
---|
| 56 | assert.areEqual(60, this.slider.getValues()[0]); |
---|
| 57 | }, |
---|
| 58 | |
---|
| 59 | testEventFired: function() { |
---|
| 60 | var executed = false, |
---|
| 61 | value, thumb; |
---|
| 62 | |
---|
| 63 | this.slider.on('change', function(slider, v, t) { |
---|
| 64 | executed = true; |
---|
| 65 | value = v; |
---|
| 66 | thumb = t; |
---|
| 67 | }, this); |
---|
| 68 | |
---|
| 69 | this.slider.setValue(0, 60); |
---|
| 70 | |
---|
| 71 | assert.isTrue(executed); |
---|
| 72 | assert.areEqual(60, value); |
---|
| 73 | assert.areEqual(this.slider.thumbs[0], thumb); |
---|
| 74 | }, |
---|
| 75 | |
---|
| 76 | testThumbMoved: function() { |
---|
| 77 | var orig = this.slider.moveThumb, |
---|
| 78 | index, animate; |
---|
| 79 | |
---|
| 80 | this.slider.moveThumb = function(i, v, a) { |
---|
| 81 | index = i; |
---|
| 82 | animate = a; |
---|
| 83 | }; |
---|
| 84 | |
---|
| 85 | this.slider.setValue(0, 60, false); |
---|
| 86 | |
---|
| 87 | assert.areEqual(0, index); |
---|
| 88 | assert.isFalse(animate); |
---|
| 89 | }, |
---|
| 90 | |
---|
| 91 | testChangeComplete: function() { |
---|
| 92 | var executed = false, |
---|
| 93 | value, thumb; |
---|
| 94 | |
---|
| 95 | this.slider.on('changecomplete', function(slider, v, t) { |
---|
| 96 | executed = true; |
---|
| 97 | value = v; |
---|
| 98 | thumb = t; |
---|
| 99 | }, this); |
---|
| 100 | |
---|
| 101 | this.slider.setValue(0, 60, undefined, true); |
---|
| 102 | |
---|
| 103 | assert.isTrue(executed); |
---|
| 104 | assert.areEqual(60, value); |
---|
| 105 | assert.areEqual(this.slider.thumbs[0], thumb); |
---|
| 106 | }, |
---|
| 107 | |
---|
| 108 | testSetMinValue: function() { |
---|
| 109 | this.slider.setMinValue(20); |
---|
| 110 | |
---|
| 111 | assert.areEqual(20, this.slider.minValue); |
---|
| 112 | assert.areEqual(50, this.slider.getValues()[0]); |
---|
| 113 | }, |
---|
| 114 | |
---|
| 115 | testSetMaxValue: function() { |
---|
| 116 | this.slider.setMaxValue(110); |
---|
| 117 | |
---|
| 118 | assert.areEqual(110, this.slider.maxValue); |
---|
| 119 | assert.areEqual(50, this.slider.getValues()[0]); |
---|
| 120 | }, |
---|
| 121 | |
---|
| 122 | testSetMinValueChangesValue: function() { |
---|
| 123 | this.slider.setMinValue(60); |
---|
| 124 | |
---|
| 125 | assert.areEqual(60, this.slider.getValues()[0]); |
---|
| 126 | assert.areEqual(70, this.slider.getValues()[1]); |
---|
| 127 | }, |
---|
| 128 | |
---|
| 129 | testSetMaxValueChangesValue: function() { |
---|
| 130 | this.slider.setMaxValue(60); |
---|
| 131 | |
---|
| 132 | assert.areEqual(50, this.slider.getValues()[0]); |
---|
| 133 | assert.areEqual(60, this.slider.getValues()[1]); |
---|
| 134 | } |
---|
| 135 | })); |
---|
| 136 | |
---|
| 137 | suite.add(new Y.Test.Case({ |
---|
| 138 | name: 'Utility functions', |
---|
| 139 | |
---|
| 140 | setUp: function() { |
---|
| 141 | this.slider = new Ext.Slider({ |
---|
| 142 | //the slider has 14px of total padding on the sides, so add this here to make the numbers easier |
---|
| 143 | width : 214, |
---|
| 144 | minValue: 100, |
---|
| 145 | maxValue: 500, |
---|
| 146 | renderTo: Ext.getBody() |
---|
| 147 | }); |
---|
| 148 | |
---|
| 149 | this.slider.render(); |
---|
| 150 | }, |
---|
| 151 | |
---|
| 152 | tearDown: function() { |
---|
| 153 | this.slider.destroy(); |
---|
| 154 | }, |
---|
| 155 | |
---|
| 156 | testGetRatio: function() { |
---|
| 157 | assert.areEqual(0.5, this.slider.getRatio()); |
---|
| 158 | }, |
---|
| 159 | |
---|
| 160 | testTranslateValue: function() { |
---|
| 161 | |
---|
| 162 | }, |
---|
| 163 | |
---|
| 164 | testReverseValue: function() { |
---|
| 165 | |
---|
| 166 | }, |
---|
| 167 | |
---|
| 168 | testNormalizeValue: function() { |
---|
| 169 | |
---|
| 170 | } |
---|
| 171 | })); |
---|
| 172 | |
---|
| 173 | suite.add(new Y.Test.Case({ |
---|
| 174 | name: 'Snapping', |
---|
| 175 | |
---|
| 176 | setUp: function() { |
---|
| 177 | this.slider = new Ext.Slider({ |
---|
| 178 | increment: 10, |
---|
| 179 | renderTo : Ext.getBody() |
---|
| 180 | }); |
---|
| 181 | |
---|
| 182 | this.slider.render(); |
---|
| 183 | }, |
---|
| 184 | |
---|
| 185 | tearDown: function() { |
---|
| 186 | this.slider.destroy(); |
---|
| 187 | }, |
---|
| 188 | |
---|
| 189 | testSnapToFloor: function() { |
---|
| 190 | this.slider.setValue(0, 12); |
---|
| 191 | |
---|
| 192 | assert.areEqual(10, this.slider.doSnap(12)); |
---|
| 193 | }, |
---|
| 194 | |
---|
| 195 | testSnapToCeil: function() { |
---|
| 196 | assert.areEqual(20, this.slider.doSnap(18)); |
---|
| 197 | assert.areEqual(20, this.slider.doSnap(15)); |
---|
| 198 | } |
---|
| 199 | })); |
---|
| 200 | |
---|
| 201 | suite.add(new Y.Test.Case({ |
---|
| 202 | name: 'Adding and removing thumbs' |
---|
| 203 | })); |
---|
| 204 | })(); |
---|