File: JsonReader.js

package info (click to toggle)
libjs-extjs 3.4.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 53,188 kB
  • ctags: 3,384
  • sloc: php: 819; xml: 537; python: 60; sql: 44; makefile: 35
file content (171 lines) | stat: -rw-r--r-- 5,296 bytes parent folder | download
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
159
160
161
162
163
164
165
166
167
168
169
170
171
/*!
 * Ext JS Library 3.4.0
 * Copyright(c) 2006-2011 Sencha Inc.
 * licensing@sencha.com
 * http://www.sencha.com/license
 */
var suite = Ext.test.session.getSuite('JsonReader');

suite.add(new Y.Test.Case({
    name: 'buildExtractors',
    setUp: function() {
        this.reader = new Ext.data.JsonReader({
            root: 'data',
            idProperty: 'id',
            totalProperty: 'totalProp',
            messageProperty: 'messageProp',
            successProperty: 'successProp',
            fields: [
               {mapping: 'mappy', name: 'inter', type: 'integer'}
            ]
        });
        this.reader.buildExtractors();
    },
    tearDown: function() {
        delete this.reader;
    },
    test_getTotal: function() {
        Y.Assert.areSame(this.reader.getTotal({ totalProp: 500}), 500);
    },
    test_getSuccess: function() {
        Y.Assert.areSame(this.reader.getSuccess({ successProp: false }), false);
    },
    test_getMessage: function() {
        Y.Assert.areSame(this.reader.getMessage({ messageProp: 'Hello' }), 'Hello');
    },
    test_getRoot: function() {
        Y.Assert.areSame(this.reader.getRoot({ data: 'data' }), 'data');
    },
    test_getId: function() {
        Y.Assert.areSame(this.reader.getId({ id: 100 }), 100);
    },
    test_mapping: function() {
        Y.Assert.areSame(this.reader.ef[0]({ mappy: 200 }), 200);
    }
}));

suite.add(new Y.Test.Case({
    name: 'readRecords',
    setUp: function() {
        this.reader = new Ext.data.JsonReader({
            root: 'data',
            idProperty: 'id',
            totalProperty: 'totalProp',
            messageProperty: 'Hello World',
            successProperty: 'successProp',
            fields: [
               {name: 'id'},
               {name: 'floater', type: 'float'},
               {name: 'bool', type: 'boolean'},
               {name: 'inter', type: 'integer'}
            ]
        });
        this.data1 = {
            id: 1,
            floater: 1.23,
            bool: true,
            inter: 8675
        };
        this.rec1 = this.reader.readRecords({
            data: [this.data1],
            successProp: true,
            totalProp: 2
        });
        this.rec2 = this.reader.readRecords({
            data: [{
                id: 2,
                floater: 4.56,
                bool: false,
                inter: 309
            }],
            successProp: false,
            totalProp: 6
        });
    },
    test_tearDown: function() {
        delete this.reader;
        delete this.data1;
        delete this.rec1;
        delete this.rec2;
    },
    test_SuccessProperty: function() {
        Y.Assert.areSame(this.rec1.success, true);
        Y.Assert.areSame(this.rec2.success, false);
    },
    test_TotalRecords: function() {
        Y.Assert.areSame(this.rec1.totalRecords, 2);
        Y.Assert.areSame(this.rec2.totalRecords, 6);
    },
    test_Records: function() {
        Y.Assert.areSame(this.rec1.records[0].data.id, this.data1.id);
        Y.Assert.areSame(this.rec1.records[0].data.floater, this.data1.floater);
        Y.Assert.areSame(this.rec1.records[0].data.bool, this.data1.bool);
        Y.Assert.areSame(this.rec1.records[0].data.inter, this.data1.inter);
    }
}));

suite.add(new Y.Test.Case({
    name: 'readResponse',
    setUp: function() {
        this.reader = new Ext.data.JsonReader({
            root: 'data',
            idProperty: 'id',
            totalProperty: 'totalProp',
            messageProperty: 'messageProp',
            successProperty: 'successProp',
            fields: [
               {name: 'id'},
               {name: 'floater', type: 'float'},
               {name: 'bool', type: 'boolean'},
               {name: 'inter', type: 'integer'}
            ]
        });
        this.data1 = {
            id: 1,
            floater: 1.23,
            bool: true,
            inter: 8675
        };
        this.rec1 = this.reader.readResponse('read', {
            data: [this.data1],
            successProp: true,
            totalProp: 2,
            messageProp: 'Hello'
        });
        this.rec2 = this.reader.readResponse('read', {
            data: [{
                id: 2,
                floater: 4.56,
                bool: false,
                inter: 309
            }],
            successProp: false,
            totalProp: 6
        });
    },
    tearDown: function() {
        delete this.reader;
        delete this.data1;
        delete this.rec1;
        delete this.rec2;
    },
    test_SuccessProperty: function() {
        Y.Assert.areSame(this.rec1.success, true);
        Y.Assert.areSame(this.rec2.success, false);
    },
    test_Records: function() {
        Y.Assert.areSame(this.rec1.data[0].id, this.data1.id);
        Y.Assert.areSame(this.rec1.data[0].floater, this.data1.floater);
        Y.Assert.areSame(this.rec1.data[0].bool, this.data1.bool);
        Y.Assert.areSame(this.rec1.data[0].inter, this.data1.inter);
    },
    test_ActionProperty: function() {
        Y.Assert.areSame(this.rec1.action, 'read');
    },
    test_MessageProperty: function() {
        Y.Assert.areSame(this.rec1.message, 'Hello');
    },
    test_RawProperty: function() {
        Y.Assert.areSame(this.rec1.raw.data[0].id, this.data1.id);
    }
}));