window.onload = function() { // textCleanup QUnit.test("textCleanup", assert => { var source = "Some\nValue\n\n\nTest" var should = "Some\nValue\n\nTest" var result = App.Utils.textCleanup(source) assert.equal(result, should, source) source = "Some\nValue\n\n \n\n\nTest" should = "Some\nValue\n\nTest" result = App.Utils.textCleanup(source) assert.equal(result, should, source) source = "Some\n\rValue\n\r\n\r\n\rTest" should = "Some\nValue\n\nTest" result = App.Utils.textCleanup(source) assert.equal(result, should, source) source = "Some\n\rValue\n\r\n\r\n\rTest\r" should = "Some\nValue\n\nTest" result = App.Utils.textCleanup(source) assert.equal(result, should, source) source = "Some\r\nValue\r\n\r\n\r\nTest\r\n" should = "Some\nValue\n\nTest" result = App.Utils.textCleanup(source) assert.equal(result, should, source) source = "Some\r\nValue\r\n\r\n\r\n\r\n\r\n\r\nTest\r\n" should = "Some\nValue\n\nTest" result = App.Utils.textCleanup(source) assert.equal(result, should, source) source = "> Welcome!\n> \n> Thank you for installing Zammad.\n> \n> You will find ..." should = "> Welcome!\n>\n> Thank you for installing Zammad.\n>\n> You will find ..." result = App.Utils.textCleanup(source) assert.equal(result, should, source) }); // text2html QUnit.test("text2html", assert => { var source = "Some\nValue\n\n\nTest" var should = "
Some
Value

Test
" var result = App.Utils.text2html(source) assert.equal(result, should, source) source = "Some\nValue\n" should = "
Some
Value
" result = App.Utils.text2html(source) assert.equal(result, should, source) source = "Some\nValue\n" should = "
Some
<b>Value</b>
" result = App.Utils.text2html(source) assert.equal(result, should, source) source = "> Welcome!\n> \n> Thank you for installing Zammad.\n> \n> You will find ..." should = "
> Welcome!
>
> Thank you for installing Zammad.
>
> You will find ...
" result = App.Utils.text2html(source) assert.equal(result, should, source) source = "Some\nValue\n" should = "
Some
Value
" result = App.Utils.text2html(source) assert.equal(result, should, source) source = "Some\rValue\r" should = "
Some
Value
" result = App.Utils.text2html(source) assert.equal(result, should, source) source = "Some\n\rValue\n\r" should = "
Some
Value
" result = App.Utils.text2html(source) assert.equal(result, should, source) source = "Some\r\nValue\r\n" should = "
Some
Value
" result = App.Utils.text2html(source) assert.equal(result, should, source) source = "Some Value 123" should = "Some   Value 123" result = App.Utils.text2html(source) assert.equal(result, should, source) source = "Some\n Value\n 123" should = "
Some
  Value
   123
" result = App.Utils.text2html(source) assert.equal(result, should, source) }); // htmlStrip QUnit.test("htmlStrip", assert => { var source = $('

lala
') var should = '
lala
' App.Utils.htmlStrip(source) assert.equal(source.get(0).outerHTML, should) source = $('



lala
') should = '
lala
' App.Utils.htmlStrip(source) assert.equal(source.get(0).outerHTML, should) source = $('



lala

') should = '
lala
' App.Utils.htmlStrip(source) assert.equal(source.get(0).outerHTML, should) source = $('



lala

') should = '

lala
' App.Utils.htmlStrip(source) assert.equal(source.get(0).outerHTML, should) }); // lastLineEmpty QUnit.test("htmlLastLineEmpty", assert => { var source = $('

lala
') assert.equal(App.Utils.htmlLastLineEmpty(source), false) source = $('

lala
') assert.equal(App.Utils.htmlLastLineEmpty(source), true) }); // html2text QUnit.test("html2text", assert => { var source = "
Some
Value

Test
" var should = "Some\nValue\n\nTest" var result = App.Utils.html2text(source) assert.equal(result, should, source) source = "
Some
Value
" should = "Some\nValue" result = App.Utils.html2text(source) assert.equal(result, should, source) source = "
Some
Value
" should = "Some\nValue" result = App.Utils.html2text(source) assert.equal(result, should, source) source = "
Some & <Value>
" should = "Some & " result = App.Utils.html2text(source) assert.equal(result, should, source) source = "
Some
<b>Value</b>
" should = "Some\nValue" result = App.Utils.html2text(source) assert.equal(result, should, source) source = "
> Welcome!
>
> Thank you for installing Zammad.
>
> You will find ...
" should = "> Welcome!\n>\n> Thank you for installing Zammad.\n>\n> You will find ..." result = App.Utils.html2text(source) assert.equal(result, should, source) source = "
test 123










--
Bob Smith
" should = "test 123 \n\n--\nBob Smith" result = App.Utils.html2text(source) assert.equal(result, should, source) source = "test 123










--
Bob Smith" should = "test 123 \n\n--\nBob Smith" result = App.Utils.html2text(source) assert.equal(result, should, source) source = "
1









Von: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
\n
Gesendet: Donnerstag, 2. April 2015 11:32
" should = "1\n\nVon: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]\nGesendet: Donnerstag, 2. April 2015 11:32" result = App.Utils.html2text(source) assert.equal(result, should, source) source = "
test 123
lalala

--

some test
" should = "test 123\nlalala\n--\nsome test" result = App.Utils.html2text(source) assert.equal(result, should, source) source = "

Was\nsoll verbessert werden:

" should = "Was soll verbessert werden:" result = App.Utils.html2text(source) assert.equal(result, should, source) // in raw format, without cleanup source = "
Some
1234
" should = "Some\n1234\n" result = App.Utils.html2text(source, true) assert.equal(result, should, source) source = "
Some
1234
" should = "Some\n 1234\n" result = App.Utils.html2text(source, true) assert.equal(result, should, source) source = "\n\n
Some
\n
1234
" should = "Some\n 1234\n" result = App.Utils.html2text(source, true) assert.equal(result, should, source) source = "
Some
1234
" should = "Some\n 1234\n" result = App.Utils.html2text(source, true) assert.equal(result, should, source) source = "
Some
\n\n
1234
\n" should = "Some\n 1234\n" result = App.Utils.html2text(source, true) assert.equal(result, should, source) source = "
test
new line
" should = "test\nnew line\n\n" result = App.Utils.html2text(source, true) assert.equal(result, should, source) source = "

Was\nsoll verbessert werden:

" should = "Was soll verbessert werden:\n" result = App.Utils.html2text(source, true) assert.equal(result, should, source) }); // phoneify QUnit.test("phoneify", assert => { var source = "+1 123 123 123-123" var should = 'tel:+1123123123123' var result = App.Utils.phoneify(source) assert.equal(result, should, source) source = "+1 123 123 A 123-123<>" should = 'tel:+1123123123123' result = App.Utils.phoneify(source) assert.equal(result, should, source) source = "+1 (123) 123 123-123" should = 'tel:+1123123123123' result = App.Utils.phoneify(source) assert.equal(result, should, source) source = "+1 (123) 123 1#23-123" should = 'tel:+11231231#23123' result = App.Utils.phoneify(source) assert.equal(result, should, source) source = "+1 (123) 12*3 1#23-123" should = 'tel:+112312*31#23123' result = App.Utils.phoneify(source) assert.equal(result, should, source) source = "+1 (123) 12+3" should = 'tel:+1123123' result = App.Utils.phoneify(source) assert.equal(result, should, source) source = "+1 (123) 123 " should = 'tel:+1123123' result = App.Utils.phoneify(source) assert.equal(result, should, source) source = " +1 (123) 123 " should = 'tel:+1123123' result = App.Utils.phoneify(source) assert.equal(result, should, source) }) // linkify QUnit.test("linkify", assert => { var source = "http://example.com" var should = 'http://example.com' var result = App.Utils.linkify(source) assert.equal(result, should, source) source = "http://example.com?some_param=lalala" should = 'http://example.com?some_param=lalala' result = App.Utils.linkify(source) assert.equal(result, should, source) source = "example.com" should = 'example.com' result = App.Utils.linkify(source) assert.equal(result, should, source) source = "some text example.com" should = 'some text example.com' result = App.Utils.linkify(source) assert.equal(result, should, source) source = "example.com some text" should = 'example.com some text' result = App.Utils.linkify(source) assert.equal(result, should, source) source = "test@example.com some text" should = 'test@example.com some text' result = App.Utils.linkify(source) assert.equal(result, should, source) source = "abc domain.de-@domain.de some text" should = 'abc domain.de-@domain.de some text' result = App.Utils.linkify(source) assert.equal(result, should, source) /* source = "example.com" should = 'http://example.com' result = App.Utils.linkify(source) assert.equal(result, should, source) */ }); // htmlEscape QUnit.test("htmlEscape", assert => { var source = "<" var should = "<" var result = App.Utils.htmlEscape(source) assert.equal(result, should, source) source = ">" should = ">" result = App.Utils.htmlEscape(source) assert.equal(result, should, source) source = "&" should = "&" result = App.Utils.htmlEscape(source) assert.equal(result, should, source) source = "&" should = "&amp;" result = App.Utils.htmlEscape(source) assert.equal(result, should, source) source = "& ;" should = "&amp ;" result = App.Utils.htmlEscape(source) assert.equal(result, should, source) source = "& amp;" should = "& amp;" result = App.Utils.htmlEscape(source) assert.equal(result, should, source) source = "'test'" should = "'test'" result = App.Utils.htmlEscape(source) assert.equal(result, should, source) source = '"test"' should = ""test"" result = App.Utils.htmlEscape(source) assert.equal(result, should, source) source = "<>" should = "<>" result = App.Utils.htmlEscape(source) assert.equal(result, should, source) source = "<<>" should = "<&lt;>" result = App.Utils.htmlEscape(source) assert.equal(result, should, source) }); // htmlRemoveTags QUnit.test("htmlRemoveTags", assert => { var source = "
test
" //var should = "
test
" var should = "test" var result = App.Utils.htmlRemoveTags($(source)) assert.equal(result.html(), should, source) source = "
test
" //should = "
test
" should = "test" result = App.Utils.htmlRemoveTags($(source)) assert.equal(result.html(), should, source) source = "some link to somewhere" should = "some link to somewhere" result = App.Utils.htmlRemoveTags($(source)) assert.equal(result.html(), should, source) source = "
some link to somewhere
" //should = "
some link to somewhere
" should = "some link to somewhere" result = App.Utils.htmlRemoveTags($(source)) assert.equal(result.html(), should, source) source = "
some link to somewhere
" //should = "
some link to somewhere
" should = "some link to somewhere" result = App.Utils.htmlRemoveTags($(source)) assert.equal(result.html(), should, source) source = "
some link to somewhere

