Reorganized the spec layout, now they are stored alongside the files
they test. Facets is close to full coverage.
Showing
8 changed files
with
60 additions
and
67 deletions
... | @@ -60,13 +60,29 @@ module.exports = function(grunt) { | ... | @@ -60,13 +60,29 @@ module.exports = function(grunt) { |
60 | 60 | ||
61 | var _ = require('lodash'); | 61 | var _ = require('lodash'); |
62 | 62 | ||
63 | var jasmineRequirejsTemplateOptions = function(withInstanbul) { | 63 | function genJasmineConfig(withCoverage, options) { |
64 | var template, templateOptions; | ||
65 | var src = [ | ||
66 | 'src/scripts/{,**/}*.js', | ||
67 | '!src/scripts/main.js', | ||
68 | ]; | ||
69 | var specs = [ | ||
70 | 'src/scripts/**/*.spec.js', | ||
71 | ]; | ||
72 | var template = require('grunt-template-jasmine-requirejs'); | ||
73 | var templateOptions = { | ||
74 | requireConfigFile: 'src/scripts/config.js', | ||
75 | requireConfig: { | ||
76 | baseUrl: 'src/scripts', | ||
77 | }, | ||
78 | }; | ||
79 | |||
80 | if (withCoverage) { | ||
64 | /* global requirejs */ | 81 | /* global requirejs */ |
65 | var callback; | 82 | templateOptions.requireConfig.callback = function() { |
66 | if (withInstanbul) { | ||
67 | callback = function() { | ||
68 | var oldLoad = requirejs.load; | 83 | var oldLoad = requirejs.load; |
69 | requirejs.load = function (context, moduleName, url) { | 84 | requirejs.load = function (context, moduleName, url) { |
85 | var origUrl = url; | ||
70 | //console.log('context=' + JSON.stringify(arguments), 'moduleName=' + moduleName, 'url=' + url); | 86 | //console.log('context=' + JSON.stringify(arguments), 'moduleName=' + moduleName, 'url=' + url); |
71 | var parts = url.split('/'); | 87 | var parts = url.split('/'); |
72 | for (var i = 0; i < parts.length; ) { | 88 | for (var i = 0; i < parts.length; ) { |
... | @@ -87,58 +103,55 @@ module.exports = function(grunt) { | ... | @@ -87,58 +103,55 @@ module.exports = function(grunt) { |
87 | } | 103 | } |
88 | } | 104 | } |
89 | url = parts.join('/'); | 105 | url = parts.join('/'); |
90 | if (url.indexOf('src/scripts/') === 0) { | 106 | if (url.match(/^src\/scripts\/(.*?\/)?[^\/]+\.spec\.js$/)) { |
107 | url = './.grunt/grunt-contrib-jasmine/' + url; | ||
108 | } else if (url.match(/^src\/scripts\/(.*?\/)?[^\/]+\.js$/)) { | ||
91 | url = './.grunt/grunt-contrib-jasmine/' + url; | 109 | url = './.grunt/grunt-contrib-jasmine/' + url; |
92 | } | 110 | } |
93 | if (url.indexOf('test/specs/') === 0) { | 111 | if (url.indexOf('test/specs/') === 0) { |
94 | url = './.grunt/grunt-contrib-jasmine/' + url; | 112 | url = './.grunt/grunt-contrib-jasmine/' + url; |
95 | } | 113 | } |
96 | //console.log('url=' + url); | 114 | //console.log('url[' + origUrl + ']=' + url); |
97 | return oldLoad.apply(this, [context, moduleName, url]); | 115 | return oldLoad.apply(this, [context, moduleName, url]); |
98 | }; | 116 | }; |
99 | }; | 117 | }; |
118 | |||
119 | var foo = _.extend({}, template); | ||
120 | var bar = template.process; | ||
121 | foo.process = function process(grunt, task, context) { | ||
122 | var src = []; | ||
123 | context.scripts.src.forEach(function(file) { | ||
124 | if (!grunt.file.isMatch(specs, file)) { | ||
125 | src.push(file); | ||
100 | } | 126 | } |
101 | return { | 127 | }); |
102 | requireConfigFile: 'src/scripts/config.js', | 128 | context.scripts.src = src; |
103 | requireConfig: { | 129 | return bar.apply(this, arguments); |
104 | baseUrl: 'src/scripts', | ||
105 | callback: callback | ||
106 | } | ||
107 | }; | ||
108 | }; | 130 | }; |
109 | 131 | ||
110 | var jasmineInstanbulTemplateOptions = function(template, nestedOptions) { | 132 | templateOptions = { |
111 | return { | ||
112 | coverage: 'bin/coverage/coverage.json', | 133 | coverage: 'bin/coverage/coverage.json', |
113 | report: 'bin/coverage', | 134 | report: 'bin/coverage', |
114 | replace: false, | 135 | replace: false, |
115 | template: template, | 136 | template: foo, |
116 | templateOptions: nestedOptions | 137 | templateOptions: templateOptions, |
138 | files: _.concat([], src, specs), | ||
117 | }; | 139 | }; |
118 | }; | 140 | template = require('grunt-template-jasmine-istanbul'); |
119 | |||
120 | var jasmineOptions = function(withCoverage, options) { | ||
121 | var defaultOptions = {}; | ||
122 | defaultOptions.template = require('grunt-template-jasmine-requirejs'); | ||
123 | defaultOptions.templateOptions = jasmineRequirejsTemplateOptions(withCoverage); | ||
124 | if (withCoverage) { | ||
125 | defaultOptions.templateOptions = jasmineInstanbulTemplateOptions(defaultOptions.template, defaultOptions.templateOptions); | ||
126 | defaultOptions.template = require('grunt-template-jasmine-istanbul'); | ||
127 | } | 141 | } |
128 | return _.extend(defaultOptions, options); | 142 | var jasmineConfig = { |
129 | }; | 143 | src: _.concat([], |
130 | 144 | src, | |
131 | grunt.initConfig({ | 145 | specs |
132 | jasmine: { | 146 | ), |
133 | all: { | 147 | options: { |
134 | src: [ | 148 | specs: specs, |
135 | 'src/scripts/{,**/}*.js', | 149 | template: template, |
136 | '!src/scripts/main.js', | 150 | templateOptions: templateOptions, |
137 | 'test/specs/**/*.js', | ||
138 | ], | ||
139 | options: jasmineOptions(false, null), | ||
140 | }, | ||
141 | }, | 151 | }, |
152 | } | ||
153 | return jasmineConfig; | ||
154 | } | ||
142 | 155 | ||
143 | }); | 156 | grunt.config.set(['jasmine', 'all'], genJasmineConfig(true)); |
144 | }; | 157 | }; | ... | ... |
... | @@ -194,10 +194,6 @@ define(function(require) { | ... | @@ -194,10 +194,6 @@ define(function(require) { |
194 | queryField: 'value_d', | 194 | queryField: 'value_d', |
195 | facetType: 'year', | 195 | facetType: 'year', |
196 | facetStats: true, | 196 | facetStats: true, |
197 | formatter: function(item) { | ||
198 | var value = parseInt(item.get('key')); | ||
199 | return '$' + value + ' - $' + (value + 1000); | ||
200 | }, | ||
201 | }; | 197 | }; |
202 | var pojoItems = [ | 198 | var pojoItems = [ |
203 | {key: '2005', value: 500}, | 199 | {key: '2005', value: 500}, |
... | @@ -247,10 +243,6 @@ define(function(require) { | ... | @@ -247,10 +243,6 @@ define(function(require) { |
247 | queryField: 'value_d', | 243 | queryField: 'value_d', |
248 | facetType: 'year', | 244 | facetType: 'year', |
249 | facetStats: true, | 245 | facetStats: true, |
250 | formatter: function(item) { | ||
251 | var value = parseInt(item.get('key')); | ||
252 | return '$' + value + ' - $' + (value + 1000); | ||
253 | }, | ||
254 | }; | 246 | }; |
255 | if (hasBefore) { | 247 | if (hasBefore) { |
256 | if (hasAfter) { | 248 | if (hasAfter) { |
... | @@ -330,4 +322,5 @@ define(function(require) { | ... | @@ -330,4 +322,5 @@ define(function(require) { |
330 | rangeSupportHelper(false, true); | 322 | rangeSupportHelper(false, true); |
331 | }); | 323 | }); |
332 | }); | 324 | }); |
325 | return {}; | ||
333 | }); | 326 | }); | ... | ... |
... | @@ -17,7 +17,8 @@ define(function(require) { | ... | @@ -17,7 +17,8 @@ define(function(require) { |
17 | var Facets = NestedModels.mixin(Backbone.Model.extend({ | 17 | var Facets = NestedModels.mixin(Backbone.Model.extend({ |
18 | initialize: function(data, options) { | 18 | initialize: function(data, options) { |
19 | this.url = function() { | 19 | this.url = function() { |
20 | return options.search.url(); | 20 | var url = options.search.url; |
21 | return _.isFunction(url) ? url.call() : url; | ||
21 | }; | 22 | }; |
22 | _.each(this.keys(), _.bind(function(facetName) { | 23 | _.each(this.keys(), _.bind(function(facetName) { |
23 | var facet = this.get(facetName); | 24 | var facet = this.get(facetName); |
... | @@ -28,6 +29,7 @@ define(function(require) { | ... | @@ -28,6 +29,7 @@ define(function(require) { |
28 | 'change:queryMax': 'item-change', | 29 | 'change:queryMax': 'item-change', |
29 | }, function(eventValue, eventKey) { | 30 | }, function(eventValue, eventKey) { |
30 | facet.on(eventKey, function(model, value, options) { | 31 | facet.on(eventKey, function(model, value, options) { |
32 | console.log('trigger', facet.get('formName'), eventValue); | ||
31 | this.trigger(eventValue, facet, null, options); | 33 | this.trigger(eventValue, facet, null, options); |
32 | }, this); | 34 | }, this); |
33 | }, this); | 35 | }, this); |
... | @@ -88,7 +90,8 @@ define(function(require) { | ... | @@ -88,7 +90,8 @@ define(function(require) { |
88 | } | 90 | } |
89 | }); | 91 | }); |
90 | facet.set('suggestions', suggestions); | 92 | facet.set('suggestions', suggestions); |
91 | if (!!options.facetSuggestions && options.childFacet === facet) { | 93 | //if (!!options.facetSuggestions && options.childFacet === facet) { |
94 | if (!!options.facetSuggestions) { | ||
92 | return; | 95 | return; |
93 | } | 96 | } |
94 | 97 | ||
... | @@ -126,10 +129,6 @@ define(function(require) { | ... | @@ -126,10 +129,6 @@ define(function(require) { |
126 | item.set({hidden: value === 0, value: value}); | 129 | item.set({hidden: value === 0, value: value}); |
127 | } else { | 130 | } else { |
128 | item = new Facet.Item({key: key, value: value}); | 131 | item = new Facet.Item({key: key, value: value}); |
129 | item.on('change:checked', function() { | ||
130 | this.trigger('item-change'); | ||
131 | facet.trigger('item-change'); | ||
132 | }, this); | ||
133 | } | 132 | } |
134 | newItems.push(item); | 133 | newItems.push(item); |
135 | }, this); | 134 | }, this); |
... | @@ -200,7 +199,7 @@ define(function(require) { | ... | @@ -200,7 +199,7 @@ define(function(require) { |
200 | var key = item.get('key'); | 199 | var key = item.get('key'); |
201 | var fromDate, toDate; | 200 | var fromDate, toDate; |
202 | if (key === 'before') { | 201 | if (key === 'before') { |
203 | return rangeFormatter('*', facet.rangeStart + '-1SECOND'); | 202 | return '[* TO ' + facet.rangeStart + '-1SECOND]'; |
204 | } | 203 | } |
205 | fromDate = new Date(key); | 204 | fromDate = new Date(key); |
206 | toDate = new Date(key); | 205 | toDate = new Date(key); | ... | ... |
src/scripts/solr/model/Facets.spec.js
0 → 100644
This diff is collapsed.
Click to expand it.
test/specs/Facets.js
deleted
100644 → 0
-
Please register or sign in to post a comment