Web Interface For Lite Argus Control modules
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.

148 lines
5.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. Ext.test.session.addTest('Ext.data.Field', {
  8. name: 'Test data field creation',
  9. setUp: function(){
  10. this.t = Ext.data.Types;
  11. this.st = Ext.data.SortTypes;
  12. },
  13. tearDown: function(){
  14. delete this.t;
  15. delete this.st;
  16. },
  17. test_alias: function(){
  18. var f;
  19. f = new Ext.data.Field({type: null});
  20. Y.Assert.areEqual(this.t.AUTO, f.type, 'Test empty alias');
  21. f = new Ext.data.Field({type: 'auto'});
  22. Y.Assert.areEqual(this.t.AUTO, f.type, 'Test auto alias');
  23. f = new Ext.data.Field({type: 'int'});
  24. Y.Assert.areEqual(this.t.INT, f.type, 'Test int alias');
  25. f = new Ext.data.Field({type: 'integer'});
  26. Y.Assert.areEqual(this.t.INT, f.type, 'Test integer alias');
  27. f = new Ext.data.Field({type: 'float'});
  28. Y.Assert.areEqual(this.t.FLOAT, f.type, 'Test float alias');
  29. f = new Ext.data.Field({type: 'number'});
  30. Y.Assert.areEqual(this.t.FLOAT, f.type, 'Test number alias');
  31. f = new Ext.data.Field({type: 'bool'});
  32. Y.Assert.areEqual(this.t.BOOL, f.type, 'Test bool alias');
  33. f = new Ext.data.Field({type: 'boolean'});
  34. Y.Assert.areEqual(this.t.BOOL, f.type, 'Test boolean alias');
  35. f = new Ext.data.Field({type: 'string'});
  36. Y.Assert.areEqual(this.t.STRING, f.type, 'Test string alias');
  37. f = new Ext.data.Field({type: 'date'});
  38. Y.Assert.areEqual(this.t.DATE, f.type, 'Test date alias');
  39. },
  40. test_type: function(){
  41. var f;
  42. f = new Ext.data.Field({type: this.t.INT});
  43. Y.Assert.areEqual(this.t.INT, f.type, 'Test int type');
  44. f = new Ext.data.Field({type: this.t.AUTO});
  45. Y.Assert.areEqual(this.t.AUTO, f.type, 'Test auto type');
  46. f = new Ext.data.Field({type: this.t.STRING});
  47. Y.Assert.areEqual(this.t.STRING, f.type, 'Test string type');
  48. },
  49. test_sortType: function(){
  50. var f,
  51. s1 = function(v){
  52. return v * v;
  53. },
  54. s2 = function(v){
  55. return Math.sqrt(v);
  56. };
  57. f = new Ext.data.Field({type: 'auto'});
  58. Y.Assert.areEqual(this.st.none, f.sortType, 'Test sort type defaults for auto');
  59. f = new Ext.data.Field({type: 'int'});
  60. Y.Assert.areEqual(this.st.none, f.sortType, 'Test sort type defaults for int');
  61. f = new Ext.data.Field({type: 'float'});
  62. Y.Assert.areEqual(this.st.none, f.sortType, 'Test sort type defaults for float');
  63. f = new Ext.data.Field({type: 'bool'});
  64. Y.Assert.areEqual(this.st.none, f.sortType, 'Test sort type defaults for bool');
  65. f = new Ext.data.Field({type: 'string'});
  66. Y.Assert.areEqual(this.st.asUCString, f.sortType, 'Test sort type defaults for string');
  67. f = new Ext.data.Field({type: 'date'});
  68. Y.Assert.areEqual(this.st.asDate, f.sortType, 'Test sort type defaults for date');
  69. f = new Ext.data.Field({
  70. type: 'auto',
  71. sortType: 'asDate'
  72. });
  73. Y.Assert.areEqual(this.st.asDate, f.sortType, 'Test with custom string sortType');
  74. f = new Ext.data.Field({
  75. type: 'int',
  76. sortType: s1
  77. });
  78. Y.Assert.areEqual(s1, f.sortType, 'Test with custom function sortType');
  79. f = new Ext.data.Field({
  80. type: 'date',
  81. sortType: s2
  82. });
  83. Y.Assert.areEqual(s2, f.sortType, 'Test with another custom function sortType');
  84. },
  85. test_convert: function(){
  86. var f,
  87. c1 = function(v){
  88. return v / 3;
  89. },
  90. c2 = function(v){
  91. return v * 4;
  92. };
  93. f = new Ext.data.Field({type: 'auto'});
  94. Y.Assert.areEqual(this.t.AUTO.convert, f.convert, 'Test convert for auto');
  95. f = new Ext.data.Field({type: 'int'});
  96. Y.Assert.areEqual(this.t.INT.convert, f.convert, 'Test convert for int');
  97. f = new Ext.data.Field({type: 'float'});
  98. Y.Assert.areEqual(this.t.FLOAT.convert, f.convert, 'Test convert for float');
  99. f = new Ext.data.Field({type: 'bool'});
  100. Y.Assert.areEqual(this.t.BOOL.convert, f.convert, 'Test convert for bool');
  101. f = new Ext.data.Field({type: 'string'});
  102. Y.Assert.areEqual(this.t.STRING.convert, f.convert, 'Test convert for string');
  103. f = new Ext.data.Field({type: 'date'});
  104. Y.Assert.areEqual(this.t.DATE.convert, f.convert, 'Test convert for date');
  105. f = new Ext.data.Field({
  106. type: 'int',
  107. convert: c1
  108. });
  109. Y.Assert.areEqual(c1, f.convert, 'Test with custom function convert');
  110. f = new Ext.data.Field({
  111. type: 'date',
  112. convert: c2
  113. });
  114. Y.Assert.areEqual(c2, f.convert, 'Test with another custom function convert');
  115. }
  116. });