From f8df620a0df4c6bd8f6110067f74a79b3dd5840b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alab=C3=AA=20Duarte?= Date: Tue, 24 Feb 2015 00:36:07 -0300 Subject: #192 - highlights only words that matches with the keywords given --- web-ui/app/js/search/results_highlighter.js | 2 +- web-ui/karma.conf.js | 1 + web-ui/test/spec/search/results_highlighter.spec.js | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 web-ui/test/spec/search/results_highlighter.spec.js (limited to 'web-ui') diff --git a/web-ui/app/js/search/results_highlighter.js b/web-ui/app/js/search/results_highlighter.js index 4a4a8eca..9109bca4 100644 --- a/web-ui/app/js/search/results_highlighter.js +++ b/web-ui/app/js/search/results_highlighter.js @@ -40,7 +40,7 @@ define( var domIdent = data.where; if(this.attr.keywords) { _.each(this.attr.keywords, function (keyword) { - $(domIdent).highlightRegex(new RegExp(keyword, 'i'), { + $(domIdent).highlightRegex(new RegExp('\\b' + keyword, 'i'), { tagType: 'em', className: 'search-highlight' }); diff --git a/web-ui/karma.conf.js b/web-ui/karma.conf.js index 48a7ac60..e19d1369 100644 --- a/web-ui/karma.conf.js +++ b/web-ui/karma.conf.js @@ -29,6 +29,7 @@ module.exports = function (config) { 'app/bower_components/foundation/js/foundation.js', 'app/bower_components/foundation/js/foundation/foundation.reveal.js', 'app/bower_components/foundation/js/foundation/foundation.offcanvas.js', + 'app/js/lib/highlightRegex.js', // hack to load RequireJS after the shim libs 'node_modules/requirejs/require.js', diff --git a/web-ui/test/spec/search/results_highlighter.spec.js b/web-ui/test/spec/search/results_highlighter.spec.js new file mode 100644 index 00000000..1631cf01 --- /dev/null +++ b/web-ui/test/spec/search/results_highlighter.spec.js @@ -0,0 +1,20 @@ +describeComponent('search/results_highlighter', function () { + 'use strict'; + var self; + + beforeEach(function () { + self = this; + }); + + it('highlights only words that matches with the keywords given', function () { + this.setupComponent('
Any one seeing too many open bugs
'); + + this.component.attr = {keywords: ["any"]}; + self.component.highlightResults(event, {where: '#text'}); + + var highlightedWords = self.component.$node.find('.search-highlight').length; + + expect(highlightedWords).toEqual(1); + }); + +}); -- cgit v1.2.3