aboutsummaryrefslogtreecommitdiff
path: root/tests/unit-tests/styles-controller-test.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit-tests/styles-controller-test.js')
-rw-r--r--tests/unit-tests/styles-controller-test.js143
1 files changed, 143 insertions, 0 deletions
diff --git a/tests/unit-tests/styles-controller-test.js b/tests/unit-tests/styles-controller-test.js
new file mode 100644
index 00000000..b98c2f51
--- /dev/null
+++ b/tests/unit-tests/styles-controller-test.js
@@ -0,0 +1,143 @@
1/**
2 * Created by JetBrains WebStorm.
3 * User: kfg834
4 * Date: 12/27/11
5 * Time: 10:52 AM
6 * To change this template use File | Settings | File Templates.
7 */
8var Montage = require("montage/core/core").Montage;
9var cmObject = require("ninjaapp/js/controllers/styles-controller"),
10 cm = cmObject.StylesController;
11
12
13describe('StylesController', function() {
14
15
16 function makeAndAppend(tag, attr) {
17 var el = document.createElement(tag);
18 if (typeof attr === 'object') {
19 for (var a in attr) {
20 if (attr.hasOwnProperty(a)) {
21 el[a] = attr[a];
22 }
23 }
24 } else if (typeof attr === 'string') {
25 el.className = (el.className + ' ' + attr).trim();
26 }
27
28 document.body.appendChild(el);
29
30 return el;
31 }
32
33 /** **************** Rule tests **************** */
34
35
36 /* Add a Rule */
37 describe('addRule', function() {
38 it('Add Rule', function() {
39 cm.activeDocument = { "_document": document };
40 var rule = cm.addRule('div#Div_1 { background-color: rgb(0, 0, 0) }');
41 expect(rule.cssText).toEqual("div#Div_1 { background-color: rgb(0, 0, 0); }");
42
43 });
44
45 });
46
47 /* Create OverRide Rule */
48 describe('createOverrideRule', function() {
49 it('Override rule created successfully', function() {
50 var object = sm.createOverrideRule('div#Div_1 { background-color: black }', 'div');
51 expect(object.rule).toEqual("div#Div_1 { background-color: black }");
52
53 });
54
55 });
56
57
58 /*Delete a Rule*/
59 describe('Delete Rule', function() {
60 it('Rule deleted successfully', function() {
61 var index = sm.deleteRule('div#Div_1 { background-color: black }');
62 expect(index).toBeGreaterThan(-1);
63 });
64
65 });
66
67
68 /* Get Dominant Rule for an Element */
69 describe('GetDominantRule-Element', function() {
70
71 it('Got Dominant rule for element successfully', function() {
72
73 var rules = ['div#Div_1 { background-color: black }',
74 '#UserContent div#Div_1 { background-color: blue }',
75 '#UserContent #Div_1 { background-color: white }',
76 'div div#Div_1 { background-color: red }'];
77
78 rules.forEach(function(rule) {
79 stylesController.addRule(rule);
80 });
81
82 var rule = sm.getDominantRuleForElement('div','background-color',true);
83 expect(rule).toEqual("#UserContent div#Div_1 { background-color: blue }");
84
85 });
86
87 });
88
89 /* Disable a Rule */
90 describe('DisableRule', function() {
91
92 it('Rule disabled successfully', function() {
93 //Type of rule is not a number
94 var rule = sm.disableRule('div#Div_1 { background-color: black }');
95 expect(rule).toEqual('div#Div_1'+ sm.CONST.GARBAGE_SELECTOR);
96
97 });
98
99 });
100
101
102 /* Enable a Rule */
103 describe('EnableRule', function() {
104 it('Rule enabled successfully', function() {
105
106 //Type of rule is not a number
107 var rule = sm.enableRule('div#Div_1 { background-color: black }');
108 expect(rule.selectorText).toEqual('div#Div_1');
109
110 //Type of rule is a number ie index
111 var rule = sm.enableRule('div#Div_1 { background-color: black }');
112 expect(rule).toEqual("div#Div_1 { background-color: black }");
113
114 });
115
116 });
117
118
119 /* Set Rule Selector */
120 describe('SetRuleSelector', function() {
121
122 it('Set Rule Selector successfully', function() {
123 var rule = sm.setRuleSelector('div#Div_1 { background-color: black }', 'Div');
124 expect(rule).toEqual("Div { background-color: black }");
125 expect(rule.specificity.specificity.id).toEqual(0);
126 //expect(rule.specificity.specificity.class).toEqual(0);
127 expect(rule.specificity.specificity.element).toEqual(1);
128 });
129
130 });
131
132
133 /*Calculate Specificity */
134 describe('Calculate Specificity', function() {
135
136 it('Calculated specificity successfully', function() {
137 var specificity = sm.calculateSpecificity(0,1);
138 expect(specificity.specificity[2]).toEqual(1);
139 });
140
141 });
142
143}); \ No newline at end of file