3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
8 * Tests Ext.data.Store functionality
12 var suite = Ext.test.session.getSuite('Ext.form.CompositeField'),
15 //builds a simple composite field
16 function buildField(config) {
17 config = config || {};
21 {xtype: 'textfield', name: 'title', width: 40, fieldLabel: 'Title'},
22 {xtype: 'textfield', name: 'firstName', flex: 1, fieldLabel: 'First'},
23 {xtype: 'textfield', name: 'lastName', flex: 1, fieldLabel: 'Last'}
27 return new Ext.form.CompositeField(config);
30 //builds and renders a FormPanel containing a composite field
31 function createForm() {
32 this.field1 = new Ext.form.TextField({name: 'firstName', flex: 1, fieldLabel: 'First'});
33 this.field2 = new Ext.form.TextField({name: 'lastName', flex: 1, fieldLabel: 'Last'});
35 this.composite = new Ext.form.CompositeField({
37 {xtype: 'textfield', name: 'title', width: 40, fieldLabel: 'Title'},
43 this.form = new Ext.form.FormPanel({
44 renderTo: Ext.getBody(),
51 //use this to tearDown createForm
52 function destroyForm() {
56 suite.add(new Y.Test.Case({
57 name: 'building the label',
59 testDefaultLabel: function() {
60 var field = buildField();
62 assert.areSame('Title, First, Last', field.fieldLabel);
65 testCustomFieldLabel: function() {
66 var field = buildField({fieldLabel: 'Custom label'});
68 assert.areSame('Custom label', field.fieldLabel);
72 suite.add(new Y.Test.Case({
76 tearDown: destroyForm,
78 testFalseIfDisabled: function() {
79 this.composite.disable();
81 assert.isFalse(this.composite.isDirty());
84 testIsClean: function() {
85 assert.isFalse(this.composite.isDirty());
88 testOneFieldDirty: function() {
89 this.field1.isDirty = function() {
93 assert.isTrue(this.composite.isDirty());
97 suite.add(new Y.Test.Case({
101 tearDown: destroyForm,
103 testPropagatesToChildren: function() {
106 var resetFunc =function() {
110 this.field1.reset = resetFunc;
111 this.field2.reset = resetFunc;
113 //we need to set this to avoid an unrelated error when resetting
114 //clearInvalid would otherwise try to clear a non-existent DOM node
115 this.composite.clearInvalid = Ext.emptyFn;
117 this.composite.reset();
119 assert.areEqual(2, callCount);
123 suite.add(new Y.Test.Case({
124 name: 'enabling and disabling',
127 tearDown: destroyForm,
129 testEnablePropagatesToChildren: function() {
132 var enableFunc =function() {
136 this.field1.enable = enableFunc;
137 this.field2.enable = enableFunc;
139 this.composite.onEnable();
141 assert.areEqual(2, callCount);
144 testDisablePropagatesToChildren: function() {
147 var disableFunc = function() {
151 this.field1.disable = disableFunc;
152 this.field2.disable = disableFunc;
154 this.composite.onDisable();
156 assert.areEqual(2, callCount);
160 suite.add(new Y.Test.Case({
161 name: 'setting read only',
164 tearDown: destroyForm,
166 testSetsSubFields: function() {
169 var func = function() {
173 this.field1.setReadOnly = func;
174 this.field2.setReadOnly = func;
176 this.composite.setReadOnly();
178 assert.areEqual(2, callCount);
181 testSetsReadOnly: function() {
182 var comp = this.composite;
184 assert.isFalse(comp.readOnly);
188 assert.isTrue(comp.readOnly);
192 // suite.add(new Y.Test.Case({
195 // setUp : createForm,
196 // tearDown: destroyForm,