2014-12-29 12:59:16 +00:00
window . onload = function ( ) {
// textCleanup
2021-10-14 14:35:12 +00:00
QUnit . test ( "textCleanup" , assert => {
2014-12-29 12:59:16 +00:00
var source = "Some\nValue\n\n\nTest"
var should = "Some\nValue\n\nTest"
2015-10-09 20:31:26 +00:00
var result = App . Utils . textCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 12:59:16 +00:00
source = "Some\nValue\n\n \n\n\nTest"
should = "Some\nValue\n\nTest"
2015-10-09 20:31:26 +00:00
result = App . Utils . textCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 12:59:16 +00:00
source = "Some\n\rValue\n\r\n\r\n\rTest"
should = "Some\nValue\n\nTest"
2015-10-09 20:31:26 +00:00
result = App . Utils . textCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 12:59:16 +00:00
source = "Some\n\rValue\n\r\n\r\n\rTest\r"
should = "Some\nValue\n\nTest"
2015-10-09 20:31:26 +00:00
result = App . Utils . textCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 12:59:16 +00:00
source = "Some\r\nValue\r\n\r\n\r\nTest\r\n"
should = "Some\nValue\n\nTest"
2015-10-09 20:31:26 +00:00
result = App . Utils . textCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 12:59:16 +00:00
source = "Some\r\nValue\r\n\r\n\r\n\r\n\r\n\r\nTest\r\n"
should = "Some\nValue\n\nTest"
2015-10-09 20:31:26 +00:00
result = App . Utils . textCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 12:59:16 +00:00
2014-12-29 23:25:57 +00:00
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 ..."
2015-10-09 20:31:26 +00:00
result = App . Utils . textCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 23:25:57 +00:00
2014-12-29 12:59:16 +00:00
} ) ;
2015-01-06 22:42:49 +00:00
// text2html
2021-10-14 14:35:12 +00:00
QUnit . test ( "text2html" , assert => {
2015-01-06 22:42:49 +00:00
var source = "Some\nValue\n\n\nTest"
var should = "<div>Some</div><div>Value</div><div><br></div><div>Test</div>"
2015-10-09 20:31:26 +00:00
var result = App . Utils . text2html ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-06 22:42:49 +00:00
source = "Some\nValue\n"
should = "<div>Some</div><div>Value</div>"
2015-10-09 20:31:26 +00:00
result = App . Utils . text2html ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-06 22:42:49 +00:00
source = "Some\n<b>Value</b>\n"
should = "<div>Some</div><div><b>Value</b></div>"
2015-10-09 20:31:26 +00:00
result = App . Utils . text2html ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-06 22:42:49 +00:00
source = "> Welcome!\n> \n> Thank you for installing Zammad.\n> \n> You will find ..."
should = "<div>> Welcome!</div><div>></div><div>> Thank you for installing Zammad.</div><div>></div><div>> You will find ...</div>"
2015-10-09 20:31:26 +00:00
result = App . Utils . text2html ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-06 22:42:49 +00:00
2020-02-10 08:06:39 +00:00
source = "Some\nValue\n"
should = "<div>Some</div><div>Value</div>"
result = App . Utils . text2html ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2020-02-10 08:06:39 +00:00
source = "Some\rValue\r"
should = "<div>Some</div><div>Value</div>"
result = App . Utils . text2html ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2020-02-10 08:06:39 +00:00
source = "Some\n\rValue\n\r"
should = "<div>Some</div><div>Value</div>"
result = App . Utils . text2html ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2020-02-10 08:06:39 +00:00
source = "Some\r\nValue\r\n"
should = "<div>Some</div><div>Value</div>"
result = App . Utils . text2html ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2020-02-10 08:06:39 +00:00
source = "Some Value 123"
should = "<div>Some Value 123</div>"
result = App . Utils . text2html ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2020-02-10 08:06:39 +00:00
source = "Some\n Value\n 123"
should = "<div>Some</div><div> Value</div><div> 123</div>"
result = App . Utils . text2html ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-06 22:42:49 +00:00
} ) ;
2016-06-29 23:27:03 +00:00
// htmlStrip
2021-10-14 14:35:12 +00:00
QUnit . test ( "htmlStrip" , assert => {
2016-06-29 23:27:03 +00:00
var source = $ ( '<div><br><b>lala</b></div>' )
var should = '<div><b>lala</b></div>'
App . Utils . htmlStrip ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( source . get ( 0 ) . outerHTML , should )
2016-06-29 23:27:03 +00:00
source = $ ( '<div><br><br><br><b>lala</b></div>' )
should = '<div><b>lala</b></div>'
App . Utils . htmlStrip ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( source . get ( 0 ) . outerHTML , should )
2016-06-29 23:27:03 +00:00
source = $ ( '<div><br><br><br><b>lala</b><br><br></div>' )
should = '<div><b>lala</b></div>'
App . Utils . htmlStrip ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( source . get ( 0 ) . outerHTML , should )
2016-06-29 23:27:03 +00:00
source = $ ( '<div><br><br><div><br></div><b>lala</b><br><br></div>' )
should = '<div><div><br></div><b>lala</b></div>'
App . Utils . htmlStrip ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( source . get ( 0 ) . outerHTML , should )
2016-06-29 23:27:03 +00:00
} ) ;
// lastLineEmpty
2021-10-14 14:35:12 +00:00
QUnit . test ( "htmlLastLineEmpty" , assert => {
2016-06-29 23:27:03 +00:00
var source = $ ( '<div><br><b>lala</b></div>' )
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . htmlLastLineEmpty ( source ) , false )
2016-06-29 23:27:03 +00:00
source = $ ( '<div><br><b>lala</b><br></div>' )
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . htmlLastLineEmpty ( source ) , true )
2016-06-29 23:27:03 +00:00
} ) ;
2015-04-02 22:29:32 +00:00
// html2text
2021-10-14 14:35:12 +00:00
QUnit . test ( "html2text" , assert => {
2015-04-02 22:29:32 +00:00
var source = "<div>Some</div><div>Value</div><div><br></div><div>Test</div>"
2015-04-03 01:11:21 +00:00
var should = "Some\nValue\n\nTest"
2015-10-09 20:31:26 +00:00
var result = App . Utils . html2text ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-04-02 22:29:32 +00:00
source = "<div>Some</div><div>Value</div>"
should = "Some\nValue"
2015-10-09 20:31:26 +00:00
result = App . Utils . html2text ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-04-02 22:29:32 +00:00
source = "<div>Some<br/>Value</div>"
should = "Some\nValue"
2015-10-09 20:31:26 +00:00
result = App . Utils . html2text ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-04-02 22:29:32 +00:00
2016-02-23 14:46:48 +00:00
source = "<div>Some & <Value></div>"
should = "Some & <Value>"
result = App . Utils . html2text ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2016-02-23 14:46:48 +00:00
2015-04-02 22:29:32 +00:00
source = "<div>Some</div><div><b>Value</b></div>"
should = "Some\n<b>Value</b>"
2015-10-09 20:31:26 +00:00
result = App . Utils . html2text ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-04-02 22:29:32 +00:00
source = "<div>> Welcome!</div><div>></div><div>> Thank you for installing Zammad.</div><div>></div><div>> You will find ...</div>"
should = "> Welcome!\n>\n> Thank you for installing Zammad.\n>\n> You will find ..."
2015-10-09 20:31:26 +00:00
result = App . Utils . html2text ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-04-02 22:29:32 +00:00
source = "<div>test 123 <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>--<br/>Bob Smith</div>"
2015-04-03 01:11:21 +00:00
should = "test 123 \n\n--\nBob Smith"
2015-10-09 20:31:26 +00:00
result = App . Utils . html2text ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-04-02 22:29:32 +00:00
2015-04-03 00:01:21 +00:00
source = "test 123 <br><br><br><br><br><br><br><br><br><br><br>--<br>Bob Smith"
2015-04-03 01:11:21 +00:00
should = "test 123 \n\n--\nBob Smith"
2015-10-09 20:31:26 +00:00
result = App . Utils . html2text ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-04-03 00:01:21 +00:00
source = "<div>1<br><br><br><br><br><br><br><br><br><br></div><div>Von: Martin Edenhofer via Znuny Support [<a href=\"mailto:support@znuny.inc\" title=\"mailto:support@znuny.inc\" target=\"_blank\">mailto:support@znuny.inc</a>]</div>\n<div>Gesendet: Donnerstag, 2. April 2015 11:32</div>"
2015-04-03 01:11:21 +00:00
should = "1\n\nVon: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]\nGesendet: Donnerstag, 2. April 2015 11:32"
2015-10-09 20:31:26 +00:00
result = App . Utils . html2text ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-04-03 00:01:21 +00:00
2015-04-03 01:11:21 +00:00
source = "<div>test 123<br/>lalala<p>--</p>some test</div>"
should = "test 123\nlalala\n--\nsome test"
2015-10-09 20:31:26 +00:00
result = App . Utils . html2text ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2016-01-12 23:55:17 +00:00
source = "<p><span>Was\nsoll verbessert werden:</span></p>"
should = "Was soll verbessert werden:"
result = App . Utils . html2text ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2016-01-12 23:55:17 +00:00
// in raw format, without cleanup
source = "<div>Some</div><div>1234</div>"
should = "Some\n1234\n"
result = App . Utils . html2text ( source , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2016-01-12 23:55:17 +00:00
source = "<div>Some</div><div> 1234</div>"
should = "Some\n 1234\n"
result = App . Utils . html2text ( source , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2016-01-12 23:55:17 +00:00
source = "\n\n<div>Some</div>\n<div> 1234</div>"
should = "Some\n 1234\n"
result = App . Utils . html2text ( source , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2016-01-12 23:55:17 +00:00
source = "<div>Some</div><div> 1234</div>"
should = "Some\n 1234\n"
result = App . Utils . html2text ( source , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2016-01-12 23:55:17 +00:00
source = "<div>Some</div>\n\n<div> 1234</div>\n"
should = "Some\n 1234\n"
result = App . Utils . html2text ( source , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2016-01-12 23:55:17 +00:00
source = "<div>test<br>new line<br></div>"
should = "test\nnew line\n\n"
result = App . Utils . html2text ( source , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2016-01-12 23:55:17 +00:00
source = "<p><span>Was\nsoll verbessert werden:</span></p>"
should = "Was soll verbessert werden:\n"
result = App . Utils . html2text ( source , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2016-01-12 23:55:17 +00:00
2015-04-02 22:29:32 +00:00
} ) ;
2017-03-14 19:10:52 +00:00
// phoneify
2021-10-14 14:35:12 +00:00
QUnit . test ( "phoneify" , assert => {
2017-03-14 19:10:52 +00:00
var source = "+1 123 123 123-123"
2017-07-28 11:55:28 +00:00
var should = 'tel:+1123123123123'
2017-03-14 19:10:52 +00:00
var result = App . Utils . phoneify ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2017-03-14 19:10:52 +00:00
source = "+1 123 123 A 123-123<>"
2017-07-28 11:55:28 +00:00
should = 'tel:+1123123123123'
result = App . Utils . phoneify ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2017-07-28 11:55:28 +00:00
source = "+1 (123) 123 123-123"
should = 'tel:+1123123123123'
result = App . Utils . phoneify ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2017-07-28 11:55:28 +00:00
source = "+1 (123) 123 1#23-123"
should = 'tel:+11231231#23123'
result = App . Utils . phoneify ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2017-07-28 11:55:28 +00:00
source = "+1 (123) 12*3 1#23-123"
should = 'tel:+112312*31#23123'
result = App . Utils . phoneify ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2017-07-28 11:55:28 +00:00
source = "+1 (123) 12+3"
should = 'tel:+1123123'
result = App . Utils . phoneify ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2017-07-28 11:55:28 +00:00
source = "+1 (123) 123 "
should = 'tel:+1123123'
result = App . Utils . phoneify ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2017-07-28 11:55:28 +00:00
source = " +1 (123) 123 "
should = 'tel:+1123123'
2017-03-14 19:10:52 +00:00
result = App . Utils . phoneify ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2017-03-14 19:10:52 +00:00
} )
2015-01-06 22:42:49 +00:00
// linkify
2021-10-14 14:35:12 +00:00
QUnit . test ( "linkify" , assert => {
2015-01-06 22:42:49 +00:00
var source = "http://example.com"
var should = '<a href="http://example.com" title="http://example.com" target="_blank">http://example.com</a>'
2015-10-09 20:31:26 +00:00
var result = App . Utils . linkify ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-06 22:42:49 +00:00
source = "http://example.com?some_param=lalala"
should = '<a href="http://example.com?some_param=lalala" title="http://example.com?some_param=lalala" target="_blank">http://example.com?some_param=lalala</a>'
2015-10-09 20:31:26 +00:00
result = App . Utils . linkify ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-06 22:42:49 +00:00
source = "example.com"
should = '<a href="http://example.com" title="http://example.com" target="_blank">example.com</a>'
2015-10-09 20:31:26 +00:00
result = App . Utils . linkify ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-06 22:42:49 +00:00
source = "some text example.com"
should = 'some text <a href="http://example.com" title="http://example.com" target="_blank">example.com</a>'
2015-10-09 20:31:26 +00:00
result = App . Utils . linkify ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-06 22:42:49 +00:00
source = "example.com some text"
should = '<a href="http://example.com" title="http://example.com" target="_blank">example.com</a> some text'
2015-10-09 20:31:26 +00:00
result = App . Utils . linkify ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-06 22:42:49 +00:00
2018-01-29 23:34:58 +00:00
source = "test@example.com some text"
should = 'test@example.com some text'
result = App . Utils . linkify ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2018-01-29 23:34:58 +00:00
source = "abc test@example.com some text"
should = 'abc test@example.com some text'
result = App . Utils . linkify ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2018-01-29 23:34:58 +00:00
2015-01-06 22:42:49 +00:00
/ *
source = "<b>example.com</b>"
should = '<b><a href="http://example.com" title="http://example.com" target="_blank">http://example.com</a></b>'
2015-10-09 20:31:26 +00:00
result = App . Utils . linkify ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-06 22:42:49 +00:00
* /
} ) ;
2014-12-29 12:59:16 +00:00
// htmlEscape
2021-10-14 14:35:12 +00:00
QUnit . test ( "htmlEscape" , assert => {
2014-12-29 12:59:16 +00:00
var source = "<"
var should = "<"
2015-10-09 20:31:26 +00:00
var result = App . Utils . htmlEscape ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 12:59:16 +00:00
source = ">"
should = ">"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlEscape ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 12:59:16 +00:00
source = "&"
should = "&"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlEscape ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 12:59:16 +00:00
source = "&"
should = "&amp;"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlEscape ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 12:59:16 +00:00
source = "& ;"
should = "&amp ;"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlEscape ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 12:59:16 +00:00
source = "& amp;"
should = "& amp;"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlEscape ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 12:59:16 +00:00
source = "'test'"
should = "'test'"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlEscape ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 12:59:16 +00:00
source = '"test"'
should = ""test""
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlEscape ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 12:59:16 +00:00
source = "<>"
should = "<>"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlEscape ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 12:59:16 +00:00
source = "<<>"
should = "<&lt;>"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlEscape ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 12:59:16 +00:00
} ) ;
2015-01-06 22:42:49 +00:00
// htmlRemoveTags
2021-10-14 14:35:12 +00:00
QUnit . test ( "htmlRemoveTags" , assert => {
2014-12-29 12:59:16 +00:00
2015-01-06 22:42:49 +00:00
var source = "<div>test</div>"
2015-09-01 00:16:50 +00:00
//var should = "<div>test</div>"
var should = "test"
2015-10-09 20:31:26 +00:00
var result = App . Utils . htmlRemoveTags ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2014-12-29 12:59:16 +00:00
2015-08-05 09:40:50 +00:00
source = "<div>test<!-- some comment --></div>"
2015-09-01 00:16:50 +00:00
//should = "<div>test</div>"
should = "test"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveTags ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-08-05 09:40:50 +00:00
2015-01-06 22:42:49 +00:00
source = "<a href=\"some_link\">some link to somewhere</a>"
2015-09-01 00:16:50 +00:00
should = "some link to somewhere"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveTags ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2014-12-29 12:59:16 +00:00
2015-01-06 22:42:49 +00:00
source = "<div><a href=\"some_link\">some link to somewhere</a></div>"
2015-09-01 00:16:50 +00:00
//should = "<div>some link to somewhere</div>"
should = "some link to somewhere"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveTags ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2014-12-29 23:25:57 +00:00
2015-01-07 14:30:13 +00:00
source = "<div><a href=\"some_link\">some link to somewhere</a><input value=\"should not be shown\"></div>"
2015-09-01 00:16:50 +00:00
//should = "<div>some link to somewhere</div>"
should = "some link to somewhere"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveTags ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-07 14:30:13 +00:00
2015-01-06 22:42:49 +00:00
source = "<div><a href=\"some_link\">some link to somewhere</a> <div><hr></div> <span>123</span> <img src=\"some_image\"/></div>"
2015-09-01 00:16:50 +00:00
//should = "<div>some link to somewhere 123 </div>"
should = "some link to somewhere 123 "
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveTags ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2014-12-29 12:59:16 +00:00
2017-06-23 07:37:54 +00:00
} ) ;
// htmlRemoveRichtext
2021-10-14 14:35:12 +00:00
QUnit . test ( "htmlRemoveRichtext" , assert => {
2017-06-23 07:37:54 +00:00
2015-11-26 09:44:28 +00:00
source = "<div><form class=\"xxx\">test 123</form><svg><use xlink:href=\"assets/images/icons.svg#icon-status\"></svg></div>"
2015-09-01 00:16:50 +00:00
//should = "<div>test 123</div>"
should = "test 123"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-07 14:30:13 +00:00
source = "<div><textarea class=\"xxx\">test 123</textarea></div>"
2015-09-01 00:16:50 +00:00
//should = "<div>test 123</div>"
should = "test 123"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-07 14:30:13 +00:00
2016-05-27 12:22:15 +00:00
source = "<div><p wrap=\"\">test 123</p></div>"
should = "<p>test 123</p>"
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2016-05-27 12:22:15 +00:00
2015-01-08 23:25:25 +00:00
source = "<div><font size=\"3\" color=\"red\">This is some text!</font></div>"
2015-09-01 00:16:50 +00:00
should = "This is some text!"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2016-06-24 12:09:09 +00:00
should = "This is some text!"
2015-12-27 22:29:04 +00:00
result = App . Utils . htmlRemoveRichtext ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-12-27 22:29:04 +00:00
2015-07-30 10:15:13 +00:00
var source = "<div><!--test comment--><a href=\"test\">test</a></div>"
2015-09-01 00:16:50 +00:00
//var should = "<div>test</div>"
var should = "test"
2015-10-09 20:31:26 +00:00
var result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2014-12-29 12:59:16 +00:00
2015-08-05 09:40:50 +00:00
source = "<div><!--[if !supportLists]--><span lang=\"DE\">1.1.1<span> </span></span><!--[endif]--><span lang=\"DE\">Description</span></div>"
2015-09-01 00:16:50 +00:00
//should = "<div><span>1.1.1<span> </span></span><span>Description</span></div>"
should = "<span>1.1.1<span> </span></span><span>Description</span>"
2015-12-27 22:29:04 +00:00
//should = '1.1.1 Description'
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-08-05 09:40:50 +00:00
2015-01-06 22:42:49 +00:00
source = "<a href=\"some_link\">some link to somewhere</a>"
2015-09-01 00:16:50 +00:00
should = "some link to somewhere"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2014-12-29 12:59:16 +00:00
2015-01-06 22:42:49 +00:00
source = "<div><a href=\"some_link\"></a> test </div>"
2015-09-01 00:16:50 +00:00
//should = "<div> test </div>"
should = " test "
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2014-12-29 12:59:16 +00:00
2015-01-06 22:42:49 +00:00
source = "<div><b></b> test </div>"
2015-09-01 00:16:50 +00:00
//should = "<div> test </div>"
should = " test "
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2014-12-29 12:59:16 +00:00
2015-01-06 22:42:49 +00:00
source = "<div><div><b></b> test </div></div>"
2015-09-01 00:16:50 +00:00
//should = "<div><div> test </div></div>"
should = "<div> test </div>"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2014-12-29 12:59:16 +00:00
2015-01-07 14:30:13 +00:00
source = "<div><div><b></b> test <input value=\"should not be shown\"></div></div>"
2015-09-01 00:16:50 +00:00
//should = "<div><div> test </div></div>"
should = "<div> test </div>"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-07 14:30:13 +00:00
2015-01-06 22:42:49 +00:00
source = "<div><div><b></b> test </div><span>123</span></div>"
2015-09-01 00:16:50 +00:00
//should = "<div><div> test </div><span>123</span></div>"
should = "<div> test </div><span>123</span>"
2015-12-27 22:29:04 +00:00
//should = '<div> test </div>123'
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2014-12-29 12:59:16 +00:00
2015-08-05 09:40:50 +00:00
source = "<div><div class=\"xxx\" title=\"some title\" lang=\"en\"><b></b> test </div></div>"
2015-09-01 00:16:50 +00:00
//should = "<div><div> test </div></div>"
should = "<div> test </div>"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-06 22:42:49 +00:00
2015-01-07 14:30:13 +00:00
source = "<div><textarea class=\"xxx\"> test </textarea></div>"
2015-09-01 00:16:50 +00:00
//should = "<div> test </div>"
should = " test "
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-07 14:30:13 +00:00
2015-01-07 00:03:18 +00:00
source = "<div><br></div>"
2015-09-01 00:16:50 +00:00
//should = "<div><br></div>"
should = "<br>"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-07 00:03:18 +00:00
source = "<div><div class=\"xxx\"><br></div></div>"
2015-09-01 00:16:50 +00:00
//should = "<div><div><br></div></div>"
should = "<div><br></div>"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-07 00:03:18 +00:00
2015-01-07 14:30:13 +00:00
source = "<div><form class=\"xxx\">test 123</form></div>"
2015-09-01 00:16:50 +00:00
//should = "<div>test 123</div>"
should = "test 123"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-07 14:30:13 +00:00
2015-12-27 22:29:04 +00:00
source = "<div><div><label for=\"Ticket_888344_group_id\">Gruppe <span>*</span></label></div><div><div></div></div><div><div><span></span><span></span></div></div><div><div><label for=\"Ticket_888344_owner_id\">Besitzer <span></span></label></div><div><div></div></div></div><div><div><div><svg><use xlink:href=\"http://localhost:3000/assets/images/icons.svg#icon-arrow-down\"></use></svg></div><span></span><span></span></div></div><div><div> <label for=\"Ticket_888344_state_id\">Status <span>*</span></label></div></div></div>\n"
//should = "<div>test 123</div>"
2016-06-24 12:09:09 +00:00
should = '<div>Gruppe <span>*</span></div><div><div></div></div><div><div><span></span><span></span></div></div><div><div>Besitzer <span></span></div><div><div></div></div></div><div><div><div></div><span></span><span></span></div></div><div><div> Status <span>*</span></div></div>'
2015-12-27 22:29:04 +00:00
result = App . Utils . htmlRemoveRichtext ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-12-27 22:29:04 +00:00
2015-11-26 09:44:28 +00:00
source = "<div><font size=\"3\" color=\"red\">This is some text!</font><svg><use xlink:href=\"assets/images/icons.svg#icon-status\"></svg></div>"
2015-09-01 00:16:50 +00:00
should = "This is some text!"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-08 23:25:25 +00:00
2016-06-24 12:09:09 +00:00
should = "This is some text!"
2015-12-27 22:29:04 +00:00
result = App . Utils . htmlRemoveRichtext ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-12-27 22:29:04 +00:00
2017-06-23 07:37:54 +00:00
var source = "<div><!--test comment--><a href=\"test\">test</a></div>"
var should = "<div>test</div>"
var result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . get ( 0 ) . outerHTML , should , source )
2017-06-23 07:37:54 +00:00
source = "<div><small>some link to somewhere</small></a>"
should = "<div>some link to somewhere</div>"
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . get ( 0 ) . outerHTML , should , source )
2017-06-23 07:37:54 +00:00
source = "<div><div class=\"xxx\"><br></div></div>"
should = "<div><div><br></div></div>"
result = App . Utils . htmlRemoveRichtext ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . get ( 0 ) . outerHTML , should , source )
2017-06-23 07:37:54 +00:00
source = "<div><table bgcolor=\"green\" aaa=\"1\"><thead><tr><th>111</th><th colspan=\"2\" abc=\"a\">aaa</th></tr></thead><tbody><tr><td>key</td><td>value</td></tr></tbody></table></div>"
should = "<div>111aaakeyvalue</div>"
result = App . Utils . htmlRemoveRichtext ( source , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result . get ( 0 ) . outerHTML , should , source )
2015-01-06 22:42:49 +00:00
} ) ;
2015-01-27 07:13:25 +00:00
// htmlCleanup
2021-10-14 14:35:12 +00:00
QUnit . test ( "htmlCleanup" , assert => {
2015-01-06 22:42:49 +00:00
2015-07-30 10:15:13 +00:00
var source = "<div><!--test comment--><a href=\"test\">test</a></div>"
2015-09-01 00:16:50 +00:00
//var should = "<div>test</div>"
2018-01-02 00:36:05 +00:00
var should = "<a href=\"test\">test</a>"
2015-10-09 20:31:26 +00:00
var result = App . Utils . htmlCleanup ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-06 22:42:49 +00:00
2016-06-24 12:09:09 +00:00
source = "<div><!--test comment--><a href=\"test\">test</a></div>"
2018-01-02 00:36:05 +00:00
should = "<a href=\"test\">test</a>"
2016-06-24 12:09:09 +00:00
result = App . Utils . htmlCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2016-06-24 12:09:09 +00:00
source = "some link to somewhere"
should = "some link to somewhere"
result = App . Utils . htmlCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2016-06-24 12:09:09 +00:00
source = "<li>a</li><li>b</li>"
should = "<li>a</li><li>b</li>"
result = App . Utils . htmlCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2016-06-24 12:09:09 +00:00
2015-01-06 22:42:49 +00:00
source = "<a href=\"some_link\">some link to somewhere</a>"
2015-09-01 00:16:50 +00:00
should = "some link to somewhere"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlCleanup ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-06 22:42:49 +00:00
2018-01-02 00:36:05 +00:00
source = "<p><a href=\"some_link\">some link to somewhere</a><p>"
should = "<a href=\"some_link\">some link to somewhere</a>"
result = App . Utils . htmlCleanup ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2018-01-02 00:36:05 +00:00
2015-08-05 09:40:50 +00:00
source = "<div><h1>some link to somewhere</h1></div>"
2016-05-12 09:24:52 +00:00
should = "<h1>some link to somewhere</h1>"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlCleanup ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-20 00:33:26 +00:00
2016-05-12 13:22:34 +00:00
source = "<div><p id=\"123\" data-id=\"abc\">some link to somewhere</p></div>"
should = "<p>some link to somewhere</p>"
result = App . Utils . htmlCleanup ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2016-05-12 13:22:34 +00:00
2015-01-20 00:33:26 +00:00
source = "<div><small>some link to somewhere</small></a>"
2015-09-01 00:16:50 +00:00
//should = "<div>some link to somewhere</div>"
should = "some link to somewhere"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlCleanup ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-20 00:33:26 +00:00
source = "<div><time>some link to somewhere</time></a>"
2015-09-01 00:16:50 +00:00
//should = "<div>some link to somewhere</div>"
should = "some link to somewhere"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlCleanup ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-06 22:42:49 +00:00
2015-08-05 09:40:50 +00:00
source = "<div><h1>some h1 for somewhere</h1><p><hr></p></div>"
2016-05-12 09:24:52 +00:00
should = "<h1>some h1 for somewhere</h1><p></p><hr><p></p>"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlCleanup ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-06 22:52:01 +00:00
source = "<div><br></div>"
2015-09-01 00:16:50 +00:00
//should = "<div><br></div>"
should = "<br>"
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlCleanup ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-07 00:03:18 +00:00
source = "<div><div class=\"xxx\"><br></div></div>"
2015-09-01 00:16:50 +00:00
//should = "<div><div><br></div></div>"
should = "<div><br></div>"
2015-11-26 09:44:28 +00:00
result = App . Utils . htmlCleanup ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2014-12-29 12:59:16 +00:00
2015-01-07 14:30:13 +00:00
source = "<div><form class=\"xxx\">test 123</form></div>"
//should = "<div>test 123<br></div>"
2015-09-01 00:16:50 +00:00
should = "test 123"
2015-11-26 09:44:28 +00:00
result = App . Utils . htmlCleanup ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-07 14:30:13 +00:00
source = "<div><form class=\"xxx\">test 123</form> some other value</div>"
2015-09-01 00:16:50 +00:00
//should = "<div>test 123 some other value</div>"
should = "test 123 some other value"
2015-11-26 09:44:28 +00:00
result = App . Utils . htmlCleanup ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-07 14:30:13 +00:00
source = "<div><form class=\"xxx\">test 123</form> some other value<input value=\"should not be shown\"></div>"
2015-09-01 00:16:50 +00:00
//should = "<div>test 123 some other value</div>"
should = "test 123 some other value"
2015-11-26 09:44:28 +00:00
result = App . Utils . htmlCleanup ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-07 14:30:13 +00:00
2015-11-26 09:44:28 +00:00
source = "<div><font size=\"3\" color=\"red\">This is some text!</font><svg><use xlink:href=\"assets/images/icons.svg#icon-status\"></svg></div>"
2015-09-01 00:16:50 +00:00
//should = "<div>This is some text!</div>"
2021-01-04 12:57:57 +00:00
should = "<font color=\"red\">This is some text!</font>"
2015-11-26 09:44:28 +00:00
result = App . Utils . htmlCleanup ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-01-07 14:30:13 +00:00
2015-08-05 09:40:50 +00:00
source = "<div><p>some link to somewhere from word<w:sdt>abc</w:sdt></p><o:p></o:p></a>"
2015-12-27 22:29:04 +00:00
//should = "<div><p>some link to somewhere from wordabc</p></div>"
should = '<p>some link to somewhere from wordabc</p>'
2015-10-09 20:31:26 +00:00
result = App . Utils . htmlCleanup ( $ ( source ) )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-08-05 09:40:50 +00:00
2015-12-27 22:29:04 +00:00
source = "<div><div><label for=\"Ticket_888344_group_id\">Gruppe <span>*</span></label></div><div><div></div></div><div><div><span></span><span></span></div></div><div><div><label for=\"Ticket_888344_owner_id\">Besitzer <span></span></label></div><div><div></div></div></div><div><div><div><svg><use xlink:href=\"http://localhost:3000/assets/images/icons.svg#icon-arrow-down\"></use></svg></div><span></span><span></span></div></div><div><div> <label for=\"Ticket_888344_state_id\">Status <span>*</span></label></div></div></div>\n"
//should = "<div>test 123</div>"
2016-06-24 12:09:09 +00:00
should = '<div>Gruppe <span>*</span></div><div><div></div></div><div><div><span></span><span></span></div></div><div><div>Besitzer <span></span></div><div><div></div></div></div><div><div><div></div><span></span><span></span></div></div><div><div> Status <span>*</span></div></div>'
2015-12-27 22:29:04 +00:00
result = App . Utils . htmlCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-12-27 22:29:04 +00:00
source = "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\"\nxmlns:w=\"urn:schemas-microsoft-com:office:word\"\nxmlns:m=\"http://schemas.microsoft.com/office/2004/12/omml\"\nxmlns=\"http://www.w3.org/TR/REC-html40\">\n\n<head>\n<meta name=Titel content=\"\">\n<meta name=Stichwörter content=\"\">\n<meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">\n<meta name=ProgId content=Word.Document>\n<meta name=Generator content=\"Microsoft Word 15\">\n<meta name=Originator content=\"Microsoft Word 15\">\n<link rel=File-List\nhref=\"file://localhost/Users/johannes/Library/Group%20Containers/UBF8T346G9.Office/msoclip1/01/clip_filelist.xml\">\n<!--[if gte mso 9]><xml>\n <o:OfficeDocumentSettings>\n <o:AllowPNG/>\n <o:PixelsPerInch>96</o:PixelsPerInch>\n </o:OfficeDocumentSettings>\n</xml><![endif]-->\n<link rel=themeData\nhref=\"file://localhost/Users/johannes/Library/Group%20Containers/UBF8T346G9.Office/msoclip1/01/clip_themedata.thmx\">\n<!--[if gte mso 9]><xml>\n <w:WordDocument>\n <w:View>Normal</w:View>\n <w:Zoom>0</w:Zoom>\n <w:TrackMoves/>\n <w:TrackFormatting/>\n <w:HyphenationZone>21</w:HyphenationZone>\n <w:PunctuationKerning/>\n <w:ValidateAgainstSchemas/>\n <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>\n <w:IgnoreMixedContent>false</w:IgnoreMixedContent>\n <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>\n <w:DoNotPromoteQF/>\n <w:LidThemeOther>DE</w:LidThemeOther>\n <w:LidThemeAsian>X-NONE</w:LidThemeAsian>\n <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>\n <w:Compatibility>\n <w:BreakWrappedTables/>\n <w:SnapToGridInCell/>\n <w:WrapTextWithPunct/>\n <w:UseAsianBreakRules/>\n <w:DontGrowAutofit/>\n <w:SplitPgBreakAndParaMark/>\n <w:EnableOpenTypeKerning/>\n <w:DontFlipMirrorIndents/>\n <w:OverrideTableStyleHps/>\n </w:Compatibility>\n <m:mathPr>\n <m:mathFont m:val=\"Cambria Math\"/>\n <m:brkBin m:val=\"before\"/>\n <m:brkBinSub m:val=\"--\"/>\n <m:smallFrac m:val=\"off\"/>\n <m:dispDef/>\n <m:lMargin m:val=\"0\"/>\n <m:rMargin m:val=\"0\"/>\n <m:defJc m:val=\"centerGroup\"/>\n <m:wrapIndent m:val=\"1440\"/>\n <m:intLim m:val=\"subSup\"/>\n <m:naryLim m:val=\"undOvr\"/>\n </m:mathPr></w:WordDocument>\n</xml><![endif]--><!--[if gte mso 9]><xml>\n <w:LatentStyles DefLockedState=\"false\" DefUnhideWhenUsed=\"false\"\n DefSemiHidden=\"false\" DefQFormat=\"false\" DefPriority=\"99\"\n LatentStyleCount=\"380\">\n <w:LsdException Locked=\"false\" Priority=\"0\" QFormat=\"true\" Name=\"Normal\"/>\n <w:LsdException Locked=\"false\" Priority=\"0\" QFormat=\"true\" Name=\"heading 1\"/>\n <w:LsdException Locked=\"false\" Priority=\"0\" SemiHidden=\"true\"\n UnhideWhenUsed=\"true\" QFormat=\"true\" Name=\"heading 2\"/>\n <w:LsdException Locked=\"false\" Priority=\"0\" SemiHidden=\"true\"\n UnhideWhenUsed=\"true\" QFormat=\"true\" Name=\"heading 3\"/>\n <w:LsdException Locked=\"false\" Priority=\"0\" SemiHidden=\"true\"\n UnhideWhenUsed=\"true\" QFormat=\"true\" Name=\"heading 4\"/>\n <w:LsdException Locked=\"false\" Priority=\"0\" SemiHidden=\"true\"\n UnhideWhenUsed=\"true\" QFormat=\"true\" Name=\"heading 5\"/>\n <w:LsdException Locked=\"false\" Priority=\"9\" SemiHidden=\"true\"\n UnhideWhenUsed=\"true\" QFormat=\"true\" Name=\"heading 6\"/>\n <w:LsdException Locked=\"false\" Priority=\"9\" SemiHidden=\"true\"\n UnhideWhenUsed=\"true\" QFormat=\"true\" Name=\"heading 7\"/>\n <w:LsdException Locked=\"false\" Priority=\"9\" SemiHidden=\"true\"\n UnhideWhenUsed=\"true\" QFormat=\"true\" Name=\"heading 8\"/>\n <w:LsdException Locked=\"false\" Priority=\"9\" SemiHidden=\"true\"\n UnhideWhenUsed=\"true\" QFormat=\"true\" Name=\"heading 9\"/>\n <w:LsdException Locked=\"false\" SemiHidden=\"true\" UnhideWhenUsed=\"true\"\n Name=\"index 1\"/>\n <w:LsdException Locked=\"false\" SemiHidden=\"true\" UnhideWhenUsed=\"true\"\n Name=\"index 2\"/>\n <w:LsdException Locked=\"false\" SemiHidden=\"true\" UnhideWhenUsed=\"true\"\n Name=\"index 3\"/>\n <w:LsdException Locked=\"false\" SemiHidden =
2017-06-23 07:37:54 +00:00
should = "<ul><li>Test 1</li><li>Test 2</li><li><i>Test 3</i></li><li>Test 4</li><li><b>Test5</b></li></ul>"
2015-12-27 22:29:04 +00:00
result = App . Utils . htmlCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) . trim ( ) , should , source )
2015-12-27 22:29:04 +00:00
source = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n<html>\n<head>\n <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>\n <title></title>\n <meta name=\"generator\" content=\"LibreOffice 4.4.7.2 (MacOSX)\"/>\n <style type=\"text/css\">\n @page { margin: 0.79in }\n p { margin-bottom: 0.1in; line-height: 120% }\n a:link { so-language: zxx }\n </style>\n</head>\n<body lang=\"en-US\" dir=\"ltr\">\n<p align=\"center\" style=\"margin-bottom: 0in; line-height: 100%\">1.\nGehe a<b>uf </b><b>https://www.pfe</b>rdiathek.ge</p>\n<p align=\"center\" style=\"margin-bottom: 0in; line-height: 100%\"><br/>\n\n</p>\n<p align=\"center\" style=\"margin-bottom: 0in; line-height: 100%\">2.\nMel<font color=\"#800000\">de Dich mit folgende</font> Zugangsdaten an:</p>\n<p align=\"center\" style=\"margin-bottom: 0in; line-height: 100%\">Benutzer:\nme@xxx.net</p>\n<p align=\"center\" style=\"margin-bottom: 0in; line-height: 100%\">Passwort:\nxxx.</p>\n</body>\n</html>"
2021-01-04 12:57:57 +00:00
should = "\n\n\n \n \n \n \n\n\n<p>1.\nGehe a<b>uf </b><b>https://www.pfe</b>rdiathek.ge</p>\n<p><br>\n\n</p>\n<p>2.\nMel<font color=\"#800000\">de Dich mit folgende</font> Zugangsdaten an:</p>\n<p>Benutzer:\nme@xxx.net</p>\n<p>Passwort:\nxxx.</p>\n\n"
2015-12-27 22:29:04 +00:00
result = App . Utils . htmlCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2015-12-27 22:29:04 +00:00
2017-06-21 15:49:35 +00:00
source = "<table bgcolor=\"green\" aaa=\"1\"><thead><tr><th colspan=\"2\" abc=\"a\">aaa</th></tr></thead><tbody><tr><td>value</td></tr></tbody></table>"
should = "<table bgcolor=\"green\"><thead><tr><th colspan=\"2\">aaa</th></tr></thead><tbody><tr><td>value</td></tr></tbody></table>"
result = App . Utils . htmlCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result . get ( 0 ) . outerHTML , should , source )
2017-06-21 15:49:35 +00:00
2018-07-16 07:23:57 +00:00
// strip out browser-inserted (broken) link (see https://github.com/zammad/zammad/issues/2019)
source = "<div><a href=\"https://example.com/#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}\">test</a></div>"
should = "<a href=\"#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}\">test</a>"
result = App . Utils . htmlCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result . html ( ) , should , source )
2018-07-16 07:23:57 +00:00
2017-06-21 15:49:35 +00:00
source = "<table bgcolor=\"green\" aaa=\"1\" style=\"color: red\"><thead><tr style=\"margin-top: 10px\"><th colspan=\"2\" abc=\"a\" style=\"margin-top: 12px\">aaa</th></tr></thead><tbody><tr><td>value</td></tr></tbody></table>"
2017-06-23 07:37:54 +00:00
should = "<table bgcolor=\"green\" style=\"color:red;\"><thead><tr style=\"margin-top:10px;\"><th colspan=\"2\" style=\"margin-top:12px;\">aaa</th></tr></thead><tbody><tr><td>value</td></tr></tbody></table>"
2017-06-21 15:49:35 +00:00
result = App . Utils . htmlCleanup ( source )
2017-06-23 07:37:54 +00:00
result . get ( 0 ) . outerHTML
2017-06-21 15:49:35 +00:00
//equal(result.get(0).outerHTML, should, source) / string order is different on browsers
2021-10-14 14:35:12 +00:00
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;' )
2017-06-21 15:49:35 +00:00
source = "<table bgcolor=\"green\" aaa=\"1\" style=\"color:red; display: none;\"><thead><tr><th colspan=\"2\" abc=\"a\">aaa</th></tr></thead><tbody><tr><td>value</td></tr></tbody></table>"
should = "<table bgcolor=\"green\" style=\"color:red;\"><thead><tr><th colspan=\"2\">aaa</th></tr></thead><tbody><tr><td>value</td></tr></tbody></table>"
result = App . Utils . htmlCleanup ( source )
//equal(result.get(0).outerHTML, should, source) / string order is different on browsers
2021-10-14 14:35:12 +00:00
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 )
2017-06-21 15:49:35 +00:00
2014-12-29 12:59:16 +00:00
} ) ;
2015-01-05 22:21:08 +00:00
// wrap
2021-10-14 14:35:12 +00:00
QUnit . test ( "wrap" , assert => {
2015-01-05 22:21:08 +00:00
var source = "some text"
var should = 'some text'
2015-10-09 20:31:26 +00:00
var result = App . Utils . wrap ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-05 22:21:08 +00:00
source = "some text\nsome other text\n"
should = "some text\nsome other text\n"
2015-10-09 20:31:26 +00:00
result = App . Utils . wrap ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-05 22:21:08 +00:00
source = "some text with some line to wrap"
should = "some text with\nsome line to\nwrap"
2015-10-09 20:31:26 +00:00
result = App . Utils . wrap ( source , 14 )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-05 22:21:08 +00:00
source = "some text\nsome other text\n"
should = "some text\nsome other text\n"
2015-10-09 20:31:26 +00:00
result = App . Utils . wrap ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-05 22:21:08 +00:00
source = "1234567890 1234567890 1234567890 1234567890"
should = "1234567890 1234567890 1234567890 1234567890"
2015-10-09 20:31:26 +00:00
result = App . Utils . wrap ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-05 22:21:08 +00:00
source = "123456789012 123456789012 123456789012"
should = "123456789012\n123456789012\n123456789012"
2015-10-09 20:31:26 +00:00
result = App . Utils . wrap ( source , 14 )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-05 22:21:08 +00:00
} ) ;
2015-12-27 22:29:04 +00:00
// remove empty lines
2021-10-14 14:35:12 +00:00
QUnit . test ( "remove empty lines" , assert => {
2015-12-27 22:29:04 +00:00
var source = "\ntest 123\n"
var should = "test 123\n"
var result = App . Utils . removeEmptyLines ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-12-27 22:29:04 +00:00
source = "\ntest\n\n123\n"
should = "test\n123\n"
result = App . Utils . removeEmptyLines ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-12-27 22:29:04 +00:00
} ) ;
2014-12-29 23:25:57 +00:00
// quote
2021-10-14 14:35:12 +00:00
QUnit . test ( "quote" , assert => {
2014-12-29 23:25:57 +00:00
var source = "some text"
var should = '> some text'
2015-10-09 20:31:26 +00:00
var result = App . Utils . quote ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 23:25:57 +00:00
source = "some text\nsome other text\n"
should = "> some text\n> some other text"
2015-10-09 20:31:26 +00:00
result = App . Utils . quote ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 23:25:57 +00:00
source = "\n\nsome text\nsome other text\n \n"
should = "> some text\n> some other text"
2015-10-09 20:31:26 +00:00
result = App . Utils . quote ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 23:25:57 +00:00
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 ..."
2015-10-09 20:31:26 +00:00
result = App . Utils . quote ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2014-12-29 23:25:57 +00:00
2015-01-05 22:21:08 +00:00
source = "Welcome! Thank you for installing Zammad. You will find ..."
should = "> Welcome! Thank you\n> for installing\n> Zammad. You will\n> find ..."
2015-10-09 20:31:26 +00:00
result = App . Utils . quote ( source , 20 )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2015-01-05 22:21:08 +00:00
2014-12-29 23:25:57 +00:00
} ) ;
2015-01-07 10:05:12 +00:00
// check signature
2021-10-14 14:35:12 +00:00
QUnit . test ( "check signature" , assert => {
2015-01-07 10:05:12 +00:00
var message = "<div>test 123 </div>"
var signature = '<div>--<br>Some Signature<br>some department</div>'
2015-10-09 20:31:26 +00:00
var result = App . Utils . signatureCheck ( message , signature )
2021-10-14 14:35:12 +00:00
assert . equal ( result , true )
2015-01-07 10:05:12 +00:00
message = "<div>test 123 <div>--<br>Some Signature<br>some department\n</div></div>"
signature = '<div>--<br>Some Signature<br>some department</div>'
2015-10-09 20:31:26 +00:00
result = App . Utils . signatureCheck ( message , signature )
2021-10-14 14:35:12 +00:00
assert . equal ( result , false )
2015-01-07 10:05:12 +00:00
message = "<div>test 123 <div>--<br>Some Signature\n<br>some department\n</div></div>"
signature = '<div>--<br>Some Signature<br>some department</div>'
2015-10-09 20:31:26 +00:00
result = App . Utils . signatureCheck ( message , signature )
2021-10-14 14:35:12 +00:00
assert . equal ( result , false )
2015-01-07 10:05:12 +00:00
message = "<div>test 123 <div>--<p>Some Signature</p>\n<p><div>some department</div>\n</p>\n</div></div>"
signature = '<div>--<br>Some Signature<br>some department</div>'
2015-10-09 20:31:26 +00:00
result = App . Utils . signatureCheck ( message , signature )
2021-10-14 14:35:12 +00:00
assert . equal ( result , false )
2015-01-07 10:05:12 +00:00
message = ""
signature = '<div>--<br>Some Signature<br>some department</div>'
2015-10-09 20:31:26 +00:00
result = App . Utils . signatureCheck ( message , signature )
2021-10-14 14:35:12 +00:00
assert . equal ( result , true )
2015-01-07 10:05:12 +00:00
message = ""
signature = "--\nSome Signature\nsome department"
2015-10-09 20:31:26 +00:00
result = App . Utils . signatureCheck ( message , signature )
2021-10-14 14:35:12 +00:00
assert . equal ( result , true )
2015-01-07 10:05:12 +00:00
} ) ;
2015-04-02 22:29:32 +00:00
// identify signature
2021-10-14 14:35:12 +00:00
QUnit . test ( "identify signature by plaintext" , assert => {
2015-04-02 22:29:32 +00:00
var message = "<div>test 123 </div>"
var should = '<div>test 123 </div>'
2018-09-25 09:43:52 +00:00
var result = App . Utils . signatureIdentifyByPlaintext ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-02 22:29:32 +00:00
message = "<div>test 123 <br/>--<br/>Bob Smith</div>"
should = '<div>test 123 <br/>--<br/>Bob Smith</div>'
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-02 22:29:32 +00:00
2015-04-03 01:11:21 +00:00
message = "<div>test 123 <br/>1<br/>2<br/>3<br/>4<br/>5<br/>6<br/>7<br/>8<br/>9<br/><br/>--<br/>Bob Smith</div>"
should = '<div>test 123 <br/>1<br/>2<br/>3<br/>4<br/>5<br/>6<br/>7<br/>8<br/>9<br/><br/><span class="js-signatureMarker"></span>--<br/>Bob Smith</div>'
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-02 22:29:32 +00:00
2015-04-03 01:11:21 +00:00
message = "<div>test 123 <br/><br/>--no not match--<br/>--<br/>Bob Smith</div>"
should = '<div>test 123 <br/><br/>--no not match--<br/><span class="js-signatureMarker"></span>--<br/>Bob Smith</div>'
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-02 22:29:32 +00:00
2015-04-03 01:11:21 +00:00
message = "<div>test 123 <br/><br/>--no not match--<br/> -- <br/>Bob Smith</div>"
should = '<div>test 123 <br/><br/>--no not match--<br/><span class="js-signatureMarker"></span> -- <br/>Bob Smith</div>'
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-02 22:29:32 +00:00
2015-04-03 01:11:21 +00:00
message = "<div>test 123 <br/><br/>--<br/>Bob Smith<br/><br/><br/><br/><br/>--<br/>Bob Smith</div>"
should = '<div>test 123 <br/><br/><span class="js-signatureMarker"></span>--<br/>Bob Smith<br/><br/><br/><br/><br/>--<br/>Bob Smith</div>'
2015-04-02 22:29:32 +00:00
//should = '<div>test 123 <br><br><br><br><br><br><br><br><br><br><br><span class="js-signatureMarker"></span>--<br>Bob Smith<br/><br/><br/><br/><br/>--<br/>Bob Smith</div>'
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-02 22:29:32 +00:00
2015-04-03 01:11:21 +00:00
message = "<div>test 123</div><div>test 123</div><div>--</div><div>Bob Smith</div>"
should = "<div>test 123</div><div>test 123</div><div><span class=\"js-signatureMarker\"></span>--</div><div>Bob Smith</div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-02 22:29:32 +00:00
2015-04-03 01:11:21 +00:00
message = "<p><span>test 123</span></p><p><span>test 123</span></p><p><span>--</span></p><p><span>Bob Smith</span></p><div></div>"
should = "<p><span>test 123</span></p><p><span>test 123</span></p><p><span><span class=\"js-signatureMarker\"></span>--</span></p><p><span>Bob Smith</span></p><div></div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2016-11-03 23:14:43 +00:00
message = "Test reply to zammad<br><br>Am 24.10.2016 18:55 schrieb "Android Support" <android-support@example.com>:<br><br>> <u></u><br>> Sehr geehrte Damen"
should = "Test reply to zammad<br><br><span class=\"js-signatureMarker\"></span>Am 24.10.2016 18:55 schrieb "Android Support" <android-support@example.com>:<br><br>> <u></u><br>> Sehr geehrte Damen"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2016-11-03 23:14:43 +00:00
message = "<br>< On 20 Oct 2016, at 12:23, Martin Edenhofer via Zammad Helpdesk wrote:<br>"
should = "<br><span class=\"js-signatureMarker\"></span>< On 20 Oct 2016, at 12:23, Martin Edenhofer via Zammad Helpdesk wrote:<br>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-02 22:29:32 +00:00
2015-04-03 00:01:21 +00:00
// apple
2015-04-04 22:20:47 +00:00
// en
2015-04-03 01:11:21 +00:00
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>On 01/04/15 10:55, Bob Smith wrote:<br/>lalala<p>--</p>some test</div>"
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>On 01/04/15 10:55, Bob Smith wrote:<br/>lalala<p>--</p>some test</div>'
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-02 22:29:32 +00:00
2015-04-04 22:20:47 +00:00
// de
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>Am 03.04.2015 um 20:58 schrieb Bob Smith <bob@example.com>:<br/>lalala</div>"
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>Am 03.04.2015 um 20:58 schrieb Bob Smith <bob@example.com>:<br/>lalala</div>'
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-02 22:29:32 +00:00
2015-04-03 00:01:21 +00:00
// ms
2015-04-04 22:20:47 +00:00
// en
2015-04-03 01:11:21 +00:00
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Sent: Donnerstag, 2. April 2015 10:00<br/>lalala</div>"
2015-04-03 01:49:40 +00:00
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Sent: Donnerstag, 2. April 2015 10:00<br/>lalala</div>'
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-03 01:49:40 +00:00
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Sent: Donnerstag, 2. April 2015 10:00<br/>Subject: lalala</div>"
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Sent: Donnerstag, 2. April 2015 10:00<br/>Subject: lalala</div>'
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-03 01:49:40 +00:00
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Sent: Donnerstag, 2. April 2015 10:00<br/>1<br/>2<br/>3<br/>4<br/>4<br/>Subject: lalala</div>"
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Sent: Donnerstag, 2. April 2015 10:00<br/>1<br/>2<br/>3<br/>4<br/>4<br/>Subject: lalala</div>'
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-02 22:29:32 +00:00
2015-04-04 22:20:47 +00:00
// de
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>Von: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Gesendet: Donnerstag, 2. April 2015 10:00<br/>Betreff: lalala</div>"
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>Von: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Gesendet: Donnerstag, 2. April 2015 10:00<br/>Betreff: lalala</div>'
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-04 22:20:47 +00:00
2015-04-03 01:11:21 +00:00
message = "<div>1<br><br></div><div>Von: Martin Edenhofer via Znuny Support [<a href=\"mailto:support@znuny.inc\" title=\"mailto:support@znuny.inc\" target=\"_blank\">mailto:support@znuny.inc</a>]</div>\n<div>Gesendet: Donnerstag, 2. April 2015 11:32</div>"
2015-04-03 01:49:40 +00:00
should = "<div>1<br><br></div><div>Von: Martin Edenhofer via Znuny Support [<a href=\"mailto:support@znuny.inc\" title=\"mailto:support@znuny.inc\" target=\"_blank\">mailto:support@znuny.inc</a>]</div>\n<div>Gesendet: Donnerstag, 2. April 2015 11:32</div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-03 01:49:40 +00:00
message = "<div>1<br><br></div><div>Von: Martin Edenhofer via Znuny Support [<a href=\"mailto:support@znuny.inc\" title=\"mailto:support@znuny.inc\" target=\"_blank\">mailto:support@znuny.inc</a>]</div>\n<div>Gesendet: Donnerstag, 2. April 2015 11:32</div><div>Betreff: lalala</div>"
should = "<div>1<br><br></div><div><span class=\"js-signatureMarker\"></span>Von: Martin Edenhofer via Znuny Support [<a href=\"mailto:support@znuny.inc\" title=\"mailto:support@znuny.inc\" target=\"_blank\">mailto:support@znuny.inc</a>]</div>\n<div>Gesendet: Donnerstag, 2. April 2015 11:32</div><div>Betreff: lalala</div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-03 01:49:40 +00:00
message = "<div>1<br><br></div><div>Von: Martin Edenhofer via Znuny Support <<a href=\"mailto:support@znuny.inc\" title=\"mailto:support@znuny.inc\" target=\"_blank\">mailto:support@znuny.inc</a>></div>\n<div>An: somebody</div><div>Datum: Donnerstag, 2. April 2015 11:32</div><div>Betreff: lalala</div>"
should = "<div>1<br><br></div><div><span class=\"js-signatureMarker\"></span>Von: Martin Edenhofer via Znuny Support <<a href=\"mailto:support@znuny.inc\" title=\"mailto:support@znuny.inc\" target=\"_blank\">mailto:support@znuny.inc</a>></div>\n<div>An: somebody</div><div>Datum: Donnerstag, 2. April 2015 11:32</div><div>Betreff: lalala</div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-03 00:01:21 +00:00
2015-10-10 08:38:54 +00:00
message = "<div>Von: "Johannes Nickel via Znuny Projects" <<a href=\"mailto:projects@znuny.inc\" title=\"mailto:projects@znuny.inc\">projects@znuny.inc</a>></div><div>An: \"Lisa Smith\" <<a href=\"mailto:lisa.smith@example.com\" title=\"mailto:lisa.smith@example.com\">lisa.smith@example.com</a>></div><div>Gesendet: Donnerstag, 2. April 2015 10:11:12</div><div>Betreff: Angebot Redundanz / Paket mit Silver Subscription [Ticket#424242]</div><div><br></div><div>Hallo Frau Smith,</div>"
should = "<div><span class=\"js-signatureMarker\"></span>Von: "Johannes Nickel via Znuny Projects" <<a href=\"mailto:projects@znuny.inc\" title=\"mailto:projects@znuny.inc\">projects@znuny.inc</a>></div><div>An: \"Lisa Smith\" <<a href=\"mailto:lisa.smith@example.com\" title=\"mailto:lisa.smith@example.com\">lisa.smith@example.com</a>></div><div>Gesendet: Donnerstag, 2. April 2015 10:11:12</div><div>Betreff: Angebot Redundanz / Paket mit Silver Subscription [Ticket#424242]</div><div><br></div><div>Hallo Frau Smith,</div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-10-10 08:38:54 +00:00
2021-10-14 14:35:12 +00:00
message = "<div>Hi Johannes,</div><div><br></div><div>das Angebot für den halben Tag bitte an uns.</div><div>Der Termin hat sich jetzt auf 10-12 Uhr verschoben, hab ich dir weitergeleitet.</div><div><br></div><div>Viele Grüße</div><div>Max</div><div><br></div><div>> On 07 Oct 2015, at 11:55, Johannes Smith <<a href=mailto:smith@example.com title=mailto:smith@example.com target=_blank>smith@example.com</a> <<a href=mailto:smith@example.com title=mailto:smith@example.com target=_blank>mailto:smith@example.com</a>>> wrote:</div><div>></div><div>> Hi,</div><div>></div><div>> assert.OK. Wer kriegt das Angebot? Ist das wirklich nur ein halber Tag?</div></div>"
should = "<div>Hi Johannes,</div><div><br></div><div>das Angebot für den halben Tag bitte an uns.</div><div>Der Termin hat sich jetzt auf 10-12 Uhr verschoben, hab ich dir weitergeleitet.</div><div><br></div><div>Viele Grüße</div><div>Max</div><div><br></div><div><span class=\"js-signatureMarker\"></span>> On 07 Oct 2015, at 11:55, Johannes Smith <<a href=mailto:smith@example.com title=mailto:smith@example.com target=_blank>smith@example.com</a> <<a href=mailto:smith@example.com title=mailto:smith@example.com target=_blank>mailto:smith@example.com</a>>> wrote:</div><div>></div><div>> Hi,</div><div>></div><div>> assert.OK. Wer kriegt das Angebot? Ist das wirklich nur ein halber Tag?</div></div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-04 22:20:47 +00:00
2016-02-11 19:17:39 +00:00
message = "Dear Mr. Smith,<div><br></div><div>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 <span style=\"line-height: 1.45; background-color: initial;\"><ABC_CONFIG_Home>/war/log/ITSMChangeCounter.log befindenden Zahl die SystemID (SysConfig) geschrieben. Dies ist ein Standardverhalten, dass auch bei der Ticketnummer verwendet wird.<br><br>Please ask me if you have questions.</span></div><div><span style=\"line-height: 1.45; background-color: initial;\"><br></span></div><div><span style=\"line-height: 1.45; background-color: initial;\">Viele Grüße,</span></div><div><div data-signature=\"true\" data-signature-id=\"1\"> Thorsten Smith\n<br>\n<br>--\n<br>Enterprise Services for ABC\n<br>\n<br>Znuny GmbH // Marienstraße 11 // 10117 Berlin // Germany\n<br>\n<br>P: +49 (0) 30 111 111 111-0\n<br>F: +49 (0) 30 111 111 111-8\n<br>W: http://znuny.com \n<br>\n<br>Location: Berlin - HRB 12345678 B Amtsgericht Berlin-Charlottenburg\n<br>Managing Director: Martin Edenhofer\n<br></div></div>"
should = "Dear Mr. Smith,<div><br></div><div>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 <span style=\"line-height: 1.45; background-color: initial;\"><ABC_CONFIG_Home>/war/log/ITSMChangeCounter.log befindenden Zahl die SystemID (SysConfig) geschrieben. Dies ist ein Standardverhalten, dass auch bei der Ticketnummer verwendet wird.<br><br>Please ask me if you have questions.</span></div><div><span style=\"line-height: 1.45; background-color: initial;\"><br></span></div><div><span style=\"line-height: 1.45; background-color: initial;\">Viele Grüße,</span></div><div><span class=\"js-signatureMarker\"></span><div data-signature=\"true\" data-signature-id=\"1\"> Thorsten Smith\n<br>\n<br>--\n<br>Enterprise Services for ABC\n<br>\n<br>Znuny GmbH // Marienstraße 11 // 10117 Berlin // Germany\n<br>\n<br>P: +49 (0) 30 111 111 111-0\n<br>F: +49 (0) 30 111 111 111-8\n<br>W: http://znuny.com \n<br>\n<br>Location: Berlin - HRB 12345678 B Amtsgericht Berlin-Charlottenburg\n<br>Managing Director: Martin Edenhofer\n<br></div></div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2016-02-11 19:17:39 +00:00
message = "Dear Mr. Smith, nice to read you,<div><div data-signature=\"true\" data-signature-id=\"1\"> Thorsten Smith\n<br>\n<br>--\n</div></div>"
should = "Dear Mr. Smith, nice to read you,<div><span class=\"js-signatureMarker\"></span><div data-signature=\"true\" data-signature-id=\"1\"> Thorsten Smith\n<br>\n<br>--\n</div></div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2016-02-11 19:17:39 +00:00
message = "Dear Mr. Smith, nice to read you,<div><div data-signature=\"true\" data-signature-id=\"9999\"> Thorsten Smith\n<br>\n<br>--\n</div></div>"
should = "Dear Mr. Smith, nice to read you,<div><div data-signature=\"true\" data-signature-id=\"9999\"> Thorsten Smith\n<br>\n<br>--\n</div></div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , false , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2016-02-11 19:17:39 +00:00
2015-04-30 07:23:01 +00:00
// fr
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>De : Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Envoyé : mercredi 29 avril 2015 17:31<br/>Objet : lalala</div>"
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>De : Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]<br/>Envoyé : mercredi 29 avril 2015 17:31<br/>Objet : lalala</div>'
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-30 07:23:01 +00:00
2015-04-04 22:20:47 +00:00
// thunderbird
// de
message = "<div><br></div><div>Viele Grüße,</div><div>Christian</div><div><br></div><div>Am 04.03.2015 um 12:47 schrieb Martin Edenhofer via Znuny Sales:</div><div>> Hallo Christian,</div>"
should = "<div><br></div><div>Viele Grüße,</div><div>Christian</div><div><br></div><div><span class=\"js-signatureMarker\"></span>Am 04.03.2015 um 12:47 schrieb Martin Edenhofer via Znuny Sales:</div><div>> Hallo Christian,</div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-04 22:20:47 +00:00
// en - Thunderbird default - http://kb.mozillazine.org/Reply_header_settings
message = "<div><br></div><div>Viele Grüße,</div><div>Christian</div><div><br></div><div>On 01-01-2007 11:00 AM, Alf Aardvark wrote:</div><div>> Hallo Christian,</div>"
should = "<div><br></div><div>Viele Grüße,</div><div>Christian</div><div><br></div><div><span class=\"js-signatureMarker\"></span>On 01-01-2007 11:00 AM, Alf Aardvark wrote:</div><div>> Hallo Christian,</div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-04 22:20:47 +00:00
// en - http://kb.mozillazine.org/Reply_header_settings
message = "<div><br></div><div>Viele Grüße,</div><div>Christian</div><div><br></div><div>Alf Aardvark wrote, on 01-01-2007 11:00 AM:</div><div>> Hallo Christian,</div>"
should = "<div><br></div><div>Viele Grüße,</div><div>Christian</div><div><br></div><div><span class=\"js-signatureMarker\"></span>Alf Aardvark wrote, on 01-01-2007 11:00 AM:</div><div>> Hallo Christian,</div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-04 22:20:47 +00:00
2015-04-03 00:01:21 +00:00
// otrs
2015-04-04 22:20:47 +00:00
// en
2015-04-03 01:11:21 +00:00
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>01/04/15 10:55 - Bob Smith wrote:<br/>lalala</div>"
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>01/04/15 10:55 - Bob Smith wrote:<br/>lalala</div>'
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-02 22:29:32 +00:00
2015-04-04 22:20:47 +00:00
// de
2015-04-03 01:11:21 +00:00
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>01/04/15 10:55 - Bob Smith schrieb:<br/>lalala</div>"
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>01/04/15 10:55 - Bob Smith schrieb:<br/>lalala</div>'
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-02 22:29:32 +00:00
2015-04-03 01:11:21 +00:00
message = "<div>test 123 <br/><br/></div><div>24.02.2015 14:20 - Roy Kaldung via Znuny Sales schrieb: </div>"
should = "<div>test 123 <br/><br/></div><div><span class=\"js-signatureMarker\"></span>24.02.2015 14:20 - Roy Kaldung via Znuny Sales schrieb: </div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-03 00:01:21 +00:00
2015-04-04 22:20:47 +00:00
// zammad
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><div data-signature=\"true\" data-signature-id=\"5\">lalala</div></div>"
should = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class=\"js-signatureMarker\"></span><div data-signature=\"true\" data-signature-id=\"5\">lalala</div></div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-04 22:20:47 +00:00
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><blockquote type=\"cite\">lalala</blockquote></div>"
should = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class=\"js-signatureMarker\"></span><blockquote type=\"cite\">lalala</blockquote></div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-04 22:20:47 +00:00
2015-04-04 22:43:01 +00:00
// gmail
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><blockquote class=\"ecxgmail_quote\">lalala</blockquote></div>"
should = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class=\"js-signatureMarker\"></span><blockquote class=\"ecxgmail_quote\">lalala</blockquote></div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-04 22:43:01 +00:00
2015-04-05 11:05:59 +00:00
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><blockquote class=\"gmail_quote\">lalala</blockquote></div>"
should = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class=\"js-signatureMarker\"></span><blockquote class=\"gmail_quote\">lalala</blockquote></div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-05 11:05:59 +00:00
2015-04-04 22:43:01 +00:00
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>Am 24. Dezember 2015 um 07:45 schrieb kathrine <kathrine@example.com>:<br/>lalala</div>"
should = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class=\"js-signatureMarker\"></span>Am 24. Dezember 2015 um 07:45 schrieb kathrine <kathrine@example.com>:<br/>lalala</div>"
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-04-04 22:43:01 +00:00
2015-09-02 07:16:31 +00:00
// word 14
// en
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>Bob Smith wrote:<br/>lalala</div>"
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>Bob Smith wrote:<br/>lalala</div>'
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-09-02 07:16:31 +00:00
// de
message = "<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/>Bob Smith schrieb:<br/>lalala</div>"
should = '<div>test 123 <br/><br/>--no not match--<br/><br/>Bob Smith<br/><span class="js-signatureMarker"></span>Bob Smith schrieb:<br/>lalala</div>'
2018-09-25 09:43:52 +00:00
result = App . Utils . signatureIdentifyByPlaintext ( message , true )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2015-09-02 07:16:31 +00:00
2015-04-02 22:29:32 +00:00
} ) ;
2018-09-25 09:43:52 +00:00
2021-10-14 14:35:12 +00:00
QUnit . test ( "identify signature by HTML" , assert => {
2018-09-25 09:43:52 +00:00
var message = "<div>test 123 </div>"
var should = message
var result = App . Utils . signatureIdentifyByHtml ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2018-09-25 09:43:52 +00:00
2021-02-11 07:51:52 +00:00
// test if, according to jQuery, invalid HTML does not cause a a crash
// https://github.com/zammad/zammad/issues/3393
message = "<td></td><table></table><div>test 123 </div>"
should = message
result = App . Utils . signatureIdentifyByHtml ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2021-02-11 07:51:52 +00:00
2018-09-25 09:43:52 +00:00
// simple case 1
message = '<div>actual content</div><blockquote>quoted content</blockquote>'
should = '<div>actual content</div><span class="js-signatureMarker"></span><blockquote>quoted content</blockquote>'
result = App . Utils . signatureIdentifyByHtml ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2018-09-25 09:43:52 +00:00
// simple case 2
message = '<div>actual content</div><blockquote>quoted content</blockquote><br><div><br></div><div><br> </div>'
should = '<div>actual content</div><span class="js-signatureMarker"></span><blockquote>quoted content</blockquote><br><div><br></div><div><br> </div>'
result = App . Utils . signatureIdentifyByHtml ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2018-09-25 09:43:52 +00:00
// simple case 3
message = '<div>actual content</div><blockquote>quoted content</blockquote><br><div>actual content 2</div>'
should = message
result = App . Utils . signatureIdentifyByHtml ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2018-09-25 09:43:52 +00:00
// simple case 4
message = ' content 0 <div>content 1</div> content 2 <blockquote>quoted content</blockquote><br><div><br></div><div><br> </div>'
should = ' content 0 <div>content 1</div> content 2 <span class="js-signatureMarker"></span><blockquote>quoted content</blockquote><br><div><br></div><div><br> </div>'
result = App . Utils . signatureIdentifyByHtml ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2018-09-25 09:43:52 +00:00
2021-07-14 13:47:26 +00:00
// Invalid html signature detection for exchange warning boxes #3571
2021-05-26 08:46:59 +00:00
message = '<div><span style="color:#9c6500;">CAUTION:</span> 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.</div><br><div><p>actual content</p><div><p>actual content 2</p></div><p> </p><div><p>actual quote</p></div><div><blockquote><p>actual quote</p></blockquote></div><div><p> </p></div><p> </p></div></div>'
should = '<div><span style="color:#9c6500;">CAUTION:</span> 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.</div><br><div><p>actual content</p><div><p>actual content 2</p></div><p> </p><div><p>actual quote</p></div><div><blockquote><p>actual quote</p></blockquote></div><div><p> </p></div><p> </p></div></div>'
result = App . Utils . signatureIdentifyByHtml ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2021-05-26 08:46:59 +00:00
2021-07-14 13:47:26 +00:00
// Invalid html signature detection for exchange warning boxes #3571
message = '<div>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.</div><br><div><p>actual content</p><div><p>actual content 2</p></div><p> </p><div><p>actual quote</p></div><div><blockquote><p>actual quote</p></blockquote></div><div><p> </p></div><p> </p></div></div>'
should = '<div>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.</div><br><div><p>actual content</p><div><p>actual content 2</p></div><p> </p><div><p>actual quote</p></div><div><blockquote><p>actual quote</p></blockquote></div><div><p> </p></div><p> </p></div></div>'
result = App . Utils . signatureIdentifyByHtml ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2021-07-14 13:47:26 +00:00
2018-09-25 09:43:52 +00:00
// Gmail via Safari on MacOS 10.12
message = ' < div dir = "ltr" > Reply with < b > gmail < / b > v i a S a f a r i o n M a c O S 1 0 . 1 2 < / d i v > < b r > \
< div > \
< div dir = "ltr" > Am Mi . , 5. Sep . 2018 um 09 : 22 Uhr schrieb Billy Zhou & lt ; bz @ zammad . com & gt ; : < br > \
< / d i v > \
< blockquote > test email content < br > \
< br > \
< / b l o c k q u o t e > \
< / d i v > '
should = ' < div dir = "ltr" > Reply with < b > gmail < / b > v i a S a f a r i o n M a c O S 1 0 . 1 2 < / d i v > < b r > \
< span class = \ "js-signatureMarker\" > < / s p a n > < d i v > \
< div dir = "ltr" > Am Mi . , 5. Sep . 2018 um 09 : 22 Uhr schrieb Billy Zhou & lt ; bz @ zammad . com & gt ; : < br > \
< / d i v > \
< blockquote > test email content < br > \
< br > \
< / b l o c k q u o t e > \
< / d i v > '
result = App . Utils . signatureIdentifyByHtml ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2018-09-25 09:43:52 +00:00
// Yahoo Mail via Safari on MacOS 10.12
message = '<div style="color:#000; background-color:#fff; font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_ym19_1_1536132243868_2594"><span id="yui_3_16_0_ym19_1_1536132243868_2593">Reply with <b id="yui_3_16_0_ym19_1_1536132243868_2597">Yahoo Mail</b> via Safari on MacOS 10.12</span></div> <div class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" style="display: block;"> <div style="font-family: Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div dir="ltr"><font size="2" face="Arial"> Billy Zhou <bz@zammad.com> schrieb am 9:08 Mittwoch, 5.September 2018:<br></font></div> <br><br> <div class="y_msg_container"><div dir="ltr">test email content<br></div><div dir="ltr"><br></div><br><br></div> </div> </div> </div></div>'
should = '<div style="color:#000; background-color:#fff; font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_ym19_1_1536132243868_2594"><span id="yui_3_16_0_ym19_1_1536132243868_2593">Reply with <b id="yui_3_16_0_ym19_1_1536132243868_2597">Yahoo Mail</b> via Safari on MacOS 10.12</span></div> <div class="qtdSeparateBR"><br><br></div><span class="js-signatureMarker"></span><div class="yahoo_quoted" style="display: block;"> <div style="font-family: Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div dir="ltr"><font size="2" face="Arial"> Billy Zhou <bz@zammad.com> schrieb am 9:08 Mittwoch, 5.September 2018:<br></font></div> <br><br> <div class="y_msg_container"><div dir="ltr">test email content<br></div><div dir="ltr"><br></div><br><br></div> </div> </div> </div></div>'
result = App . Utils . signatureIdentifyByHtml ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2018-09-25 09:43:52 +00:00
// Thunderbird 52 on MacOS 10.12
message = ' Reply with < b > Thunderbird 52 < / b > o n M a c O S 1 0 . 1 2 < b r > \
< br > \
< div class = "moz-cite-prefix" > Am 04.09 . 18 um 15 : 32 schrieb Billy \
Zhou : < br > \
< / d i v > \
< blockquote type = "cite" \
cite = "mid:da18ed01-b187-a383-bfe7-72663cf82a83@zammad.com" > test \
email content \
< br > \
< br > \
< / b l o c k q u o t e > \
< br > '
should = ' Reply with < b > Thunderbird 52 < / b > o n M a c O S 1 0 . 1 2 < b r > \
< br > \
< div class = "moz-cite-prefix" > Am 04.09 . 18 um 15 : 32 schrieb Billy \
Zhou : < br > \
< / d i v > \
< span class = \ "js-signatureMarker\"></span><blockquote type=" cite " cite=" mid : da18ed01 - b187 - a383 - bfe7 - 72663 cf82a83 @ zammad . com " > test \
email content \
< br > \
< br > \
< / b l o c k q u o t e > \
< br > '
result = App . Utils . signatureIdentifyByHtml ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2018-09-25 09:43:52 +00:00
// Apple Mail on MacOS 10
message = '<div class="">Reply by <b class="">Apple Mail</b> on MacOS 10.</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On 4. Sep 2018, at 15:32, Billy Zhou <<a href="mailto:bz@zammad.com" class="">bz@zammad.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">test email content<br class=""><br class=""></div></div></blockquote></div><br class="">'
should = '<div class="">Reply by <b class="">Apple Mail</b> on MacOS 10.</div><div class=""><br class=""></div><br class=""><span class=\"js-signatureMarker\"></span><div><blockquote type="cite" class=""><div class="">On 4. Sep 2018, at 15:32, Billy Zhou <<a href="mailto:bz@zammad.com" class="">bz@zammad.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">test email content<br class=""><br class=""></div></div></blockquote></div><br class="">'
result = App . Utils . signatureIdentifyByHtml ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2018-09-25 09:43:52 +00:00
// Office 365 (10325.20118) on Windows 10 Build 1803
// With German marker: -----Ursprüngliche Nachricht-----
// Using fallback to signatureIdentifyByPlaintext
message = ' < div > \
< p > Reply with Office 365 ( 10325.20118 ) on Windows 10 Build 1803 < / p > \
< p > < / p > \
< p > < b > fett < / b > < / p > \
< p > < / p > \
< span class = "js-signatureMarker" > < / s p a n > < p > - - < / p > \
< p > Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany</p>\
< p > < / p > \
< p > P : + 49 ( 0 ) 30 55 57 160 - 0 < / p > \
< p > F : + 49 ( 0 ) 30 55 57 160 - 99 < / p > \
< p > W : < a href = "https://zammad.com" rel = "nofollow noreferrer noopener" target = "_blank" > https : //zammad.com</a></p>\
< p > < / p > \
< p > Location : Berlin - HRB 163946 B Amtsgericht Berlin - Charlottenburg < / p > \
< p > Managing Director : Martin Edenhofer < / p > \
< p > < / p > \
< p > -- -- - Ursprüngliche Nachricht -- -- - < br > Von : Billy Zhou & lt ; bz @ zammad . com & gt ; < br > Gesendet : Dienstag , 4. September 2018 15 : 33 < br > An : me @ zammad . com < br > Betreff : test email title < / p > \
< p > < / p > \
< p > test email content < / p > \
< p > < / p > \
< / d i v > '
should = ' < div > \
< p > Reply with Office 365 ( 10325.20118 ) on Windows 10 Build 1803 < / p > \
< p > < / p > \
< p > < b > fett < / b > < / p > \
< p > < / p > \
< span class = "js-signatureMarker" > < / s p a n > < p > < s p a n c l a s s = \ " j s - s i g n a t u r e M a r k e r \ " > < / s p a n > - - < / p > \
< p > Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany</p>\
< p > < / p > \
< p > P : + 49 ( 0 ) 30 55 57 160 - 0 < / p > \
< p > F : + 49 ( 0 ) 30 55 57 160 - 99 < / p > \
< p > W : < a href = "https://zammad.com" rel = "nofollow noreferrer noopener" target = "_blank" > https : //zammad.com</a></p>\
< p > < / p > \
< p > Location : Berlin - HRB 163946 B Amtsgericht Berlin - Charlottenburg < / p > \
< p > Managing Director : Martin Edenhofer < / p > \
< p > < / p > \
< p > -- -- - Ursprüngliche Nachricht -- -- - < br > Von : Billy Zhou & lt ; bz @ zammad . com & gt ; < br > Gesendet : Dienstag , 4. September 2018 15 : 33 < br > An : me @ zammad . com < br > Betreff : test email title < / p > \
< p > < / p > \
< p > test email content < / p > \
< p > < / p > \
< / d i v > '
result = App . Utils . signatureIdentifyByHtml ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2018-09-25 09:43:52 +00:00
// Office 365 (10325.20118) on Windows 10 Build 1803
// With English marker: -----Original Message-----
// Using fallback to signatureIdentifyByPlaintext
message = ' < div > \
< p > Reply with Office 365 ( 10325.20118 ) on Windows 10 Build 1803 < / p > \
< p > < / p > \
< p > < b > fett < / b > < / p > \
< p > < / p > \
< span class = "js-signatureMarker" > < / s p a n > < p > - - < / p > \
< p > Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany</p>\
< p > < / p > \
< p > P : + 49 ( 0 ) 30 55 57 160 - 0 < / p > \
< p > F : + 49 ( 0 ) 30 55 57 160 - 99 < / p > \
< p > W : < a href = "https://zammad.com" rel = "nofollow noreferrer noopener" target = "_blank" > https : //zammad.com</a></p>\
< p > < / p > \
< p > Location : Berlin - HRB 163946 B Amtsgericht Berlin - Charlottenburg < / p > \
< p > Managing Director : Martin Edenhofer < / p > \
< p > < / p > \
< p > -- -- - Original Message -- -- - < br > Von : Billy Zhou & lt ; bz @ zammad . com & gt ; < br > Gesendet : Dienstag , 4. September 2018 15 : 33 < br > An : me @ zammad . com < br > Betreff : test email title < / p > \
< p > < / p > \
< p > test email content < / p > \
< p > < / p > \
< / d i v > '
should = ' < div > \
< p > Reply with Office 365 ( 10325.20118 ) on Windows 10 Build 1803 < / p > \
< p > < / p > \
< p > < b > fett < / b > < / p > \
< p > < / p > \
< span class = "js-signatureMarker" > < / s p a n > < p > < s p a n c l a s s = \ " j s - s i g n a t u r e M a r k e r \ " > < / s p a n > - - < / p > \
< p > Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany</p>\
< p > < / p > \
< p > P : + 49 ( 0 ) 30 55 57 160 - 0 < / p > \
< p > F : + 49 ( 0 ) 30 55 57 160 - 99 < / p > \
< p > W : < a href = "https://zammad.com" rel = "nofollow noreferrer noopener" target = "_blank" > https : //zammad.com</a></p>\
< p > < / p > \
< p > Location : Berlin - HRB 163946 B Amtsgericht Berlin - Charlottenburg < / p > \
< p > Managing Director : Martin Edenhofer < / p > \
< p > < / p > \
< p > -- -- - Original Message -- -- - < br > Von : Billy Zhou & lt ; bz @ zammad . com & gt ; < br > Gesendet : Dienstag , 4. September 2018 15 : 33 < br > An : me @ zammad . com < br > Betreff : test email title < / p > \
< p > < / p > \
< p > test email content < / p > \
< p > < / p > \
< / d i v > '
result = App . Utils . signatureIdentifyByHtml ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2018-09-25 09:43:52 +00:00
// Office 365 (10325.20118) on Windows 10 Build 1803
// With German marker: -----Ursprüngliche Nachricht-----
// Without any existing <span class="js-signatureMarker"></span>
// Using fallback to signatureIdentifyByPlaintext
message = ' < div > \
< p > Reply with Office 365 ( 10325.20118 ) on Windows 10 Build 1803 < / p > \
< p > < / p > \
< p > < b > fett < / b > < / p > \
< p > < / p > \
< p > -- < / p > \
< p > Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany</p>\
< p > < / p > \
< p > P : + 49 ( 0 ) 30 55 57 160 - 0 < / p > \
< p > F : + 49 ( 0 ) 30 55 57 160 - 99 < / p > \
< p > W : < a href = "https://zammad.com" rel = "nofollow noreferrer noopener" target = "_blank" > https : //zammad.com</a></p>\
< p > < / p > \
< p > Location : Berlin - HRB 163946 B Amtsgericht Berlin - Charlottenburg < / p > \
< p > Managing Director : Martin Edenhofer < / p > \
< p > < / p > \
< p > -- -- - Ursprüngliche Nachricht -- -- - < br > Von : Billy Zhou & lt ; bz @ zammad . com & gt ; < br > Gesendet : Dienstag , 4. September 2018 15 : 33 < br > An : me @ zammad . com < br > Betreff : test email title < / p > \
< p > < / p > \
< p > test email content < / p > \
< p > < / p > \
< / d i v > '
should = ' < div > \
< p > Reply with Office 365 ( 10325.20118 ) on Windows 10 Build 1803 < / p > \
< p > < / p > \
< p > < b > fett < / b > < / p > \
< p > < / p > \
< p > < span class = \ "js-signatureMarker\" > < / s p a n > - - < / p > \
< p > Zammad GmbH // Marienstraße 11 // 10117 Berlin // Germany</p>\
< p > < / p > \
< p > P : + 49 ( 0 ) 30 55 57 160 - 0 < / p > \
< p > F : + 49 ( 0 ) 30 55 57 160 - 99 < / p > \
< p > W : < a href = "https://zammad.com" rel = "nofollow noreferrer noopener" target = "_blank" > https : //zammad.com</a></p>\
< p > < / p > \
< p > Location : Berlin - HRB 163946 B Amtsgericht Berlin - Charlottenburg < / p > \
< p > Managing Director : Martin Edenhofer < / p > \
< p > < / p > \
< p > -- -- - Ursprüngliche Nachricht -- -- - < br > Von : Billy Zhou & lt ; bz @ zammad . com & gt ; < br > Gesendet : Dienstag , 4. September 2018 15 : 33 < br > An : me @ zammad . com < br > Betreff : test email title < / p > \
< p > < / p > \
< p > test email content < / p > \
< p > < / p > \
< / d i v > '
result = App . Utils . signatureIdentifyByHtml ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should )
2018-09-25 09:43:52 +00:00
} ) ;
2016-10-15 00:38:08 +00:00
// check attachment references
2021-10-14 14:35:12 +00:00
QUnit . test ( "check check attachment reference" , assert => {
2016-10-15 00:38:08 +00:00
var message = 'some not existing'
var result = false
var verify = App . Utils . checkAttachmentReference ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2016-10-15 00:38:08 +00:00
message = 'some attachment for you'
result = 'Attachment'
verify = App . Utils . checkAttachmentReference ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2016-10-15 00:38:08 +00:00
message = 'your attachment.'
result = 'Attachment'
verify = App . Utils . checkAttachmentReference ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2016-10-15 00:38:08 +00:00
message = 'some otherattachment for you'
result = false
verify = App . Utils . checkAttachmentReference ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2016-10-15 00:38:08 +00:00
message = 'some attachmentother for you'
result = false
verify = App . Utils . checkAttachmentReference ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2016-10-15 00:38:08 +00:00
message = 'someattachment'
result = false
verify = App . Utils . checkAttachmentReference ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2016-10-15 00:38:08 +00:00
message = 'As enclosed you will find.'
result = 'Enclosed'
verify = App . Utils . checkAttachmentReference ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2019-07-26 14:44:30 +00:00
2019-07-30 13:52:14 +00:00
message = '<div>Hi Test,</div><div><blockquote>On Monday, 22 July 2019, 14:07:54, Test User wrote:<br><br>Test attachment <br></blockquote></div>'
result = false
verify = App . Utils . checkAttachmentReference ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2019-07-30 13:52:14 +00:00
message = '<div>Hi Test,</div><div><blockquote type="cite">cite attachment </blockquote></div>'
result = false
verify = App . Utils . checkAttachmentReference ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2019-07-30 13:52:14 +00:00
message = '<div>Hi Test,</div><div><blockquote class="ecxgmail_quote">ecxgmail_quote attachment </blockquote></div>'
2019-07-26 14:44:30 +00:00
result = false
verify = App . Utils . checkAttachmentReference ( message )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2016-10-15 00:38:08 +00:00
} ) ;
2015-01-12 22:15:39 +00:00
// replace tags
2021-10-14 14:35:12 +00:00
QUnit . test ( "check replace tags" , assert => {
2018-11-01 06:33:12 +00:00
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 )
2022-01-12 10:53:36 +00:00
l = ( H + 11 ) % 12 + 1
if ( l < 10 ) {
l = ' ' + l
}
P = H >= 12 ? 'pm' : 'am'
return m + '/' + d + '/' + yfull + ' ' + l + ':' + M + ' ' + P
2018-11-01 06:33:12 +00:00
}
2015-01-12 22:15:39 +00:00
var message = "<div>#{user.firstname} #{user.lastname}</div>"
var result = '<div>Bob Smith</div>'
var data = {
user : {
firstname : 'Bob' ,
lastname : 'Smith' ,
} ,
}
2015-10-09 20:31:26 +00:00
var verify = App . Utils . replaceTags ( message , data )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2015-01-12 22:15:39 +00:00
message = "<div>#{user.firstname} #{user.lastname}</div>"
result = '<div>Bob Smith</div>'
data = {
user : {
firstname : function ( ) { return 'Bob' } ,
lastname : function ( ) { return 'Smith' } ,
} ,
}
2015-10-09 20:31:26 +00:00
verify = App . Utils . replaceTags ( message , data )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2015-01-12 22:15:39 +00:00
message = "<div>#{user.firstname} #{user.lastname}</div>"
2016-05-06 07:53:24 +00:00
result = '<div>Bob -</div>'
data = {
user : {
firstname : 'Bob' ,
} ,
}
verify = App . Utils . replaceTags ( message , data )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2016-05-06 07:53:24 +00:00
message = "<div>#{user.firstname} #{user.lastname}</div>"
result = '<div>Bob 0</div>'
data = {
user : {
firstname : 'Bob' ,
lastname : 0 ,
} ,
}
verify = App . Utils . replaceTags ( message , data )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2016-05-06 07:53:24 +00:00
message = "<div>#{user.firstname} #{user.lastname}</div>"
result = '<div>Bob -</div>'
data = {
user : {
firstname : 'Bob' ,
lastname : '' ,
} ,
}
verify = App . Utils . replaceTags ( message , data )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2016-05-06 07:53:24 +00:00
message = "<div>#{user.firstname} #{user.not.existing.test}</div>"
result = '<div>Bob -</div>'
2015-01-12 22:15:39 +00:00
data = {
user : {
firstname : 'Bob' ,
} ,
}
2015-10-09 20:31:26 +00:00
verify = App . Utils . replaceTags ( message , data )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2015-01-12 22:15:39 +00:00
2016-05-06 10:34:04 +00:00
message = "<div>#{user.firstname} #{not.existing.test}</div>"
result = '<div>Bob -</div>'
data = {
user : {
firstname : 'Bob' ,
} ,
}
verify = App . Utils . replaceTags ( message , data )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2016-05-06 10:34:04 +00:00
message = "<div>#{user.firstname} #{not.existing.test}</div>"
result = '<div>Bob -</div>'
data = {
user : {
firstname : 'Bob' ,
not : null ,
} ,
}
verify = App . Utils . replaceTags ( message , data )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2016-05-06 10:34:04 +00:00
message = "<div>#{user.firstname} #{not.existing.test}</div>"
result = '<div>Bob -</div>'
data = {
user : {
firstname : 'Bob' ,
not : { } ,
} ,
}
verify = App . Utils . replaceTags ( message , data )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2016-05-06 10:34:04 +00:00
2017-07-24 13:25:37 +00:00
message = "<div>#{user.firstname} #{<a href=\"/test\">user.lastname</a>}</div>"
result = '<div>Bob Smith</div>'
data = {
user : {
firstname : 'Bob' ,
lastname : 'Smith' ,
} ,
}
verify = App . Utils . replaceTags ( message , data )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2018-10-31 16:41:35 +00:00
user = new App . User ( {
firstname : 'Bob' ,
2019-08-12 07:53:24 +00:00
lastname : 'Smith Good' ,
2018-10-31 16:41:35 +00:00
created _at : '2018-10-31T10:00:00Z' ,
} )
message = "<div>#{user.firstname} #{user.created_at}</div>"
2018-11-01 06:33:12 +00:00
result = '<div>Bob ' + formatTimestamp ( '2018-10-31T10:00:00Z' ) + '</div>'
2018-10-31 16:41:35 +00:00
data = {
user : user
}
verify = App . Utils . replaceTags ( message , data )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2018-10-31 16:41:35 +00:00
message = "<div>#{user.firstname} #{user.created_at.date}</div>"
result = '<div>Bob -</div>'
data = {
user : user
}
verify = App . Utils . replaceTags ( message , data )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2018-10-31 16:41:35 +00:00
message = "<div>#{user.firstname} #{user.created.date}</div>"
result = '<div>Bob -</div>'
data = {
user : user
}
verify = App . Utils . replaceTags ( message , data )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2019-08-12 07:53:24 +00:00
message = "<a href=\"https://example.co/q=#{user.lastname}\">some text</a>"
result = '<a href=\"https://example.co/q=Smith%20Good\">some text</a>'
data = {
user : user
}
verify = App . Utils . replaceTags ( message , data , true )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2015-01-27 07:38:17 +00:00
} ) ;
// check attibute validation
2021-10-14 14:35:12 +00:00
QUnit . test ( "check attibute validation" , assert => {
2015-01-27 07:38:17 +00:00
var string = '123'
2015-10-09 20:31:26 +00:00
var result = '123'
var verify = App . Utils . htmlAttributeCleanup ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-01-27 07:38:17 +00:00
string = '123!'
2015-10-09 20:31:26 +00:00
result = '123'
verify = App . Utils . htmlAttributeCleanup ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-01-27 07:38:17 +00:00
string = '12 3!'
2015-10-09 20:31:26 +00:00
result = '123'
verify = App . Utils . htmlAttributeCleanup ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-01-27 07:38:17 +00:00
string = '12-3!'
2015-10-09 20:31:26 +00:00
result = '12-3'
verify = App . Utils . htmlAttributeCleanup ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-01-27 07:38:17 +00:00
string = '12_3!'
2015-10-09 20:31:26 +00:00
result = '12_3'
verify = App . Utils . htmlAttributeCleanup ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-01-27 07:38:17 +00:00
string = '^12_3!'
2015-10-09 20:31:26 +00:00
result = '12_3'
verify = App . Utils . htmlAttributeCleanup ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-01-27 07:38:17 +00:00
string = '^1\n 2_3!'
2015-10-09 20:31:26 +00:00
result = '12_3'
verify = App . Utils . htmlAttributeCleanup ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-01-27 07:38:17 +00:00
string = 'abc?'
2015-10-09 20:31:26 +00:00
result = 'abc'
verify = App . Utils . htmlAttributeCleanup ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-01-27 07:38:17 +00:00
string = 'abc."'
2015-10-09 20:31:26 +00:00
result = 'abc'
verify = App . Utils . htmlAttributeCleanup ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-01-27 07:38:17 +00:00
string = '#abc!^'
2015-10-09 20:31:26 +00:00
result = 'abc'
verify = App . Utils . htmlAttributeCleanup ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-01-27 07:38:17 +00:00
2015-01-27 07:50:40 +00:00
string = 'abc()=$'
2015-10-09 20:31:26 +00:00
result = 'abc'
verify = App . Utils . htmlAttributeCleanup ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-01-27 07:50:40 +00:00
2015-01-27 08:14:25 +00:00
string = "abc()=$\n123\rß"
2015-10-09 20:31:26 +00:00
result = 'abc123'
verify = App . Utils . htmlAttributeCleanup ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-01-27 07:38:17 +00:00
2015-01-12 22:15:39 +00:00
} ) ;
2015-01-28 22:12:16 +00:00
// check form diff
2021-10-14 14:35:12 +00:00
QUnit . test ( "check form diff" , assert => {
2015-01-28 22:12:16 +00:00
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 = { }
2015-10-09 20:31:26 +00:00
var result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
dataNow = {
owner _id : '1' ,
pending _date : '2015-01-28T09:39:00Z' ,
}
dataLast = {
owner _id : '' ,
pending _date : '2015-01-28T09:39:00Z' ,
}
diff = { }
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
dataNow = {
pending _date : '2015-01-28T09:39:00Z' ,
}
dataLast = {
owner _id : 1 ,
pending _date : '2015-01-28T09:39:00Z' ,
}
diff = { }
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
dataNow = {
owner _id : '' ,
pending _date : '2015-01-28T09:39:00Z' ,
}
dataLast = {
pending _date : '2015-01-28T09:39:00Z' ,
}
diff = {
}
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
dataNow = {
owner _id : '' ,
state _ids : [ 1 , 5 , 6 , 7 ] ,
}
dataLast = { }
diff = {
state _ids : [ '1' , '5' , '6' , '7' ] ,
}
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
dataNow = {
owner _id : 1 ,
state _ids : [ 1 , 5 , 7 , 6 ] ,
}
dataLast = {
owner _id : '' ,
state _ids : [ 1 , 5 , 6 , 7 ] ,
}
diff = { }
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
dataNow = {
owner _id : 1 ,
state _ids : [ 1 , 5 , 6 , 7 ] ,
}
dataLast = {
state _ids : [ '1' , '5' , '7' ] ,
}
diff = {
state _ids : [ '6' ] ,
}
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
dataNow = {
owner _id : '' ,
state _ids : [ 1 , 5 , 6 , 7 ] ,
}
dataLast = {
owner _id : 1 ,
state _ids : [ 1 , 5 , 6 , 7 ] ,
}
diff = { }
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
dataNow = {
owner _id : '' ,
state _ids : [ 1 , 5 , 6 , 7 ] ,
}
dataLast = {
owner _id : 5 ,
state _ids : [ 1 , 5 , 6 , 7 ] ,
}
diff = {
owner _id : ''
}
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
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'
}
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
dataNow = {
pending _time : undefined
}
dataLast = {
pending _time : null
}
diff = { }
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
dataNow = {
ticket : {
pending _time : undefined ,
} ,
}
dataLast = {
ticket : {
pending _time : null ,
} ,
}
diff = { }
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
dataNow = {
test : '123' ,
ticket : {
pending _time : undefined ,
} ,
}
dataLast = {
test : '123' ,
ticket : {
pending _time : null ,
} ,
}
diff = { }
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
dataNow = {
test : '123' ,
}
dataLast = { }
diff = {
test : '123' ,
}
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
dataNow = {
test : '123' ,
}
dataLast = {
test : [ 1 , 2 , 3 , 4 ]
}
diff = {
test : '123' ,
}
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
dataNow = {
test : '123' ,
}
dataLast = {
test : {
1 : 1 ,
2 : 2 ,
}
}
diff = {
test : '123' ,
}
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
dataNow = {
test : [ 1 , 2 , 3 , '4' ]
}
dataLast = {
test : '123' ,
}
diff = {
test : [ '1' , '2' , '3' , '4' ]
}
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
dataNow = {
test : {
1 : 1 ,
2 : 2 ,
}
}
dataLast = {
test : '123' ,
}
diff = {
test : {
1 : '1' ,
2 : '2' ,
}
}
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
2018-10-30 21:51:20 +00:00
// 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 )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff for a newly created attribute that is blank' )
2018-10-30 21:51:20 +00:00
dataNow = {
test : '' ,
}
dataLast = {
test : '123' ,
}
diff = {
test : '' ,
}
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff for setting a previously valid value to blank' )
2018-10-30 21:51:20 +00:00
2015-01-28 22:12:16 +00:00
dataNow = {
test : '123' ,
ticket : {
pending _time : undefined ,
} ,
}
dataLast = {
ticket : {
pending _time : null ,
} ,
}
diff = {
test : '123' ,
}
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-28 22:12:16 +00:00
2015-01-29 13:19:11 +00:00
dataNow = undefined
dataLast = undefined
diff = { }
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-29 13:19:11 +00:00
dataNow = { }
2021-08-20 08:56:23 +00:00
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 }
2015-01-29 13:19:11 +00:00
diff = { }
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-29 13:19:11 +00:00
// 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' ,
}
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-29 13:19:11 +00:00
dataNow = {
number : '10013' ,
Article : [ no1 , 2 ] ,
}
dataLast = {
number : "10012" ,
title : "some subject 123äöü" ,
Article : [ no2 , no3 ] ,
}
diff = {
number : '10013' ,
Article : [ '2' ] ,
}
2015-10-09 20:31:26 +00:00
result = App . Utils . formDiff ( dataNow , dataLast )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( result , diff , 'check form diff' )
2015-01-29 13:19:11 +00:00
2015-01-28 22:12:16 +00:00
} ) ;
2015-10-02 21:41:41 +00:00
// check decimal format
2021-10-14 14:35:12 +00:00
QUnit . test ( "check decimal format" , assert => {
2015-10-02 21:41:41 +00:00
var string = '123'
2015-10-09 20:31:26 +00:00
var result = '123.00'
var verify = App . Utils . decimal ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-10-02 21:41:41 +00:00
string = '0.6'
2015-10-09 20:31:26 +00:00
result = '0.60'
verify = App . Utils . decimal ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-10-02 21:41:41 +00:00
2015-10-03 07:25:40 +00:00
string = '6'
2015-10-09 20:31:26 +00:00
result = '6.00'
verify = App . Utils . decimal ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-10-03 07:25:40 +00:00
string = 6.5
2015-10-09 20:31:26 +00:00
result = '6.50'
verify = App . Utils . decimal ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-10-03 07:25:40 +00:00
2015-10-02 21:41:41 +00:00
string = '111111.6'
2015-10-09 20:31:26 +00:00
result = '111111.60'
verify = App . Utils . decimal ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-10-02 21:41:41 +00:00
string = '111111.622'
2015-10-09 20:31:26 +00:00
result = '111111.62'
verify = App . Utils . decimal ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-10-02 21:41:41 +00:00
string = 'abc.6'
2015-10-09 20:31:26 +00:00
result = 'abc.6'
verify = App . Utils . decimal ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-10-09 20:31:26 +00:00
string = ''
result = ''
verify = App . Utils . decimal ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-10-09 20:31:26 +00:00
string = undefined
result = ''
verify = App . Utils . decimal ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-10-09 20:31:26 +00:00
string = null
result = ''
verify = App . Utils . decimal ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-10-02 21:41:41 +00:00
} ) ;
// check formatTime format
2021-10-14 14:35:12 +00:00
QUnit . test ( "check formatTime format" , assert => {
2015-10-02 21:41:41 +00:00
var string = '123'
2015-10-09 20:31:26 +00:00
var result = '123'
var verify = App . Utils . formatTime ( string , 0 )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-10-02 21:41:41 +00:00
string = '6'
2015-10-09 20:31:26 +00:00
result = '06'
verify = App . Utils . formatTime ( string , 2 )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-10-09 20:31:26 +00:00
string = ''
result = '00'
verify = App . Utils . formatTime ( string , 2 )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-10-09 20:31:26 +00:00
string = undefined
result = ''
verify = App . Utils . formatTime ( string , 2 )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-10-09 20:31:26 +00:00
string = null
result = ''
verify = App . Utils . formatTime ( string , 2 )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result , string )
2015-10-02 21:41:41 +00:00
} ) ;
2016-04-04 13:54:37 +00:00
// check diffPosition
2021-10-14 14:35:12 +00:00
QUnit . test ( "check diffPosition format" , assert => {
2016-04-04 13:54:37 +00:00
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 )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2016-04-04 13:54:37 +00:00
a = [ 2 , 3 , 4 ]
b = [ 1 , 2 , 3 , 4 ]
result = [
{
position : 0 ,
id : 1 ,
} ,
]
verify = App . Utils . diffPositionAdd ( a , b )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2016-04-04 13:54:37 +00:00
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 )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2016-04-04 13:54:37 +00:00
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 )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2016-04-04 13:54:37 +00:00
a = [ 4 , 3 , 1 ]
b = [ 1 , 2 , 3 , 4 , 5 ]
result = false
verify = App . Utils . diffPositionAdd ( a , b )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2016-04-04 22:04:48 +00:00
a = [ 'Ticket-347' , 'TicketCreateScreen-2217' ]
b = [ 'Ticket-347' , 'TicketCreateScreen-2217' , 'TicketCreateScreen-71517' ]
result = [
{
position : 2 ,
id : 'TicketCreateScreen-71517' ,
} ,
]
verify = App . Utils . diffPositionAdd ( a , b )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2016-04-04 22:04:48 +00:00
2016-04-04 13:54:37 +00:00
} ) ;
2017-06-23 07:37:54 +00:00
// check textLengthWithUrl format
2021-10-14 14:35:12 +00:00
QUnit . test ( "check textLengthWithUrl format" , assert => {
2017-06-23 07:37:54 +00:00
var string = '123'
var result = 3
var verify = App . Utils . textLengthWithUrl ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2017-06-23 07:37:54 +00:00
string = '123 http is not here'
result = 20
verify = App . Utils . textLengthWithUrl ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2017-06-23 07:37:54 +00:00
string = '123 http://host is not here'
result = 39
verify = App . Utils . textLengthWithUrl ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2017-06-23 07:37:54 +00:00
string = '123 http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX is not here'
result = 39
verify = App . Utils . textLengthWithUrl ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2017-06-23 07:37:54 +00:00
string = 'http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
result = 23
verify = App . Utils . textLengthWithUrl ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2017-06-23 07:37:54 +00:00
string = 'http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX, some other text'
result = 23 + 17
verify = App . Utils . textLengthWithUrl ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2017-06-23 07:37:54 +00:00
string = 'some other text,http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
result = 23 + 16
verify = App . Utils . textLengthWithUrl ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2017-06-23 07:37:54 +00:00
string = 'some other text, http://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX?abc=123;aaa=ab+c usw'
result = 23 + 21
verify = App . Utils . textLengthWithUrl ( string )
2021-10-14 14:35:12 +00:00
assert . equal ( verify , result )
2017-06-23 07:37:54 +00:00
} ) ;
2017-10-08 19:52:15 +00:00
// check getRecipientArticle format
2021-10-14 14:35:12 +00:00
QUnit . test ( 'check getRecipientArticle format' , assert => {
2017-10-08 19:52:15 +00:00
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 )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 19:52:15 +00:00
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 = {
2017-10-18 00:44:02 +00:00
to : customer . email ,
2017-10-08 19:52:15 +00:00
cc : '' ,
body : '' ,
in _reply _to : 'message_id2' ,
}
verify = App . Utils . getRecipientArticle ( ticket , article , article . created _by , article . type )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 19:52:15 +00:00
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' ,
} ,
2017-10-18 00:44:02 +00:00
from : 'article_created_by@example.com' ,
2017-10-08 19:52:15 +00:00
created _by : {
login : 'login' ,
firstname : 'firstname' ,
lastname : 'lastname' ,
email : 'article_created_by@example.com' ,
} ,
}
result = {
2018-10-02 04:50:04 +00:00
to : 'customer@example.com' ,
2017-10-08 19:52:15 +00:00
cc : '' ,
body : '' ,
in _reply _to : 'message_id3' ,
}
verify = App . Utils . getRecipientArticle ( ticket , article , article . created _by , article . type )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 19:52:15 +00:00
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 )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 19:52:15 +00:00
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 )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 19:52:15 +00:00
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 )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 19:52:15 +00:00
2018-01-31 13:13:23 +00:00
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 )
console . log ( verify )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2018-01-31 13:13:23 +00:00
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 )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2018-01-31 13:13:23 +00:00
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 )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2018-01-31 13:13:23 +00:00
2017-10-08 19:52:15 +00:00
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 = {
2018-01-31 13:13:23 +00:00
message _id : 'message_id8' ,
2017-10-08 19:52:15 +00:00
created _by : agent ,
type : {
name : 'email' ,
} ,
sender : {
name : 'Agent' ,
} ,
2017-10-09 01:57:23 +00:00
from : 'customer2@example.com' ,
2017-10-08 19:52:15 +00:00
to : 'customer@example.com' ,
}
result = {
2017-10-09 01:57:23 +00:00
to : 'customer2@example.com' ,
2017-10-08 19:52:15 +00:00
cc : '' ,
body : '' ,
2018-01-31 13:13:23 +00:00
in _reply _to : 'message_id8' ,
2017-10-08 19:52:15 +00:00
}
verify = App . Utils . getRecipientArticle ( ticket , article , article . created _by , article . type )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 19:52:15 +00:00
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 = {
2018-01-31 13:13:23 +00:00
message _id : 'message_id9' ,
2017-10-08 19:52:15 +00:00
created _by : agent ,
type : {
name : 'email' ,
} ,
sender : {
name : 'Agent' ,
} ,
from : 'agent@example.com' ,
to : 'customer@example.com' ,
}
result = {
2017-10-09 01:57:23 +00:00
to : 'customer@example.com' ,
2017-10-08 19:52:15 +00:00
cc : '' ,
body : '' ,
2018-01-31 13:13:23 +00:00
in _reply _to : 'message_id9' ,
2017-10-08 19:52:15 +00:00
}
verify = App . Utils . getRecipientArticle ( ticket , article , article . created _by , article . type )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 19:52:15 +00:00
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 = {
2018-01-31 13:13:23 +00:00
message _id : 'message_id10' ,
2017-10-08 19:52:15 +00:00
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 : '' ,
2018-01-31 13:13:23 +00:00
in _reply _to : 'message_id10' ,
2017-10-08 19:52:15 +00:00
}
verify = App . Utils . getRecipientArticle ( ticket , article , article . created _by , article . type )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 19:52:15 +00:00
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 = {
2018-01-31 13:13:23 +00:00
message _id : 'message_id11' ,
2017-10-08 19:52:15 +00:00
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 : '' ,
2018-01-31 13:13:23 +00:00
in _reply _to : 'message_id11' ,
2017-10-08 19:52:15 +00:00
}
verify = App . Utils . getRecipientArticle ( ticket , article , article . created _by , article . type , [ ] , true )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 19:52:15 +00:00
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 = {
2018-01-31 13:13:23 +00:00
message _id : 'message_id12' ,
2017-10-08 19:52:15 +00:00
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 : '' ,
2018-01-31 13:13:23 +00:00
in _reply _to : 'message_id12' ,
2017-10-08 19:52:15 +00:00
}
verify = App . Utils . getRecipientArticle ( ticket , article , agent , article . type , [ ] , true )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 19:52:15 +00:00
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 = {
2018-01-31 13:13:23 +00:00
message _id : 'message_id13' ,
2017-10-08 19:52:15 +00:00
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 : '' ,
2018-01-31 13:13:23 +00:00
in _reply _to : 'message_id13' ,
2017-10-08 19:52:15 +00:00
}
email _addresses = [
{
email : 'zammad@example.com' ,
} ,
{
email : 'zammad2@example.com' ,
}
]
verify = App . Utils . getRecipientArticle ( ticket , article , agent , article . type , email _addresses , true )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 19:52:15 +00:00
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 = {
2018-01-31 13:13:23 +00:00
message _id : 'message_id14' ,
2017-10-08 19:52:15 +00:00
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 : '' ,
2018-01-31 13:13:23 +00:00
in _reply _to : 'message_id14' ,
2017-10-08 19:52:15 +00:00
}
email _addresses = [
{
email : 'zammad@example.com' ,
} ,
{
email : 'zammad2@example.com' ,
}
]
verify = App . Utils . getRecipientArticle ( ticket , article , agent , article . type , email _addresses , true )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 19:52:15 +00:00
customer = {
login : 'login' ,
firstname : 'firstname' ,
lastname : 'lastname' ,
email : 'zammad@example.com' ,
}
ticket = {
customer : customer ,
}
article = {
2018-01-31 13:13:23 +00:00
message _id : 'message_id15' ,
2017-10-08 19:52:15 +00:00
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 : '' ,
2018-01-31 13:13:23 +00:00
in _reply _to : 'message_id15' ,
2017-10-08 19:52:15 +00:00
}
email _addresses = [
{
email : 'zammad@example.com' ,
} ,
{
email : 'zammad2@example.com' ,
}
]
verify = App . Utils . getRecipientArticle ( ticket , article , agent , article . type , email _addresses , true )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 19:52:15 +00:00
2017-10-08 22:54:51 +00:00
customer = {
login : 'login' ,
firstname : 'firstname' ,
lastname : 'lastname' ,
email : 'customer@example.com' ,
}
ticket = {
customer : customer ,
}
article = {
2018-01-31 13:13:23 +00:00
message _id : 'message_id16' ,
2017-10-08 22:54:51 +00:00
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 = {
2017-10-09 01:57:23 +00:00
to : 'customer1@example.com, customer2@example.com, customer@example.com' ,
2017-10-08 22:54:51 +00:00
cc : '' ,
body : '' ,
2018-01-31 13:13:23 +00:00
in _reply _to : 'message_id16' ,
2017-10-08 22:54:51 +00:00
}
email _addresses = [
{
email : 'zammad@example.com' ,
} ,
{
email : 'zammad2@example.com' ,
}
]
verify = App . Utils . getRecipientArticle ( ticket , article , agent , article . type , email _addresses , true )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 22:54:51 +00:00
customer = {
login : 'login' ,
firstname : 'firstname' ,
lastname : 'lastname' ,
email : 'customer@example.com' ,
}
ticket = {
customer : customer ,
}
article = {
2018-01-31 13:13:23 +00:00
message _id : 'message_id17' ,
2017-10-08 22:54:51 +00:00
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 = {
2017-10-09 01:57:23 +00:00
to : 'customer1@example.com, customer2@example.com, customer2+2@example.com, customer@example.com' ,
2017-10-08 22:54:51 +00:00
cc : '' ,
body : '' ,
2018-01-31 13:13:23 +00:00
in _reply _to : 'message_id17' ,
2017-10-08 22:54:51 +00:00
}
email _addresses = [
{
email : 'zammad@example.com' ,
} ,
{
email : 'zammad2@example.com' ,
}
]
verify = App . Utils . getRecipientArticle ( ticket , article , agent , article . type , email _addresses , true )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 22:54:51 +00:00
customer = {
login : 'login' ,
firstname : 'firstname' ,
lastname : 'lastname' ,
email : 'customer@example.com' ,
}
agent = {
login : 'login' ,
firstname : 'firstname' ,
lastname : 'lastname' ,
2017-10-08 23:37:08 +00:00
email : 'zammad@example.com' ,
2017-10-08 22:54:51 +00:00
}
ticket = {
customer : customer ,
}
article = {
2018-01-31 13:13:23 +00:00
message _id : 'message_id18' ,
2017-10-08 22:54:51 +00:00
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 : '' ,
2018-01-31 13:13:23 +00:00
in _reply _to : 'message_id18' ,
2017-10-08 22:54:51 +00:00
}
email _addresses = [
{
email : 'zammad@example.com' ,
} ,
{
email : 'zammad2@example.com' ,
}
]
verify = App . Utils . getRecipientArticle ( ticket , article , agent , article . type , email _addresses , true )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 22:54:51 +00:00
2017-10-08 23:37:08 +00:00
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 = {
2018-01-31 13:13:23 +00:00
message _id : 'message_id19' ,
2017-10-08 23:37:08 +00:00
created _by : agent ,
type : {
name : 'email' ,
} ,
sender : {
name : 'Agent' ,
} ,
2017-10-09 00:21:07 +00:00
from : 'Sender <zammad@example.com>' ,
to : 'Customer <customer@example.com>' ,
2017-10-08 23:37:08 +00:00
cc : '' ,
}
result = {
to : 'customer@example.com' ,
cc : '' ,
body : '' ,
2018-01-31 13:13:23 +00:00
in _reply _to : 'message_id19' ,
2017-10-08 23:37:08 +00:00
}
email _addresses = [
{
email : 'zammad@example.com' ,
} ,
{
email : 'zammad2@example.com' ,
}
]
verify = App . Utils . getRecipientArticle ( ticket , article , agent , article . type , email _addresses , false )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-08 23:37:08 +00:00
2017-10-09 01:57:23 +00:00
agent = {
login : 'login' ,
firstname : 'firstname' ,
lastname : 'lastname' ,
email : 'agent@example.com' ,
}
ticket = {
customer : agent ,
}
article = {
2018-01-31 13:13:23 +00:00
message _id : 'message_id20' ,
2017-10-09 01:57:23 +00:00
created _by : agent ,
type : {
name : 'email' ,
} ,
sender : {
name : 'Agent' ,
} ,
from : 'Agent <Agent@Example.com>' ,
to : 'Sender <zammad@example.com>' ,
cc : '' ,
}
result = {
to : 'agent@example.com' ,
cc : '' ,
body : '' ,
2018-01-31 13:13:23 +00:00
in _reply _to : 'message_id20' ,
2017-10-09 01:57:23 +00:00
}
email _addresses = [
{
email : 'zammad@example.com' ,
} ,
{
email : 'zammad2@example.com' ,
}
]
verify = App . Utils . getRecipientArticle ( ticket , article , agent , article . type , email _addresses , false )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2018-05-07 12:30:39 +00:00
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 <Agent@Example.com>' ,
to : 'somebodyelse@example.com, Zammad <zammad@example.com>' ,
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 )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2017-10-09 01:57:23 +00:00
2018-08-10 07:19:37 +00:00
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 )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2018-08-10 07:19:37 +00:00
2018-10-02 04:50:04 +00:00
// 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' ,
} ,
2018-10-22 17:15:54 +00:00
from : 'article lastname <article_customer@example.com>' ,
2018-10-02 04:50:04 +00:00
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 )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2018-10-02 04:50:04 +00:00
// 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 )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2018-10-02 04:50:04 +00:00
2021-06-18 11:07:14 +00:00
// 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 <article_customer@example.com>' ,
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 )
2021-10-14 14:35:12 +00:00
assert . deepEqual ( verify , result )
2021-06-18 11:07:14 +00:00
2017-10-08 19:52:15 +00:00
} ) ;
2021-10-14 14:35:12 +00:00
QUnit . test ( "contentTypeCleanup" , assert => {
2018-02-22 13:51:59 +00:00
var source = "image/png"
var should = "image/png"
var result = App . Utils . contentTypeCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2018-02-22 13:51:59 +00:00
source = "image/png; some.file"
should = "image/png"
result = App . Utils . contentTypeCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2018-02-22 13:51:59 +00:00
source = "image/png;some.file"
should = "image/png"
result = App . Utils . contentTypeCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2018-02-22 13:51:59 +00:00
source = "image/jpeg;some.file"
should = "image/jpeg"
result = App . Utils . contentTypeCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2018-02-22 13:51:59 +00:00
source = "image/jpg;some.file"
should = "image/jpg"
result = App . Utils . contentTypeCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2018-02-22 13:51:59 +00:00
source = "image/gif;some.file"
should = "image/gif"
result = App . Utils . contentTypeCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2018-02-22 13:51:59 +00:00
source = "image/gif\n;some.file"
should = "image/gif"
result = App . Utils . contentTypeCleanup ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2018-06-27 13:38:25 +00:00
} ) ;
// htmlImage2DataUrl
2021-10-14 14:35:12 +00:00
QUnit . test ( "htmlImage2DataUrl" , assert => {
2018-06-27 13:38:25 +00:00
var source = '<div>test 13</div>'
var should = '<div>test 13</div>'
var result = App . Utils . htmlImage2DataUrl ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2018-06-27 13:38:25 +00:00
source = 'some test'
should = 'some test'
result = App . Utils . htmlImage2DataUrl ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2018-06-27 13:38:25 +00:00
source = '<img src="some url">some test'
should = '<img src="data:,">some test'
result = App . Utils . htmlImage2DataUrl ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2018-06-27 13:38:25 +00:00
source = '<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAADAAEDAREAAhEBAxEB/8QAFAABAAAAAAAAAAAAAAAAAAAACv/EABQQAQAAAAAAAAAAAAAAAAAAAAD/xAAUAQEAAAAAAAAAAAAAAAAAAAAF/8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEQMRAD8AbgQDv//Z">some test'
should = '<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAADAAEDAREAAhEBAxEB/8QAFAABAAAAAAAAAAAAAAAAAAAACv/EABQQAQAAAAAAAAAAAAAAAAAAAAD/xAAUAQEAAAAAAAAAAAAAAAAAAAAF/8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEQMRAD8AbgQDv//Z">some test'
result = App . Utils . htmlImage2DataUrl ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2018-06-27 13:38:25 +00:00
source = '<img src="data:image/jpeg;base64,some_data_123">some <img src="some url">test'
should = '<img src="data:image/jpeg;base64,some_data_123">some <img src="data:,">test'
result = App . Utils . htmlImage2DataUrl ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2018-06-27 13:38:25 +00:00
2019-10-11 15:04:01 +00:00
// GitHub issue #2305
2018-10-29 08:18:03 +00:00
source = '<img src="cid:1234">some test'
should = '<img src="cid:1234">some test'
result = App . Utils . htmlImage2DataUrl ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2018-10-29 08:18:03 +00:00
2019-10-11 15:04:01 +00:00
// GitHub issue #2701
source = '<img alt="foo">some test'
should = '<img alt="foo">some test'
result = App . Utils . htmlImage2DataUrl ( source )
2021-10-14 14:35:12 +00:00
assert . equal ( result , should , source )
2019-10-11 15:04:01 +00:00
2018-06-27 13:38:25 +00:00
} ) ;
2021-10-14 14:35:12 +00:00
QUnit . test ( 'App.Utils.icon()' , assert => {
2019-02-27 07:42:56 +00:00
// When given no arguments,
// expect @icon() to return null
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . icon ( ) , null , 'with no arguments' )
2019-02-27 07:42:56 +00:00
// On a modern browser and when given a single argument,
// expect @icon(name) to return an <svg> tag
window . svgPolyfill = false
svgTag = '<svg class="icon icon-foo "><use xlink:href="assets/images/icons.svg#icon-foo" /></svg>'
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . icon ( 'foo' ) , svgTag , 'with one arg / no SVG polyfill' )
2019-02-27 07:42:56 +00:00
// On a modern browser and when given two arguments,
// expect @icon(name) to return an <svg> tag
// with second arg as add'l class name
window . svgPolyfill = false
svgTag = '<svg class="icon icon-foo bar"><use xlink:href="assets/images/icons.svg#icon-foo" /></svg>'
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . icon ( 'foo' , 'bar' ) , svgTag , 'with two args / no SVG polyfill' )
2019-02-27 07:42:56 +00:00
// On a browser requiring SVG polyfill and when given a single argument,
// expect @icon(name, class) to return an <svg> tag
// with pathless xlink:href attr
window . svgPolyfill = true
svgTag = '<svg class="icon icon-foo "><use xlink:href="#icon-foo" /></svg>'
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . icon ( 'foo' ) , svgTag , 'with one arg / SVG polyfill' )
2019-02-27 07:42:56 +00:00
// On a browser requiring SVG polyfill and when given two arguments,
// expect @icon(name, class) to return an <svg> tag
// with pathless xlink:href attr and second arg as add'l class name
window . svgPolyfill = true
svgTag = '<svg class="icon icon-foo bar"><use xlink:href="#icon-foo" /></svg>'
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . icon ( 'foo' , 'bar' ) , svgTag , 'with two args / SVG polyfill' )
2019-02-27 07:42:56 +00:00
// For a left-to-right browser language and when given an argument containing '{start}' or '{end}',
// expect @icon(name) to return an <svg> tag
// replacing '{start}' with 'left' and '{end}' with 'right'
window . svgPolyfill = false
App . i18n . dir = function ( ) { return 'ltr' }
svgTag = '<svg class="icon icon-arrow-left "><use xlink:href="assets/images/icons.svg#icon-arrow-left" /></svg>'
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . icon ( 'arrow-{start}' ) , svgTag , 'for ltr locale / name includes "{start}"' )
2019-02-27 07:42:56 +00:00
svgTag = '<svg class="icon icon-arrow-right "><use xlink:href="assets/images/icons.svg#icon-arrow-right" /></svg>'
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . icon ( 'arrow-{end}' ) , svgTag , 'for ltr locale / name includes "{end}"' )
2019-02-27 07:42:56 +00:00
// For a right-to-left browser language and when given an argument containing '{start}' or '{end}',
// expect @icon(name) to return an <svg> tag
// replacing '{start}' with 'left' and '{end}' with 'right'
window . svgPolyFill = false
App . i18n . dir = function ( ) { return 'rtl' }
svgTag = '<svg class="icon icon-arrow-right "><use xlink:href="assets/images/icons.svg#icon-arrow-right" /></svg>'
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . icon ( 'arrow-{start}' ) , svgTag , 'for rtl locale / name includes "{start}"' )
2019-02-27 07:42:56 +00:00
svgTag = '<svg class="icon icon-arrow-left "><use xlink:href="assets/images/icons.svg#icon-arrow-left" /></svg>'
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . icon ( 'arrow-{end}' ) , svgTag , 'for rtl locale / name includes "{end}"' )
2019-02-27 07:42:56 +00:00
} ) ;
2020-03-06 06:56:58 +00:00
var source1 = '<img src="/assets/images/avatar-bg.png">some test'
$ ( '#image2data1' ) . html ( source1 )
var htmlImage2DataUrlTest1 = function ( ) {
2021-10-14 14:35:12 +00:00
QUnit . test ( "htmlImage2DataUrl1 async" , assert => {
2020-03-06 06:56:58 +00:00
var result1 = App . Utils . htmlImage2DataUrl ( source1 )
2021-10-14 14:35:12 +00:00
assert . ok ( result1 . match ( /some test/ ) , source1 )
assert . ok ( ! result1 . match ( /avatar-bg.png/ ) , source1 )
assert . ok ( result1 . match ( /^\<img src=\"data:image\/png;base64,/ ) , source1 )
2018-06-27 13:38:25 +00:00
} ) ;
2020-03-06 06:56:58 +00:00
}
$ ( '#image2data1 img' ) . one ( 'load' , htmlImage2DataUrlTest1 )
2018-06-27 13:38:25 +00:00
2020-03-06 06:56:58 +00:00
var source2 = '<img src="/assets/images/chat-demo-avatar.png">some test'
$ ( '#image2data2' ) . html ( source2 )
2020-03-20 13:01:06 +00:00
var htmlImage2DataUrlTest2Success = function ( element ) {
2021-10-14 14:35:12 +00:00
QUnit . test ( 'htmlImage2DataUrl2 async' , assert => {
assert . ok ( ! $ ( element ) . html ( ) . match ( /chat-demo-avatar/ ) , source2 )
assert . ok ( $ ( element ) . get ( 0 ) . outerHTML . match ( /^\<img src=\"data:image\/png;base64,/ ) , source2 )
assert . ok ( $ ( element ) . attr ( 'style' ) , 'max-width: 100%;' )
2020-03-06 06:56:58 +00:00
} ) ;
2018-06-27 13:38:25 +00:00
}
2020-03-20 13:01:06 +00:00
var htmlImage2DataUrlTest2Fail = function ( ) {
2021-10-14 14:35:12 +00:00
QUnit . test ( 'htmlImage2DataUrl2 async' , assert => {
assert . ok ( false , 'fail callback is exectuted!' )
2020-03-20 13:01:06 +00:00
} ) ;
}
2021-06-11 13:26:05 +00:00
// 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 = '<img src="/assets/images/8000x300.jpg" alt="test.jpeg">jpeg image'
$ ( '#jpegImage' ) . html ( jpegImageSource )
var htmlImage2DataUrlTest3 = function ( ) {
2021-10-14 14:35:12 +00:00
QUnit . test ( "htmlImage2DataUrl3 async" , assert => {
2021-06-11 13:26:05 +00:00
var result = App . Utils . htmlImage2DataUrl ( jpegImageSource )
2021-10-14 14:35:12 +00:00
assert . ok ( result . match ( /jpeg image/ ) , jpegImageSource )
assert . ok ( result . match ( /^\<img src=\"data:image\/jpeg;base64,/ ) , jpegImageSource )
2021-06-11 13:26:05 +00:00
} ) ;
}
$ ( '#jpegImage img' ) . one ( 'load' , htmlImage2DataUrlTest3 )
var pngImageSource = '<img src="/assets/images/1000x1000.png" alt="test.png">png image'
$ ( '#pngImage' ) . html ( pngImageSource )
var htmlImage2DataUrlTest4 = function ( ) {
2021-10-14 14:35:12 +00:00
QUnit . test ( "htmlImage2DataUrl4 async" , assert => {
2021-06-11 13:26:05 +00:00
var result = App . Utils . htmlImage2DataUrl ( pngImageSource )
2021-10-14 14:35:12 +00:00
assert . ok ( result . match ( /png image/ ) , pngImageSource )
assert . ok ( result . match ( /^\<img src=\"data:image\/png;base64,/ ) , pngImageSource )
2021-06-11 13:26:05 +00:00
} ) ;
}
$ ( '#pngImage img' ) . one ( 'load' , htmlImage2DataUrlTest4 )
var jpegImageSourceWithoutAlt = '<img src="/assets/images/8000x300.jpg">jpeg image'
$ ( '#jpegImage2' ) . html ( jpegImageSourceWithoutAlt )
var htmlImage2DataUrlTest5 = function ( ) {
2021-10-14 14:35:12 +00:00
QUnit . test ( "htmlImage2DataUrl5 async" , assert => {
2021-06-11 13:26:05 +00:00
var result = App . Utils . htmlImage2DataUrl ( jpegImageSourceWithoutAlt )
2021-10-14 14:35:12 +00:00
assert . ok ( result . match ( /jpeg image/ ) , jpegImageSourceWithoutAlt )
assert . ok ( result . match ( /^\<img src=\"data:image\/png;base64,/ ) , jpegImageSourceWithoutAlt )
2021-06-11 13:26:05 +00:00
} ) ;
}
$ ( '#jpegImage2 img' ) . one ( 'load' , htmlImage2DataUrlTest5 )
2020-03-20 13:01:06 +00:00
App . Utils . htmlImage2DataUrlAsyncInline ( $ ( '#image2data2' ) , { success : htmlImage2DataUrlTest2Success , fail : htmlImage2DataUrlTest2Fail } )
2018-06-27 13:38:25 +00:00
2018-07-16 07:23:57 +00:00
}
2019-03-07 08:39:16 +00:00
2021-10-14 14:35:12 +00:00
QUnit . test ( 'App.Utils.baseUrl()' , assert => {
2021-05-26 08:46:59 +00:00
configGetBackup = App . Config . get
2019-03-07 08:39:16 +00:00
// When FQDN is undefined or null,
// expect @baseUrl() to return window.location.origin
App . Config . get = function ( key ) { return undefined }
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . baseUrl ( ) , window . location . origin , 'with undefined FQDN' )
2019-03-07 08:39:16 +00:00
App . Config . get = function ( key ) { return null }
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . baseUrl ( ) , window . location . origin , 'with null FQDN' )
2019-03-07 08:39:16 +00:00
// 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'
}
}
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . baseUrl ( ) , window . location . origin , 'with FQDN zammad.example.com' )
2019-03-07 08:39:16 +00:00
// 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'
}
}
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . baseUrl ( ) , 'https://foo.zammad.com' , 'with any other FQDN (and https scheme)' )
2019-03-07 08:39:16 +00:00
App . Config . get = function ( key ) {
if ( key === 'fqdn' ) {
return 'bar.zammad.com'
} else if ( key === 'http_type' ) {
return 'http'
}
}
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . baseUrl ( ) , 'http://bar.zammad.com' , 'with any other FQDN (and http scheme)' )
2021-05-26 08:46:59 +00:00
App . Config . get = configGetBackup
2019-03-07 08:39:16 +00:00
} ) ;
2021-10-14 14:35:12 +00:00
QUnit . test ( 'App.Utils.joinUrlComponents()' , assert => {
2019-03-07 08:39:16 +00:00
// When given a list of strings,
// expect @joinUrlComponents() to join them with slashes
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . joinUrlComponents ( 'foo' , 'bar' , 'baz' ) , 'foo/bar/baz' , 'with a destructured list of strings' )
2019-03-07 08:39:16 +00:00
// When given an array of strings,
// expect @joinUrlComponents() to join them with slashes
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . joinUrlComponents ( [ 'foo' , 'bar' , 'baz' ] ) , 'foo/bar/baz' , 'with an array of strings' )
2019-03-07 08:39:16 +00:00
// When given a list of many types,
// expect @joinUrlComponents() to join their string representations with slashes
2021-10-14 14:35:12 +00:00
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' )
2019-03-07 08:39:16 +00:00
// When given a list including null or undefined,
// expect @joinUrlComponents() to filter them out of the results before joining the rest with slashes
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . joinUrlComponents ( 'foo' , undefined , 'bar' , null , 'baz' ) , 'foo/bar/baz' , 'with a list including null or undefined' )
2019-03-07 08:39:16 +00:00
} ) ;
2020-02-10 08:06:39 +00:00
2021-10-14 14:35:12 +00:00
QUnit . test ( 'App.Utils.clipboardHtmlIsWithText()' , assert => {
2020-02-10 08:06:39 +00:00
// no content with text
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . clipboardHtmlIsWithText ( '<div></div>' ) , false )
assert . equal ( App . Utils . clipboardHtmlIsWithText ( '<div> </div>' ) , false )
assert . equal ( App . Utils . clipboardHtmlIsWithText ( '<div><img src="test.jpg"/></div>' ) , false )
assert . equal ( App . Utils . clipboardHtmlIsWithText ( '<div><!-- some comment --></div>' ) , false )
assert . equal ( App . Utils . clipboardHtmlIsWithText ( '<div><!-- some comment --> </div>' ) , false )
assert . equal ( App . Utils . clipboardHtmlIsWithText ( "<div><!-- some comment --> \n </div>" ) , false )
2020-02-10 08:06:39 +00:00
// content with text
2021-10-14 14:35:12 +00:00
assert . equal ( App . Utils . clipboardHtmlIsWithText ( 'test' ) , true )
assert . equal ( App . Utils . clipboardHtmlIsWithText ( '<div>test</div>' ) , true )
assert . equal ( App . Utils . clipboardHtmlIsWithText ( '<meta http-equiv="content-type" content="text/html; charset=utf-8">sometext' ) , true )
2020-02-10 08:06:39 +00:00
} ) ;
2021-10-14 14:35:12 +00:00
QUnit . test ( 'App.Utils.clipboardHtmlInsertPreperation()' , assert => {
assert . equal ( App . Utils . clipboardHtmlInsertPreperation ( '<div></div>' , { } ) , '' )
assert . equal ( App . Utils . clipboardHtmlInsertPreperation ( '<div> </div>' , { } ) , ' ' )
assert . equal ( App . Utils . clipboardHtmlInsertPreperation ( '<div><img src="test.jpg"/></div>' , { } ) , '<img src="test.jpg">' )
assert . equal ( App . Utils . clipboardHtmlInsertPreperation ( '<div><!-- some comment --></div>' , { } ) , '' )
assert . equal ( App . Utils . clipboardHtmlInsertPreperation ( '<div><!-- some comment --> </div>' , { } ) , ' ' )
assert . equal ( App . Utils . clipboardHtmlInsertPreperation ( "<div><!-- some comment --> \n </div>" , { } ) , " \n " )
assert . equal ( App . Utils . clipboardHtmlInsertPreperation ( 'test' , { } ) , 'test' )
assert . equal ( App . Utils . clipboardHtmlInsertPreperation ( '<div>test</div>' , { } ) , 'test' )
assert . equal ( App . Utils . clipboardHtmlInsertPreperation ( '<meta http-equiv="content-type" content="text/html; charset=utf-8">sometext' , { } ) , '<div>sometext</div>' )
assert . equal ( App . Utils . clipboardHtmlInsertPreperation ( '<div><b>test</b> 123</div>' , { mode : 'textonly' } ) , 'test 123' )
assert . equal ( App . Utils . clipboardHtmlInsertPreperation ( '<div><b>test</b><br> 123</div>' , { mode : 'textonly' } ) , 'test 123' )
assert . equal ( App . Utils . clipboardHtmlInsertPreperation ( '<div><b>test</b><br> 123</div>' , { mode : 'textonly' , multiline : true } ) , 'test<br> 123' )
2020-02-10 08:06:39 +00:00
} ) ;
2021-10-14 14:35:12 +00:00
QUnit . test ( 'App.Utils.signatureIdentifyByHtmlHelper()' , assert => {
2020-02-11 15:15:05 +00:00
result = App . Utils . signatureIdentifyByHtmlHelper ( "<script>alert('fish2');</script><blockquote></blockquote>" )
2021-10-14 14:35:12 +00:00
assert . equal ( result , "<script>alert('fish2');</script><span class=\"js-signatureMarker\"></span><blockquote></blockquote>" , 'signatureIdentifyByHtmlHelper does not reactivate alert' )
2020-02-11 15:15:05 +00:00
} ) ;
2021-02-11 07:51:52 +00:00
2021-10-14 14:35:12 +00:00
QUnit . test ( "#safeParseHtml" , assert => {
2021-02-11 07:51:52 +00:00
var unwrap = input => $ ( '<div>' ) . html ( input ) [ 0 ] . innerHTML
var html = "<div>test 123 </div>"
var result = App . Utils . safeParseHtml ( html )
var should = html
2021-10-14 14:35:12 +00:00
assert . equal ( unwrap ( result ) , html )
2021-02-11 07:51:52 +00:00
// test if, according to jQuery, invalid HTML does not cause a a crash
// https://github.com/zammad/zammad/issues/3393
html = "<td></td><table></table><div>test 123 </div>"
should = "<table></table><div>test 123 </div>"
result = App . Utils . safeParseHtml ( html )
2021-10-14 14:35:12 +00:00
assert . equal ( unwrap ( result ) , should )
2021-02-11 07:51:52 +00:00
} )