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.

214 lines
5.9 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. /**
  16. * Tests Ext.data.Store functionality
  17. * @author Ed Spencer
  18. */
  19. (function() {
  20. var suite = Ext.test.session.getSuite('Ext.form.CompositeField'),
  21. assert = Y.Assert;
  22. //builds a simple composite field
  23. function buildField(config) {
  24. config = config || {};
  25. Ext.applyIf(config, {
  26. items: [
  27. {xtype: 'textfield', name: 'title', width: 40, fieldLabel: 'Title'},
  28. {xtype: 'textfield', name: 'firstName', flex: 1, fieldLabel: 'First'},
  29. {xtype: 'textfield', name: 'lastName', flex: 1, fieldLabel: 'Last'}
  30. ]
  31. });
  32. return new Ext.form.CompositeField(config);
  33. };
  34. //builds and renders a FormPanel containing a composite field
  35. function createForm() {
  36. this.field1 = new Ext.form.TextField({name: 'firstName', flex: 1, fieldLabel: 'First'});
  37. this.field2 = new Ext.form.TextField({name: 'lastName', flex: 1, fieldLabel: 'Last'});
  38. this.composite = new Ext.form.CompositeField({
  39. items: [
  40. {xtype: 'textfield', name: 'title', width: 40, fieldLabel: 'Title'},
  41. this.field1,
  42. this.field2
  43. ]
  44. });
  45. this.form = new Ext.form.FormPanel({
  46. renderTo: Ext.getBody(),
  47. items : [
  48. this.composite
  49. ]
  50. });
  51. };
  52. //use this to tearDown createForm
  53. function destroyForm() {
  54. this.form.destroy();
  55. };
  56. suite.add(new Y.Test.Case({
  57. name: 'building the label',
  58. testDefaultLabel: function() {
  59. var field = buildField();
  60. assert.areSame('Title, First, Last', field.fieldLabel);
  61. },
  62. testCustomFieldLabel: function() {
  63. var field = buildField({fieldLabel: 'Custom label'});
  64. assert.areSame('Custom label', field.fieldLabel);
  65. }
  66. }));
  67. suite.add(new Y.Test.Case({
  68. name: 'isDirty',
  69. setUp : createForm,
  70. tearDown: destroyForm,
  71. testFalseIfDisabled: function() {
  72. this.composite.disable();
  73. assert.isFalse(this.composite.isDirty());
  74. },
  75. testIsClean: function() {
  76. assert.isFalse(this.composite.isDirty());
  77. },
  78. testOneFieldDirty: function() {
  79. this.field1.isDirty = function() {
  80. return true;
  81. };
  82. assert.isTrue(this.composite.isDirty());
  83. }
  84. }));
  85. suite.add(new Y.Test.Case({
  86. name: 'reset',
  87. setUp : createForm,
  88. tearDown: destroyForm,
  89. testPropagatesToChildren: function() {
  90. var callCount = 0;
  91. var resetFunc =function() {
  92. callCount ++;
  93. };
  94. this.field1.reset = resetFunc;
  95. this.field2.reset = resetFunc;
  96. //we need to set this to avoid an unrelated error when resetting
  97. //clearInvalid would otherwise try to clear a non-existent DOM node
  98. this.composite.clearInvalid = Ext.emptyFn;
  99. this.composite.reset();
  100. assert.areEqual(2, callCount);
  101. }
  102. }));
  103. suite.add(new Y.Test.Case({
  104. name: 'enabling and disabling',
  105. setUp : createForm,
  106. tearDown: destroyForm,
  107. testEnablePropagatesToChildren: function() {
  108. var callCount = 0;
  109. var enableFunc =function() {
  110. callCount ++;
  111. };
  112. this.field1.enable = enableFunc;
  113. this.field2.enable = enableFunc;
  114. this.composite.onEnable();
  115. assert.areEqual(2, callCount);
  116. },
  117. testDisablePropagatesToChildren: function() {
  118. var callCount = 0;
  119. var disableFunc = function() {
  120. callCount ++;
  121. };
  122. this.field1.disable = disableFunc;
  123. this.field2.disable = disableFunc;
  124. this.composite.onDisable();
  125. assert.areEqual(2, callCount);
  126. }
  127. }));
  128. suite.add(new Y.Test.Case({
  129. name: 'setting read only',
  130. setUp : createForm,
  131. tearDown: destroyForm,
  132. testSetsSubFields: function() {
  133. var callCount = 0;
  134. var func = function() {
  135. callCount ++;
  136. };
  137. this.field1.setReadOnly = func;
  138. this.field2.setReadOnly = func;
  139. this.composite.setReadOnly();
  140. assert.areEqual(2, callCount);
  141. },
  142. testSetsReadOnly: function() {
  143. var comp = this.composite;
  144. assert.isFalse(comp.readOnly);
  145. comp.setReadOnly();
  146. assert.isTrue(comp.readOnly);
  147. }
  148. }));
  149. // suite.add(new Y.Test.Case({
  150. // name: 'resizing',
  151. //
  152. // setUp : createForm,
  153. // tearDown: destroyForm,
  154. //
  155. // testResizing
  156. //
  157. // }));
  158. })();