ComponentTreeNode.js
3.41 KB
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
Ext.define('PageAnalyzer.models.ComponentTreeNode', {
extend: 'Ext.data.Model',
fields: [
{ name: 'text', type: 'string' },
{ name: 'compId', type: 'string' },
{ name: 'refName', type: 'string' },
{ name: 'width', type: 'int'},
{ name: 'height', type: 'int'},
{ name: 'x', type: 'int'},
{ name: 'y', type: 'int'},
{ name: 'cssClass', type: 'string'},
{ name: 'xtype', type: 'string' },
{ name: 'rendered', type: 'boolean' },
{ name: 'hidden', type: 'boolean' },
{ name: 'isContainer', type: 'boolean' },
{ name: 'isElement', type: 'boolean' },
{ name: 'isComponent', type: 'boolean', defualtValue: false }
],
jasmineTpl: [
'expect(Ext.widget({cfg})).toHaveLayout({spec});'
],
isSimpleType: function(val) {
// var t = (typeof val);
// return (t == 'number' || t == 'string' || t == 'boolean');
return Ext.isPrimitive(val);
},
isArray: function(val) {
var t = (typeof val);
return (Ext.isArray(val) || t == 'Ext.util.Queue');
},
getComponentConfig: function(initCfg) {
var me = this,
cfg = {},
arry;
initCfg = (initCfg.isComponent)
? initCfg.initialConfig
: initCfg;
if (me.isSimpleType(initCfg)) {
return initCfg;
}
Ext.Object.each(initCfg, function(name, val){
if (val) {
if (me.isSimpleType(val)) {
cfg[name] = val;
} else if (val.isComponent) {
cfg[name] = me.getComponentConfig(val.initialConfig);
cfg['xtype'] = val.getXType();
} else if (me.isArray(val)) {
arry = cfg[name] || (cfg[name] = []);
Ext.each(val, function(v) {
if (v) {
arry.push(me.getComponentConfig(v));
}
}, me);
} else {
cfg[name] = me.getComponentConfig(val);
}
}
});
return cfg;
},
getTestSpec: function() {
var data = this.data,
spec = {},
children = this.childNodes,
len = children.length,
specs = [],
child, i, name;
if (data.refName == 'items' || data.refName == 'dockedItems') {
for (i = 0; i < len; i++) {
child = children[i];
if (!child.data.hidden) {
spec[i] = child.getTestSpec();
}
}
return spec;
} else if (data.isElement) {
var dims = [];
dims.push(data.x, data.y, data.width, data.height);
return {
xywh: dims.join(' ')
};
} else {
for (i = 0; i < len; i++) {
child = children[i];
name = child.data.refName;
if (!child.data.hidden) {
spec[name] = child.getTestSpec();
}
}
return spec;
}
},
getJasmineSpec: function(){
var me = this,
data = me.data,
ctx = {
spec: Ext.JSON.encodeValue(me.getTestSpec(), '\n')
};
return Ext.XTemplate.getTpl(me, 'jasmineTpl').apply(ctx);
}
});