2c0f2df7 by Adam Heath

Very close to full coverage now on Facet.

1 parent 8534addb
...@@ -70,6 +70,12 @@ define(function(require) { ...@@ -70,6 +70,12 @@ define(function(require) {
70 }); 70 });
71 expect(got).toEqual(wantedCheckedKeys); 71 expect(got).toEqual(wantedCheckedKeys);
72 }); 72 });
73 var item2 = ascItemOrder[2];
74 it('foobar', function() {
75 console.log(JSON.stringify(items.models));
76 items.remove(item2);
77 console.log(item2, JSON.stringify(items.models));
78 });
73 } 79 }
74 describe('type[field]', function() { 80 describe('type[field]', function() {
75 var facetOptions = { 81 var facetOptions = {
...@@ -226,55 +232,102 @@ define(function(require) { ...@@ -226,55 +232,102 @@ define(function(require) {
226 }); 232 });
227 createExpects(true, [false, false, false, false, false]); 233 createExpects(true, [false, false, false, false, false]);
228 }); 234 });
229 describe('type[year; before]', function() { 235 function rangeSupportHelper(hasBefore, hasAfter) {
236 function createBeforeAfterExpects(all, orderedItems) {
237 if (!hasBefore) {
238 orderedItems.shift();
239 }
240 if (!hasAfter) {
241 orderedItems.pop();
242 }
243 createExpects(all, orderedItems);
244 }
245 describe('type[year]' + (hasBefore ? ' hasBefore' : '') + (hasAfter ? ' hasAfter' : ''), function() {
230 var facetOptions = { 246 var facetOptions = {
231 queryField: 'value_d', 247 queryField: 'value_d',
232 facetType: 'year', 248 facetType: 'year',
233 facetStats: true, 249 facetStats: true,
234 other: 'all',
235 formatter: function(item) { 250 formatter: function(item) {
236 var value = parseInt(item.get('key')); 251 var value = parseInt(item.get('key'));
237 return '$' + value + ' - $' + (value + 1000); 252 return '$' + value + ' - $' + (value + 1000);
238 }, 253 },
239 }; 254 };
255 if (hasBefore) {
256 if (hasAfter) {
257 facetOptions.other = 'all';
258 } else {
259 facetOptions.other = 'before';
260 }
261 } else if (hasAfter) {
262 facetOptions.other = 'after';
263 }
240 var pojoItems = [ 264 var pojoItems = [
241 {key: 'before', value: 2000},
242 {key: '2005', value: 500}, 265 {key: '2005', value: 500},
243 {key: '2004', value: 400}, 266 {key: '2004', value: 400},
244 {key: '2003', value: 300}, 267 {key: '2003', value: 300},
245 {key: '2002', value: 200}, 268 {key: '2002', value: 200},
246 {key: '2001', value: 100}, 269 {key: '2001', value: 100},
247 {key: 'after', value: 1500},
248 ]; 270 ];
249 ascItemOrder = ['before', '2001', '2002', '2003', '2004', '2005', 'after']; 271 var beforeItem = {key: 'before', value: 2000};
272 var afterItem = {key: 'after', value: 1500};
273 ascItemOrder = ['2001', '2002', '2003', '2004', '2005'];
250 var c0; 274 var c0;
251 beforeEach(function() { 275 beforeEach(function() {
252 f = new Facet(null, facetOptions); 276 f = new Facet(null, facetOptions);
253 items = f.get('items'); 277 items = f.get('items');
254 c0 = f.get('checkedKeys'); 278 c0 = f.get('checkedKeys');
255 }); 279 });
280 if (hasAfter) {
281 ascItemOrder.push('after');
282 pojoItems.push(afterItem);
283 }
284 if (hasBefore) {
285 ascItemOrder.unshift('before');
286 pojoItems.unshift(beforeItem);
287 }
256 createPojoItems(pojoItems); 288 createPojoItems(pojoItems);
257 describe('query', function() { 289 describe('query', function() {
258 describe('has', function() { 290 describe('min', function() {
259 it('min', function() { 291 beforeEach(function() {
260 f.set({queryMin: 1000, queryMax: undefined}); 292 f.set({queryMin: '2002', queryMax: undefined});
293 });
294 createBeforeAfterExpects(true, [false, false, false, false, false, false, false]);
295 it('result', function() {
261 expect(f.get('hasQuery')).toBe(false); 296 expect(f.get('hasQuery')).toBe(false);
262 }); 297 });
263 it('max', function() { 298 });
264 f.set({queryMin: undefined, queryMax: 5000}); 299 describe('max', function() {
300 beforeEach(function() {
301 f.set({queryMin: undefined, queryMax: '2004'});
302 });
303 createBeforeAfterExpects(true, [false, false, false, false, false, false, false]);
304 it('result', function() {
265 expect(f.get('hasQuery')).toBe(false); 305 expect(f.get('hasQuery')).toBe(false);
266 }); 306 });
267 it('min+max', function() { 307 });
268 f.set({queryMin: 1000, queryMax: 5000}); 308 describe('min+max', function() {
309 beforeEach(function() {
310 f.set({queryMin: '1980', queryMax: '1984'});
311 });
312 createBeforeAfterExpects(false, [false, false, false, false, false, false, false]);
313 it('result', function() {
269 expect(f.get('hasQuery')).toBe(true); 314 expect(f.get('hasQuery')).toBe(true);
270 }); 315 });
316 describe('checkedKeys: [2002, 2003]', function() {
317 beforeEach(function() {
318 f.set('checkedKeys', ['2002', '2003']);
319 });
320 createBeforeAfterExpects(false, [false, false, true, true, false, false, false]);
271 }); 321 });
272 }); 322 });
273 createExpects(true, [false, false, false, false, false, false, false]);
274 it('foo', function() {
275 console.log(JSON.stringify(items.models));
276 }); 323 });
324 createBeforeAfterExpects(true, [false, false, false, false, false, false, false]);
277 }); 325 });
326 }
327 rangeSupportHelper(true, true);
328 rangeSupportHelper(true, false);
329 rangeSupportHelper(false, false);
330 rangeSupportHelper(false, true);
278 }); 331 });
279 }); 332 });
280 }); 333 });
......