Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-03-31 02:39:30 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-03-31 02:39:30 +0400
commit735c091090f0a49f1900bf8358ef1d1847b52519 (patch)
tree2f0e211c56c434271c2ec2e16aa10f01d5c0e021 /plugins/CoreHome/angularjs/common/directives
parentec6f4d383df28e111848addf9b3c7cc2845013c5 (diff)
refs #4691 added more example tests and fixed a bug found because of the tests
Diffstat (limited to 'plugins/CoreHome/angularjs/common/directives')
-rw-r--r--plugins/CoreHome/angularjs/common/directives/autocomplete-matched.js3
-rw-r--r--plugins/CoreHome/angularjs/common/directives/autocomplete-matched_test.js43
2 files changed, 45 insertions, 1 deletions
diff --git a/plugins/CoreHome/angularjs/common/directives/autocomplete-matched.js b/plugins/CoreHome/angularjs/common/directives/autocomplete-matched.js
index a052482ce6..a78154b49a 100644
--- a/plugins/CoreHome/angularjs/common/directives/autocomplete-matched.js
+++ b/plugins/CoreHome/angularjs/common/directives/autocomplete-matched.js
@@ -30,7 +30,8 @@ angular.module('piwikApp.directive').directive('piwikAutocompleteMatched', funct
}
var content = element.html();
- var startTerm = content.toLowerCase().indexOf(searchTerm);
+ var startTerm = content.toLowerCase().indexOf(searchTerm.toLowerCase());
+
if (-1 !== startTerm) {
var word = content.substr(startTerm, searchTerm.length);
content = content.replace(word, '<span class="autocompleteMatched">' + word + '</span>');
diff --git a/plugins/CoreHome/angularjs/common/directives/autocomplete-matched_test.js b/plugins/CoreHome/angularjs/common/directives/autocomplete-matched_test.js
new file mode 100644
index 0000000000..2518687b97
--- /dev/null
+++ b/plugins/CoreHome/angularjs/common/directives/autocomplete-matched_test.js
@@ -0,0 +1,43 @@
+/*!
+ * Piwik - Web Analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+describe('piwikAutocompleteMatchedDirective', function() {
+ var $compile;
+ var $rootScope;
+
+ beforeEach(module('piwikApp.directive'));
+ beforeEach(inject(function(_$compile_, _$rootScope_){
+ $compile = _$compile_;
+ $rootScope = _$rootScope_;
+ }));
+
+ function assertRenderedContentIs(query, expectedResult) {
+ var template = '<div piwik-autocomplete-matched="\'' + query + '\'">My Content</div>';
+ var element = $compile(template)($rootScope);
+ $rootScope.$digest();
+ expect(element.html()).to.eql(expectedResult);
+ }
+
+ describe('#piwikAutocompleteMatched()', function() {
+
+ it('should not change anything if query does not match the text', function() {
+ assertRenderedContentIs('Whatever', 'My Content');
+ });
+
+ it('should wrap the matching part and find case insensitive', function() {
+ assertRenderedContentIs('y cont', 'M<span class="autocompleteMatched">y Cont</span>ent');
+ });
+
+ it('should be able to wrap the whole content', function() {
+ assertRenderedContentIs('my content', '<span class="autocompleteMatched">My Content</span>');
+ });
+
+ it('should find matching content case sensitive', function() {
+ assertRenderedContentIs('My Co', '<span class="autocompleteMatched">My Co</span>ntent');
+ });
+ });
+}); \ No newline at end of file