From de730a4505257ab7783400e332bf9c425789214b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Tue, 30 Dec 2014 21:05:40 +0100 Subject: [PATCH] Add some basic tests for filters --- bower.json | 4 ++- js/glowingbear.js | 5 +++- test/karma.conf.js | 2 ++ test/unit/filters.js | 65 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 test/unit/filters.js diff --git a/bower.json b/bower.json index 8557a60..cb3a694 100644 --- a/bower.json +++ b/bower.json @@ -8,8 +8,10 @@ "dependencies": { "angular": "1.3.x", "angular-route": "1.3.x", + "angular-sanitize": "1.3.x", + "angular-touch": "1.3.x", "angular-loader": "1.3.x", - "angular-mocks": "~1.3.x", + "angular-mocks": "1.3.x", "html5-boilerplate": "~4.3.0" } } diff --git a/js/glowingbear.js b/js/glowingbear.js index 66b9730..90679ad 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -3,7 +3,10 @@ var weechat = angular.module('weechat', ['ngRoute', 'localStorage', 'weechatModels', 'plugins', 'IrcUtils', 'ngSanitize', 'ngWebsockets', 'ngTouch']); weechat.config(['$compileProvider', function ($compileProvider) { - $compileProvider.debugInfoEnabled(false); + // hack to determine whether we're executing the tests + if (typeof(it) === "undefined" && typeof(describe) === "undefined") { + $compileProvider.debugInfoEnabled(false); + } }]); weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', '$log', 'models', 'connection', 'notifications', 'utils', function ($rootScope, $scope, $store, $timeout, $log, models, connection, notifications, utils) { diff --git a/test/karma.conf.js b/test/karma.conf.js index 94d1739..66e3f04 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -7,6 +7,8 @@ module.exports = function(config){ 'bower_components/angular/angular.js', 'bower_components/angular-route/angular-route.js', 'bower_components/angular-mocks/angular-mocks.js', + 'bower_components/angular-sanitize/angular-sanitize.js', + 'bower_components/angular-touch/angular-touch.js', 'js/localstorage.js', 'js/weechat.js', 'js/irc-utils.js', diff --git a/test/unit/filters.js b/test/unit/filters.js new file mode 100644 index 0000000..934996e --- /dev/null +++ b/test/unit/filters.js @@ -0,0 +1,65 @@ +var weechat = angular.module('weechat'); + +describe('Filters', function() { + beforeEach(module('weechat')); + /*beforeEach(module(function($provide) { + $provide.value('version', 'TEST_VER'); + }));*/ + + it('has an irclinky filter', inject(function($filter) { + expect($filter('irclinky')).not.toBeNull(); + })); + + describe('irclinky', function() { + it('should not mess up text', inject(function(irclinkyFilter) { + expect(irclinkyFilter('foo')).toEqual('foo'); + })); + + it('should linkify IRC channels', inject(function(irclinkyFilter) { + expect(irclinkyFilter('#foo')).toEqual('#foo'); + })); + + it('should not mess up IRC channels surrounded by HTML entities', inject(function(irclinkyFilter) { + expect(irclinkyFilter('<"#foo">')).toEqual('<"#foo">'); + })); + }); + + describe('inlinecolour', function() { + it('should not mess up normal text', inject(function(inlinecolourFilter) { + expect(inlinecolourFilter('foo')).toEqual('foo'); + expect(inlinecolourFilter('test #foobar baz')).toEqual('test #foobar baz'); + })); + + it('should detect inline colours in #rrggbb format', inject(function(inlinecolourFilter) { + expect(inlinecolourFilter('#123456')).toEqual('#123456
'); + expect(inlinecolourFilter('#aabbcc')).toEqual('#aabbcc
'); + })); + + it('should not detect inline colours in #rgb format', inject(function(inlinecolourFilter) { + expect(inlinecolourFilter('#123')).toEqual('#123'); + expect(inlinecolourFilter('#abc')).toEqual('#abc'); + })); + + it('should detect inline colours in rgb(12,34,56) and rgba(12,34,56,0.78) format', inject(function(inlinecolourFilter) { + expect(inlinecolourFilter('rgb(1,2,3)')).toEqual('rgb(1,2,3)
'); + expect(inlinecolourFilter('rgb(1,2,3);')).toEqual('rgb(1,2,3);
'); + expect(inlinecolourFilter('rgba(1,2,3,0.4)')).toEqual('rgba(1,2,3,0.4)
'); + expect(inlinecolourFilter('rgba(255,123,0,0.5);')).toEqual('rgba(255,123,0,0.5);
'); + })); + + it('should tolerate whitespace in between numbers in rgb/rgba colours', inject(function(inlinecolourFilter) { + expect(inlinecolourFilter('rgb( 1\t, 2 , 3 )')).toEqual('rgb( 1\t, 2 , 3 )
'); + })); + + it('should handle multiple and mixed occurrences of colour values', inject(function(inlinecolourFilter) { + expect(inlinecolourFilter('rgb(1,2,3) #123456')).toEqual('rgb(1,2,3)
#123456
'); + expect(inlinecolourFilter('#f00baa #123456 #234567')).toEqual('#f00baa
#123456
#234567
'); + expect(inlinecolourFilter('rgba(1,2,3,0.4) foorgb(50,100,150)')).toEqual('rgba(1,2,3,0.4)
foorgb(50,100,150)
'); + })); + + it('should not replace HTML escaped 𞉀', inject(function(inlinecolourFilter) { + expect(inlinecolourFilter('𞉀')).toEqual('𞉀'); + })); + }); + +});