You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
5.7 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. var suite = Ext.test.session.getSuite('JsonReader');
  16. suite.add(new Y.Test.Case({
  17. name: 'buildExtractors',
  18. setUp: function() {
  19. this.reader = new Ext.data.JsonReader({
  20. root: 'data',
  21. idProperty: 'id',
  22. totalProperty: 'totalProp',
  23. messageProperty: 'messageProp',
  24. successProperty: 'successProp',
  25. fields: [
  26. {mapping: 'mappy', name: 'inter', type: 'integer'}
  27. ]
  28. });
  29. this.reader.buildExtractors();
  30. },
  31. tearDown: function() {
  32. delete this.reader;
  33. },
  34. test_getTotal: function() {
  35. Y.Assert.areSame(this.reader.getTotal({ totalProp: 500}), 500);
  36. },
  37. test_getSuccess: function() {
  38. Y.Assert.areSame(this.reader.getSuccess({ successProp: false }), false);
  39. },
  40. test_getMessage: function() {
  41. Y.Assert.areSame(this.reader.getMessage({ messageProp: 'Hello' }), 'Hello');
  42. },
  43. test_getRoot: function() {
  44. Y.Assert.areSame(this.reader.getRoot({ data: 'data' }), 'data');
  45. },
  46. test_getId: function() {
  47. Y.Assert.areSame(this.reader.getId({ id: 100 }), 100);
  48. },
  49. test_mapping: function() {
  50. Y.Assert.areSame(this.reader.ef[0]({ mappy: 200 }), 200);
  51. }
  52. }));
  53. suite.add(new Y.Test.Case({
  54. name: 'readRecords',
  55. setUp: function() {
  56. this.reader = new Ext.data.JsonReader({
  57. root: 'data',
  58. idProperty: 'id',
  59. totalProperty: 'totalProp',
  60. messageProperty: 'Hello World',
  61. successProperty: 'successProp',
  62. fields: [
  63. {name: 'id'},
  64. {name: 'floater', type: 'float'},
  65. {name: 'bool', type: 'boolean'},
  66. {name: 'inter', type: 'integer'}
  67. ]
  68. });
  69. this.data1 = {
  70. id: 1,
  71. floater: 1.23,
  72. bool: true,
  73. inter: 8675
  74. };
  75. this.rec1 = this.reader.readRecords({
  76. data: [this.data1],
  77. successProp: true,
  78. totalProp: 2
  79. });
  80. this.rec2 = this.reader.readRecords({
  81. data: [{
  82. id: 2,
  83. floater: 4.56,
  84. bool: false,
  85. inter: 309
  86. }],
  87. successProp: false,
  88. totalProp: 6
  89. });
  90. },
  91. test_tearDown: function() {
  92. delete this.reader;
  93. delete this.data1;
  94. delete this.rec1;
  95. delete this.rec2;
  96. },
  97. test_SuccessProperty: function() {
  98. Y.Assert.areSame(this.rec1.success, true);
  99. Y.Assert.areSame(this.rec2.success, false);
  100. },
  101. test_TotalRecords: function() {
  102. Y.Assert.areSame(this.rec1.totalRecords, 2);
  103. Y.Assert.areSame(this.rec2.totalRecords, 6);
  104. },
  105. test_Records: function() {
  106. Y.Assert.areSame(this.rec1.records[0].data.id, this.data1.id);
  107. Y.Assert.areSame(this.rec1.records[0].data.floater, this.data1.floater);
  108. Y.Assert.areSame(this.rec1.records[0].data.bool, this.data1.bool);
  109. Y.Assert.areSame(this.rec1.records[0].data.inter, this.data1.inter);
  110. }
  111. }));
  112. suite.add(new Y.Test.Case({
  113. name: 'readResponse',
  114. setUp: function() {
  115. this.reader = new Ext.data.JsonReader({
  116. root: 'data',
  117. idProperty: 'id',
  118. totalProperty: 'totalProp',
  119. messageProperty: 'messageProp',
  120. successProperty: 'successProp',
  121. fields: [
  122. {name: 'id'},
  123. {name: 'floater', type: 'float'},
  124. {name: 'bool', type: 'boolean'},
  125. {name: 'inter', type: 'integer'}
  126. ]
  127. });
  128. this.data1 = {
  129. id: 1,
  130. floater: 1.23,
  131. bool: true,
  132. inter: 8675
  133. };
  134. this.rec1 = this.reader.readResponse('read', {
  135. data: [this.data1],
  136. successProp: true,
  137. totalProp: 2,
  138. messageProp: 'Hello'
  139. });
  140. this.rec2 = this.reader.readResponse('read', {
  141. data: [{
  142. id: 2,
  143. floater: 4.56,
  144. bool: false,
  145. inter: 309
  146. }],
  147. successProp: false,
  148. totalProp: 6
  149. });
  150. },
  151. tearDown: function() {
  152. delete this.reader;
  153. delete this.data1;
  154. delete this.rec1;
  155. delete this.rec2;
  156. },
  157. test_SuccessProperty: function() {
  158. Y.Assert.areSame(this.rec1.success, true);
  159. Y.Assert.areSame(this.rec2.success, false);
  160. },
  161. test_Records: function() {
  162. Y.Assert.areSame(this.rec1.data[0].id, this.data1.id);
  163. Y.Assert.areSame(this.rec1.data[0].floater, this.data1.floater);
  164. Y.Assert.areSame(this.rec1.data[0].bool, this.data1.bool);
  165. Y.Assert.areSame(this.rec1.data[0].inter, this.data1.inter);
  166. },
  167. test_ActionProperty: function() {
  168. Y.Assert.areSame(this.rec1.action, 'read');
  169. },
  170. test_MessageProperty: function() {
  171. Y.Assert.areSame(this.rec1.message, 'Hello');
  172. },
  173. test_RawProperty: function() {
  174. Y.Assert.areSame(this.rec1.raw.data[0].id, this.data1.id);
  175. }
  176. }));