123
" //should = "
some link to somewhere 123
" should = "some link to somewhere 123 " result = App.Utils.htmlRemoveTags($(source)) assert.equal(result.html(), should, source) }); // htmlRemoveRichtext QUnit.test("htmlRemoveRichtext", assert => { source = "
test 123
" //should = "
test 123
" should = "test 123" result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) source = "
" //should = "
test 123
" should = "test 123" result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) source = "

test 123

" should = "

test 123

" result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) source = "
This is some text!
" should = "This is some text!" result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) should = "This is some text!" result = App.Utils.htmlRemoveRichtext(source) assert.equal(result.html(), should, source) var source = "
test
" //var should = "
test
" var should = "test" var result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) source = "
1.1.1     Description
" //should = "
1.1.1     Description
" should = "1.1.1     Description" //should = '1.1.1 Description' result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) source = "some link to somewhere" should = "some link to somewhere" result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) source = "
test
" //should = "
test
" should = " test " result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) source = "
test
" //should = "
test
" should = " test " result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) source = "
test
" //should = "
test
" should = "
test
" result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) source = "
test
" //should = "
test
" should = "
test
" result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) source = "
test
123
" //should = "
test
123
" should = "
test
123" //should = '
test
123' result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) source = "
test
" //should = "
test
" should = "
test
" result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) source = "
" //should = "
test
" should = " test " result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) source = "

" //should = "

" should = "
" result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) source = "

" //should = "

" should = "

" result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) source = "
test 123
" //should = "
test 123
" should = "test 123" result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) source = "
\n" //should = "
test 123
" should = '
Gruppe *
Besitzer
Status *
' result = App.Utils.htmlRemoveRichtext(source) assert.equal(result.html(), should, source) source = "
This is some text!
" should = "This is some text!" result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.html(), should, source) should = "This is some text!" result = App.Utils.htmlRemoveRichtext(source) assert.equal(result.html(), should, source) var source = "
test
" var should = "
test
" var result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.get(0).outerHTML, should, source) source = "
some link to somewhere" should = "
some link to somewhere
" result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.get(0).outerHTML, should, source) source = "

" should = "

