1
/* Copyright 2010-2011 Canonical Ltd. This software is licensed under the
2
* GNU Affero General Public License version 3 (see the file LICENSE).
5
base: '../../../build/yui/',
6
filter: 'raw', combine: false, fetchCSS: false
7
}).use('test', 'console', 'lpresults.ui.form', function(Y) {
9
var TextField = Y.lpresults.ui.TextField,
10
TextareaField = Y.lpresults.ui.TextareaField,
11
SubmitButton = Y.lpresults.ui.SubmitButton,
12
FormButton = Y.lpresults.ui.FormButton,
13
Form = Y.lpresults.ui.Form;
15
var suite = new Y.Test.Suite('form Tests');
17
// Test the TextField.
18
suite.add(new Y.Test.Case({
22
this.text = new TextField({
30
tearDown: function() {
31
Y.one('#scaffolding').set('innerHTML', '');
34
testRender: function() {
35
this.text.render('#scaffolding');
36
var contentBox = this.text.get('contentBox'),
37
label = contentBox.one('.label'),
38
caption = label.one('.caption'),
39
separator = label.one('.separator'),
40
required = label.one('.required');
41
Y.Assert.areEqual('Field', caption.get('text'));
42
Y.Assert.areEqual(' ', separator.get('text'));
43
Y.Assert.areEqual('(Required)', required.get('text'));
47
suite.add(new Y.Test.Case({
48
name: 'TextareaField',
51
this.text = new TextareaField(
59
tearDown: function() {
60
Y.one('#scaffolding').set('innerHTML', '');
63
testRender: function() {
64
this.text.render('#scaffolding');
65
var contentBox = this.text.get('contentBox'),
66
label = contentBox.one('.label'),
67
caption = label.one('.caption'),
68
separator = label.one('.separator'),
69
required = label.one('.required');
70
Y.Assert.areEqual('Field', caption.get('text'));
71
Y.Assert.areEqual(' ', separator.get('text'));
72
Y.Assert.areEqual('(Required)', required.get('text'));
76
suite.add(new Y.Test.Case({
79
tearDown: function() {
80
Y.one('#scaffolding').set('innerHTML', '');
83
testRender: function() {
84
var field = new FormButton({label: 'Save changes'});
85
field.render('#scaffolding');
86
var boundingBox = field.get('boundingBox');
87
var contentBox = field.get('contentBox');
88
var buttonNode = contentBox.one('input');
89
Y.Assert.areEqual('span', boundingBox.get('nodeName').toLowerCase());
90
Y.Assert.areEqual('save_changes', buttonNode.get('name'));
91
Y.Assert.areEqual('Save changes', buttonNode.get('value'));
92
Y.Assert.isTrue(buttonNode.hasClass('button'));
96
suite.add(new Y.Test.Case({
100
this.text = new TextField({
106
this.save = new SubmitButton({
109
this.quit = new SubmitButton({
112
this.form = new Form();
115
tearDown: function() {
116
Y.one('#scaffolding').set('innerHTML', '');
119
testAddActionAfterRender: function() {
120
this.form.render('#scaffolding');
121
this.form.add(this.text);
122
this.form.add(this.save);
123
this.form.add(this.quit);
124
var contentBox = this.form.get('contentBox'),
125
actions = contentBox.all('.form-actions input');
126
Y.ArrayAssert.itemsAreEqual(['Save', 'Quit'], actions.get('value'));
129
testAddActionBeforeRender: function() {
130
this.form.add(this.text);
131
this.form.add(this.save);
132
this.form.add(this.quit);
133
this.form.render('#scaffolding');
134
var contentBox = this.form.get('contentBox'),
135
actions = contentBox.all('.form-actions input');
136
Y.ArrayAssert.itemsAreEqual(['Save', 'Quit'], actions.get('value'));
139
testSummary: function() {
140
this.form.set('summary', 'Nice form');
141
this.form.add(this.text);
142
this.form.render('#scaffolding');
143
var contentBox = this.form.get('contentBox'),
144
header = contentBox.one('h2');
145
Y.Assert.areEqual('Nice form', header.get('text'));
149
// Lock, stock, and two smoking barrels.
150
var handle_complete = function(data) {
151
window.status = '::::' + JSON.stringify(data);
153
Y.Test.Runner.on('complete', handle_complete);
154
Y.Test.Runner.add(suite);
156
var console = new Y.Console({newestOnTop: false});
157
console.render('#log');
159
Y.on('domready', function() {