PageRenderTime 41ms CodeModel.GetById 34ms app.highlight 6ms RepoModel.GetById 0ms app.codeStats 0ms

/javascripts/lib/test/unit/data/JsonReader.js

https://bitbucket.org/ksokmesa/sina-asian
JavaScript | 171 lines | 162 code | 3 blank | 6 comment | 0 complexity | 2f0e90ab15a540ddb906ad1248ded974 MD5 | raw file
Possible License(s): GPL-3.0
  1/*!
  2 * Ext JS Library 3.2.1
  3 * Copyright(c) 2006-2010 Ext JS, Inc.
  4 * licensing@extjs.com
  5 * http://www.extjs.com/license
  6 */
  7var suite = Ext.test.session.getSuite('JsonReader');
  8
  9suite.add(new Y.Test.Case({
 10    name: 'buildExtractors',
 11    setUp: function() {
 12        this.reader = new Ext.data.JsonReader({
 13            root: 'data',
 14            idProperty: 'id',
 15            totalProperty: 'totalProp',
 16            messageProperty: 'messageProp',
 17            successProperty: 'successProp',
 18            fields: [
 19               {mapping: 'mappy', name: 'inter', type: 'integer'}
 20            ]
 21        });
 22        this.reader.buildExtractors();
 23    },
 24    tearDown: function() {
 25        delete this.reader;
 26    },
 27    test_getTotal: function() {
 28        Y.Assert.areSame(this.reader.getTotal({ totalProp: 500}), 500);
 29    },
 30    test_getSuccess: function() {
 31        Y.Assert.areSame(this.reader.getSuccess({ successProp: false }), false);
 32    },
 33    test_getMessage: function() {
 34        Y.Assert.areSame(this.reader.getMessage({ messageProp: 'Hello' }), 'Hello');
 35    },
 36    test_getRoot: function() {
 37        Y.Assert.areSame(this.reader.getRoot({ data: 'data' }), 'data');
 38    },
 39    test_getId: function() {
 40        Y.Assert.areSame(this.reader.getId({ id: 100 }), 100);
 41    },
 42    test_mapping: function() {
 43        Y.Assert.areSame(this.reader.ef[0]({ mappy: 200 }), 200);
 44    }
 45}));
 46
 47suite.add(new Y.Test.Case({
 48    name: 'readRecords',
 49    setUp: function() {
 50        this.reader = new Ext.data.JsonReader({
 51            root: 'data',
 52            idProperty: 'id',
 53            totalProperty: 'totalProp',
 54            messageProperty: 'Hello World',
 55            successProperty: 'successProp',
 56            fields: [
 57               {name: 'id'},
 58               {name: 'floater', type: 'float'},
 59               {name: 'bool', type: 'boolean'},
 60               {name: 'inter', type: 'integer'}
 61            ]
 62        });
 63        this.data1 = {
 64            id: 1,
 65            floater: 1.23,
 66            bool: true,
 67            inter: 8675
 68        };
 69        this.rec1 = this.reader.readRecords({
 70            data: [this.data1],
 71            successProp: true,
 72            totalProp: 2
 73        });
 74        this.rec2 = this.reader.readRecords({
 75            data: [{
 76                id: 2,
 77                floater: 4.56,
 78                bool: false,
 79                inter: 309
 80            }],
 81            successProp: false,
 82            totalProp: 6
 83        });
 84    },
 85    test_tearDown: function() {
 86        delete this.reader;
 87        delete this.data1;
 88        delete this.rec1;
 89        delete this.rec2;
 90    },
 91    test_SuccessProperty: function() {
 92        Y.Assert.areSame(this.rec1.success, true);
 93        Y.Assert.areSame(this.rec2.success, false);
 94    },
 95    test_TotalRecords: function() {
 96        Y.Assert.areSame(this.rec1.totalRecords, 2);
 97        Y.Assert.areSame(this.rec2.totalRecords, 6);
 98    },
 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);
104    }
105}));
106
107suite.add(new Y.Test.Case({
108    name: 'readResponse',
109    setUp: function() {
110        this.reader = new Ext.data.JsonReader({
111            root: 'data',
112            idProperty: 'id',
113            totalProperty: 'totalProp',
114            messageProperty: 'messageProp',
115            successProperty: 'successProp',
116            fields: [
117               {name: 'id'},
118               {name: 'floater', type: 'float'},
119               {name: 'bool', type: 'boolean'},
120               {name: 'inter', type: 'integer'}
121            ]
122        });
123        this.data1 = {
124            id: 1,
125            floater: 1.23,
126            bool: true,
127            inter: 8675
128        };
129        this.rec1 = this.reader.readResponse('read', {
130            data: [this.data1],
131            successProp: true,
132            totalProp: 2,
133            messageProp: 'Hello'
134        });
135        this.rec2 = this.reader.readResponse('read', {
136            data: [{
137                id: 2,
138                floater: 4.56,
139                bool: false,
140                inter: 309
141            }],
142            successProp: false,
143            totalProp: 6
144        });
145    },
146    tearDown: function() {
147        delete this.reader;
148        delete this.data1;
149        delete this.rec1;
150        delete this.rec2;
151    },
152    test_SuccessProperty: function() {
153        Y.Assert.areSame(this.rec1.success, true);
154        Y.Assert.areSame(this.rec2.success, false);
155    },
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);
161    },
162    test_ActionProperty: function() {
163        Y.Assert.areSame(this.rec1.action, 'read');
164    },
165    test_MessageProperty: function() {
166        Y.Assert.areSame(this.rec1.message, 'Hello');
167    },
168    test_RawProperty: function() {
169        Y.Assert.areSame(this.rec1.raw.data[0].id, this.data1.id);
170    }
171}));