" result = App.Utils.htmlRemoveRichtext($(source)) assert.equal(result.get(0).outerHTML, should, source) source = "
111aaa
keyvalue
" should = "
111aaakeyvalue
" result = App.Utils.htmlRemoveRichtext(source, true) assert.equal(result.get(0).outerHTML, should, source) }); // htmlCleanup QUnit.test("htmlCleanup", assert => { var source = "
test
" //var should = "
test
" var should = "test" var result = App.Utils.htmlCleanup($(source)) assert.equal(result.html(), should, source) source = "
test
" should = "test" result = App.Utils.htmlCleanup(source) assert.equal(result.html(), should, source) source = "some link to somewhere" should = "some link to somewhere" result = App.Utils.htmlCleanup(source) assert.equal(result.html(), should, source) source = "
  • a
  • b
  • " should = "
  • a
  • b
  • " result = App.Utils.htmlCleanup(source) assert.equal(result.html(), should, source) source = "some link to somewhere" should = "some link to somewhere" result = App.Utils.htmlCleanup($(source)) assert.equal(result.html(), should, source) source = "

    some link to somewhere

    " should = "some link to somewhere" result = App.Utils.htmlCleanup($(source)) assert.equal(result.html(), should, source) source = "

    some link to somewhere

    " should = "

    some link to somewhere

    " result = App.Utils.htmlCleanup($(source)) assert.equal(result.html(), should, source) source = "

    some link to somewhere

    " should = "

    some link to somewhere

    " result = App.Utils.htmlCleanup($(source)) assert.equal(result.html(), should, source) source = "
    some link to somewhere" //should = "
    some link to somewhere
    " should = "some link to somewhere" result = App.Utils.htmlCleanup($(source)) assert.equal(result.html(), should, source) source = "
    " //should = "
    some link to somewhere
    " should = "some link to somewhere" result = App.Utils.htmlCleanup($(source)) assert.equal(result.html(), should, source) source = "

    some h1 for somewhere


    " should = "

    some h1 for somewhere


    " result = App.Utils.htmlCleanup($(source)) assert.equal(result.html(), should, source) source = "

    " //should = "

    " should = "
    " result = App.Utils.htmlCleanup($(source)) assert.equal(result.html(), should, source) source = "

    " //should = "

    " should = "

    " result = App.Utils.htmlCleanup($(source)) assert.equal(result.html(), should, source) source = "
    test 123
    " //should = "
    test 123
    " should = "test 123" result = App.Utils.htmlCleanup($(source)) assert.equal(result.html(), should, source) source = "
    test 123
    some other value
    " //should = "
    test 123 some other value
    " should = "test 123 some other value" result = App.Utils.htmlCleanup($(source)) assert.equal(result.html(), should, source) source = "
    test 123
    some other value
    " //should = "
    test 123 some other value
    " should = "test 123 some other value" result = App.Utils.htmlCleanup($(source)) assert.equal(result.html(), should, source) source = "
    This is some text!
    " //should = "
    This is some text!
    " should = "This is some text!" result = App.Utils.htmlCleanup($(source)) assert.equal(result.html(), should, source) source = "

    some link to somewhere from wordabc

    " //should = "

    some link to somewhere from wordabc

    " should = '

    some link to somewhere from wordabc

    ' result = App.Utils.htmlCleanup($(source)) assert.equal(result.html(), should, source) source = "
    \n" //should = "
    test 123
    " should = '
    Gruppe *
    Besitzer
    Status *
    ' result = App.Utils.htmlCleanup(source) assert.equal(result.html(), should, source) source = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n

    ·            \nTest 1

    \n\n

    ·            \nTest 2

    \n\n

    ·            \nTest 3

    \n\n

    ·            \nTest 4

    \n\n

    ·            \nTest5

    \n\n\n\n\n" should = "
    • Test 1
    • Test 2
    • Test 3
    • Test 4
    • Test5
    " result = App.Utils.htmlCleanup(source) assert.equal(result.html().trim(), should, source) source = "\n\n\n \n \n \n \n\n\n

    1.\nGehe auf https://www.pferdiathek.ge

    \n


    \n\n

    \n

    2.\nMelde Dich mit folgende Zugangsdaten an:

    \n

    Benutzer:\nme@xxx.net

    \n

    Passwort:\nxxx.

    \n\n" should = "\n\n\n \n \n \n \n\n\n

    1.\nGehe auf https://www.pferdiathek.ge

    \n


    \n\n

    \n

    2.\nMelde Dich mit folgende Zugangsdaten an:

    \n

    Benutzer:\nme@xxx.net

    \n

    Passwort:\nxxx.

    \n\n" result = App.Utils.htmlCleanup(source) assert.equal(result.html(), should, source) source = "
    aaa
    value
    " should = "
    aaa
    value
    " result = App.Utils.htmlCleanup(source) assert.equal(result.get(0).outerHTML, should, source) // strip out browser-inserted (broken) link (see https://github.com/zammad/zammad/issues/2019) source = "" should = "test" result = App.Utils.htmlCleanup(source) assert.equal(result.html(), should, source) source = "
    aaa
    value
    " should = "
    aaa
    value
    " result = App.Utils.htmlCleanup(source) result.get(0).outerHTML //equal(result.get(0).outerHTML, should, source) / string order is different on browsers assert.equal(result.first().attr('bgcolor'), 'green') assert.equal(result.first().attr('style'), 'color:red;') assert.equal(result.first().attr('aaa'), undefined) assert.equal(result.find('tr').first().attr('style'), 'margin-top:10px;') assert.equal(result.find('th').first().attr('colspan'), '2') assert.equal(result.find('th').first().attr('abc'), undefined) assert.equal(result.find('th').first().attr('style'), 'margin-top:12px;') source = "
    aaa
    value
    " should = "
    aaa
    value
    " result = App.Utils.htmlCleanup(source) //equal(result.get(0).outerHTML, should, source) / string order is different on browsers assert.equal(result.first().attr('bgcolor'), 'green') assert.equal(result.first().attr('style'), 'color:red;') assert.equal(result.first().attr('aaa'), undefined) assert.equal(result.find('tr').first().attr('style'), undefined) assert.equal(result.find('th').first().attr('colspan'), '2') assert.equal(result.find('th').first().attr('abc'), undefined) assert.equal(result.find('th').first().attr('style'), undefined) // https://github.com/zammad/zammad/issues/4445 source = 'This is a black font colour with white background' should = 'This is a black font colour with white background' result = App.Utils.htmlCleanup(source) assert.equal(result.html(), should, source) source = '
    This is a black font colour with white background
    ' should = '
    This is a black font colour with white background
    ' result = App.Utils.htmlCleanup(source) assert.equal(result.html(), should, source) }); // wrap QUnit.test("wrap", assert => { var source = "some text" var should = 'some text' var result = App.Utils.wrap(source) assert.equal(result, should, source) source = "some text\nsome other text\n" should = "some text\nsome other text\n" result = App.Utils.wrap(source) assert.equal(result, should, source) source = "some text with some line to wrap" should = "some text with\nsome line to\nwrap" result = App.Utils.wrap(source, 14) assert.equal(result, should, source) source = "some text\nsome other text\n" should = "some text\nsome other text\n" result = App.Utils.wrap(source) assert.equal(result, should, source) source = "1234567890 1234567890 1234567890 1234567890" should = "1234567890 1234567890 1234567890 1234567890" result = App.Utils.wrap(source) assert.equal(result, should, source) source = "123456789012 123456789012 123456789012" should = "123456789012\n123456789012\n123456789012" result = App.Utils.wrap(source, 14) assert.equal(result, should, source) }); // remove empty lines QUnit.test("remove empty lines", assert => { var source = "\ntest 123\n" var should = "test 123\n" var result = App.Utils.removeEmptyLines(source) assert.equal(result, should, source) source = "\ntest\n\n123\n" should = "test\n123\n" result = App.Utils.removeEmptyLines(source) assert.equal(result, should, source) }); // quote QUnit.test("quote", assert => { var source = "some text" var should = '> some text' var result = App.Utils.quote(source) assert.equal(result, should, source) source = "some text\nsome other text\n" should = "> some text\n> some other text" result = App.Utils.quote(source) assert.equal(result, should, source) source = "\n\nsome text\nsome other text\n \n" should = "> some text\n> some other text" result = App.Utils.quote(source) assert.equal(result, should, source) source = "Welcome!\n\nThank you for installing Zammad.\n\nYou will find ..." should = "> Welcome!\n>\n> Thank you for installing Zammad.\n>\n> You will find ..." result = App.Utils.quote(source) assert.equal(result, should, source) source = "Welcome! Thank you for installing Zammad. You will find ..." should = "> Welcome! Thank you\n> for installing\n> Zammad. You will\n> find ..." result = App.Utils.quote(source, 20) assert.equal(result, should, source) }); // check signature QUnit.test("check signature", assert => { var message = "
    test 123
    " var signature = '
    --
    Some Signature
    some department
    ' var result = App.Utils.signatureCheck(message, signature) assert.equal(result, true) message = "
    test 123
    --
    Some Signature
    some department\n
    " signature = '
    --
    Some Signature
    some department
    ' result = App.Utils.signatureCheck(message, signature) assert.equal(result, false) message = "
    test 123
    --
    Some Signature\n
    some department\n
    " signature = '
    --
    Some Signature
    some department
    ' result = App.Utils.signatureCheck(message, signature) assert.equal(result, false) message = "
    test 123
    --

    Some Signature

    \n

    some department
    \n

    \n
    " signature = '
    --
    Some Signature
    some department
    ' result = App.Utils.signatureCheck(message, signature) assert.equal(result, false) message = "" signature = '
    --
    Some Signature
    some department
    ' result = App.Utils.signatureCheck(message, signature) assert.equal(result, true) message = "" signature = "--\nSome Signature\nsome department" result = App.Utils.signatureCheck(message, signature) assert.equal(result, true) }); QUnit.test('remove signature', assert => { var message = '
    test 123
    ' var should = '
    test 123
    ' var result = App.Utils.signatureRemoveByHtml(message) assert.equal(result, should) var message = '
    test 123

    ' var should = '
    test 123

    ' var result = App.Utils.signatureRemoveByHtml(message) assert.equal(result, should) var message = 'test 123' var should = 'test 123' var result = App.Utils.signatureRemoveByHtml(message) assert.equal(result, should) var message = '
    test 123
    Test Admin Agent
    -----
    ' var should = '
    test 123
    ' var result = App.Utils.signatureRemoveByHtml(message) assert.equal(result, should) var message = '
    test 123
    Test Admin Agent
    -----
    ' var should = '
    test 123
    ' var result = App.Utils.signatureRemoveByHtml(message) assert.equal(result, should) var message = '
    test 123

    Test Admin Agent
    -----
    ' var should = '
    test 123
    ' var result = App.Utils.signatureRemoveByHtml(message) assert.equal(result, should) var message = 'test 123
    Test Admin Agent
    -----
    ' var should = 'test 123' var result = App.Utils.signatureRemoveByHtml(message) assert.equal(result, should) }) // identify signature QUnit.test("identify signature by plaintext", assert => { var message = "
    test 123
    " var should = '
    test 123
    ' var result = App.Utils.signatureIdentifyByPlaintext(message) assert.equal(result, should) message = "
    test 123
    --
    Bob Smith
    " should = '
    test 123
    --
    Bob Smith
    ' result = App.Utils.signatureIdentifyByPlaintext(message) assert.equal(result, should) message = "
    test 123
    1
    2
    3
    4
    5
    6
    7
    8
    9

    --
    Bob Smith
    " should = '
    test 123
    1
    2
    3
    4
    5
    6
    7
    8
    9

    --
    Bob Smith
    ' result = App.Utils.signatureIdentifyByPlaintext(message) assert.equal(result, should) message = "
    test 123

    --no not match--
    --
    Bob Smith
    " should = '
    test 123

    --no not match--
    --
    Bob Smith
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "
    test 123

    --no not match--
    --
    Bob Smith
    " should = '
    test 123

    --no not match--
    --
    Bob Smith
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "
    test 123

    --
    Bob Smith




    --
    Bob Smith
    " should = '
    test 123

    --
    Bob Smith




    --
    Bob Smith
    ' //should = '
    test 123










    --
    Bob Smith




    --
    Bob Smith
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "
    test 123
    test 123
    --
    Bob Smith
    " should = "
    test 123
    test 123
    --
    Bob Smith
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "

    test 123

    test 123

    --

    Bob Smith

    " should = "

    test 123

    test 123

    --

    Bob Smith

    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "Test reply to zammad

    Am 24.10.2016 18:55 schrieb "Android Support" <android-support@example.com>:

    >
    > Sehr geehrte Damen" should = "Test reply to zammad

    Am 24.10.2016 18:55 schrieb "Android Support" <android-support@example.com>:

    >
    > Sehr geehrte Damen" result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "
    < On 20 Oct 2016, at 12:23, Martin Edenhofer via Zammad Helpdesk wrote:
    " should = "
    < On 20 Oct 2016, at 12:23, Martin Edenhofer via Zammad Helpdesk wrote:
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) // apple // en message = "
    test 123

    --no not match--

    Bob Smith
    On 01/04/15 10:55, Bob Smith wrote:
    lalala

    --

    some test
    " should = '
    test 123

    --no not match--

    Bob Smith
    On 01/04/15 10:55, Bob Smith wrote:
    lalala

    --

    some test
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) // de message = "
    test 123

    --no not match--

    Bob Smith
    Am 03.04.2015 um 20:58 schrieb Bob Smith <bob@example.com>:
    lalala
    " should = '
    test 123

    --no not match--

    Bob Smith
    Am 03.04.2015 um 20:58 schrieb Bob Smith <bob@example.com>:
    lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) // ms // en message = "
    test 123

    --no not match--

    Bob Smith
    From: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
    Sent: Donnerstag, 2. April 2015 10:00
    lalala
    " should = '
    test 123

    --no not match--

    Bob Smith
    From: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
    Sent: Donnerstag, 2. April 2015 10:00
    lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "
    test 123

    --no not match--

    Bob Smith
    From: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
    Sent: Donnerstag, 2. April 2015 10:00
    Subject: lalala
    " should = '
    test 123

    --no not match--

    Bob Smith
    From: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
    Sent: Donnerstag, 2. April 2015 10:00
    Subject: lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "
    test 123

    --no not match--

    Bob Smith
    From: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
    Sent: Donnerstag, 2. April 2015 10:00
    1
    2
    3
    4
    4
    Subject: lalala
    " should = '
    test 123

    --no not match--

    Bob Smith
    From: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
    Sent: Donnerstag, 2. April 2015 10:00
    1
    2
    3
    4
    4
    Subject: lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) // de message = "
    test 123

    --no not match--

    Bob Smith
    Von: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
    Gesendet: Donnerstag, 2. April 2015 10:00
    Betreff: lalala
    " should = '
    test 123

    --no not match--

    Bob Smith
    Von: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
    Gesendet: Donnerstag, 2. April 2015 10:00
    Betreff: lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "
    1

    Von: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
    \n
    Gesendet: Donnerstag, 2. April 2015 11:32
    " should = "
    1

    Von: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
    \n
    Gesendet: Donnerstag, 2. April 2015 11:32
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "
    1

    Von: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
    \n
    Gesendet: Donnerstag, 2. April 2015 11:32
    Betreff: lalala
    " should = "
    1

    Von: Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
    \n
    Gesendet: Donnerstag, 2. April 2015 11:32
    Betreff: lalala
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "
    1

    Von: Martin Edenhofer via Zammad Support <mailto:support@zammad.inc>
    \n
    An: somebody
    Datum: Donnerstag, 2. April 2015 11:32
    Betreff: lalala
    " should = "
    1

    Von: Martin Edenhofer via Zammad Support <mailto:support@zammad.inc>
    \n
    An: somebody
    Datum: Donnerstag, 2. April 2015 11:32
    Betreff: lalala
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "
    Von: "Johannes Nickel via Zammad Projects" <projects@zammad.inc>
    An: \"Lisa Smith\" <lisa.smith@example.com>
    Gesendet: Donnerstag, 2. April 2015 10:11:12
    Betreff: Angebot Redundanz / Paket mit Silver Subscription [Ticket#424242]

    Hallo Frau Smith,
    " should = "
    Von: "Johannes Nickel via Zammad Projects" <projects@zammad.inc>
    An: \"Lisa Smith\" <lisa.smith@example.com>
    Gesendet: Donnerstag, 2. April 2015 10:11:12
    Betreff: Angebot Redundanz / Paket mit Silver Subscription [Ticket#424242]

    Hallo Frau Smith,
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "
    Hi Johannes,

    das Angebot für den halben Tag bitte an uns.
    Der Termin hat sich jetzt auf 10-12 Uhr verschoben, hab ich dir weitergeleitet.

    Viele Grüße
    Max

    > On 07 Oct 2015, at 11:55, Johannes Smith <smith@example.com <mailto:smith@example.com>> wrote:
    >
    > Hi,
    >
    > assert.OK. Wer kriegt das Angebot? Ist das wirklich nur ein halber Tag?
    " should = "
    Hi Johannes,

    das Angebot für den halben Tag bitte an uns.
    Der Termin hat sich jetzt auf 10-12 Uhr verschoben, hab ich dir weitergeleitet.

    Viele Grüße
    Max

    > On 07 Oct 2015, at 11:55, Johannes Smith <smith@example.com <mailto:smith@example.com>> wrote:
    >
    > Hi,
    >
    > assert.OK. Wer kriegt das Angebot? Ist das wirklich nur ein halber Tag?
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "Dear Mr. Smith,

    it seems to be, dass Sie den AutoIncrement Nummerngenerator für Ihre ITSMChangeManagement Installation verwenden. Seit ABC 3.2 wird führend vor der sich in der Datei <ABC_CONFIG_Home>/war/log/ITSMChangeCounter.log  befindenden Zahl die SystemID (SysConfig) geschrieben. Dies ist ein Standardverhalten, dass auch bei der Ticketnummer verwendet wird.

    Please ask me if you have questions.

    Viele Grüße,
      Thorsten Smith\n
    \n
    --\n
    Enterprise Services for ABC\n
    \n
    Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany\n
    \n
    P: +49 (0) 30 111 111 111-0\n
    F: +49 (0) 30 111 111 111-8\n
    W: http://zammad.com \n
    \n
    Location: Berlin - HRB 12345678 B Amtsgericht Berlin-Charlottenburg\n
    Managing Director: Martin Edenhofer\n
    " should = "Dear Mr. Smith,

    it seems to be, dass Sie den AutoIncrement Nummerngenerator für Ihre ITSMChangeManagement Installation verwenden. Seit ABC 3.2 wird führend vor der sich in der Datei <ABC_CONFIG_Home>/war/log/ITSMChangeCounter.log  befindenden Zahl die SystemID (SysConfig) geschrieben. Dies ist ein Standardverhalten, dass auch bei der Ticketnummer verwendet wird.

    Please ask me if you have questions.

    Viele Grüße,
      Thorsten Smith\n
    \n
    --\n
    Enterprise Services for ABC\n
    \n
    Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany\n
    \n
    P: +49 (0) 30 111 111 111-0\n
    F: +49 (0) 30 111 111 111-8\n
    W: http://zammad.com \n
    \n
    Location: Berlin - HRB 12345678 B Amtsgericht Berlin-Charlottenburg\n
    Managing Director: Martin Edenhofer\n
    " result = App.Utils.signatureIdentifyByPlaintext(message, true, true) assert.equal(result, should) message = "Dear Mr. Smith, nice to read you,
      Thorsten Smith\n
    \n
    --\n
    " should = "Dear Mr. Smith, nice to read you,
      Thorsten Smith\n
    \n
    --\n
    " result = App.Utils.signatureIdentifyByPlaintext(message, true, true) assert.equal(result, should) message = "Dear Mr. Smith, nice to read you,
      Thorsten Smith\n
    \n
    --\n
    " should = "Dear Mr. Smith, nice to read you,
      Thorsten Smith\n
    \n
    --\n
    " result = App.Utils.signatureIdentifyByPlaintext(message, false, true) assert.equal(result, should) // fr message = "
    test 123

    --no not match--

    Bob Smith
    De : Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
    Envoyé : mercredi 29 avril 2015 17:31
    Objet : lalala
    " should = '
    test 123

    --no not match--

    Bob Smith
    De : Martin Edenhofer via Zammad Support [mailto:support@zammad.inc]
    Envoyé : mercredi 29 avril 2015 17:31
    Objet : lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) // thunderbird // de message = "

    Viele Grüße,
    Christian

    Am 04.03.2015 um 12:47 schrieb Martin Edenhofer via Zammad Sales:
    > Hallo Christian,
    " should = "

    Viele Grüße,
    Christian

    Am 04.03.2015 um 12:47 schrieb Martin Edenhofer via Zammad Sales:
    > Hallo Christian,
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) // en - Thunderbird default - http://kb.mozillazine.org/Reply_header_settings message = "

    Viele Grüße,
    Christian

    On 01-01-2007 11:00 AM, Alf Aardvark wrote:
    > Hallo Christian,
    " should = "

    Viele Grüße,
    Christian

    On 01-01-2007 11:00 AM, Alf Aardvark wrote:
    > Hallo Christian,
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) // en - http://kb.mozillazine.org/Reply_header_settings message = "

    Viele Grüße,
    Christian

    Alf Aardvark wrote, on 01-01-2007 11:00 AM:
    > Hallo Christian,
    " should = "

    Viele Grüße,
    Christian

    Alf Aardvark wrote, on 01-01-2007 11:00 AM:
    > Hallo Christian,
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) // otrs // en message = "
    test 123

    --no not match--

    Bob Smith
    01/04/15 10:55 - Bob Smith wrote:
    lalala
    " should = '
    test 123

    --no not match--

    Bob Smith
    01/04/15 10:55 - Bob Smith wrote:
    lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) // de message = "
    test 123

    --no not match--

    Bob Smith
    01/04/15 10:55 - Bob Smith schrieb:
    lalala
    " should = '
    test 123

    --no not match--

    Bob Smith
    01/04/15 10:55 - Bob Smith schrieb:
    lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "
    test 123

    24.02.2015 14:20 - Roy Kaldung via Zammad Sales schrieb:  
    " should = "
    test 123

    24.02.2015 14:20 - Roy Kaldung via Zammad Sales schrieb:  
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) // zammad message = "
    test 123

    --no not match--

    Bob Smith
    lalala
    " should = "
    test 123

    --no not match--

    Bob Smith
    lalala
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "
    test 123

    --no not match--

    Bob Smith
    lalala
    " should = "
    test 123

    --no not match--

    Bob Smith
    lalala
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) // gmail message = "
    test 123

    --no not match--

    Bob Smith
    lalala
    " should = "
    test 123

    --no not match--

    Bob Smith
    lalala
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "
    test 123

    --no not match--

    Bob Smith
    lalala
    " should = "
    test 123

    --no not match--

    Bob Smith
    lalala
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) message = "
    test 123

    --no not match--

    Bob Smith
    Am 24. Dezember 2015 um 07:45 schrieb kathrine <kathrine@example.com>:
    lalala
    " should = "
    test 123

    --no not match--

    Bob Smith
    Am 24. Dezember 2015 um 07:45 schrieb kathrine <kathrine@example.com>:
    lalala
    " result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) // word 14 // en message = "
    test 123

    --no not match--

    Bob Smith
    Bob Smith wrote:
    lalala
    " should = '
    test 123

    --no not match--

    Bob Smith
    Bob Smith wrote:
    lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) // de message = "
    test 123

    --no not match--

    Bob Smith
    Bob Smith schrieb:
    lalala
    " should = '
    test 123

    --no not match--

    Bob Smith
    Bob Smith schrieb:
    lalala
    ' result = App.Utils.signatureIdentifyByPlaintext(message, true) assert.equal(result, should) }); QUnit.test("identify signature by HTML", assert => { var message = "
    test 123
    " var should = message var result = App.Utils.signatureIdentifyByHtml(message) assert.equal(result, should) // test if, according to jQuery, invalid HTML does not cause a a crash // https://github.com/zammad/zammad/issues/3393 message = "
    test 123
    " should = message result = App.Utils.signatureIdentifyByHtml(message) assert.equal(result, should) // simple case 1 message = '
    actual content
    quoted content
    ' should = '
    actual content
    quoted content
    ' result = App.Utils.signatureIdentifyByHtml(message) assert.equal(result, should) // simple case 2 message = '
    actual content
    quoted content



    ' should = '
    actual content
    quoted content



    ' result = App.Utils.signatureIdentifyByHtml(message) assert.equal(result, should) // simple case 3 message = '
    actual content
    quoted content

    actual content 2
    ' should = message result = App.Utils.signatureIdentifyByHtml(message) assert.equal(result, should) // simple case 4 message = ' content 0
    content 1
    content 2
    quoted content



    ' should = ' content 0
    content 1
    content 2
    quoted content



    ' result = App.Utils.signatureIdentifyByHtml(message) assert.equal(result, should) // Invalid html signature detection for exchange warning boxes #3571 message = '
    CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

    actual content

    actual content 2

     

    actual quote

    actual quote

     

     

    ' should = '
    CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

    actual content

    actual content 2

     

    actual quote

    actual quote

     

     

    ' result = App.Utils.signatureIdentifyByHtml(message) assert.equal(result, should) // Invalid html signature detection for exchange warning boxes #3571 message = '
    CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

    actual content

    actual content 2

     

    actual quote

    actual quote

     

     

    ' should = '
    CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

    actual content

    actual content 2

     

    actual quote

    actual quote

     

     

    ' result = App.Utils.signatureIdentifyByHtml(message) assert.equal(result, should) // Gmail via Safari on MacOS 10.12 message = '
    Reply with gmail via Safari on MacOS 10.12

    \
    \
    Am Mi., 5. Sep. 2018 um 09:22 Uhr schrieb Billy Zhou <bz@zammad.com>:
    \
    \
    test email content
    \
    \
    \
    ' should = '
    Reply with gmail via Safari on MacOS 10.12

    \
    \
    Am Mi., 5. Sep. 2018 um 09:22 Uhr schrieb Billy Zhou <bz@zammad.com>:
    \
    \
    test email content
    \
    \
    \
    ' result = App.Utils.signatureIdentifyByHtml(message) assert.equal(result, should) // Yahoo Mail via Safari on MacOS 10.12 message = '
    Reply with Yahoo Mail via Safari on MacOS 10.12


    Billy Zhou <bz@zammad.com> schrieb am 9:08 Mittwoch, 5.September 2018:


    test email content



    ' should = '
    Reply with Yahoo Mail via Safari on MacOS 10.12


    Billy Zhou <bz@zammad.com> schrieb am 9:08 Mittwoch, 5.September 2018:


    test email content



    ' result = App.Utils.signatureIdentifyByHtml(message) assert.equal(result, should) // Thunderbird 52 on MacOS 10.12 message = 'Reply with Thunderbird 52 on MacOS 10.12
    \
    \
    Am 04.09.18 um 15:32 schrieb Billy\ Zhou:
    \
    \
    test\ email content\
    \
    \
    \
    ' should = 'Reply with Thunderbird 52 on MacOS 10.12
    \
    \
    Am 04.09.18 um 15:32 schrieb Billy\ Zhou:
    \
    \
    test\ email content\
    \
    \
    \
    ' result = App.Utils.signatureIdentifyByHtml(message) assert.equal(result, should) // Apple Mail on MacOS 10 message = '
    Reply by Apple Mail on MacOS 10.


    On 4. Sep 2018, at 15:32, Billy Zhou <bz@zammad.com> wrote:

    test email content


    ' should = '
    Reply by Apple Mail on MacOS 10.


    On 4. Sep 2018, at 15:32, Billy Zhou <bz@zammad.com> wrote:

    test email content


    ' result = App.Utils.signatureIdentifyByHtml(message) assert.equal(result, should) // Office 365 (10325.20118) on Windows 10 Build 1803 // With German marker: -----Ursprüngliche Nachricht----- // Using fallback to signatureIdentifyByPlaintext message = '
    \

    Reply with Office 365 (10325.20118) on Windows 10 Build 1803

    \

    \

    fett

    \

    \

    --

    \

    Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany

    \

    \

    P: +49 (0) 30 55 57 160-0

    \

    F: +49 (0) 30 55 57 160-99

    \

    W: https://zammad.com

    \

    \

    Location: Berlin - HRB 163946 B Amtsgericht Berlin-Charlottenburg

    \

    Managing Director: Martin Edenhofer

    \

    \

    -----Ursprüngliche Nachricht-----
    Von: Billy Zhou <bz@zammad.com>
    Gesendet: Dienstag, 4. September 2018 15:33
    An: me@zammad.com
    Betreff: test email title

    \

    \

    test email content

    \

    \
    ' should = '
    \

    Reply with Office 365 (10325.20118) on Windows 10 Build 1803

    \

    \

    fett

    \

    \

    --

    \

    Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany

    \

    \

    P: +49 (0) 30 55 57 160-0

    \

    F: +49 (0) 30 55 57 160-99

    \

    W: https://zammad.com

    \

    \

    Location: Berlin - HRB 163946 B Amtsgericht Berlin-Charlottenburg

    \

    Managing Director: Martin Edenhofer

    \

    \

    -----Ursprüngliche Nachricht-----
    Von: Billy Zhou <bz@zammad.com>
    Gesendet: Dienstag, 4. September 2018 15:33
    An: me@zammad.com
    Betreff: test email title

    \

    \

    test email content

    \

    \
    ' result = App.Utils.signatureIdentifyByHtml(message) assert.equal(result, should) // Office 365 (10325.20118) on Windows 10 Build 1803 // With English marker: -----Original Message----- // Using fallback to signatureIdentifyByPlaintext message = '
    \

    Reply with Office 365 (10325.20118) on Windows 10 Build 1803

    \

    \

    fett

    \

    \

    --

    \

    Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany

    \

    \

    P: +49 (0) 30 55 57 160-0

    \

    F: +49 (0) 30 55 57 160-99

    \

    W: https://zammad.com

    \

    \

    Location: Berlin - HRB 163946 B Amtsgericht Berlin-Charlottenburg

    \

    Managing Director: Martin Edenhofer

    \

    \

    -----Original Message-----
    Von: Billy Zhou <bz@zammad.com>
    Gesendet: Dienstag, 4. September 2018 15:33
    An: me@zammad.com
    Betreff: test email title

    \

    \

    test email content

    \

    \
    ' should = '
    \

    Reply with Office 365 (10325.20118) on Windows 10 Build 1803

    \

    \

    fett

    \

    \

    --

    \

    Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany

    \

    \

    P: +49 (0) 30 55 57 160-0

    \

    F: +49 (0) 30 55 57 160-99

    \

    W: https://zammad.com

    \

    \

    Location: Berlin - HRB 163946 B Amtsgericht Berlin-Charlottenburg

    \

    Managing Director: Martin Edenhofer

    \

    \

    -----Original Message-----
    Von: Billy Zhou <bz@zammad.com>
    Gesendet: Dienstag, 4. September 2018 15:33
    An: me@zammad.com
    Betreff: test email title

    \

    \

    test email content

    \

    \
    ' result = App.Utils.signatureIdentifyByHtml(message) assert.equal(result, should) // Office 365 (10325.20118) on Windows 10 Build 1803 // With German marker: -----Ursprüngliche Nachricht----- // Without any existing // Using fallback to signatureIdentifyByPlaintext message = '
    \

    Reply with Office 365 (10325.20118) on Windows 10 Build 1803

    \

    \

    fett

    \

    \

    --

    \

    Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany

    \

    \

    P: +49 (0) 30 55 57 160-0

    \

    F: +49 (0) 30 55 57 160-99

    \

    W: https://zammad.com

    \

    \

    Location: Berlin - HRB 163946 B Amtsgericht Berlin-Charlottenburg

    \

    Managing Director: Martin Edenhofer

    \

    \

    -----Ursprüngliche Nachricht-----
    Von: Billy Zhou <bz@zammad.com>
    Gesendet: Dienstag, 4. September 2018 15:33
    An: me@zammad.com
    Betreff: test email title

    \

    \

    test email content

    \

    \
    ' should = '
    \

    Reply with Office 365 (10325.20118) on Windows 10 Build 1803

    \

    \

    fett

    \

    \

    --

    \

    Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany

    \

    \

    P: +49 (0) 30 55 57 160-0

    \

    F: +49 (0) 30 55 57 160-99

    \

    W: https://zammad.com

    \

    \

    Location: Berlin - HRB 163946 B Amtsgericht Berlin-Charlottenburg

    \

    Managing Director: Martin Edenhofer

    \

    \

    -----Ursprüngliche Nachricht-----
    Von: Billy Zhou <bz@zammad.com>
    Gesendet: Dienstag, 4. September 2018 15:33
    An: me@zammad.com
    Betreff: test email title

    \

    \

    test email content

    \

    \
    ' result = App.Utils.signatureIdentifyByHtml(message) assert.equal(result, should) }); // check attachment references QUnit.test("check check attachment reference", assert => { var message = 'some not existing' var result = false var verify = App.Utils.checkAttachmentReference(message) assert.equal(verify, result) message = 'some attachment for you' result = 'attachment' verify = App.Utils.checkAttachmentReference(message) assert.equal(verify, result) message = 'your attachment.' result = 'attachment' verify = App.Utils.checkAttachmentReference(message) assert.equal(verify, result) message = 'some otherattachment for you' result = false verify = App.Utils.checkAttachmentReference(message) assert.equal(verify, result) message = 'some attachmentother for you' result = false verify = App.Utils.checkAttachmentReference(message) assert.equal(verify, result) message = 'someattachment' result = false verify = App.Utils.checkAttachmentReference(message) assert.equal(verify, result) message = 'As enclosed you will find.' result = 'enclosed' verify = App.Utils.checkAttachmentReference(message) assert.equal(verify, result) message = '
    Hi Test,
    On Monday, 22 July 2019, 14:07:54, Test User wrote:

    Test attachment
    ' result = false verify = App.Utils.checkAttachmentReference(message) assert.equal(verify, result) message = '
    Hi Test,
    cite attachment
    ' result = false verify = App.Utils.checkAttachmentReference(message) assert.equal(verify, result) message = '
    Hi Test,
    ecxgmail_quote attachment
    ' result = false verify = App.Utils.checkAttachmentReference(message) assert.equal(verify, result) message = '
    Hi Test,
    ecxgmail_quote attachment
    ' result = false verify = App.Utils.checkAttachmentReference(message) assert.equal(verify, result) }); // replace tags QUnit.test("check replace tags", assert => { var formatNumber = function(num, digits) { while (num.toString().length < digits) { num = '0' + num } return num } var formatTimestamp = function(timestamp) { localTime = new Date(Date.parse(timestamp)) d = formatNumber(localTime.getDate(), 2) m = formatNumber(localTime.getMonth() + 1, 2) yfull = localTime.getFullYear() M = formatNumber(localTime.getMinutes(), 2) H = formatNumber(localTime.getHours(), 2) l = (H + 11) % 12 + 1 if (l < 10) { l = ' ' + l } P = H >= 12 ? 'pm' : 'am' return m + '/' + d + '/' + yfull + ' ' + l + ':' + M + ' ' + P } var message = "
    #{user.firstname} #{user.lastname}
    " var result = '
    Bob Smith
    ' var data = { user: { firstname: 'Bob', lastname: 'Smith', }, } var verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) message = "
    #{user.firstname} #{user.lastname}
    " result = '
    Bob Smith
    ' data = { user: { firstname: function() { return 'Bob' }, lastname: function() { return 'Smith' }, }, } verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) message = "
    #{user.firstname} #{user.lastname}
    " result = '
    Bob -
    ' data = { user: { firstname: 'Bob', }, } verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) message = "
    #{user.firstname} #{user.lastname}
    " result = '
    Bob 0
    ' data = { user: { firstname: 'Bob', lastname: 0, }, } verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) message = "
    #{user.firstname} #{user.lastname}
    " result = '
    Bob -
    ' data = { user: { firstname: 'Bob', lastname: '', }, } verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) message = "
    #{user.firstname} #{user.not.existing.test}
    " result = '
    Bob -
    ' data = { user: { firstname: 'Bob', }, } verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) message = "
    #{user.firstname} #{not.existing.test}
    " result = '
    Bob -
    ' data = { user: { firstname: 'Bob', }, } verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) message = "
    #{user.firstname} #{not.existing.test}
    " result = '
    Bob -
    ' data = { user: { firstname: 'Bob', not: null, }, } verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) message = "
    #{user.firstname} #{not.existing.test}
    " result = '
    Bob -
    ' data = { user: { firstname: 'Bob', not: {}, }, } verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) message = "
    #{user.firstname} #{user.lastname}
    " result = '
    Bob Smith
    ' data = { user: { firstname: 'Bob', lastname: 'Smith', }, } verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) message = "
    issue #4973 #{user,firstname}
    " result = '
    issue #4973 -
    ' data = { user: { firstname: 'Bob', lastname: 'Smith', }, } verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) user = new App.User({ firstname: 'Bob', lastname: 'Smith Good', created_at: '2018-10-31T10:00:00Z', }) message = "
    #{user.firstname} #{user.created_at}
    " result = '
    Bob ' + formatTimestamp('2018-10-31T10:00:00Z') + '
    ' data = { user: user } verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) message = "
    #{user.firstname} #{user.created_at.date}
    " result = '
    Bob -
    ' data = { user: user } verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) message = "
    #{user.firstname} #{user.created.date}
    " result = '
    Bob -
    ' data = { user: user } verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) message = "some text" result = 'some text' data = { user: user } verify = App.Utils.replaceTags(message, data, true) assert.equal(verify, result) var attribute_external_source = { name: 'external_data_source', display: 'external_data_source', tag: 'autocompletion_ajax_external_data_source', null: true }; App.Ticket.configure_attributes.push(attribute_external_source) data = { ticket: { external_data_source: { value: 1234, label: 'Example Label' } } } message = "some text" result = 'some text' verify = App.Utils.replaceTags(message, data, true) assert.equal(verify, result) message = "some text" result = 'some text' verify = App.Utils.replaceTags(message, data, true) assert.equal(verify, result) data = { ticket: {} } message = "Test: #{ticket.external_data_source}" result = 'Test: -' verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) data = { ticket: {} } message = "Test: #{ticket.external_data_source.value}" result = 'Test: -' verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) var attribute_select = { name: 'select', display: 'select', tag: 'select', null: true, nulloption: true, options: { a: 'Value A', b: 'Value B' }, value: null, historical_options: { a: 'Value A', b: 'Value B', c: 'Value C' } } App.Ticket.configure_attributes.push(attribute_select) data = { ticket: { select: 'b', } } message = "Test: #{ticket.select}" result = 'Test: b' verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) message = "Test: #{ticket.select.value}" result = 'Test: Value B' verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) data = { ticket: {} } message = "Test: #{ticket.select}" result = 'Test: -' verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) data = { ticket: {} } message = "Test: #{ticket.select.value}" result = 'Test: -' verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) var attribute_multiselect = { name: 'multiselect', display: 'multiselect', tag: 'multiselect', null: true, nulloption: true, options: { a: 'Value A', b: 'Value B', c: 'Value C' }, value: null, historical_options: { a: 'Value A', b: 'Value B', c: 'Value C' } } App.Ticket.configure_attributes.push(attribute_multiselect) data = { ticket: { multiselect: ['a', 'b'], } } message = "Test: #{ticket.multiselect}" result = 'Test: a, b' verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) message = "Test: #{ticket.multiselect.value}" result = 'Test: Value A, Value B' verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) data = { ticket: {} } message = "Test: #{ticket.multiselect}" result = 'Test: -' verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) data = { ticket: {} } message = "Test: #{ticket.multiselect.value}" result = 'Test: -' verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) message = "
    #{user.avatar(100, 100)}
    " result = '
    ' data = { user: user } verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) user = new App.User({ firstname: 'Bob', lastname: 'Smith Good', created_at: '2018-10-31T10:00:00Z', image: '808d0f10f81c8b1117608cb22a73076e' }) message = "
    #{user.avatar(100, 100)}
    " result = '
    ' data = { user: user } verify = App.Utils.replaceTags(message, data) assert.equal(verify, result) }); // check attibute validation QUnit.test("check attibute validation", assert => { var string = '123' var result = '123' var verify = App.Utils.htmlAttributeCleanup(string) assert.equal(verify, result, string) string = '123!' result = '123' verify = App.Utils.htmlAttributeCleanup(string) assert.equal(verify, result, string) string = '12 3!' result = '123' verify = App.Utils.htmlAttributeCleanup(string) assert.equal(verify, result, string) string = '12-3!' result = '12-3' verify = App.Utils.htmlAttributeCleanup(string) assert.equal(verify, result, string) string = '12_3!' result = '12_3' verify = App.Utils.htmlAttributeCleanup(string) assert.equal(verify, result, string) string = '^12_3!' result = '12_3' verify = App.Utils.htmlAttributeCleanup(string) assert.equal(verify, result, string) string = '^1\n 2_3!' result = '12_3' verify = App.Utils.htmlAttributeCleanup(string) assert.equal(verify, result, string) string = 'abc?' result = 'abc' verify = App.Utils.htmlAttributeCleanup(string) assert.equal(verify, result, string) string = 'abc."' result = 'abc' verify = App.Utils.htmlAttributeCleanup(string) assert.equal(verify, result, string) string = '#abc!^' result = 'abc' verify = App.Utils.htmlAttributeCleanup(string) assert.equal(verify, result, string) string = 'abc()=$' result = 'abc' verify = App.Utils.htmlAttributeCleanup(string) assert.equal(verify, result, string) string = "abc()=$\n123\rß" result = 'abc123' verify = App.Utils.htmlAttributeCleanup(string) assert.equal(verify, result, string) }); // check form diff QUnit.test("check form diff", assert => { var dataNow = { owner_id: 1, pending_date: '2015-01-28T09:39:00Z', } var dataLast = { owner_id: '', pending_date: '2015-01-28T09:39:00Z', } var diff = {} var result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { owner_id: '1', pending_date: '2015-01-28T09:39:00Z', } dataLast = { owner_id: '', pending_date: '2015-01-28T09:39:00Z', } diff = {} result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { pending_date: '2015-01-28T09:39:00Z', } dataLast = { owner_id: 1, pending_date: '2015-01-28T09:39:00Z', } diff = {} result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { owner_id: '', pending_date: '2015-01-28T09:39:00Z', } dataLast = { pending_date: '2015-01-28T09:39:00Z', } diff = { } result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { owner_id: '', state_ids: [1,5,6,7], } dataLast = {} diff = { state_ids: ['1','5','6','7'], } result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { owner_id: 1, state_ids: [1,5,7,6], } dataLast = { owner_id: '', state_ids: [1,5,6,7], } diff = {} result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { owner_id: 1, state_ids: [1,5,6,7], } dataLast = { state_ids: ['1','5','7'], } diff = { state_ids: ['6'], } result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { owner_id: '', state_ids: [1,5,6,7], } dataLast = { owner_id: 1, state_ids: [1,5,6,7], } diff = {} result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { owner_id: '', state_ids: [1,5,6,7], } dataLast = { owner_id: 5, state_ids: [1,5,6,7], } diff = { owner_id: '' } result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { state_id: 4, pending_time: '2015-01-28T11:34:00Z' } dataLast = { state_id: 5, pending_time: undefined } diff = { state_id: '4', pending_time: '2015-01-28T11:34:00Z' } result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { pending_time: undefined } dataLast = { pending_time: null } diff = {} result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { ticket: { pending_time: undefined, }, } dataLast = { ticket: { pending_time: null, }, } diff = {} result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { test: '123', ticket: { pending_time: undefined, }, } dataLast = { test: '123', ticket: { pending_time: null, }, } diff = {} result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { test: '123', } dataLast = {} diff = { test: '123', } result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { test: '123', } dataLast = { test: [1,2,3,4] } diff = { test: '123', } result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { test: '123', } dataLast = { test: { 1: 1, 2: 2, } } diff = { test: '123', } result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { test: [1,2,3,'4'] } dataLast = { test: '123', } diff = { test: ['1','2','3','4'] } result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { test: { 1: 1, 2: 2, } } dataLast = { test: '123', } diff = { test: { 1: '1', 2: '2', } } result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') // regression test for issue #2042 - incorrect notification when closing a tab after setting up an object // A newly created attribute will have the empty string as its value, this should be ignored for formDiff comparison dataNow = { test: '', } dataLast = {} diff = {} result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff for a newly created attribute that is blank') dataNow = { test: '', } dataLast = { test: '123', } diff = { test: '', } result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff for setting a previously valid value to blank') dataNow = { test: '123', ticket: { pending_time: undefined, }, } dataLast = { ticket: { pending_time: null, }, } diff = { test: '123', } result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = undefined dataLast = undefined diff = {} result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = {} dataLast = {"number":"10012","title":"some subject 123äöü","group_id":1,"owner_id":1,"customer_id":2,"state_id":3,"priority_id":2,"article":{"from":"Test Admin Agent","to":"","cc":"","body":"dasdad","content_type":"text/html","ticket_id":12,"type_id":9,"sender_id":1,"internal":false,"form_id":"523405147"},"updated_at":"2015-01-29T09:22:23.000Z","pending_time":"2015-01-28T22:22:00.000Z","id":12} diff = {} result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') // do not compare content of data instances/objects no = function test_object() { this.a = function() { return 123; } this.b = function() { return '1234'; } this.c = function() { return [123]; } this.d = [1,2,3]; this.e = 'abc'; } no1 = new no() no2 = new no() no3 = new no() dataNow = { number:'10013', Article: [no1], } dataLast = { number: "10012", title: "some subject 123äöü", Article: [ no2, no3 ], } diff = { number:'10013', } result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { number:'10013', Article: [no1,2], } dataLast = { number: "10012", title: "some subject 123äöü", Article: [ no2, no3 ], } diff = { number:'10013', Article: ['2'], } result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff') dataNow = { array: [1,2] } dataLast = { array: [2, 3] } diff = { array: ['1', '3'] } result = App.Utils.formDiff(dataNow, dataLast) assert.deepEqual(result, diff, 'check form diff in arrays both ways') }); // check decimal format QUnit.test("check decimal format", assert => { var string = '123' var result = '123.00' var verify = App.Utils.decimal(string) assert.equal(verify, result, string) string = '0.6' result = '0.60' verify = App.Utils.decimal(string) assert.equal(verify, result, string) string = '6' result = '6.00' verify = App.Utils.decimal(string) assert.equal(verify, result, string) string = 6.5 result = '6.50' verify = App.Utils.decimal(string) assert.equal(verify, result, string) string = '111111.6' result = '111111.60' verify = App.Utils.decimal(string) assert.equal(verify, result, string) string = '111111.622' result = '111111.62' verify = App.Utils.decimal(string) assert.equal(verify, result, string) string = 'abc.6' result = 'abc.6' verify = App.Utils.decimal(string) assert.equal(verify, result, string) string = '' result = '' verify = App.Utils.decimal(string) assert.equal(verify, result, string) string = undefined result = '' verify = App.Utils.decimal(string) assert.equal(verify, result, string) string = null result = '' verify = App.Utils.decimal(string) assert.equal(verify, result, string) }); // check formatTime format QUnit.test("check formatTime format", assert => { var string = '123' var result = '123' var verify = App.Utils.formatTime(string, 0) assert.equal(verify, result, string) string = '6' result = '06' verify = App.Utils.formatTime(string, 2) assert.equal(verify, result, string) string = '' result = '00' verify = App.Utils.formatTime(string, 2) assert.equal(verify, result, string) string = undefined result = '' verify = App.Utils.formatTime(string, 2) assert.equal(verify, result, string) string = null result = '' verify = App.Utils.formatTime(string, 2) assert.equal(verify, result, string) }); // check diffPosition QUnit.test("check diffPosition format", assert => { var a = [1,2,3,4] var b = [1,2,3,4,5] var result = [ { position: 4, id: 5, }, ] var verify = App.Utils.diffPositionAdd(a, b) assert.deepEqual(verify, result) a = [2,3,4] b = [1,2,3,4] result = [ { position: 0, id: 1, }, ] verify = App.Utils.diffPositionAdd(a, b) assert.deepEqual(verify, result) a = [2,3,4] b = [1,2,3,4,5] result = [ { position: 0, id: 1, }, { position: 4, id: 5, }, ] verify = App.Utils.diffPositionAdd(a, b) assert.deepEqual(verify, result) a = [2,3,4] b = [1,99,12,2,3,4,5] result = [ { position: 0, id: 1, }, { position: 1, id: 99, }, { position: 2, id: 12, }, { position: 6, id: 5, }, ] verify = App.Utils.diffPositionAdd(a, b) assert.deepEqual(verify, result) a = [4,3,1] b = [1,2,3,4,5] result = false verify = App.Utils.diffPositionAdd(a, b) assert.deepEqual(verify, result) a = ['Ticket-347', 'TicketCreateScreen-2217'] b = ['Ticket-347', 'TicketCreateScreen-2217', 'TicketCreateScreen-71517'] result = [ { position: 2, id: 'TicketCreateScreen-71517', }, ] verify = App.Utils.diffPositionAdd(a, b) assert.deepEqual(verify, result) }); // check textLengthWithUrl format QUnit.test("check textLengthWithUrl format", assert => { var string = '123' var result = 3 var verify = App.Utils.textLengthWithUrl(string) assert.equal(verify, result) string = '123 http is not here' result = 20 verify = App.Utils.textLengthWithUrl(string) assert.equal(verify, result) string = '123 http://host is not here' result = 39 verify = App.Utils.textLengthWithUrl(string) assert.equal(verify, result) string = '123 http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX is not here' result = 39 verify = App.Utils.textLengthWithUrl(string) assert.equal(verify, result) string = 'http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' result = 23 verify = App.Utils.textLengthWithUrl(string) assert.equal(verify, result) string = 'http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX, some other text' result = 23 + 17 verify = App.Utils.textLengthWithUrl(string) assert.equal(verify, result) string = 'some other text,http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' result = 23 + 16 verify = App.Utils.textLengthWithUrl(string) assert.equal(verify, result) string = 'some other text, http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX?abc=123;aaa=ab+c usw' result = 23 + 21 verify = App.Utils.textLengthWithUrl(string) assert.equal(verify, result) }); // check getRecipientArticle format QUnit.test('check getRecipientArticle format', assert => { var customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } var ticket = { customer: customer, } var article = { type: { name: 'phone', }, sender: { name: 'Customer', }, from: customer.email, to: 'some group', message_id: 'message_id1', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', }, } var result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id1', } var verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { type: { name: 'phone', }, sender: { name: 'Customer', }, from: customer.email, message_id: 'message_id2', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', }, } result = { to: customer.email, cc: '', body: '', in_reply_to: 'message_id2', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id3', type: { name: 'phone', }, sender: { name: 'Agent', }, from: 'article_created_by@example.com', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', }, } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id3', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id4', created_by: customer, type: { name: 'web', }, sender: { name: 'Customer', }, from: customer.email, to: 'some group', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', }, } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id4', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id5', type: { name: 'web', }, sender: { name: 'Customer', }, from: customer.email, created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', } } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id5', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id6', type: { name: 'email', }, sender: { name: 'Customer', }, from: customer.email, to: 'some group', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', } } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id6', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id7', type: { name: 'email', }, sender: { name: 'Customer', }, from: 'some other invalid part, ' + customer.email, to: 'some group', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', } } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id7', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id7.1', type: { name: 'email', }, sender: { name: 'Customer', }, from: 'some other invalid part, Some Realname ' + customer.email, to: 'some group', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', } } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id7.1', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) console.log(verify) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id7.2', type: { name: 'email', }, sender: { name: 'Customer', }, from: 'some other invalid part, Some Realname ' + customer.email + ' , abc', to: 'some group', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', } } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id7.2', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) console.log(verify) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id8', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'customer2@example.com', to: 'customer@example.com', } result = { to: 'customer2@example.com', cc: '', body: '', in_reply_to: 'message_id8', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id9', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'agent@example.com', to: 'customer@example.com', } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id9', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id10', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'Agent@Example.com', to: 'customer@example.com', cc: 'zammad@example.com', } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id10', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id11', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'Agent@Example.com', to: 'customer@example.com, agent@example.com', cc: 'zammad@example.com', } result = { to: 'customer@example.com, agent@example.com', cc: 'zammad@example.com', body: '', in_reply_to: 'message_id11', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type, [], true) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id12', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'Agent@Example.com', to: 'customeR@EXAMPLE.com, agent@example.com', cc: 'zammad@example.com, customer@example.com', } result = { to: 'customer@example.com, agent@example.com', cc: 'zammad@example.com', body: '', in_reply_to: 'message_id12', } verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, [], true) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id13', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'Agent@Example.com', to: 'customeR@EXAMPLE.com, agent@example.com, zammad2@EXAMPLE.com', cc: 'zammad@example.com, customer2@example.com', } result = { to: 'customer@example.com, agent@example.com', cc: 'customer2@example.com', body: '', in_reply_to: 'message_id13', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, true) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'AGENT@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id14', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'Agent@Example.com', to: 'customeR@EXAMPLE.com, agent@example.com, zammad2@EXAMPLE.com', cc: 'zammad@example.com, customer2@example.com', } result = { to: 'customer@example.com, agent@example.com', cc: 'customer2@example.com', body: '', in_reply_to: 'message_id14', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, true) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'zammad@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id15', created_by: customer, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'zammad@EXAMPLE.com', to: 'customeR@EXAMPLE.com, agent@example.com, zammad2@EXAMPLE.com', cc: 'zammad@example.com, customer2@example.com', } result = { to: 'customer@example.com, agent@example.com', cc: 'customer2@example.com', body: '', in_reply_to: 'message_id15', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, true) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id16', created_by: customer, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'customer@example.com', to: 'customer1@example.com, customer2@example.com, zammad@example.com', cc: '', } result = { to: 'customer1@example.com, customer2@example.com, customer@example.com', cc: '', body: '', in_reply_to: 'message_id16', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, true) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id17', created_by: customer, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'customer@example.com', to: 'customer1@example.com, customer2@example.com, zammad@example.com, customer2+2@example.com', cc: '', } result = { to: 'customer1@example.com, customer2@example.com, customer2+2@example.com, customer@example.com', cc: '', body: '', in_reply_to: 'message_id17', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, true) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'zammad@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id18', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'zammad@example.com', to: 'customer@example.com', cc: '', } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id18', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, true) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'customer@example.com', } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'zammad@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id19', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'Sender ', to: 'Customer ', cc: '', } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id19', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, false) assert.deepEqual(verify, result) agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: agent, } article = { message_id: 'message_id20', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'Agent ', to: 'Sender ', cc: '', } result = { to: 'agent@example.com', cc: '', body: '', in_reply_to: 'message_id20', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, false) assert.deepEqual(verify, result) agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: agent, } article = { message_id: 'message_id20', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: 'Agent ', to: 'somebodyelse@example.com, Zammad ', cc: '', } result = { to: 'agent@example.com', cc: '', body: '', in_reply_to: 'message_id20', } email_addresses = [ { email: 'zammad@example.com', }, { email: 'zammad2@example.com', } ] verify = App.Utils.getRecipientArticle(ticket, article, agent, article.type, email_addresses, false) assert.deepEqual(verify, result) customer = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: "'customer@example.com'", } agent = { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'agent@example.com', } ticket = { customer: customer, } article = { message_id: 'message_id21', created_by: agent, type: { name: 'email', }, sender: { name: 'Agent', }, from: customer.email, to: 'agent@example.com', } result = { to: 'customer@example.com', cc: '', body: '', in_reply_to: 'message_id21', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) assert.deepEqual(verify, result) // Regression test for issue #2184 // Case 1 // 1. Create a "Received Call" Ticket for article_customer // 2. Change the Customer of the ticket to ticket_customer (but article.from still points to article_customer) // 3. Reply to the first Article // Recipient SHOULD BE Article.from var article_customer = { login: 'login', firstname: 'article', lastname: 'lastname', email: 'article_customer@example.com', } var ticket_customer = { login: 'login2', firstname: 'ticket', lastname: 'lastname', email: 'ticket_customer@example.com', } ticket = { customer: ticket_customer, } article = { type: { name: 'phone', }, sender: { name: 'Customer', }, from: 'article lastname ', to: 'some group', message_id: 'message_id22', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', }, } result = { to: 'article_customer@example.com', cc: '', body: '', in_reply_to: 'message_id22', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) assert.deepEqual(verify, result) // Regression test for issue #2184 // Case 2 // 1. Create a "Outbound Call" Ticket for article_customer // 2. Change the Customer of the Ticket to ticket_customer (but article.to still points to article_customer) // 3. Reply to the first Article // Recipient SHOULD BE Article.to article_customer = { login: 'login', firstname: 'article', lastname: 'lastname', email: 'article_customer@example.com', } ticket_customer = { login: 'login2', firstname: 'ticket', lastname: 'lastname', email: 'ticket_customer@example.com', } ticket = { customer: ticket_customer, } article = { type: { name: 'phone', }, sender: { name: 'Agent', }, from: 'agent1@example.com', to: article_customer.email, message_id: 'message_id23', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', }, } result = { to: 'article_customer@example.com', cc: '', body: '', in_reply_to: 'message_id23', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type) assert.deepEqual(verify, result) // https://github.com/zammad/zammad/issues/2551 // If "From:" is local address and "Reply-To:" is available, use it var article_customer = { login: 'login', firstname: 'article', lastname: 'lastname', email: 'article_customer@example.com', } var ticket_customer = { login: 'login2', firstname: 'ticket', lastname: 'lastname', email: 'ticket_customer@example.com', } ticket = { customer: ticket_customer, } article = { type: { name: 'email', }, sender: { name: 'Customer', }, from: 'article lastname ', to: 'some group', reply_to: 'asd@example.com', message_id: 'message_id22', created_by: { login: 'login', firstname: 'firstname', lastname: 'lastname', email: 'article_created_by@example.com', }, } email_addresses = [{ email: 'article_customer@example.com'}] result = { to: 'asd@example.com', cc: '', body: '', in_reply_to: 'message_id22', } verify = App.Utils.getRecipientArticle(ticket, article, article.created_by, article.type, email_addresses) assert.deepEqual(verify, result) }); QUnit.test("contentTypeCleanup", assert => { var source = "image/png" var should = "image/png" var result = App.Utils.contentTypeCleanup(source) assert.equal(result, should, source) source = "image/png; some.file" should = "image/png" result = App.Utils.contentTypeCleanup(source) assert.equal(result, should, source) source = "image/png;some.file" should = "image/png" result = App.Utils.contentTypeCleanup(source) assert.equal(result, should, source) source = "image/jpeg;some.file" should = "image/jpeg" result = App.Utils.contentTypeCleanup(source) assert.equal(result, should, source) source = "image/jpg;some.file" should = "image/jpg" result = App.Utils.contentTypeCleanup(source) assert.equal(result, should, source) source = "image/gif;some.file" should = "image/gif" result = App.Utils.contentTypeCleanup(source) assert.equal(result, should, source) source = "image/gif\n;some.file" should = "image/gif" result = App.Utils.contentTypeCleanup(source) assert.equal(result, should, source) }); // htmlImage2DataUrl QUnit.test("htmlImage2DataUrl", assert => { var source = '
    test 13
    ' var should = '
    test 13
    ' var result = App.Utils.htmlImage2DataUrl(source) assert.equal(result, should, source) source = 'some test' should = 'some test' result = App.Utils.htmlImage2DataUrl(source) assert.equal(result, should, source) source = 'some test' should = 'some test' result = App.Utils.htmlImage2DataUrl(source) assert.equal(result, should, source) source = 'some test' should = 'some test' result = App.Utils.htmlImage2DataUrl(source) assert.equal(result, should, source) source = 'some test' should = 'some test' result = App.Utils.htmlImage2DataUrl(source) assert.equal(result, should, source) // GitHub issue #2305 source = 'some test' should = 'some test' result = App.Utils.htmlImage2DataUrl(source) assert.equal(result, should, source) // GitHub issue #2701 source = 'foosome test' should = 'foosome test' result = App.Utils.htmlImage2DataUrl(source) assert.equal(result, should, source) }); QUnit.test('App.Utils.icon()', assert => { // When given no arguments, // expect @icon() to return null assert.equal(App.Utils.icon(), null, 'with no arguments') // On a modern browser and when given a single argument, // expect @icon(name) to return an tag window.svgPolyfill = false svgTag = '' assert.equal(App.Utils.icon('foo'), svgTag, 'with one arg / no SVG polyfill') // On a modern browser and when given two arguments, // expect @icon(name) to return an tag // with second arg as add'l class name window.svgPolyfill = false svgTag = '' assert.equal(App.Utils.icon('foo', 'bar'), svgTag, 'with two args / no SVG polyfill') // On a browser requiring SVG polyfill and when given a single argument, // expect @icon(name, class) to return an tag // with pathless xlink:href attr window.svgPolyfill = true svgTag = '' assert.equal(App.Utils.icon('foo'), svgTag, 'with one arg / SVG polyfill') // On a browser requiring SVG polyfill and when given two arguments, // expect @icon(name, class) to return an tag // with pathless xlink:href attr and second arg as add'l class name window.svgPolyfill = true svgTag = '' assert.equal(App.Utils.icon('foo', 'bar'), svgTag, 'with two args / SVG polyfill') // For a left-to-right browser language and when given an argument containing '{start}' or '{end}', // expect @icon(name) to return an tag // replacing '{start}' with 'left' and '{end}' with 'right' window.svgPolyfill = false App.i18n.dir = function() { return 'ltr' } svgTag = '' assert.equal(App.Utils.icon('arrow-{start}'), svgTag, 'for ltr locale / name includes "{start}"') svgTag = '' assert.equal(App.Utils.icon('arrow-{end}'), svgTag, 'for ltr locale / name includes "{end}"') // For a right-to-left browser language and when given an argument containing '{start}' or '{end}', // expect @icon(name) to return an tag // replacing '{start}' with 'left' and '{end}' with 'right' window.svgPolyFill = false App.i18n.dir = function() { return 'rtl' } svgTag = '' assert.equal(App.Utils.icon('arrow-{start}'), svgTag, 'for rtl locale / name includes "{start}"') svgTag = '' assert.equal(App.Utils.icon('arrow-{end}'), svgTag, 'for rtl locale / name includes "{end}"') }); var source1 = 'some test' $('#image2data1').html(source1) var htmlImage2DataUrlTest1 = function() { QUnit.test("htmlImage2DataUrl1 async", assert => { var result1 = App.Utils.htmlImage2DataUrl(source1) assert.ok(result1.match(/some test/), source1) assert.ok(!result1.match(/avatar-bg.png/), source1) assert.ok(result1.match(/^\ { assert.ok(!$(element).html().match(/chat-demo-avatar/), source2) assert.ok($(element).get(0).outerHTML.match(/^\ { assert.ok(false, 'fail callback is exectuted!') }); } // Gitlab Issue #3538 // Jpeg images should convert to jpegs // This functionality uses alt attribute present in img tag to get file type // if alt attribute is missing then it will default to image/png var jpegImageSource = 'test.jpegjpeg image' $('#jpegImage').html(jpegImageSource) var htmlImage2DataUrlTest3 = function() { QUnit.test("htmlImage2DataUrl3 async", assert => { var result = App.Utils.htmlImage2DataUrl(jpegImageSource) assert.ok(result.match(/jpeg image/), jpegImageSource) assert.ok(result.match(/^\ { var result = App.Utils.htmlImage2DataUrl(pngImageSource) assert.ok(result.match(/png image/), pngImageSource) assert.ok(result.match(/^\ { var result = App.Utils.htmlImage2DataUrl(jpegImageSourceWithoutAlt) assert.ok(result.match(/jpeg image/), jpegImageSourceWithoutAlt) assert.ok(result.match(/^\ { configGetBackup = App.Config.get // When FQDN is undefined or null, // expect @baseUrl() to return window.location.origin App.Config.get = function(key) { return undefined } assert.equal(App.Utils.baseUrl(), window.location.origin, 'with undefined FQDN') App.Config.get = function(key) { return null } assert.equal(App.Utils.baseUrl(), window.location.origin, 'with null FQDN') // When FQDN is zammad.example.com, // expect @baseUrl() to return window.location.origin App.Config.get = function(key) { if (key === 'fqdn') { return 'zammad.example.com' } } assert.equal(App.Utils.baseUrl(), window.location.origin, 'with FQDN zammad.example.com') // Otherwise, // expect @baseUrl() to return FQDN with current HTTP(S) scheme App.Config.get = function(key) { if (key === 'fqdn') { return 'foo.zammad.com' } else if (key === 'http_type') { return 'https' } } assert.equal(App.Utils.baseUrl(), 'https://foo.zammad.com', 'with any other FQDN (and https scheme)') App.Config.get = function(key) { if (key === 'fqdn') { return 'bar.zammad.com' } else if (key === 'http_type') { return 'http' } } assert.equal(App.Utils.baseUrl(), 'http://bar.zammad.com', 'with any other FQDN (and http scheme)') App.Config.get = configGetBackup }); QUnit.test('App.Utils.joinUrlComponents()', assert => { // When given a list of strings, // expect @joinUrlComponents() to join them with slashes assert.equal(App.Utils.joinUrlComponents('foo', 'bar', 'baz'), 'foo/bar/baz', 'with a destructured list of strings') // When given an array of strings, // expect @joinUrlComponents() to join them with slashes assert.equal(App.Utils.joinUrlComponents(['foo', 'bar', 'baz']), 'foo/bar/baz', 'with an array of strings') // When given a list of many types, // expect @joinUrlComponents() to join their string representations with slashes assert.equal(App.Utils.joinUrlComponents(0, 1, 'two', true, false, { foo: 'bar' }), '0/1/two/true/false/[object Object]', 'with a list of many types') // When given a list including null or undefined, // expect @joinUrlComponents() to filter them out of the results before joining the rest with slashes assert.equal(App.Utils.joinUrlComponents('foo', undefined, 'bar', null, 'baz'), 'foo/bar/baz', 'with a list including null or undefined') }); QUnit.test('App.Utils.clipboardHtmlIsWithText()', assert => { // no content with text assert.equal(App.Utils.clipboardHtmlIsWithText('
    '), false) assert.equal(App.Utils.clipboardHtmlIsWithText('
    '), false) assert.equal(App.Utils.clipboardHtmlIsWithText('
    '), false) assert.equal(App.Utils.clipboardHtmlIsWithText('
    '), false) assert.equal(App.Utils.clipboardHtmlIsWithText('
    '), false) assert.equal(App.Utils.clipboardHtmlIsWithText("
    \n
    "), false) // content with text assert.equal(App.Utils.clipboardHtmlIsWithText('test'), true) assert.equal(App.Utils.clipboardHtmlIsWithText('
    test
    '), true) assert.equal(App.Utils.clipboardHtmlIsWithText('sometext'), true) }); QUnit.test('App.Utils.clipboardHtmlInsertPreperation()', assert => { assert.equal(App.Utils.clipboardHtmlInsertPreperation('
    ', {}), '') assert.equal(App.Utils.clipboardHtmlInsertPreperation('
    ', {}), ' ') assert.equal(App.Utils.clipboardHtmlInsertPreperation('
    ', {}), '') assert.equal(App.Utils.clipboardHtmlInsertPreperation('
    ', {}), '') assert.equal(App.Utils.clipboardHtmlInsertPreperation('
    ', {}), ' ') assert.equal(App.Utils.clipboardHtmlInsertPreperation("
    \n
    ", {}), " \n ") assert.equal(App.Utils.clipboardHtmlInsertPreperation('test', {}), 'test') assert.equal(App.Utils.clipboardHtmlInsertPreperation('
    test
    ', {}), 'test') assert.equal(App.Utils.clipboardHtmlInsertPreperation('sometext', {}), 'sometext') assert.equal(App.Utils.clipboardHtmlInsertPreperation('
    test 123
    ', { mode: 'textonly' }), 'test 123') assert.equal(App.Utils.clipboardHtmlInsertPreperation('
    test
    123
    ', { mode: 'textonly' }), 'test 123') assert.equal(App.Utils.clipboardHtmlInsertPreperation('
    test
    123
    ', { mode: 'textonly', multiline: true }), 'test
    123') }); QUnit.test('App.Utils.signatureIdentifyByHtmlHelper()', assert => { result = App.Utils.signatureIdentifyByHtmlHelper("<script>alert('fish2');</script>
    ") assert.equal(result, "<script>alert('fish2');</script>
    ", 'signatureIdentifyByHtmlHelper does not reactivate alert') }); QUnit.test("#safeParseHtml", assert => { var unwrap = input => $('
    ').html(input)[0].innerHTML var html = "
    test 123
    " var result = App.Utils.safeParseHtml(html) var should = html assert.equal(unwrap(result), html) // test if, according to jQuery, invalid HTML does not cause a a crash // https://github.com/zammad/zammad/issues/3393 html = "
    test 123
    " should = "
    test 123
    " result = App.Utils.safeParseHtml(html) assert.equal(unwrap(result), should) }) QUnit.test("#buildEmailAddress", assert => { assert.equal( App.Utils.buildEmailAddress(undefined, 'undef@example.com'), 'undef@example.com' ) assert.equal( App.Utils.buildEmailAddress(null, 'null@example.com'), 'null@example.com' ) assert.equal( App.Utils.buildEmailAddress('', 'nobody@example.com'), 'nobody@example.com' ) assert.equal( App.Utils.buildEmailAddress('John Doe', 'john.doe@example.com'), 'John Doe ' ) assert.equal( App.Utils.buildEmailAddress('Somebody @ "Company"', 'some.body@example.com'), '"Somebody @ \\"Company\\"" ' ) })