Merge pull request #528 from glowing-bear/add-filter-tests
Add some basic tests for filters
This commit is contained in:
commit
e56acbc923
4 changed files with 74 additions and 2 deletions
|
@ -8,8 +8,10 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"angular": "1.3.x",
|
"angular": "1.3.x",
|
||||||
"angular-route": "1.3.x",
|
"angular-route": "1.3.x",
|
||||||
|
"angular-sanitize": "1.3.x",
|
||||||
|
"angular-touch": "1.3.x",
|
||||||
"angular-loader": "1.3.x",
|
"angular-loader": "1.3.x",
|
||||||
"angular-mocks": "~1.3.x",
|
"angular-mocks": "1.3.x",
|
||||||
"html5-boilerplate": "~4.3.0"
|
"html5-boilerplate": "~4.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
|
|
||||||
var weechat = angular.module('weechat', ['ngRoute', 'localStorage', 'weechatModels', 'plugins', 'IrcUtils', 'ngSanitize', 'ngWebsockets', 'ngTouch']);
|
var weechat = angular.module('weechat', ['ngRoute', 'localStorage', 'weechatModels', 'plugins', 'IrcUtils', 'ngSanitize', 'ngWebsockets', 'ngTouch']);
|
||||||
weechat.config(['$compileProvider', function ($compileProvider) {
|
weechat.config(['$compileProvider', function ($compileProvider) {
|
||||||
|
// hack to determine whether we're executing the tests
|
||||||
|
if (typeof(it) === "undefined" && typeof(describe) === "undefined") {
|
||||||
$compileProvider.debugInfoEnabled(false);
|
$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) {
|
weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', '$log', 'models', 'connection', 'notifications', 'utils', function ($rootScope, $scope, $store, $timeout, $log, models, connection, notifications, utils) {
|
||||||
|
|
|
@ -7,6 +7,8 @@ module.exports = function(config){
|
||||||
'bower_components/angular/angular.js',
|
'bower_components/angular/angular.js',
|
||||||
'bower_components/angular-route/angular-route.js',
|
'bower_components/angular-route/angular-route.js',
|
||||||
'bower_components/angular-mocks/angular-mocks.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/localstorage.js',
|
||||||
'js/weechat.js',
|
'js/weechat.js',
|
||||||
'js/irc-utils.js',
|
'js/irc-utils.js',
|
||||||
|
|
65
test/unit/filters.js
Normal file
65
test/unit/filters.js
Normal file
|
@ -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('<a href="#" onclick="var $scope = angular.element(event.target).scope(); $scope.openBuffer(\'#foo\'); $scope.$apply();">#foo</a>');
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should not mess up IRC channels surrounded by HTML entities', inject(function(irclinkyFilter) {
|
||||||
|
expect(irclinkyFilter('<"#foo">')).toEqual('<"<a href="#" onclick="var $scope = angular.element(event.target).scope(); $scope.openBuffer(\'#foo">\'); $scope.$apply();">#foo"></a>');
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
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 <div class="colourbox" style="background-color:#123456"></div>');
|
||||||
|
expect(inlinecolourFilter('#aabbcc')).toEqual('#aabbcc <div class="colourbox" style="background-color:#aabbcc"></div>');
|
||||||
|
}));
|
||||||
|
|
||||||
|
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) <div class="colourbox" style="background-color:rgb(1,2,3)"></div>');
|
||||||
|
expect(inlinecolourFilter('rgb(1,2,3);')).toEqual('rgb(1,2,3); <div class="colourbox" style="background-color:rgb(1,2,3);"></div>');
|
||||||
|
expect(inlinecolourFilter('rgba(1,2,3,0.4)')).toEqual('rgba(1,2,3,0.4) <div class="colourbox" style="background-color:rgba(1,2,3,0.4)"></div>');
|
||||||
|
expect(inlinecolourFilter('rgba(255,123,0,0.5);')).toEqual('rgba(255,123,0,0.5); <div class="colourbox" style="background-color:rgba(255,123,0,0.5);"></div>');
|
||||||
|
}));
|
||||||
|
|
||||||
|
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 ) <div class="colourbox" style="background-color:rgb( 1\t, 2 , 3 )"></div>');
|
||||||
|
}));
|
||||||
|
|
||||||
|
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) <div class="colourbox" style="background-color:rgb(1,2,3)"></div> #123456 <div class="colourbox" style="background-color:#123456"></div>');
|
||||||
|
expect(inlinecolourFilter('#f00baa #123456 #234567')).toEqual('#f00baa <div class="colourbox" style="background-color:#f00baa"></div> #123456 <div class="colourbox" style="background-color:#123456"></div> #234567 <div class="colourbox" style="background-color:#234567"></div>');
|
||||||
|
expect(inlinecolourFilter('rgba(1,2,3,0.4) foorgb(50,100,150)')).toEqual('rgba(1,2,3,0.4) <div class="colourbox" style="background-color:rgba(1,2,3,0.4)"></div> foorgb(50,100,150) <div class="colourbox" style="background-color:rgb(50,100,150)"></div>');
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should not replace HTML escaped 𞉀', inject(function(inlinecolourFilter) {
|
||||||
|
expect(inlinecolourFilter('𞉀')).toEqual('𞉀');
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in a new issue