"
should = "some link to somewhere"
result = App.Utils.htmlCleanup( $(source) )
equal( result.html(), should, source )
source = "
"
result = App.Utils.htmlCleanup( $(source) )
equal( result.html(), should, source )
source = "
"
result = App.Utils.htmlCleanup( $(source) )
equal( result.html(), should, source )
source = "
"
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 = "
"
should = "test 123 some other value"
result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source )
source = "
"
should = "test 123 some other value"
result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source )
source = "
"
should = "This is some text!"
result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source )
source = "
some link to somewhere from wordabc
"
should = "
some link to somewhere from wordabc
"
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 )
});
// 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 = "
test 123
--
Some Signature
\n
some department
\n\n
"
signature = '
--
Some Signature
some department
'
result = App.Utils.signatureCheck( message, signature )
equal( result, false )
message = ""
signature = '
--
Some Signature
some department
'
result = App.Utils.signatureCheck( message, signature )
equal( result, true )
message = ""
signature = "--\nSome Signature\nsome department"
result = App.Utils.signatureCheck( message, signature )
equal( result, true )
});
// identify signature
test( "identify signature", function() {
var message = "
test 123
"
var should = '
test 123
'
var result = App.Utils.signatureIdentify( message )
equal( result, should )
message = "
test 123
--
Bob Smith
"
should = '
test 123
--
Bob Smith
'
result = App.Utils.signatureIdentify( message )
equal( result, should )
message = "
test 123
1
2
3
4
5
6
7
8
9
--
Bob Smith
"
should = '
test 123
1
2
3
4
5
6
7
8
9
--
Bob Smith
'
result = App.Utils.signatureIdentify( message )
equal( result, should )
message = "
test 123
--no not match--
--
Bob Smith
"
should = '
test 123
--no not match--
--
Bob Smith
'
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
message = "
test 123
--no not match--
--
Bob Smith
"
should = '
test 123
--no not match--
--
Bob Smith
'
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
message = "
test 123
--
Bob Smith
--
Bob Smith
"
should = '
test 123
--
Bob Smith
--
Bob Smith
'
//should = '
test 123
--
Bob Smith
--
Bob Smith
'
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
message = "
test 123
test 123
--
Bob Smith
"
should = "
test 123
test 123
--
Bob Smith
"
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
message = "
test 123
test 123
--
Bob Smith
"
should = "
test 123
test 123
--
Bob Smith
"
result = App.Utils.signatureIdentify( message, true )
// apple
// en
message = "
test 123
--no not match--
Bob Smith
On 01/04/15 10:55, Bob Smith wrote:
lalala
--
some test
"
should = '
test 123
--no not match--
Bob Smith
On 01/04/15 10:55, Bob Smith wrote:
lalala
--
some test
'
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
// de
message = "
test 123
--no not match--
Bob Smith
Am 03.04.2015 um 20:58 schrieb Bob Smith <bob@example.com>:
lalala
"
should = '
test 123
--no not match--
Bob Smith
Am 03.04.2015 um 20:58 schrieb Bob Smith <bob@example.com>:
lalala
'
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
// ms
// en
message = "
test 123
--no not match--
Bob Smith
From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
Sent: Donnerstag, 2. April 2015 10:00
lalala
"
should = '
test 123
--no not match--
Bob Smith
From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
Sent: Donnerstag, 2. April 2015 10:00
lalala
'
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
message = "
test 123
--no not match--
Bob Smith
From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
Sent: Donnerstag, 2. April 2015 10:00
Subject: lalala
"
should = '
test 123
--no not match--
Bob Smith
From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
Sent: Donnerstag, 2. April 2015 10:00
Subject: lalala
'
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
message = "
test 123
--no not match--
Bob Smith
From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
Sent: Donnerstag, 2. April 2015 10:00
1
2
3
4
4
Subject: lalala
"
should = '
test 123
--no not match--
Bob Smith
From: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
Sent: Donnerstag, 2. April 2015 10:00
1
2
3
4
4
Subject: lalala
'
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
// de
message = "
test 123
--no not match--
Bob Smith
Von: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
Gesendet: Donnerstag, 2. April 2015 10:00
Betreff: lalala
"
should = '
test 123
--no not match--
Bob Smith
Von: Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
Gesendet: Donnerstag, 2. April 2015 10:00
Betreff: lalala
'
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
message = "
1
\n
Gesendet: Donnerstag, 2. April 2015 11:32
"
should = "
1
\n
Gesendet: Donnerstag, 2. April 2015 11:32
"
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
message = "
1
\n
Gesendet: Donnerstag, 2. April 2015 11:32
Betreff: lalala
"
should = "
1
\n
Gesendet: Donnerstag, 2. April 2015 11:32
Betreff: lalala
"
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
message = "
1
\n
An: somebody
Datum: Donnerstag, 2. April 2015 11:32
Betreff: lalala
"
should = "
1
\n
An: somebody
Datum: Donnerstag, 2. April 2015 11:32
Betreff: lalala
"
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
message = "
Gesendet: Donnerstag, 2. April 2015 10:11:12
Betreff: Angebot Redundanz / Paket mit Silver Subscription [Ticket#424242]
Hallo Frau Smith,
"
should = "
Gesendet: Donnerstag, 2. April 2015 10:11:12
Betreff: Angebot Redundanz / Paket mit Silver Subscription [Ticket#424242]
Hallo Frau Smith,
"
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
// fr
message = "
test 123
--no not match--
Bob Smith
De : Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
Envoyé : mercredi 29 avril 2015 17:31
Objet : lalala
"
should = '
test 123
--no not match--
Bob Smith
De : Martin Edenhofer via Znuny Support [mailto:support@znuny.inc]
Envoyé : mercredi 29 avril 2015 17:31
Objet : lalala
'
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
// thunderbird
// de
message = "
Viele Grüße,
Christian
Am 04.03.2015 um 12:47 schrieb Martin Edenhofer via Znuny Sales:
> Hallo Christian,
"
should = "
Viele Grüße,
Christian
Am 04.03.2015 um 12:47 schrieb Martin Edenhofer via Znuny Sales:
> Hallo Christian,
"
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
// en - Thunderbird default - http://kb.mozillazine.org/Reply_header_settings
message = "
Viele Grüße,
Christian
On 01-01-2007 11:00 AM, Alf Aardvark wrote:
> Hallo Christian,
"
should = "
Viele Grüße,
Christian
On 01-01-2007 11:00 AM, Alf Aardvark wrote:
> Hallo Christian,
"
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
// en - http://kb.mozillazine.org/Reply_header_settings
message = "
Viele Grüße,
Christian
Alf Aardvark wrote, on 01-01-2007 11:00 AM:
> Hallo Christian,
"
should = "
Viele Grüße,
Christian
Alf Aardvark wrote, on 01-01-2007 11:00 AM:
> Hallo Christian,
"
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
// otrs
// en
message = "
test 123
--no not match--
Bob Smith
01/04/15 10:55 - Bob Smith wrote:
lalala
"
should = '
test 123
--no not match--
Bob Smith
01/04/15 10:55 - Bob Smith wrote:
lalala
'
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
// de
message = "
test 123
--no not match--
Bob Smith
01/04/15 10:55 - Bob Smith schrieb:
lalala
"
should = '
test 123
--no not match--
Bob Smith
01/04/15 10:55 - Bob Smith schrieb:
lalala
'
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
message = "
test 123
24.02.2015 14:20 - Roy Kaldung via Znuny Sales schrieb:
"
should = "
test 123
24.02.2015 14:20 - Roy Kaldung via Znuny Sales schrieb:
"
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
// zammad
message = "
test 123
--no not match--
Bob Smith
lalala
"
should = "
test 123
--no not match--
Bob Smith
lalala
"
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
message = "
test 123
--no not match--
Bob Smith
lalala
"
should = "
test 123
--no not match--
Bob Smith
lalala
"
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
// gmail
message = "
test 123
--no not match--
Bob Smith
lalala
"
should = "
test 123
--no not match--
Bob Smith
lalala
"
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
message = "
test 123
--no not match--
Bob Smith
lalala
"
should = "
test 123
--no not match--
Bob Smith
lalala
"
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
message = "
test 123
--no not match--
Bob Smith
Am 24. Dezember 2015 um 07:45 schrieb kathrine <kathrine@example.com>:
lalala
"
should = "
test 123
--no not match--
Bob Smith
Am 24. Dezember 2015 um 07:45 schrieb kathrine <kathrine@example.com>:
lalala
"
result = App.Utils.signatureIdentify( message, true )
equal( result, should )
});
// replace tags
test( "check replace tags", function() {
var message = "
#{user.firstname} #{user.lastname}
"
var result = '
Bob Smith
'
var data = {
user: {
firstname: 'Bob',
lastname: 'Smith',
},
}
var verify = App.Utils.replaceTags( message, data )
equal( verify, result )
message = "
#{user.firstname} #{user.lastname}
"
result = '
Bob Smith
'
data = {
user: {
firstname: function() { return 'Bob' },
lastname: function() { return 'Smith' },
},
}
verify = App.Utils.replaceTags( message, data )
equal( verify, result )
message = "
#{user.firstname} #{user.lastname}
"
result = '
Bob
'
data = {
user: {
firstname: 'Bob',
},
}
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 = "
123
"
result = false
verify = App.Utils.lastLineEmpty( message )
equal( verify, result, message )
message = "
123
"
result = false
verify = App.Utils.lastLineEmpty( message )
equal( verify, result, message )
message = "
"
result = true
verify = App.Utils.lastLineEmpty( message )
equal( verify, result, message )
message = "
"
result = true
verify = App.Utils.lastLineEmpty( message )
equal( verify, result, message )
message = "
"
result = true
verify = App.Utils.lastLineEmpty( message )
equal( verify, result, message )
message = "
\n \n\t"
result = true
verify = App.Utils.lastLineEmpty( message )
equal( verify, result, message )
message = "
\n \n\t"
result = true
verify = App.Utils.lastLineEmpty( message )
equal( verify, result, message )
message = "
\n
\n \n\t"
result = true
verify = App.Utils.lastLineEmpty( message )
equal( verify, result, message )
});
// check attibute validation
test( "check attibute validation", function() {
var string = '123'
var result = '123'
var verify = App.Utils.htmlAttributeCleanup( string )
equal( verify, result, string )
string = '123!'
result = '123'
verify = App.Utils.htmlAttributeCleanup( string )
equal( verify, result, string )
string = '12 3!'
result = '123'
verify = App.Utils.htmlAttributeCleanup( string )
equal( verify, result, string )
string = '12-3!'
result = '12-3'
verify = App.Utils.htmlAttributeCleanup( string )
equal( verify, result, string )
string = '12_3!'
result = '12_3'
verify = App.Utils.htmlAttributeCleanup( string )
equal( verify, result, string )
string = '^12_3!'
result = '12_3'
verify = App.Utils.htmlAttributeCleanup( string )
equal( verify, result, string )
string = '^1\n 2_3!'
result = '12_3'
verify = App.Utils.htmlAttributeCleanup( string )
equal( verify, result, string )
string = 'abc?'
result = 'abc'
verify = App.Utils.htmlAttributeCleanup( string )
equal( verify, result, string )
string = 'abc."'
result = 'abc'
verify = App.Utils.htmlAttributeCleanup( string )
equal( verify, result, string )
string = '#abc!^'
result = 'abc'
verify = App.Utils.htmlAttributeCleanup( string )
equal( verify, result, string )
string = 'abc()=$'
result = 'abc'
verify = App.Utils.htmlAttributeCleanup( string )
equal( verify, result, string )
string = "abc()=$\n123\rß"
result = 'abc123'
verify = App.Utils.htmlAttributeCleanup( string )
equal( verify, result, string )
});
// check form diff
test( "check form diff", function() {
var dataNow = {
owner_id: 1,
pending_date: '2015-01-28T09:39:00Z',
}
var dataLast = {
owner_id: '',
pending_date: '2015-01-28T09:39:00Z',
}
var diff = {}
var result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
owner_id: '1',
pending_date: '2015-01-28T09:39:00Z',
}
dataLast = {
owner_id: '',
pending_date: '2015-01-28T09:39:00Z',
}
diff = {}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
pending_date: '2015-01-28T09:39:00Z',
}
dataLast = {
owner_id: 1,
pending_date: '2015-01-28T09:39:00Z',
}
diff = {}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
owner_id: '',
pending_date: '2015-01-28T09:39:00Z',
}
dataLast = {
pending_date: '2015-01-28T09:39:00Z',
}
diff = {
owner_id: '',
}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
owner_id: '',
state_ids: [1,5,6,7],
}
dataLast = {}
diff = {
owner_id: '',
state_ids: ['1','5','6','7'],
}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
owner_id: 1,
state_ids: [1,5,7,6],
}
dataLast = {
owner_id: '',
state_ids: [1,5,6,7],
}
diff = {}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
owner_id: 1,
state_ids: [1,5,6,7],
}
dataLast = {
state_ids: ['1','5','7'],
}
diff = {
owner_id: '',
state_ids: ['6'],
}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
owner_id: '',
state_ids: [1,5,6,7],
}
dataLast = {
owner_id: 1,
state_ids: [1,5,6,7],
}
diff = {}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
owner_id: '',
state_ids: [1,5,6,7],
}
dataLast = {
owner_id: 5,
state_ids: [1,5,6,7],
}
diff = {
owner_id: ''
}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
state_id: 4,
pending_time: '2015-01-28T11:34:00Z'
}
dataLast = {
state_id: 5,
pending_time: undefined
}
diff = {
state_id: '4',
pending_time: '2015-01-28T11:34:00Z'
}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
pending_time: undefined
}
dataLast = {
pending_time: null
}
diff = {}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
ticket: {
pending_time: undefined,
},
}
dataLast = {
ticket: {
pending_time: null,
},
}
diff = {}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
test: '123',
ticket: {
pending_time: undefined,
},
}
dataLast = {
test: '123',
ticket: {
pending_time: null,
},
}
diff = {}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
test: '123',
}
dataLast = {}
diff = {
test: '123',
}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
test: '123',
}
dataLast = {
test: [1,2,3,4]
}
diff = {
test: '123',
}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
test: '123',
}
dataLast = {
test: {
1: 1,
2: 2,
}
}
diff = {
test: '123',
}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
test: [1,2,3,'4']
}
dataLast = {
test: '123',
}
diff = {
test: ['1','2','3','4']
}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
test: {
1: 1,
2: 2,
}
}
dataLast = {
test: '123',
}
diff = {
test: {
1: '1',
2: '2',
}
}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
test: '123',
ticket: {
pending_time: undefined,
},
}
dataLast = {
ticket: {
pending_time: null,
},
}
diff = {
test: '123',
}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = undefined
dataLast = undefined
diff = {}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {}
dataLast = {"number":"10012","title":"some subject 123äöü","group_id":1,"owner_id":1,"customer_id":2,"state_id":3,"priority_id":2,"article":{"from":"Test Master Agent","to":"","cc":"","body":"dasdad","content_type":"text/html","ticket_id":12,"type_id":9,"sender_id":1,"internal":false,"form_id":"523405147"},"updated_at":"2015-01-29T09:22:23.000Z","pending_time":"2015-01-28T22:22:00.000Z","id":12}
diff = {}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
// do not compare content of data instances/objects
no = function test_object() {
this.a = function() { return 123; }
this.b = function() { return '1234'; }
this.c = function() { return [123]; }
this.d = [1,2,3];
this.e = 'abc';
}
no1 = new no()
no2 = new no()
no3 = new no()
dataNow = {
number:'10013',
Article: [no1],
}
dataLast = {
number: "10012",
title: "some subject 123äöü",
Article: [ no2, no3 ],
}
diff = {
number:'10013',
}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
dataNow = {
number:'10013',
Article: [no1,2],
}
dataLast = {
number: "10012",
title: "some subject 123äöü",
Article: [ no2, no3 ],
}
diff = {
number:'10013',
Article: ['2'],
}
result = App.Utils.formDiff( dataNow, dataLast )
deepEqual( result, diff, 'check form diff' );
});
}