window.onload = function() {
// textCleanup
test("textCleanup", function() {
var source = "Some\nValue\n\n\nTest"
var should = "Some\nValue\n\nTest"
var result = App.Utils.textCleanup(source)
equal(result, should, source)
source = "Some\nValue\n\n \n\n\nTest"
should = "Some\nValue\n\nTest"
result = App.Utils.textCleanup(source)
equal(result, should, source)
source = "Some\n\rValue\n\r\n\r\n\rTest"
should = "Some\nValue\n\nTest"
result = App.Utils.textCleanup(source)
equal(result, should, source)
source = "Some\n\rValue\n\r\n\r\n\rTest\r"
should = "Some\nValue\n\nTest"
result = App.Utils.textCleanup(source)
equal(result, should, source)
source = "Some\r\nValue\r\n\r\n\r\nTest\r\n"
should = "Some\nValue\n\nTest"
result = App.Utils.textCleanup(source)
equal(result, should, source)
source = "Some\r\nValue\r\n\r\n\r\n\r\n\r\n\r\nTest\r\n"
should = "Some\nValue\n\nTest"
result = App.Utils.textCleanup(source)
equal(result, should, source)
source = "> Welcome!\n> \n> Thank you for installing Zammad.\n> \n> You will find ..."
should = "> Welcome!\n>\n> Thank you for installing Zammad.\n>\n> You will find ..."
result = App.Utils.textCleanup(source)
equal(result, should, source)
});
// text2html
test("text2html", function() {
var source = "Some\nValue\n\n\nTest"
var should = "
Some
Value
Test
"
var result = App.Utils.text2html(source)
equal(result, should, source)
source = "Some\nValue\n"
should = "
Some
Value
"
result = App.Utils.text2html(source)
equal(result, should, source)
source = "Some\nValue\n"
should = "
Some
<b>Value</b>
"
result = App.Utils.text2html(source)
equal(result, should, source)
source = "> Welcome!\n> \n> Thank you for installing Zammad.\n> \n> You will find ..."
should = "
> Welcome!
>
> Thank you for installing Zammad.
>
> You will find ...
"
result = App.Utils.text2html(source)
equal(result, should, source)
});
// html2text
test("html2text", function() {
var source = "
Some
Value
Test
"
var should = "Some\nValue\n\nTest"
var result = App.Utils.html2text(source)
equal(result, should, source)
source = "
Some
Value
"
should = "Some\nValue"
result = App.Utils.html2text(source)
equal(result, should, source)
source = "
Some Value
"
should = "Some\nValue"
result = App.Utils.html2text(source)
equal(result, should, source)
source = "
Some & <Value>
"
should = "Some & "
result = App.Utils.html2text(source)
equal(result, should, source)
source = "
Some
<b>Value</b>
"
should = "Some\nValue"
result = App.Utils.html2text(source)
equal(result, should, source)
source = "
> Welcome!
>
> Thank you for installing Zammad.
>
> You will find ...
"
should = "> Welcome!\n>\n> Thank you for installing Zammad.\n>\n> You will find ..."
result = App.Utils.html2text(source)
equal(result, should, source)
source = "
test 123
-- Bob Smith
"
should = "test 123 \n\n--\nBob Smith"
result = App.Utils.html2text(source)
equal(result, should, source)
source = "test 123
-- Bob Smith"
should = "test 123 \n\n--\nBob Smith"
result = App.Utils.html2text(source)
equal(result, should, source)
source = "
"
should = "1\n\nVon: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]\nGesendet: Donnerstag, 2. April 2015 11:32"
result = App.Utils.html2text(source)
equal(result, should, source)
source = "
test 123 lalala
--
some test
"
should = "test 123\nlalala\n--\nsome test"
result = App.Utils.html2text(source)
equal(result, should, source)
source = "
Was\nsoll verbessert werden:
"
should = "Was soll verbessert werden:"
result = App.Utils.html2text(source)
equal(result, should, source)
// in raw format, without cleanup
source = "
Some
1234
"
should = "Some\n1234\n"
result = App.Utils.html2text(source, true)
equal(result, should, source)
source = "
Some
1234
"
should = "Some\n 1234\n"
result = App.Utils.html2text(source, true)
equal(result, should, source)
source = "\n\n
Some
\n
1234
"
should = "Some\n 1234\n"
result = App.Utils.html2text(source, true)
equal(result, should, source)
source = "
Some
1234
"
should = "Some\n 1234\n"
result = App.Utils.html2text(source, true)
equal(result, should, source)
source = "
Some
\n\n
1234
\n"
should = "Some\n 1234\n"
result = App.Utils.html2text(source, true)
equal(result, should, source)
source = "
test new line
"
should = "test\nnew line\n\n"
result = App.Utils.html2text(source, true)
equal(result, should, source)
source = "
Was\nsoll verbessert werden:
"
should = "Was soll verbessert werden:\n"
result = App.Utils.html2text(source, true)
equal(result, should, source)
});
// linkify
test("linkify", function() {
var source = "http://example.com"
var should = 'http://example.com'
var result = App.Utils.linkify(source)
equal(result, should, source)
source = "http://example.com?some_param=lalala"
should = 'http://example.com?some_param=lalala'
result = App.Utils.linkify(source)
equal(result, should, source)
source = "example.com"
should = 'example.com'
result = App.Utils.linkify(source)
equal(result, should, source)
source = "some text example.com"
should = 'some text example.com'
result = App.Utils.linkify(source)
equal(result, should, source)
source = "example.com some text"
should = 'example.com some text'
result = App.Utils.linkify(source)
equal(result, should, source)
/*
source = "example.com"
should = 'http://example.com'
result = App.Utils.linkify(source)
equal(result, should, source)
*/
});
// htmlEscape
test("htmlEscape", function() {
var source = "<"
var should = "<"
var result = App.Utils.htmlEscape(source)
equal(result, should, source)
source = ">"
should = ">"
result = App.Utils.htmlEscape(source)
equal(result, should, source)
source = "&"
should = "&"
result = App.Utils.htmlEscape(source)
equal(result, should, source)
source = "&"
should = "&"
result = App.Utils.htmlEscape(source)
equal(result, should, source)
source = "& ;"
should = "& ;"
result = App.Utils.htmlEscape(source)
equal(result, should, source)
source = "& amp;"
should = "& amp;"
result = App.Utils.htmlEscape(source)
equal(result, should, source)
source = "'test'"
should = "'test'"
result = App.Utils.htmlEscape(source)
equal(result, should, source)
source = '"test"'
should = ""test""
result = App.Utils.htmlEscape(source)
equal(result, should, source)
source = "<>"
should = "<>"
result = App.Utils.htmlEscape(source)
equal(result, should, source)
source = "<<>"
should = "<<>"
result = App.Utils.htmlEscape(source)
equal(result, should, source)
});
// htmlRemoveTags
test("htmlRemoveTags", function() {
var source = "
test
"
//var should = "
test
"
var should = "test"
var result = App.Utils.htmlRemoveTags($(source))
equal(result.html(), should, source)
source = "
test
"
//should = "
test
"
should = "test"
result = App.Utils.htmlRemoveTags($(source))
equal(result.html(), should, source)
source = "some link to somewhere"
should = "some link to somewhere"
result = App.Utils.htmlRemoveTags($(source))
equal(result.html(), should, source)
source = "
"
should = "some link to somewhere 123 "
result = App.Utils.htmlRemoveTags($(source))
equal(result.html(), should, source)
source = ""
//should = "
test 123
"
should = "test 123"
result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source)
source = ""
//should = "
test 123
"
should = "test 123"
result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source)
source = "
This is some text!
"
//should = "
This is some text!
"
should = "This is some text!"
result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source)
result = App.Utils.htmlRemoveRichtext(source)
equal(result.html(), should, source)
});
// htmlRemoveRichtext
test("htmlRemoveRichtext", function() {
var source = "
"
var should = "test"
var result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source)
source = "
1.1.1Description
"
//should = "
1.1.1Description
"
should = "1.1.1Description"
//should = '1.1.1 Description'
result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source)
source = "some link to somewhere"
should = "some link to somewhere"
result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source)
source = "
test
"
//should = "
test
"
should = " test "
result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source)
source = "
test
"
//should = "
test
"
should = " test "
result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source)
source = "
test
"
//should = "
test
"
should = "
test
"
result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source)
source = "
test
"
//should = "
test
"
should = "
test
"
result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source)
source = "
test
123
"
//should = "
test
123
"
should = "
test
123"
//should = '
test
123'
result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source)
source = "
"
should = "test 123"
result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source)
source = "
\n"
//should = "
test 123
"
should = '
Gruppe *
Besitzer
Status *
'
result = App.Utils.htmlRemoveRichtext(source)
equal(result.html(), should, source)
source = "
This is some text!
"
//should = "
This is some text!
"
should = "This is some text!"
result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source)
result = App.Utils.htmlRemoveRichtext(source)
equal(result.html(), should, source)
});
// htmlCleanup
test("htmlCleanup", function() {
var source = "
"
var should = "test"
var result = App.Utils.htmlCleanup($(source))
equal(result.html(), should, source)
source = "some link to somewhere"
should = "some link to somewhere"
result = App.Utils.htmlCleanup($(source))
equal(result.html(), should, source)
source = "
some link to somewhere
"
//should = "
some link to somewhere
"
should = "
some link to somewhere
"
result = App.Utils.htmlCleanup($(source))
equal(result.html(), should, source)
source = "
some link to somewhere"
//should = "
some link to somewhere
"
should = "some link to somewhere"
result = App.Utils.htmlCleanup($(source))
equal(result.html(), should, source)
source = "
"
//should = "
some link to somewhere
"
should = "some link to somewhere"
result = App.Utils.htmlCleanup($(source))
equal(result.html(), should, source)
source = "
some h1 for somewhere
"
//should = "
some h1 for somewhere
"
should = "
some h1 for somewhere
"
//should = '
some h1 for somewhere
'
result = App.Utils.htmlCleanup($(source))
equal(result.html(), should, source)
source = "
"
//should = "
"
should = " "
result = App.Utils.htmlCleanup($(source))
equal(result.html(), should, source)
source = "
\n\n"
result = App.Utils.htmlCleanup(source)
equal(result.html(), should, source)
});
// wrap
test("wrap", function() {
var source = "some text"
var should = 'some text'
var result = App.Utils.wrap(source)
equal(result, should, source)
source = "some text\nsome other text\n"
should = "some text\nsome other text\n"
result = App.Utils.wrap(source)
equal(result, should, source)
source = "some text with some line to wrap"
should = "some text with\nsome line to\nwrap"
result = App.Utils.wrap(source, 14)
equal(result, should, source)
source = "some text\nsome other text\n"
should = "some text\nsome other text\n"
result = App.Utils.wrap(source)
equal(result, should, source)
source = "1234567890 1234567890 1234567890 1234567890"
should = "1234567890 1234567890 1234567890 1234567890"
result = App.Utils.wrap(source)
equal(result, should, source)
source = "123456789012 123456789012 123456789012"
should = "123456789012\n123456789012\n123456789012"
result = App.Utils.wrap(source, 14)
equal(result, should, source)
});
// remove empty lines
test("remove empty lines", function() {
var source = "\ntest 123\n"
var should = "test 123\n"
var result = App.Utils.removeEmptyLines(source)
equal(result, should, source)
source = "\ntest\n\n123\n"
should = "test\n123\n"
result = App.Utils.removeEmptyLines(source)
equal(result, should, source)
});
// quote
test("quote", function() {
var source = "some text"
var should = '> some text'
var result = App.Utils.quote(source)
equal(result, should, source)
source = "some text\nsome other text\n"
should = "> some text\n> some other text"
result = App.Utils.quote(source)
equal(result, should, source)
source = "\n\nsome text\nsome other text\n \n"
should = "> some text\n> some other text"
result = App.Utils.quote(source)
equal(result, should, source)
source = "Welcome!\n\nThank you for installing Zammad.\n\nYou will find ..."
should = "> Welcome!\n>\n> Thank you for installing Zammad.\n>\n> You will find ..."
result = App.Utils.quote(source)
equal(result, should, source)
source = "Welcome! Thank you for installing Zammad. You will find ..."
should = "> Welcome! Thank you\n> for installing\n> Zammad. You will\n> find ..."
result = App.Utils.quote(source, 20)
equal(result, should, source)
});
// check signature
test("check signature", function() {
var message = "
test 123
"
var signature = '
-- Some Signature some department
'
var result = App.Utils.signatureCheck(message, signature)
equal(result, true)
message = "
test 123
-- Some Signature some department\n
"
signature = '
-- Some Signature some department
'
result = App.Utils.signatureCheck(message, signature)
equal(result, false)
message = "
test 123
-- Some Signature\n some department\n
"
signature = '
-- Some Signature some department
'
result = App.Utils.signatureCheck(message, signature)
equal(result, false)
message = "
> OK. Wer kriegt das Angebot? Ist das wirklich nur ein halber Tag?
"
result = App.Utils.signatureIdentify(message, true)
equal(result, should)
message = "Dear Mr. Smith,
it seems to be, dass Sie den AutoIncrement Nummerngenerator für Ihre ITSMChangeManagement Installation verwenden. Seit ABC 3.2 wird führend vor der sich in der Datei <ABC_CONFIG_Home>/war/log/ITSMChangeCounter.log befindenden Zahl die SystemID (SysConfig) geschrieben. Dies ist ein Standardverhalten, dass auch bei der Ticketnummer verwendet wird.
Please ask me if you have questions.
Viele Grüße,
Thorsten Smith\n \n --\n Enterprise Services for ABC\n \n Znuny GmbH // Marienstraße 11 // 10117 Berlin // Germany\n \n P: +49 (0) 30 111 111 111-0\n F: +49 (0) 30 111 111 111-8\n W: http://znuny.com \n \n Location: Berlin - HRB 12345678 B Amtsgericht Berlin-Charlottenburg\n Managing Director: Martin Edenhofer\n
"
should = "Dear Mr. Smith,
it seems to be, dass Sie den AutoIncrement Nummerngenerator für Ihre ITSMChangeManagement Installation verwenden. Seit ABC 3.2 wird führend vor der sich in der Datei <ABC_CONFIG_Home>/war/log/ITSMChangeCounter.log befindenden Zahl die SystemID (SysConfig) geschrieben. Dies ist ein Standardverhalten, dass auch bei der Ticketnummer verwendet wird.
Please ask me if you have questions.
Viele Grüße,
Thorsten Smith\n \n --\n Enterprise Services for ABC\n \n Znuny GmbH // Marienstraße 11 // 10117 Berlin // Germany\n \n P: +49 (0) 30 111 111 111-0\n F: +49 (0) 30 111 111 111-8\n W: http://znuny.com \n \n Location: Berlin - HRB 12345678 B Amtsgericht Berlin-Charlottenburg\n Managing Director: Martin Edenhofer\n
"
result = App.Utils.signatureIdentify(message, true, true)
equal(result, should)
message = "Dear Mr. Smith, nice to read you,
Thorsten Smith\n \n --\n
"
should = "Dear Mr. Smith, nice to read you,
Thorsten Smith\n \n --\n
"
result = App.Utils.signatureIdentify(message, true, true)
equal(result, should)
message = "Dear Mr. Smith, nice to read you,
'
data = {
user: {
firstname: 'Bob',
not: {},
},
}
verify = App.Utils.replaceTags(message, data)
equal(verify, result)
});
// check if last line is a empty line
test("check if last line is a empty line", function() {
var message = "123"
var result = false
var verify = App.Utils.lastLineEmpty(message)
equal(verify, result, message)
message = "