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.

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