import * as TextFormatting from '@/helpers/TextFormatting';

describe('TextFormatting.js', function() {
    it('should return valid channel links', function() {
        let tests = [
            ['#channel', '<a class="u-link kiwi-channel" data-channel-name="#channel">#channel</a>'],
            ['#channel;', '<a class="u-link kiwi-channel" data-channel-name="#channel">#channel</a>;'],
            ['#chan;nel', '<a class="u-link kiwi-channel" data-channel-name="#chan;nel">#chan;nel</a>'],
            ['#channel.', '<a class="u-link kiwi-channel" data-channel-name="#channel">#channel</a>.'],
            ['#chan;el;', '<a class="u-link kiwi-channel" data-channel-name="#chan;el">#chan;el</a>;'],
            ['#chan[n]el,', '<a class="u-link kiwi-channel" data-channel-name="#chan[n]el">#chan[n]el</a>,'],
            ['@#channel:', '@<a class="u-link kiwi-channel" data-channel-name="#channel">#channel</a>:'],
            ['@&channel,', '@<a class="u-link kiwi-channel" data-channel-name="&amp;channel">&amp;channel</a>,'],
        ];

        tests.forEach((c) => {
            let formatted = TextFormatting.linkifyChannels(c[0]);
            expect(formatted).to.equal(c[1]);
        });
    });

    it('should return valid url links', function() {
        let tests = [
            ['http://example.com', 'http://example.com'],
            ['http://127.0.0.1', 'http://127.0.0.1'],
            ['http://example.com:8080', 'http://example.com:8080'],
            ['http://127.0.0.1:8001', 'http://127.0.0.1:8001'],
            ['http://example.com/test.html?test=foo#bar', 'http://example.com/test.html?test=foo#bar'],
            ['http://127.0.0.1/test.html?test=foo#bar', 'http://127.0.0.1/test.html?test=foo#bar'],
            ['www.example.com', 'http://www.example.com'],
            ['https://www.example.com', 'https://www.example.com'],
            ['https://127.0.0.1/test.html?test=foo#bar', 'https://127.0.0.1/test.html?test=foo#bar'],
            ['http://2001:0000:1234:0000:0000:C1C0:ABCD:0876/', 'http://2001:0000:1234:0000:0000:C1C0:ABCD:0876/'],
            ['http://[2001:db8:1f70::999:de8:7648:6e8]:100/', 'http://[2001:db8:1f70::999:de8:7648:6e8]:100/'],
            ['ldap://[2001:db8::7]/c=GB?objectClass?one', 'ldap://[2001:db8::7]/c=GB?objectClass?one'],
        ];

        tests.forEach((c) => {
            let linkified = TextFormatting.linkifyUrls(c[0]);
            expect(linkified.urls[0]).to.equal(c[1]);
        });
    });

    it('should reject invalid urls', function() {
        let tests = ['test', 'example.com', 'test:8080', '127.0.0.1/test.html'];

        tests.forEach((c) => {
            let linkified = TextFormatting.linkifyUrls(c);
            expect(linkified.urls.length).to.equal(0);
        });
    });
});

@@ -1282,39 +1282,36 @@
 %5B%0A            %5B'
-http://
+www.
 example.com', 'h
@@ -1308,32 +1308,36 @@
 e.com', 'http://
+www.
 example.com'%5D,%0A 
@@ -1360,20 +1360,36 @@
 p://
-127.0.0.1', 
+example.com'%5D,%0A            %5B
 'htt
@@ -1447,76 +1447,24 @@
 080'
-, 'http://example.com:8080'%5D,%0A            %5B'http://127.0.0.1:8001', 
+%5D,%0A            %5B
 'htt
@@ -1502,53 +1502,8 @@
    %5B
-'http://example.com/test.html?test=foo#bar', 
 'htt
@@ -1602,238 +1602,65 @@
 bar'
-, 'http://127.0.0.1/test.html?test=foo#bar'%5D,%0A            %5B'www.example.com', 'http://www.example.com'%5D,%0A            %5B'https://www.example.com', 'https://www.example.com'%5D,%0A            %5B'https://127.0.0.1/test.html?test=foo#bar', 
+%5D,%0A            %5B'https://www.example.com'%5D,%0A            %5B
 'htt
@@ -1717,59 +1717,8 @@
    %5B
-'http://2001:0000:1234:0000:0000:C1C0:ABCD:0876/', 
 'htt
@@ -1829,118 +1829,24 @@
 00/'
-, 'http://%5B2001:db8:1f70::999:de8:7648:6e8%5D:100/'%5D,%0A            %5B'ldap://%5B2001:db8::7%5D/c=GB?objectClass?one', 
+%5D,%0A            %5B
 'lda
@@ -1984,32 +1984,88 @@
 kifyUrls(c%5B0%5D);%0A
+            let compare = c.length === 2 ? c%5B1%5D : c%5B0%5D;%0A
             expe
@@ -2088,35 +2088,38 @@
 s%5B0%5D).to.equal(c
-%5B1%5D
+ompare
 );%0A        %7D);%0A 

Tidy TextFormatting.spec.js