~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/app/javascript/tests/test_picker.js

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-06-02 22:22:29 UTC
  • mfrom: (13146.1.9 picker-suggestion-menu-0)
  • Revision ID: launchpad@pqm.canonical.com-20110602222229-40ti4w3zvw7nwcw7
[r=jcsackett][bug=97266] Use standard events with the picker
        suggestion widget. Fix broken picker widget and
        test_title_ellipsisification YUI test

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
    fetchCSS: false
8
8
    }).use('test', 'console', 'node', 'lp', 'lp.client', 'escape', 'event',
9
9
        'event-focus', 'event-simulate', 'lazr.picker','lp.app.picker',
 
10
        'node-event-simulate',
10
11
        function(Y) {
11
12
 
12
13
var Assert = Y.Assert;
47
48
            {"value": "frieda", "title": "Frieda", "css": "sprite-person",
48
49
                "description": "frieda@example.com", "api_uri": "~/frieda"}
49
50
        ];
 
51
        this.text_input = null;
 
52
        this.select_menu = null;
50
53
    },
51
54
 
52
55
    tearDown: function() {
 
56
        if (this.select_menu !== null) {
 
57
            Y.one('body').removeChild(this.select_menu);
 
58
            }
 
59
        if (this.text_input !== null) {
 
60
            Y.one('body').removeChild(this.text_input);
 
61
            }
53
62
        cleanup_widget(this.picker);
54
63
    },
55
64
 
123
132
    test_TextFieldPickerPlugin_selected_item_is_saved: function () {
124
133
        // The picker saves the selected value to its associated
125
134
        // textfield if one is defined.
126
 
        var search_input = Y.Node.create(
127
 
                '<input id="field.initval" value="foo" />');
128
 
        node = Y.one(document.body).appendChild(search_input);
 
135
        this.text_input = Y.Node.create(
 
136
                '<input id="field.testfield" value="foo" />');
 
137
        node = Y.one(document.body).appendChild(this.text_input);
129
138
        this.create_picker();
130
139
        this.picker.plug(Y.lazr.TextFieldPickerPlugin,
131
 
                         {input_element: '[id="field.initval"]'});
 
140
                         {input_element: '[id="field.testfield"]'});
132
141
        this.picker.set('results', this.vocabulary);
133
142
        this.picker.render();
134
143
        var got_focus = false;
135
 
        search_input.on('focus', function(e) {
 
144
        this.text_input.on('focus', function(e) {
136
145
            got_focus = true;
137
146
        });
138
147
        simulate(
139
148
            this.picker.get('boundingBox').one('.yui3-picker-results'),
140
149
                'li:nth-child(1)', 'click');
141
150
        Assert.areEqual(
142
 
            'fred', Y.one('[id="field.initval"]').get("value"));
 
151
            'fred', Y.one('[id="field.testfield"]').get("value"));
143
152
        Assert.isTrue(got_focus, "focus didn't go to the search input.");
144
153
    },
145
154
 
181
190
        Assert.areEqual(
182
191
                undefined, save_flag.event_has_fired,
183
192
                "save event wasn't fired.");
 
193
    },
 
194
 
 
195
    test_connect_select_menu: function() {
 
196
        // connect_select_menu() connects the select menu's onchange event to
 
197
        // copy the selected value to the text input field.
 
198
        this.text_input = Y.Node.create(
 
199
                '<input id="field.testfield" value="foo" />');
 
200
        node = Y.one(document.body).appendChild(this.text_input);
 
201
        this.select_menu = Y.Node.create(
 
202
            '<select id="field.testfield-suggestions"> ' +
 
203
            '    <option value="">Did you mean...</option>' +
 
204
            '    <option value="fnord">Fnord Snarf (fnord)</option>' +
 
205
            '</select>');
 
206
        Y.one('body').appendChild(this.select_menu);
 
207
        var select_menu = Y.DOM.byId('field.testfield-suggestions');
 
208
        var text_input = Y.DOM.byId('field.testfield');
 
209
        Y.lp.app.picker.connect_select_menu(select_menu, text_input);
 
210
        select_menu.selectedIndex = 1;
 
211
        Y.Event.simulate(select_menu, 'change');
 
212
        Assert.areEqual(
 
213
            'fnord', text_input.value,
 
214
            "Select menu's onchange handler failed.");
184
215
    }
185
216
}));
186
217