~launchpad-results/launchpad-results/trunk

« back to all changes in this revision

Viewing changes to static/js/ui/tests/test_form.js

  • Committer: Marc Tardif
  • Date: 2011-08-16 17:14:31 UTC
  • mfrom: (22.1.1 trunk)
  • Revision ID: marc.tardif@canonical.com-20110816171431-3wh9kvfok083ba0k
Added searching interface for systems.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
 
2
 * GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 */
 
4
YUI({
 
5
    base: '../../../build/yui/',
 
6
    filter: 'raw', combine: false, fetchCSS: false
 
7
    }).use('test', 'console', 'lpresults.ui.form', function(Y) {
 
8
 
 
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;
 
14
 
 
15
    var suite = new Y.Test.Suite('form Tests');
 
16
 
 
17
    // Test the TextField.
 
18
    suite.add(new Y.Test.Case({
 
19
        name: 'TextField',
 
20
 
 
21
        setUp: function() {
 
22
            this.text = new TextField({
 
23
                name: 'field',
 
24
                label: 'Field',
 
25
                required: true,
 
26
                value: 'value',
 
27
                hint: 'Some hint'});
 
28
        },
 
29
 
 
30
        tearDown: function() {
 
31
            Y.one('#scaffolding').set('innerHTML', '');
 
32
        },
 
33
 
 
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'));
 
44
        }
 
45
    }));
 
46
 
 
47
    suite.add(new Y.Test.Case({
 
48
        name: 'TextareaField',
 
49
 
 
50
        setUp: function() {
 
51
            this.text = new TextareaField(
 
52
                {name: 'field',
 
53
                 label: 'Field',
 
54
                 required: true,
 
55
                 value: 'value',
 
56
                 hint: 'Some hint'});
 
57
        },
 
58
 
 
59
        tearDown: function() {
 
60
            Y.one('#scaffolding').set('innerHTML', '');
 
61
        },
 
62
 
 
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'));
 
73
        }
 
74
    }));
 
75
 
 
76
    suite.add(new Y.Test.Case({
 
77
        name: 'FormButton',
 
78
 
 
79
        tearDown: function() {
 
80
            Y.one('#scaffolding').set('innerHTML', '');
 
81
        },
 
82
 
 
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'));
 
93
        }
 
94
    }));
 
95
 
 
96
    suite.add(new Y.Test.Case({
 
97
        name: 'Form',
 
98
 
 
99
        setUp: function() {
 
100
            this.text = new TextField({
 
101
                name: 'field',
 
102
                label: 'Field',
 
103
                required: true,
 
104
                value: 'value',
 
105
                hint: 'Some hint'});
 
106
            this.save = new SubmitButton({
 
107
                name: 'save',
 
108
                value: 'Save'});
 
109
            this.quit = new SubmitButton({
 
110
                name: 'quit',
 
111
                value: 'Quit'});
 
112
            this.form = new Form();
 
113
        },
 
114
 
 
115
        tearDown: function() {
 
116
            Y.one('#scaffolding').set('innerHTML', '');
 
117
        },
 
118
 
 
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'));
 
127
        },
 
128
 
 
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'));
 
137
        },
 
138
 
 
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'));
 
146
        }
 
147
    }));
 
148
 
 
149
    // Lock, stock, and two smoking barrels.
 
150
    var handle_complete = function(data) {
 
151
        window.status = '::::' + JSON.stringify(data);
 
152
        };
 
153
    Y.Test.Runner.on('complete', handle_complete);
 
154
    Y.Test.Runner.add(suite);
 
155
 
 
156
    var console = new Y.Console({newestOnTop: false});
 
157
    console.render('#log');
 
158
 
 
159
    Y.on('domready', function() {
 
160
        Y.Test.Runner.run();
 
161
        });
 
162
});