3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
7 var suite = Ext.test.session.getSuite('JsonReader');
9 suite.add(new Y.Test.Case({
10 name: 'buildExtractors',
12 this.reader = new Ext.data.JsonReader({
15 totalProperty: 'totalProp',
16 messageProperty: 'messageProp',
17 successProperty: 'successProp',
19 {mapping: 'mappy', name: 'inter', type: 'integer'}
22 this.reader.buildExtractors();
24 tearDown: function() {
27 test_getTotal: function() {
28 Y.Assert.areSame(this.reader.getTotal({ totalProp: 500}), 500);
30 test_getSuccess: function() {
31 Y.Assert.areSame(this.reader.getSuccess({ successProp: false }), false);
33 test_getMessage: function() {
34 Y.Assert.areSame(this.reader.getMessage({ messageProp: 'Hello' }), 'Hello');
36 test_getRoot: function() {
37 Y.Assert.areSame(this.reader.getRoot({ data: 'data' }), 'data');
39 test_getId: function() {
40 Y.Assert.areSame(this.reader.getId({ id: 100 }), 100);
42 test_mapping: function() {
43 Y.Assert.areSame(this.reader.ef[0]({ mappy: 200 }), 200);
47 suite.add(new Y.Test.Case({
50 this.reader = new Ext.data.JsonReader({
53 totalProperty: 'totalProp',
54 messageProperty: 'Hello World',
55 successProperty: 'successProp',
58 {name: 'floater', type: 'float'},
59 {name: 'bool', type: 'boolean'},
60 {name: 'inter', type: 'integer'}
69 this.rec1 = this.reader.readRecords({
74 this.rec2 = this.reader.readRecords({
85 test_tearDown: function() {
91 test_SuccessProperty: function() {
92 Y.Assert.areSame(this.rec1.success, true);
93 Y.Assert.areSame(this.rec2.success, false);
95 test_TotalRecords: function() {
96 Y.Assert.areSame(this.rec1.totalRecords, 2);
97 Y.Assert.areSame(this.rec2.totalRecords, 6);
99 test_Records: function() {
100 Y.Assert.areSame(this.rec1.records[0].data.id, this.data1.id);
101 Y.Assert.areSame(this.rec1.records[0].data.floater, this.data1.floater);
102 Y.Assert.areSame(this.rec1.records[0].data.bool, this.data1.bool);
103 Y.Assert.areSame(this.rec1.records[0].data.inter, this.data1.inter);
107 suite.add(new Y.Test.Case({
108 name: 'readResponse',
110 this.reader = new Ext.data.JsonReader({
113 totalProperty: 'totalProp',
114 messageProperty: 'messageProp',
115 successProperty: 'successProp',
118 {name: 'floater', type: 'float'},
119 {name: 'bool', type: 'boolean'},
120 {name: 'inter', type: 'integer'}
129 this.rec1 = this.reader.readResponse('read', {
135 this.rec2 = this.reader.readResponse('read', {
146 tearDown: function() {
152 test_SuccessProperty: function() {
153 Y.Assert.areSame(this.rec1.success, true);
154 Y.Assert.areSame(this.rec2.success, false);
156 test_Records: function() {
157 Y.Assert.areSame(this.rec1.data[0].id, this.data1.id);
158 Y.Assert.areSame(this.rec1.data[0].floater, this.data1.floater);
159 Y.Assert.areSame(this.rec1.data[0].bool, this.data1.bool);
160 Y.Assert.areSame(this.rec1.data[0].inter, this.data1.inter);
162 test_ActionProperty: function() {
163 Y.Assert.areSame(this.rec1.action, 'read');
165 test_MessageProperty: function() {
166 Y.Assert.areSame(this.rec1.message, 'Hello');
168 test_RawProperty: function() {
169 Y.Assert.areSame(this.rec1.raw.data[0].id, this.data1.id);