Skip to content

Commit 354572a

Browse files
committed
Added additional tests
1 parent effeddc commit 354572a

File tree

3 files changed

+115
-3
lines changed

3 files changed

+115
-3
lines changed

dist/assets/js/plugins/storeLocator/jquery.storelocator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v2.0.6 - 2015-03-27
1+
/*! jQuery Google Maps Store Locator - v2.0.6 - 2015-03-28
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2015 Bjorn Holine; Licensed MIT */
44

dist/assets/js/plugins/storeLocator/jquery.storelocator.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/storeLocator_test.js

+113-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
/**
2424
* 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
2626
*/
2727

2828
module('storeLocator', {
@@ -105,6 +105,16 @@
105105
}, 1000);
106106
});
107107

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+
108118
/**
109119
* Empty object test
110120
*/
@@ -118,5 +128,107 @@
118128
deepEqual($this.isEmptyObject(emptyObj), true, 'Empty object test');
119129
deepEqual($this.isEmptyObject(nonEmptyObj), false, 'Empty object fail test');
120130
});
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+
121233

122234
}(jQuery));

0 commit comments

Comments
 (0)