From 10ebe9b6286ecedcf8db431b06219c94e133a16a Mon Sep 17 00:00:00 2001 From: Lautaro Cozzani Rodriguez Date: Tue, 10 Feb 2015 18:33:51 -0300 Subject: [PATCH 1/3] upgrade dependencies and fix test --- bower.json | 6 +++--- test/angularWordCloudTest.js | 31 +++++++++++++++++-------------- test/helpers.js | 29 ----------------------------- 3 files changed, 20 insertions(+), 46 deletions(-) delete mode 100755 test/helpers.js diff --git a/bower.json b/bower.json index 2035e8b..29f882f 100755 --- a/bower.json +++ b/bower.json @@ -8,10 +8,10 @@ "components" ], "dependencies": { - "angular": "~1.2.0" + "angular": "1.2.9" }, "devDependencies": { - "angular-mocks": "*", - "angular-scenario": "*" + "angular-mocks": "1.2.9", + "angular-scenario": "1.2.9" } } diff --git a/test/angularWordCloudTest.js b/test/angularWordCloudTest.js index f6b1f45..6e2f47a 100755 --- a/test/angularWordCloudTest.js +++ b/test/angularWordCloudTest.js @@ -26,12 +26,12 @@ describe("Word Cloud Directive", function() { }); it('should add the elements to the dom', function() { - expect(element).toBeTag('DIV'); - expect(element).toHaveClass('word-cloud-group'); + // expect(element).toBeTag('DIV'); + expect(element.hasClass('word-cloud-group')).toBeTruthy(); var words = element.find('span'); expect(words.length).toBe(3); - expect(words.eq(0)).toHaveClass('word-cloud-group-item'); + expect(words.eq(0).hasClass('word-cloud-group-item')).toBeTruthy(); expect(words.eq(0).attr('style')).toBe(undefined); expect(words.eq(0).find('a').text()).toBe('one'); expect(words.eq(1).find('a').text()).toBe('two'); @@ -93,6 +93,8 @@ describe("Word Cloud Directive", function() { describe('with an array', function() { + + describe('using integer sizes', function() { beforeEach(function() { @@ -115,8 +117,8 @@ describe("Word Cloud Directive", function() { it('should not set the size of the buttons individually', function() { //expect(element.find('span').eq(0).css('font-size')).not.toBeOneOf(['1em','16px']); - expect(element.find('span').eq(1).css('font-size')).not.toBeOneOf(['3em','48px']); - expect(element.find('span').eq(2).css('font-size')).not.toBeOneOf(['2em','32px']); + expect(['3em','48px'].indexOf(element.find('span').eq(1).css('font-size')) === -1); + expect(['2em','32px'].indexOf(element.find('span').eq(2).css('font-size')) === -1); }); }); @@ -179,15 +181,16 @@ describe("Word Cloud Directive", function() { it('should keep the words in the order they came in', function() { var buttons = element.find('span'); + expect(buttons.length).toBe(3); expect(buttons.eq(0).find('p').text()).toBe('one'); expect(buttons.eq(1).find('p').text()).toBe('two'); expect(buttons.eq(2).find('p').text()).toBe('three'); }); it('should set the size of the buttons individually', function() { - expect(element.find('span').eq(0).css('font-size')).toBeOneOf(['1em','16px']); - expect(element.find('span').eq(1).css('font-size')).toBeOneOf(['3em','48px']); - expect(element.find('span').eq(2).css('font-size')).toBeOneOf(['2em','32px']); + expect(['1em','16px'].indexOf(element.find('span').eq(0).css('font-size')) !== -1); + expect(['3em','48px'].indexOf(element.find('span').eq(1).css('font-size')) !== -1); + expect(['2em','32px'].indexOf(element.find('span').eq(2).css('font-size')) !== -1); }); }); @@ -207,9 +210,9 @@ describe("Word Cloud Directive", function() { }); it('should set the size of the buttons individually', function() { - expect(element.find('span').eq(0).css('font-size')).toBeOneOf(['1em','16px']); - expect(element.find('span').eq(1).css('font-size')).toBeOneOf(['2em','32px']); - expect(element.find('span').eq(2).css('font-size')).toBeOneOf(['3em','48px']); + expect(['1em','16px'].indexOf(element.find('span').eq(0).css('font-size')) !== -1); + expect(['2em','32px'].indexOf(element.find('span').eq(1).css('font-size')) !== -1); + expect(['3em','48px'].indexOf(element.find('span').eq(2).css('font-size')) !== -1); }); }); @@ -229,9 +232,9 @@ describe("Word Cloud Directive", function() { }); it('should set the size of the buttons individually', function() { - expect(element.find('span').eq(0).css('font-size')).toBeOneOf(['3em','48px']); - expect(element.find('span').eq(1).css('font-size')).toBeOneOf(['2em','32px']); - expect(element.find('span').eq(2).css('font-size')).toBeOneOf(['1em','16px']); + expect(['3em','48px'].indexOf(element.find('span').eq(0).css('font-size')) !== -1); + expect(['2em','32px'].indexOf(element.find('span').eq(1).css('font-size')) !== -1); + expect(['1em','16px'].indexOf(element.find('span').eq(2).css('font-size')) !== -1); }); }); diff --git a/test/helpers.js b/test/helpers.js deleted file mode 100755 index 50460c1..0000000 --- a/test/helpers.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Created with IntelliJ IDEA. - * User: Joe Linn - * Date: 8/9/13 - * Time: 12:12 PM - * To change this template use File | Settings | File Templates. - */ -beforeEach(function(){ - this.addMatchers({ - toHaveClass: function(cls){ - this.message = function(){ - return "Expected '" + angular.mock.dump(this.actual) + "'"+(this.isNot?" not":"")+" to have class '" + cls + "'."; - }; - return this.actual.hasClass(cls); - }, - toBeTag: function(tag) { - this.message = function(){ - return "Expected '" + angular.mock.dump(this.actual) + "'"+(this.isNot?" not":"")+" to be a '" + tag + "' tag."; - }; - return this.actual.prop('tagName') == tag; - }, - toBeOneOf: function(options) { - this.message = function() { - return "Expected '" + this.actual + "'" + (this.isNot?" not":"") + " to be one of "+options+"."; - }; - return options.indexOf(this.actual) >= 0; - } - }); -}); From 43e86134d17b0f65a314c9e4c6b6c1b85543b077 Mon Sep 17 00:00:00 2001 From: Lautaro Cozzani Rodriguez Date: Tue, 10 Feb 2015 18:41:24 -0300 Subject: [PATCH 2/3] use custom object instead of just (word, size, rawSize) --- example.html | 8 ++++++-- src/angular-word-cloud.js | 7 +++++-- test/angularWordCloudTest.js | 27 ++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/example.html b/example.html index 6d262ac..f7180eb 100755 --- a/example.html +++ b/example.html @@ -25,7 +25,7 @@

List

- +

Clicked word:
@@ -63,7 +63,11 @@

Data

var doc = null; angular.module('ExampleApp', ['vr.directives.wordCloud']) .controller('MainCtrl', ['$scope', function($scope) { - $scope.words = [ {word:'one',size: '16px'}, {word:'two',size:'13px'}, {word:'three',size:'20px'} ]; + $scope.words = [ + {word:'one',size: '16px',custom:'I'}, + {word:'two',size:'13px',custom:'II'}, + {word:'three',size:'20px',custom:'III'} + ]; $scope.clickMe1 = function(word) { return $scope.word1 = word; }; diff --git a/src/angular-word-cloud.js b/src/angular-word-cloud.js index c6f615f..e182409 100755 --- a/src/angular-word-cloud.js +++ b/src/angular-word-cloud.js @@ -68,11 +68,14 @@ angular.module('vr.directives.wordCloud',[]) words = []; } - words = words.map(function(e) { return {word: e.word, size: e.size, rawSize: parseFloat(e.size) }; }); + words = words.map(function(e) { + e.rawSize = parseFloat(e.size); + return e; + }); scope.mywords = words; - }; + }; scope.fontSize = function(size) { if((''+size).search("(px|em|in|cm|mm|ex|pt|pc|%)+") == -1) { return size+'em'; diff --git a/test/angularWordCloudTest.js b/test/angularWordCloudTest.js index 6e2f47a..a18269d 100755 --- a/test/angularWordCloudTest.js +++ b/test/angularWordCloudTest.js @@ -93,7 +93,32 @@ describe("Word Cloud Directive", function() { describe('with an array', function() { - + describe('using custom properties', function() { + beforeEach(function() { + $rootScope.words = [ + {word:'one',size:1, custom: 'value one'}, + {word:'two',size:3, custom: 'value two'}, + {word:'three',size:2, custom: 'value three'} + ]; + + /*jshint quotmark: double */ + element = $compile( + "" + + "

" + + "{{ word.word }}-{{ word.custom }}" + + "

" + + "
")($rootScope); + + $rootScope.$digest(); + }); + + it('should use ', function() { + var buttons = element.find('span'); + expect(buttons.eq(0).find('p').text()).toBe('one-value one'); + expect(buttons.eq(1).find('p').text()).toBe('two-value two'); + expect(buttons.eq(2).find('p').text()).toBe('three-value three'); + }); + }); describe('using integer sizes', function() { From ac427e2bc02fecceb3ecba3f9f981efdc5b57d17 Mon Sep 17 00:00:00 2001 From: Lautaro Cozzani Rodriguez Date: Tue, 10 Feb 2015 20:35:26 -0300 Subject: [PATCH 3/3] build an increase version --- bower.json | 2 +- build/angular-word-cloud.js | 7 +++++-- build/angular-word-cloud.min.js | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bower.json b/bower.json index 29f882f..0d9e2ab 100755 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-word-cloud", - "version": "0.1.3", + "version": "0.1.4", "main": "./build/angular-word-cloud.min.js", "ignore": [ "**/.*", diff --git a/build/angular-word-cloud.js b/build/angular-word-cloud.js index c6f615f..e182409 100644 --- a/build/angular-word-cloud.js +++ b/build/angular-word-cloud.js @@ -68,11 +68,14 @@ angular.module('vr.directives.wordCloud',[]) words = []; } - words = words.map(function(e) { return {word: e.word, size: e.size, rawSize: parseFloat(e.size) }; }); + words = words.map(function(e) { + e.rawSize = parseFloat(e.size); + return e; + }); scope.mywords = words; - }; + }; scope.fontSize = function(size) { if((''+size).search("(px|em|in|cm|mm|ex|pt|pc|%)+") == -1) { return size+'em'; diff --git a/build/angular-word-cloud.min.js b/build/angular-word-cloud.min.js index 8de3a1a..7b52566 100644 --- a/build/angular-word-cloud.min.js +++ b/build/angular-word-cloud.min.js @@ -1,2 +1,2 @@ -/*! angular-word-cloud 2013-11-18 */ -angular.module("vr.directives.wordCloud",[]).directive("wordCloud",["$interpolate",function(a){return{restrict:"EA",replace:!0,transclude:!0,scope:{words:"=",sort:"@"},template:"
",controller:["$scope","$transclude",function(a,b){a.initClick=function(c){b(function(b,d){a.clickFn=d[c]})}}],compile:function(b,c){var d=angular.isUndefined(c.type)?"list":c.type;switch(d){case"cloud":b.children().eq(0).attr("style","font-size: "+a.startSymbol()+" fontSize(word.size) "+a.endSymbol()+";");break;case"list":}return function(a,b,c){a.clickFn=function(){},angular.isUndefined(c.ngClick)||a.initClick(c.ngClick);var d=function(){var b=angular.copy(a.words);angular.isArray(b)&&b.length>0?angular.isObject(b[0])?(angular.isUndefined(b[0].word)||angular.isUndefined(b[0].size))&&(b=[]):b=b.map(function(a){return{word:a,size:1}}):b=[],b=b.map(function(a){return{word:a.word,size:a.size,rawSize:parseFloat(a.size)}}),a.mywords=b};a.fontSize=function(a){return-1==(""+a).search("(px|em|in|cm|mm|ex|pt|pc|%)+")?a+"em":a},a.$watch("words",function(){d()},!0),a.$watch("sort",function(b){b||(b="no"),a.param="alpha"==b.substr(0,5)?"word":"no"==b?"":"rawSize",a.reverse="desc"==b.substr(-4).toLowerCase()})}}}}]); \ No newline at end of file +/*! angular-word-cloud 2015-02-10 */ +angular.module("vr.directives.wordCloud",[]).directive("wordCloud",["$interpolate",function(a){return{restrict:"EA",replace:!0,transclude:!0,scope:{words:"=",sort:"@"},template:"
",controller:["$scope","$transclude",function(a,b){a.initClick=function(c){b(function(b,d){a.clickFn=d[c]})}}],compile:function(b,c){var d=angular.isUndefined(c.type)?"list":c.type;switch(d){case"cloud":b.children().eq(0).attr("style","font-size: "+a.startSymbol()+" fontSize(word.size) "+a.endSymbol()+";");break;case"list":}return function(a,b,c){a.clickFn=function(){},angular.isUndefined(c.ngClick)||a.initClick(c.ngClick);var d=function(){var b=angular.copy(a.words);angular.isArray(b)&&b.length>0?angular.isObject(b[0])?(angular.isUndefined(b[0].word)||angular.isUndefined(b[0].size))&&(b=[]):b=b.map(function(a){return{word:a,size:1}}):b=[],b=b.map(function(a){return a.rawSize=parseFloat(a.size),a}),a.mywords=b};a.fontSize=function(a){return-1==(""+a).search("(px|em|in|cm|mm|ex|pt|pc|%)+")?a+"em":a},a.$watch("words",function(){d()},!0),a.$watch("sort",function(b){b||(b="no"),a.param="alpha"==b.substr(0,5)?"word":"no"==b?"":"rawSize",a.reverse="desc"==b.substr(-4).toLowerCase()})}}}}]); \ No newline at end of file