6bada521 by Adam Heath

Reorganized the spec layout, now they are stored alongside the files

they test.  Facets is close to full coverage.
1 parent e3b61d72
......@@ -60,13 +60,29 @@ module.exports = function(grunt) {
var _ = require('lodash');
var jasmineRequirejsTemplateOptions = function(withInstanbul) {
/* global requirejs */
var callback;
if (withInstanbul) {
callback = function() {
function genJasmineConfig(withCoverage, options) {
var template, templateOptions;
var src = [
'src/scripts/{,**/}*.js',
'!src/scripts/main.js',
];
var specs = [
'src/scripts/**/*.spec.js',
];
var template = require('grunt-template-jasmine-requirejs');
var templateOptions = {
requireConfigFile: 'src/scripts/config.js',
requireConfig: {
baseUrl: 'src/scripts',
},
};
if (withCoverage) {
/* global requirejs */
templateOptions.requireConfig.callback = function() {
var oldLoad = requirejs.load;
requirejs.load = function (context, moduleName, url) {
var origUrl = url;
//console.log('context=' + JSON.stringify(arguments), 'moduleName=' + moduleName, 'url=' + url);
var parts = url.split('/');
for (var i = 0; i < parts.length; ) {
......@@ -87,58 +103,55 @@ module.exports = function(grunt) {
}
}
url = parts.join('/');
if (url.indexOf('src/scripts/') === 0) {
if (url.match(/^src\/scripts\/(.*?\/)?[^\/]+\.spec\.js$/)) {
url = './.grunt/grunt-contrib-jasmine/' + url;
} else if (url.match(/^src\/scripts\/(.*?\/)?[^\/]+\.js$/)) {
url = './.grunt/grunt-contrib-jasmine/' + url;
}
if (url.indexOf('test/specs/') === 0) {
url = './.grunt/grunt-contrib-jasmine/' + url;
}
//console.log('url=' + url);
//console.log('url[' + origUrl + ']=' + url);
return oldLoad.apply(this, [context, moduleName, url]);
};
};
}
return {
requireConfigFile: 'src/scripts/config.js',
requireConfig: {
baseUrl: 'src/scripts',
callback: callback
}
};
};
var jasmineInstanbulTemplateOptions = function(template, nestedOptions) {
return {
coverage: 'bin/coverage/coverage.json',
report: 'bin/coverage',
replace: false,
template: template,
templateOptions: nestedOptions
};
};
var foo = _.extend({}, template);
var bar = template.process;
foo.process = function process(grunt, task, context) {
var src = [];
context.scripts.src.forEach(function(file) {
if (!grunt.file.isMatch(specs, file)) {
src.push(file);
}
});
context.scripts.src = src;
return bar.apply(this, arguments);
};
var jasmineOptions = function(withCoverage, options) {
var defaultOptions = {};
defaultOptions.template = require('grunt-template-jasmine-requirejs');
defaultOptions.templateOptions = jasmineRequirejsTemplateOptions(withCoverage);
if (withCoverage) {
defaultOptions.templateOptions = jasmineInstanbulTemplateOptions(defaultOptions.template, defaultOptions.templateOptions);
defaultOptions.template = require('grunt-template-jasmine-istanbul');
templateOptions = {
coverage: 'bin/coverage/coverage.json',
report: 'bin/coverage',
replace: false,
template: foo,
templateOptions: templateOptions,
files: _.concat([], src, specs),
};
template = require('grunt-template-jasmine-istanbul');
}
return _.extend(defaultOptions, options);
};
grunt.initConfig({
jasmine: {
all: {
src: [
'src/scripts/{,**/}*.js',
'!src/scripts/main.js',
'test/specs/**/*.js',
],
options: jasmineOptions(false, null),
var jasmineConfig = {
src: _.concat([],
src,
specs
),
options: {
specs: specs,
template: template,
templateOptions: templateOptions,
},
},
}
return jasmineConfig;
}
});
grunt.config.set(['jasmine', 'all'], genJasmineConfig(true));
};
......
......@@ -194,10 +194,6 @@ define(function(require) {
queryField: 'value_d',
facetType: 'year',
facetStats: true,
formatter: function(item) {
var value = parseInt(item.get('key'));
return '$' + value + ' - $' + (value + 1000);
},
};
var pojoItems = [
{key: '2005', value: 500},
......@@ -247,10 +243,6 @@ define(function(require) {
queryField: 'value_d',
facetType: 'year',
facetStats: true,
formatter: function(item) {
var value = parseInt(item.get('key'));
return '$' + value + ' - $' + (value + 1000);
},
};
if (hasBefore) {
if (hasAfter) {
......@@ -330,4 +322,5 @@ define(function(require) {
rangeSupportHelper(false, true);
});
});
return {};
});
......
......@@ -17,7 +17,8 @@ define(function(require) {
var Facets = NestedModels.mixin(Backbone.Model.extend({
initialize: function(data, options) {
this.url = function() {
return options.search.url();
var url = options.search.url;
return _.isFunction(url) ? url.call() : url;
};
_.each(this.keys(), _.bind(function(facetName) {
var facet = this.get(facetName);
......@@ -28,6 +29,7 @@ define(function(require) {
'change:queryMax': 'item-change',
}, function(eventValue, eventKey) {
facet.on(eventKey, function(model, value, options) {
console.log('trigger', facet.get('formName'), eventValue);
this.trigger(eventValue, facet, null, options);
}, this);
}, this);
......@@ -88,7 +90,8 @@ define(function(require) {
}
});
facet.set('suggestions', suggestions);
if (!!options.facetSuggestions && options.childFacet === facet) {
//if (!!options.facetSuggestions && options.childFacet === facet) {
if (!!options.facetSuggestions) {
return;
}
......@@ -126,10 +129,6 @@ define(function(require) {
item.set({hidden: value === 0, value: value});
} else {
item = new Facet.Item({key: key, value: value});
item.on('change:checked', function() {
this.trigger('item-change');
facet.trigger('item-change');
}, this);
}
newItems.push(item);
}, this);
......@@ -200,7 +199,7 @@ define(function(require) {
var key = item.get('key');
var fromDate, toDate;
if (key === 'before') {
return rangeFormatter('*', facet.rangeStart + '-1SECOND');
return '[* TO ' + facet.rangeStart + '-1SECOND]';
}
fromDate = new Date(key);
toDate = new Date(key);
......
define(function(require) {
'use strict';
var _ = require('underscore');
var Backbone = require('backbone');
var Facets = require('solr/model/Facets');
describe('Facets', function() {
it('loads', function() {
expect(Facets).toBeDefined();
});
});
});