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) {
230 var facetOptions = { 236 function createBeforeAfterExpects(all, orderedItems) {
231 queryField: 'value_d', 237 if (!hasBefore) {
232 facetType: 'year', 238 orderedItems.shift();
233 facetStats: true, 239 }
234 other: 'all', 240 if (!hasAfter) {
235 formatter: function(item) { 241 orderedItems.pop();
236 var value = parseInt(item.get('key')); 242 }
237 return '$' + value + ' - $' + (value + 1000); 243 createExpects(all, orderedItems);
238 }, 244 }
239 }; 245 describe('type[year]' + (hasBefore ? ' hasBefore' : '') + (hasAfter ? ' hasAfter' : ''), function() {
240 var pojoItems = [ 246 var facetOptions = {
241 {key: 'before', value: 2000}, 247 queryField: 'value_d',
242 {key: '2005', value: 500}, 248 facetType: 'year',
243 {key: '2004', value: 400}, 249 facetStats: true,
244 {key: '2003', value: 300}, 250 formatter: function(item) {
245 {key: '2002', value: 200}, 251 var value = parseInt(item.get('key'));
246 {key: '2001', value: 100}, 252 return '$' + value + ' - $' + (value + 1000);
247 {key: 'after', value: 1500}, 253 },
248 ]; 254 };
249 ascItemOrder = ['before', '2001', '2002', '2003', '2004', '2005', 'after']; 255 if (hasBefore) {
250 var c0; 256 if (hasAfter) {
251 beforeEach(function() { 257 facetOptions.other = 'all';
252 f = new Facet(null, facetOptions); 258 } else {
253 items = f.get('items'); 259 facetOptions.other = 'before';
254 c0 = f.get('checkedKeys'); 260 }
255 }); 261 } else if (hasAfter) {
256 createPojoItems(pojoItems); 262 facetOptions.other = 'after';
257 describe('query', function() { 263 }
258 describe('has', function() { 264 var pojoItems = [
259 it('min', function() { 265 {key: '2005', value: 500},
260 f.set({queryMin: 1000, queryMax: undefined}); 266 {key: '2004', value: 400},
261 expect(f.get('hasQuery')).toBe(false); 267 {key: '2003', value: 300},
268 {key: '2002', value: 200},
269 {key: '2001', value: 100},
270 ];
271 var beforeItem = {key: 'before', value: 2000};
272 var afterItem = {key: 'after', value: 1500};
273 ascItemOrder = ['2001', '2002', '2003', '2004', '2005'];
274 var c0;
275 beforeEach(function() {
276 f = new Facet(null, facetOptions);
277 items = f.get('items');
278 c0 = f.get('checkedKeys');
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 }
288 createPojoItems(pojoItems);
289 describe('query', function() {
290 describe('min', function() {
291 beforeEach(function() {
292 f.set({queryMin: '2002', queryMax: undefined});
293 });
294 createBeforeAfterExpects(true, [false, false, false, false, false, false, false]);
295 it('result', function() {
296 expect(f.get('hasQuery')).toBe(false);
297 });
262 }); 298 });
263 it('max', function() { 299 describe('max', function() {
264 f.set({queryMin: undefined, queryMax: 5000}); 300 beforeEach(function() {
265 expect(f.get('hasQuery')).toBe(false); 301 f.set({queryMin: undefined, queryMax: '2004'});
302 });
303 createBeforeAfterExpects(true, [false, false, false, false, false, false, false]);
304 it('result', function() {
305 expect(f.get('hasQuery')).toBe(false);
306 });
266 }); 307 });
267 it('min+max', function() { 308 describe('min+max', function() {
268 f.set({queryMin: 1000, queryMax: 5000}); 309 beforeEach(function() {
269 expect(f.get('hasQuery')).toBe(true); 310 f.set({queryMin: '1980', queryMax: '1984'});
311 });
312 createBeforeAfterExpects(false, [false, false, false, false, false, false, false]);
313 it('result', function() {
314 expect(f.get('hasQuery')).toBe(true);
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]);
321 });
270 }); 322 });
271 }); 323 });
324 createBeforeAfterExpects(true, [false, false, false, false, false, false, false]);
272 }); 325 });
273 createExpects(true, [false, false, false, false, false, false, false]); 326 }
274 it('foo', function() { 327 rangeSupportHelper(true, true);
275 console.log(JSON.stringify(items.models)); 328 rangeSupportHelper(true, false);
276 }); 329 rangeSupportHelper(false, false);
277 }); 330 rangeSupportHelper(false, true);
278 }); 331 });
279 }); 332 });
280 }); 333 });
......