|
22 | 22 |
|
23 | 23 | /**
|
24 | 24 | * This file contains very minimal testing. I may or may not do more extensive tests -
|
25 |
| - * more or lesss playing around with it for the frist time |
| 25 | + * more or less playing around with it for the first time |
26 | 26 | */
|
27 | 27 |
|
28 | 28 | module('storeLocator', {
|
|
105 | 105 | }, 1000);
|
106 | 106 | });
|
107 | 107 |
|
| 108 | + /** |
| 109 | + * Round number |
| 110 | + */ |
| 111 | + test('roundNumber()', 2, function() { |
| 112 | + var $this = $('#map-container').data('plugin_storeLocator'); |
| 113 | + |
| 114 | + deepEqual($this.roundNumber(2.345432, 0), 2, 'Round down test'); |
| 115 | + deepEqual($this.roundNumber(2.694928, 0), 3, 'Round up test'); |
| 116 | + }); |
| 117 | + |
108 | 118 | /**
|
109 | 119 | * Empty object test
|
110 | 120 | */
|
|
118 | 128 | deepEqual($this.isEmptyObject(emptyObj), true, 'Empty object test');
|
119 | 129 | deepEqual($this.isEmptyObject(nonEmptyObj), false, 'Empty object fail test');
|
120 | 130 | });
|
| 131 | + |
| 132 | + /** |
| 133 | + * Empty object values test |
| 134 | + */ |
| 135 | + test('hasEmptyObjectVals()', 3, function() { |
| 136 | + var $this = $('#map-container').data('plugin_storeLocator'); |
| 137 | + var emptyObj = {}; |
| 138 | + var emptyObjVals = { |
| 139 | + 'test1' : '', |
| 140 | + 'test2' : '' |
| 141 | + }; |
| 142 | + var nonEmptyObj = { |
| 143 | + 'test': 'testing' |
| 144 | + }; |
| 145 | + |
| 146 | + deepEqual($this.hasEmptyObjectVals(emptyObj), true, 'Empty object test'); |
| 147 | + deepEqual($this.hasEmptyObjectVals(emptyObjVals), true, 'Empty object vals test'); |
| 148 | + deepEqual($this.hasEmptyObjectVals(nonEmptyObj), false, 'Empty object fail test'); |
| 149 | + }); |
| 150 | + |
| 151 | + |
| 152 | + /** |
| 153 | + * Sort locations (array of objects) numerically by distance test |
| 154 | + */ |
| 155 | + test('sortNumerically()', 1, function() { |
| 156 | + var $this = $('#map-container').data('plugin_storeLocator'); |
| 157 | + var positiveTest = [ |
| 158 | + { 'distance': 9 }, |
| 159 | + { 'distance': 2 }, |
| 160 | + { 'distance': 30 }, |
| 161 | + { 'distance': 5 } |
| 162 | + ]; |
| 163 | + var positiveMatch = [ |
| 164 | + { 'distance': 2 }, |
| 165 | + { 'distance': 5 }, |
| 166 | + { 'distance': 9 }, |
| 167 | + { 'distance': 30 } |
| 168 | + ]; |
| 169 | + |
| 170 | + $this.sortNumerically(positiveTest); |
| 171 | + |
| 172 | + deepEqual(positiveTest, positiveMatch, 'Positive test'); |
| 173 | + }); |
| 174 | + |
| 175 | + /** |
| 176 | + * Filter data test |
| 177 | + */ |
| 178 | + test('filterData()', 2, function() { |
| 179 | + var filter, filters, locationset, locationMatch, locationsMatch, inclusiveTest, exclusiveTest; |
| 180 | + var $this = $('#map-container').data('plugin_storeLocator'); |
| 181 | + |
| 182 | + // Single filter |
| 183 | + filter = { |
| 184 | + 'city': ['Minneapolis'] |
| 185 | + }; |
| 186 | + |
| 187 | + // Multi-filter |
| 188 | + filters = { |
| 189 | + 'city': ['Minneapolis', 'St. Paul'] |
| 190 | + }; |
| 191 | + |
| 192 | + locationset = [{ |
| 193 | + 'city': 'St. Paul', |
| 194 | + 'state': 'MN' |
| 195 | + }, { |
| 196 | + 'city': 'Des Moines', |
| 197 | + 'state': 'IA' |
| 198 | + }, { |
| 199 | + 'city': 'Minneapolis', |
| 200 | + 'state': 'MN' |
| 201 | + }]; |
| 202 | + |
| 203 | + locationMatch = [{ |
| 204 | + 'city': 'Minneapolis', |
| 205 | + 'state': 'MN' |
| 206 | + }]; |
| 207 | + |
| 208 | + locationsMatch = [{ |
| 209 | + 'city': 'St. Paul', |
| 210 | + 'state': 'MN' |
| 211 | + }, { |
| 212 | + 'city': 'Minneapolis', |
| 213 | + 'state': 'MN' |
| 214 | + }]; |
| 215 | + |
| 216 | + inclusiveTest = $.grep(locationset, function (val, i) { |
| 217 | + return $this.filterData(val, filter); |
| 218 | + }); |
| 219 | + |
| 220 | + // Inclusive test |
| 221 | + deepEqual(inclusiveTest, locationMatch, 'Inclusive filtering test'); |
| 222 | + |
| 223 | + $this.settings.exclusiveFiltering = true; |
| 224 | + |
| 225 | + exclusiveTest = $.grep(locationset, function (val, i) { |
| 226 | + return $this.filterData(val, filters); |
| 227 | + }); |
| 228 | + |
| 229 | + // Exclusive test |
| 230 | + deepEqual(exclusiveTest, locationsMatch, 'Exclusive filtering test'); |
| 231 | + }); |
| 232 | + |
121 | 233 |
|
122 | 234 | }(jQuery));
|
0 commit comments