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
|
describe('fiveui.Rules', function() {
it('round trips via JSON', function() {
var ruleIn = new fiveui.Rule(42, 'testRule',
'see: http://test.description/',
'function() { console.log("fail"); }');
var jsonRule = jQuery.toJSON(ruleIn);
var ruleOut = fiveui.Rule.fromJSON(JSON.parse(jsonRule));
expect(ruleOut.id).toBe(ruleIn.id);
expect(ruleOut.name).toBe(ruleIn.name);
expect(ruleOut.description).toBe(ruleIn.description);
expect(ruleOut.ruleStr).toBe(ruleIn.ruleStr);
});
});
describe('fiveui.RuleSet', function() {
it('round trips via JSON, without deps', function() {
var rule1 = new fiveui.Rule(42, 'r1', 'desc1', 'rule txt1');
var rule2 = new fiveui.Rule(43, 'r2', 'desc2', 'rule txt2');
var ruleSet = new fiveui.RuleSet(42, 'rule set', 'desc', '', [rule1, rule2]);
var jsonSet = jQuery.toJSON(ruleSet);
var restoredSet = fiveui.RuleSet.fromJSON(42, JSON.parse(jsonSet));
expect(restoredSet.id).toBe(ruleSet.id);
expect(restoredSet.name).toBe(ruleSet.name);
expect(restoredSet.description).toBe(ruleSet.description);
expect(restoredSet.source).toEqual(ruleSet.source);
expect(restoredSet.rules).toEqual(ruleSet.rules);
expect(restoredSet.dependencies.length).toBe(0);
});
it('round trips via JSON, with deps', function() {
var rule1 = new fiveui.Rule(42, 'r1', 'desc1', 'rule txt1');
var rule2 = new fiveui.Rule(43, 'r2', 'desc2', 'rule txt2');
var ruleSet = new fiveui.RuleSet(42, 'rule set', 'desc', [rule1, rule2],
'', ['dep1.js', 'dep2.js']);
var jsonSet = jQuery.toJSON(ruleSet);
var restoredSet = fiveui.RuleSet.fromJSON(42, JSON.parse(jsonSet));
expect(restoredSet.id).toBe(ruleSet.id);
expect(restoredSet.name).toBe(ruleSet.name);
expect(restoredSet.description).toBe(ruleSet.description);
expect(restoredSet.rules.length).toBe(ruleSet.rules.length);
expect(restoredSet.dependencies).toEqual(ruleSet.dependencies);
});
});
|