forked from zgrossbart/jdd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjdd_test.js
158 lines (117 loc) · 9.36 KB
/
jdd_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*******************************************************************************
*
* Copyright 2015-2017 Zack Grossbart
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
'use strict';
QUnit.test( 'Object compare tests', function( assert ) {
$('#textarealeft').val('{"Aidan Gillen": {"array": ["Game of Thron\\"es","The Wire"],"string": "some string","int": 2,"aboolean": true, "boolean": true,"object": {"foo": "bar","object1": {"new prop1": "new prop value"},"object2": {"new prop1": "new prop value"},"object3": {"new prop1": "new prop value"},"object4": {"new prop1": "new prop value"}}},"Amy Ryan": {"one": "In Treatment","two": "The Wire"},"Annie Fitzgerald": ["Big Love","True Blood"],"Anwan Glover": ["Treme","The Wire"],"Alexander Skarsgard": ["Generation Kill","True Blood"], "Clarke Peters": null}');
$('#textarearight').val('{"Aidan Gillen": {"array": ["Game of Thrones","The Wire"],"string": "some string","int": "2","otherint": 4, "aboolean": "true", "boolean": false,"object": {"foo": "bar"}},"Amy Ryan": ["In Treatment","The Wire"],"Annie Fitzgerald": ["True Blood","Big Love","The Sopranos","Oz"],"Anwan Glover": ["Treme","The Wire"],"Alexander Skarsg?rd": ["Generation Kill","True Blood"],"Alice Farmer": ["The Corner","Oz","The Wire"]}');
jdd.compare();
// This test makes sure there wasn't a parsing error
assert.ok(jdd.diffs.length > 0, 'Checking for parsing errors' );
assert.ok(jdd.diffs.length === 18, 'Checking for the correct number of differences' );
var typeCount = 0;
var eqCount = 0;
var missingCount = 0;
_.each(jdd.diffs, function(diff) {
if (diff.type === jdd.EQUALITY) {
eqCount++;
} else if (diff.type === jdd.MISSING) {
missingCount++;
} else if (diff.type === jdd.TYPE) {
typeCount++;
}
});
assert.ok(eqCount === 4, 'Checking unequal values' );
assert.ok(missingCount === 11, 'Checking missing values' );
assert.ok(typeCount === 3, 'Checking incorrect types' );
$('#textarealeft').val('');
$('#textarearight').val('');
jdd.setupNewDiff();
});
QUnit.test( 'Array to object compare tests', function( assert ) {
$('#textarealeft').val('[{ "OBJ_ID": "CN=Kate Smith,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com", "userAccountControl": "512", "objectGUID": "b3067a77-875b-4208-9ee3-39128adeb654", "lastLogon": "0", "sAMAccountName": "ksmith", "userPrincipalName": "[email protected]", "distinguishedName": "CN=Kate Smith,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com"},{ "OBJ_ID": "CN=Timothy Swan,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com", "userAccountControl": "512", "objectGUID": "c3f7dae9-9b4f-4d55-a1ec-bf9ef45061c3", "lastLogon": "130766915788304915", "sAMAccountName": "tswan", "userPrincipalName": "[email protected]", "distinguishedName": "CN=Timothy Swan,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com"}]');
$('#textarearight').val('{"foo":[{ "OBJ_ID": "CN=Timothy Swan,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com", "userAccountControl": "512", "objectGUID": "c3f7dae9-9b4f-4d55-a1ec-bf9ef45061c3", "lastLogon": "130766915788304915", "sAMAccountName": "tswan", "userPrincipalName": "[email protected]", "distinguishedName": "CN=Timothy Swan,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com"}]}');
jdd.compare();
// This test makes sure there wasn't a parsing error
assert.ok(jdd.diffs.length > 0, 'Checking for parsing errors' );
assert.ok(jdd.diffs.length === 1, 'Checking for the correct number of differences' );
// console.log('jdd.diffs: ' + JSON.stringify(jdd.diffs));
assert.ok(jdd.diffs[0].type === jdd.TYPE, 'Checking incorrect type' );
$('#textarealeft').val('');
$('#textarearight').val('');
jdd.setupNewDiff();
});
QUnit.test( 'Array compare tests', function( assert ) {
$('#textarealeft').val('[{ "OBJ_ID": "CN=Kate Smith,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com", "userAccountControl": "512", "objectGUID": "b3067a77-875b-4208-9ee3-39128adeb654", "lastLogon": "0", "sAMAccountName": "ksmith", "userPrincipalName": "[email protected]", "distinguishedName": "CN=Kate Smith,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com"},{ "OBJ_ID": "CN=Timothy Swan,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com", "userAccountControl": "512", "objectGUID": "c3f7dae9-9b4f-4d55-a1ec-bf9ef45061c3", "lastLogon": "130766915788304915", "sAMAccountName": "tswan", "userPrincipalName": "[email protected]", "distinguishedName": "CN=Timothy Swan,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com"}]');
$('#textarearight').val('[{ "OBJ_ID": "CN=Timothy Swan,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com", "userAccountControl": "512", "objectGUID": "c3f7dae9-9b4f-4d55-a1ec-bf9ef45061c3", "lastLogon": "130766915788304915", "sAMAccountName": "tswan", "userPrincipalName": "[email protected]", "distinguishedName": "CN=Timothy Swan,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com"}]');
jdd.compare();
// This test makes sure there wasn't a parsing error
assert.ok(jdd.diffs.length > 0, 'Checking for parsing errors' );
assert.ok(jdd.diffs.length === 7, 'Checking for the correct number of differences' );
var eqCount = 0;
var missingCount = 0;
_.each(jdd.diffs, function(diff) {
if (diff.type === jdd.EQUALITY) {
eqCount++;
} else if (diff.type === jdd.MISSING) {
missingCount++;
}
});
assert.ok(eqCount === 6, 'Checking unequal values' );
assert.ok(missingCount === 1, 'Checking missing values' );
$('#textarealeft').val('');
$('#textarearight').val('');
jdd.setupNewDiff();
});
QUnit.test( 'Object to array compare tests', function( assert ) {
$('#textarealeft').val('{"foo":[{ "OBJ_ID": "CN=Kate Smith,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com", "userAccountControl": "512", "objectGUID": "b3067a77-875b-4208-9ee3-39128adeb654", "lastLogon": "0", "sAMAccountName": "ksmith", "userPrincipalName": "[email protected]", "distinguishedName": "CN=Kate Smith,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com"},{ "OBJ_ID": "CN=Timothy Swan,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com", "userAccountControl": "512", "objectGUID": "c3f7dae9-9b4f-4d55-a1ec-bf9ef45061c3", "lastLogon": "130766915788304915", "sAMAccountName": "tswan", "userPrincipalName": "[email protected]", "distinguishedName": "CN=Timothy Swan,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com"}]}');
$('#textarearight').val('[{ "OBJ_ID": "CN=Timothy Swan,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com", "userAccountControl": "512", "objectGUID": "c3f7dae9-9b4f-4d55-a1ec-bf9ef45061c3", "lastLogon": "130766915788304915", "sAMAccountName": "tswan", "userPrincipalName": "[email protected]", "distinguishedName": "CN=Timothy Swan,OU=Users,OU=Willow,DC=cloudaddc,DC=qalab,DC=cam,DC=novell,DC=com"}]');
jdd.compare();
// This test makes sure there wasn't a parsing error
assert.ok(jdd.diffs.length > 0, 'Checking for parsing errors' );
assert.ok(jdd.diffs.length === 1, 'Checking for the correct number of differences' );
assert.ok(jdd.diffs[0].type === jdd.TYPE, 'Checking incorrect type' );
$('#textarealeft').val('');
$('#textarearight').val('');
jdd.setupNewDiff();
});
QUnit.test( 'Arrays order test', function( assert ) {
$('#textarealeft').val('{"a": [1,2,3],"b":"abc"}');
$('#textarearight').val('{"b":"abc","a": [1,3,2]}');
jdd.compare();
// This test makes sure there wasn't a parsing error
assert.ok(jdd.diffs.length > 0, 'Checking for parsing errors' );
assert.ok(jdd.diffs.length === 2, 'Checking for the correct number of differences' );
assert.ok(jdd.diffs[0].type === jdd.EQUALITY, 'Checking incorrect type' );
$('#textarealeft').val('');
$('#textarearight').val('');
jdd.setupNewDiff();
});
QUnit.test( 'Arrays ignore order test', function( assert ) {
$('#textarealeft').val('{"a": [1,2,3],"b":"abc"}');
$('#textarearight').val('{"b":"abc","a": [1,3,2]}');
$('#ignore-array-order').prop('checked', true);
jdd.compare();
assert.ok(jdd.diffs.length === 0, 'Checking for the correct number of differences' );
$('#textarealeft').val('');
$('#textarearight').val('');
jdd.setupNewDiff();
});
QUnit.done(function() {
$('div.initContainer').hide();
$('div.diffContainer').hide();
});