"use strict"; import angular from "angular"; import "angular-mocks"; import "../../src/main"; describe('Filters', function() { beforeEach(angular.mock.module('weechat')); /*beforeEach(module(function($provide) { $provide.value('version', 'TEST_VER'); }));*/ it('has an irclinky filter', angular.mock.inject(function($filter) { expect($filter('irclinky')).not.toBeNull(); })); describe('conditionalLinkify', function() { it('should create links from an url', angular.mock.inject(function($filter) { var url = 'asdf https://a.example.com/wiki/asdf_qwer_(rivi%C3%A8re) Some text.', link = 'asdf https://a.example.com/wiki/asdf_qwer_(rivi%C3%A8re) Some text.', result = $filter('conditionalLinkify')(url); expect(result).toEqual(link); })); it('should not make emails into links', angular.mock.inject(function($filter) { var url = 'asdf@gmail.com', link = 'asdf@gmail.com', result = $filter('conditionalLinkify')(url); expect(result).toEqual(link); })); }); describe('irclinky', function() { it('should not mess up text', angular.mock.inject(function(irclinkyFilter) { expect(irclinkyFilter('foo')).toEqual('foo'); })); it('should linkify IRC channels', angular.mock.inject(function(irclinkyFilter) { expect(irclinkyFilter('#foo')).toEqual('#foo'); })); it('should not mess up IRC channels surrounded by HTML entities', angular.mock.inject(function(irclinkyFilter) { expect(irclinkyFilter('<"#foo">')).toEqual('<"\');">#foo">'); })); it('should not touch links created by `linky`', angular.mock.inject(function($filter, DOMfilterFilter) { var url = 'http://foo.bar/#baz', link = $filter('conditionalLinkify')(url), result = DOMfilterFilter(link, 'irclinky').$$unwrapTrustedValue(); expect(result).toEqual(link); })); }); describe('inlinecolour', function() { it('should not mess up normal text', angular.mock.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', angular.mock.inject(function(inlinecolourFilter) { expect(inlinecolourFilter('#123456')).toEqual('#123456
'); expect(inlinecolourFilter('#aabbcc')).toEqual('#aabbcc '); })); it('should not detect inline colours in #rgb format', angular.mock.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', angular.mock.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', angular.mock.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', angular.mock.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 ', angular.mock.inject(function(inlinecolourFilter) { expect(inlinecolourFilter('')).toEqual(''); })); }); describe('DOMfilter', function() { it('should run a filter on all text nodes', angular.mock.inject(function(DOMfilterFilter) { var dom = 'abcdefgh
i', expected = 'ABCDEFGH
I', result = DOMfilterFilter(dom, 'uppercase').$$unwrapTrustedValue(); expect(result).toEqual(expected); })); it('should pass additional arguments to the filter', angular.mock.inject(function(DOMfilterFilter) { var dom = '12
3.14159265', expected = '1.002.00
3.14', result = DOMfilterFilter(dom, 'number', 2).$$unwrapTrustedValue(); expect(result).toEqual(expected); })); it('should never lock up like in bug #688', angular.mock.inject(function($filter, DOMfilterFilter) { var msg = '#crash http://google.com', linked = $filter('conditionalLinkify')(msg), irclinked = DOMfilterFilter(linked, 'irclinky'); // With the bug, the DOMfilterFilter call ends up in an infinite loop. // I.e. if we ever got this far, the bug is fixed. })); }); describe('codify', function() { it('should not mess up text', angular.mock.inject(function(codifyFilter) { expect(codifyFilter('foo')).toEqual('foo'); })); it('should codify single snippets', angular.mock.inject(function(codifyFilter) { expect(codifyFilter('z `foo` z')).toEqual('z `foo
` z');
expect(codifyFilter('z `a` z')).toEqual('z `a
` z');
expect(codifyFilter('z ```foo``` z')).toEqual('z ```foo
``` z');
}));
it('should codify multiple snippets', angular.mock.inject(function(codifyFilter) {
expect(codifyFilter('z `foo` z `bar` `baz`')).toEqual('z `foo
` z `bar
` `baz
`');
}));
it('should not codify empty snippets', angular.mock.inject(function(codifyFilter) {
expect(codifyFilter('``')).toEqual('``');
}));
it('should not codify single backticks', angular.mock.inject(function(codifyFilter) {
expect(codifyFilter('foo`bar')).toEqual('foo`bar');
}));
it('should not codify double backticks', angular.mock.inject(function(codifyFilter) {
expect(codifyFilter('some ``non-code``')).toEqual('some ``non-code``');
}));
it('should not codify pseudo-fancy quotes', angular.mock.inject(function(codifyFilter) {
expect(codifyFilter('some ``fancy qoutes\'\'')).toEqual('some ``fancy qoutes\'\'');
}));
it('should not codify stuff in the middle of a word or URL', angular.mock.inject(function(codifyFilter) {
expect(codifyFilter('https://foo.bar/`wat`')).toEqual('https://foo.bar/`wat`');
expect(codifyFilter('Weird`ness`')).toEqual('Weird`ness`');
}));
});
});