~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/app/javascript/lazr/wizard/tests/wizard.js

[r=deryck][bug=803954] Bring lazr-js source into lp tree and package
        yui as a dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2010, Canonical Ltd. All rights reserved. */
 
2
 
 
3
YUI().use('lazr.wizard', 'lazr.testing.runner',
 
4
          'lazr.testing.mockio', 'node', 'event', 'event-simulate',
 
5
          'dump', 'console', function(Y) {
 
6
 
 
7
var Assert = Y.Assert;  // For easy access to isTrue(), etc.
 
8
 
 
9
 
 
10
/*
 
11
 * A wrapper for the Y.Event.simulate() function.  The wrapper accepts
 
12
 * CSS selectors and Node instances instead of raw nodes.
 
13
 */
 
14
function simulate(widget, selector, evtype, options) {
 
15
    var rawnode = Y.Node.getDOMNode(widget.one(selector));
 
16
    Y.Event.simulate(rawnode, evtype, options);
 
17
}
 
18
 
 
19
/* Helper function to cleanup and destroy a form wizard instance */
 
20
function cleanup_wizard(wizard) {
 
21
    if (wizard.get('rendered')) {
 
22
        var bb = wizard.get('boundingBox');
 
23
        if (Y.Node.getDOMNode(bb)){
 
24
            bb.get('parentNode').removeChild(bb);
 
25
        }
 
26
    }
 
27
 
 
28
    // Kill the widget itself.
 
29
    wizard.destroy();
 
30
}
 
31
 
 
32
/* Helper function that creates a new form wizard instance. */
 
33
function make_wizard(cfg) {
 
34
    var wizard = new Y.lazr.wizard.Wizard(cfg);
 
35
    wizard.render();
 
36
    return wizard;
 
37
}
 
38
 
 
39
/* Helper array of steps for creating a wizard */
 
40
var default_steps = [
 
41
    new Y.lazr.wizard.Step({
 
42
        form_content: "Hello."
 
43
    })
 
44
];
 
45
 
 
46
var suite = new Y.Test.Suite("Wizard Tests");
 
47
 
 
48
suite.add(new Y.Test.Case({
 
49
 
 
50
    name: 'wizard_basics',
 
51
 
 
52
    setUp: function() {
 
53
        wizard_steps = [
 
54
            new Y.lazr.wizard.Step({
 
55
                title: "Step One",
 
56
                form_content: [
 
57
                    'Here is an input: ',
 
58
                    '<input type="text" name="field1" id="field1" />',
 
59
                    'Here is another input: ',
 
60
                    '<input type="text" name="field2" id="field2" />'
 
61
                    ].join(""),
 
62
                funcLoad: function() {},
 
63
                funcCleanUp: function() {}
 
64
            })
 
65
            ]
 
66
        this.wizard = make_wizard({
 
67
            headerContent: 'Form for testing',
 
68
            steps: wizard_steps,
 
69
            xy: [0, 0]
 
70
        });
 
71
 
 
72
        // Ensure window size is constant for tests
 
73
        this.width = window.top.outerWidth;
 
74
        this.height = window.top.outerHeight;
 
75
        window.top.resizeTo(800, 600);
 
76
    },
 
77
 
 
78
    tearDown: function() {
 
79
        window.top.resizeTo(this.width, this.height);
 
80
        cleanup_wizard(this.wizard);
 
81
    },
 
82
 
 
83
    _should: {
 
84
        // The following tests will only be deemed to have passed if
 
85
        // they raise an error.
 
86
        error: {
 
87
            test_wizard_needs_steps: true,
 
88
            test_cant_go_back_when_at_first_step: true,
 
89
            test_cant_go_forward_when_at_last_step: true
 
90
        }
 
91
    },
 
92
 
 
93
    test_wizard_can_be_instantiated: function() {
 
94
        var wizard = new Y.lazr.wizard.Wizard({
 
95
            steps: default_steps
 
96
        });
 
97
        Assert.isInstanceOf(
 
98
            Y.lazr.wizard.Wizard,
 
99
            wizard,
 
100
            "Wizard could not be instantiated.");
 
101
        cleanup_wizard(wizard);
 
102
    },
 
103
 
 
104
    test_wizard_needs_steps: function() {
 
105
        // The wizard will raise an error if no steps are provided. Note
 
106
        // that this test will raise the error; this is expected
 
107
        // behaviour and is declared in the _should object, above.
 
108
        var wizard = new Y.lazr.wizard.Wizard();
 
109
        Assert.isInstanceOf(
 
110
            Y.lazr.wizard.Wizard,
 
111
            wizard,
 
112
            "Wizard could not be instantiated.");
 
113
        cleanup_wizard(wizard);
 
114
    },
 
115
 
 
116
    test_body_content_is_single_node: function() {
 
117
        Assert.areEqual(
 
118
            1,
 
119
            new Y.NodeList(this.wizard.getStdModNode("body")).size(),
 
120
            "The body content should be a single node, not a node list.");
 
121
    },
 
122
 
 
123
    test_form_content_in_body_content: function() {
 
124
        // The form_content should be included in the body of the
 
125
        // wizard during initialization.
 
126
        var body_content = this.wizard.getStdModNode("body");
 
127
 
 
128
        // Ensure the body_content contains our form node.
 
129
        Assert.isTrue(
 
130
            body_content.contains(this.wizard.form_node),
 
131
            "The form node is part of the body content.");
 
132
 
 
133
        // And then make sure that the user-supplied form_content is
 
134
        // included in the form node:
 
135
        Assert.areNotEqual(
 
136
            body_content.get("innerHTML").search(
 
137
                this.wizard.get("form_content")));
 
138
    },
 
139
 
 
140
    test_first_input_has_focus: function() {
 
141
        // The first input element in the form content should have
 
142
        // focus.
 
143
        var first_input = this.wizard.form_node.one('#field1');
 
144
 
 
145
        // Hide the wizard and ensure that the first input does not
 
146
        // have the focus.
 
147
        this.wizard.hide();
 
148
        first_input.blur();
 
149
 
 
150
        var test = this;
 
151
        var focused = false;
 
152
 
 
153
        var onFocus = function(e) {
 
154
            focused = true;
 
155
        };
 
156
 
 
157
        first_input.on('focus', onFocus);
 
158
 
 
159
        this.wizard.show();
 
160
        Assert.isTrue(focused,
 
161
            "The form wizard's first input field receives focus " +
 
162
            "when the wizard is shown.");
 
163
    },
 
164
 
 
165
    test_form_submit_in_body_content: function() {
 
166
        // The body content should include the submit button.
 
167
        var body_content = this.wizard.getStdModNode("body");
 
168
        Assert.isTrue(
 
169
            body_content.contains(
 
170
                this.wizard.get("form_submit_button")),
 
171
            "The body content includes the form_submit_button.");
 
172
    },
 
173
 
 
174
    test_users_submit_button_in_body_content: function() {
 
175
        // If a user supplies a custom submit button, it should be included
 
176
        // in the form instead of the default one.
 
177
        var submit_button = Y.Node.create(
 
178
            '<input type="submit" value="Hit me!" />');
 
179
        var wizard = new Y.lazr.wizard.Wizard({
 
180
            steps: [
 
181
                new Y.lazr.wizard.Step({
 
182
                    form_content: 'Here is an input: ' +
 
183
                        '<input type="text" name="field1" id="field1" />'
 
184
                })
 
185
            ],
 
186
            form_submit_button: submit_button
 
187
        });
 
188
        wizard.render();
 
189
 
 
190
        // Ensure the button has been used in the form:
 
191
        Assert.isTrue(
 
192
            wizard.form_node.contains(submit_button),
 
193
            "The form should include the users submit button.");
 
194
 
 
195
        cleanup_wizard(wizard);
 
196
    },
 
197
 
 
198
    test_form_cancel_in_body_content: function() {
 
199
        // The body content should include the cancel button.
 
200
        var body_content = this.wizard.getStdModNode("body");
 
201
        Assert.isTrue(
 
202
            body_content.contains(
 
203
                this.wizard.get("form_cancel_button")),
 
204
            "The body content includes the form_cancel_button.");
 
205
    },
 
206
 
 
207
    test_users_cancel_button_in_body_content: function() {
 
208
        // If a user supplies a custom cancel button, it should be included
 
209
        // in the form instead of the default one.
 
210
        var cancel_button = Y.Node.create(
 
211
            '<button type="" value="cancel" />');
 
212
        var wizard = new Y.lazr.wizard.Wizard({
 
213
            steps: [
 
214
                new Y.lazr.wizard.Step({
 
215
                    form_content: 'Here is an input: ' +
 
216
                        '<input type="text" name="field1" id="field1" />'
 
217
                })
 
218
            ],
 
219
            form_cancel_button: cancel_button
 
220
        });
 
221
        wizard.render();
 
222
 
 
223
        // Ensure the button has been used in the form:
 
224
        Assert.isTrue(
 
225
            wizard.form_node.contains(cancel_button),
 
226
            "The form should include the users cancel button.");
 
227
 
 
228
        cleanup_wizard(wizard);
 
229
    },
 
230
 
 
231
    test_hide_when_cancel_clicked: function() {
 
232
        // The form wizard should hide when the cancel button is clicked.
 
233
 
 
234
        var bounding_box = this.wizard.get('boundingBox');
 
235
        Assert.isFalse(
 
236
            bounding_box.hasClass('yui3-lazr-wizard-hidden'),
 
237
            "The form is not hidden initially.");
 
238
 
 
239
        simulate(
 
240
            this.wizard.form_node,
 
241
            "button[type=button]",
 
242
            'click');
 
243
 
 
244
        Assert.isTrue(
 
245
            bounding_box.hasClass('yui3-lazr-wizard-hidden'),
 
246
            "The form is hidden after cancel is clicked.");
 
247
    },
 
248
 
 
249
    test_error_displayed_on_showError: function() {
 
250
        // The error message should be in the body content.
 
251
 
 
252
        this.wizard.showError("My special error");
 
253
 
 
254
        var body_content = this.wizard.getStdModNode("body");
 
255
        Assert.areNotEqual(
 
256
            body_content.get("innerHTML").search("My special error"),
 
257
            -1,
 
258
            "The error text was included in the body content.");
 
259
    },
 
260
 
 
261
    test_tags_stripped_from_errors: function() {
 
262
        // Any tags in error messages will be stripped out.
 
263
        // That is, as long as they begin and end with ASCII '<' and '>'
 
264
        // chars. Not sure what to do about unicode, for example.
 
265
        this.wizard.showError("<h2>My special error</h2>");
 
266
 
 
267
        var body_content = this.wizard.getStdModNode("body");
 
268
        Assert.areEqual(
 
269
            -1,
 
270
            body_content.get("innerHTML").search("<h2>"),
 
271
            "The tags were stripped from the error message.");
 
272
    },
 
273
 
 
274
    test_error_cleared_on_clearError: function() {
 
275
        // The error message should be cleared from the body content.
 
276
        this.wizard.showError("My special error");
 
277
        this.wizard.clearError();
 
278
        var body_content = this.wizard.getStdModNode("body");
 
279
        Assert.areEqual(
 
280
            body_content.get("innerHTML").search("My special error"),
 
281
            -1,
 
282
            "The error text is cleared from the body content.");
 
283
    },
 
284
 
 
285
    test_wizard_centered_when_shown: function() {
 
286
        // If the 'centered' attribute is set, the wizard should be
 
287
        // centered in the viewport when shown.
 
288
        Assert.areEqual('[0, 0]', Y.dump(this.wizard.get('xy')),
 
289
                        "Position is initially 0,0.");
 
290
        this.wizard.show();
 
291
        Assert.areEqual('[0, 0]', Y.dump(this.wizard.get('xy')),
 
292
                        "Position is not updated if widget not centered.");
 
293
        this.wizard.hide();
 
294
 
 
295
        this.wizard.set('centered', true);
 
296
        this.wizard.show();
 
297
        var centered_pos_before_resize = this.wizard.get('xy');
 
298
        Assert.areNotEqual('[0, 0]', Y.dump(centered_pos_before_resize),
 
299
                           "Position is updated when centered attr set.");
 
300
        this.wizard.hide();
 
301
 
 
302
        var centered = false;
 
303
        function watch_centering() {
 
304
            centered = true;
 
305
        }
 
306
        Y.Do.after(watch_centering, this.wizard, 'centered');
 
307
 
 
308
        // The position is updated after resizing the window and re-showing:
 
309
        window.top.resizeTo(850, 550);
 
310
        this.wizard.show();
 
311
 
 
312
        Assert.isTrue(centered,
 
313
            "The wizard centers itself when it is shown with the centered " +
 
314
            "attribute set.");
 
315
    },
 
316
 
 
317
    test_form_content_as_node: function() {
 
318
        // The form content can also be passed as a node, rather than
 
319
        // a string of HTML.
 
320
        var form_content_div = Y.Node.create("<div />");
 
321
        var input_node = Y.Node.create(
 
322
            '<input type="text" name="field1" value="val1" />');
 
323
        form_content_div.appendChild(input_node);
 
324
 
 
325
        var wizard = make_wizard({
 
326
            headerContent: 'Form for testing',
 
327
            steps: [
 
328
                new Y.lazr.wizard.Step({
 
329
                    form_content: form_content_div
 
330
                })
 
331
            ]
 
332
        });
 
333
 
 
334
        Assert.isTrue(
 
335
            wizard.form_node.contains(input_node),
 
336
            "Failed to pass the form content as a Y.Node instance.");
 
337
        cleanup_wizard(wizard);
 
338
    },
 
339
 
 
340
    test_first_step_load_called_on_wizard_load: function() {
 
341
        // The load() function of the first step will be called when the
 
342
        // wizard is instantiated.
 
343
        var load_called = false;
 
344
        var wizard_steps = [
 
345
            new Y.lazr.wizard.Step({
 
346
                form_content: "Nothing to see here.",
 
347
                funcLoad: function() {
 
348
                    load_called = true;
 
349
                }
 
350
            })
 
351
        ]
 
352
        var wizard = make_wizard({
 
353
            steps: wizard_steps
 
354
        });
 
355
        wizard.render();
 
356
 
 
357
        Assert.isTrue(
 
358
            load_called,
 
359
            "The funcLoad callback of the first step was not called.");
 
360
    },
 
361
 
 
362
    test_step_load_called_on_wizard_next: function() {
 
363
        // When wizard.next() is called, the next Step's funcLoad
 
364
        // callback will be called.
 
365
        var load_called = false;
 
366
        var wizard_steps = [
 
367
            new Y.lazr.wizard.Step({
 
368
                form_content: "Nothing to see here."
 
369
            }),
 
370
            new Y.lazr.wizard.Step({
 
371
                form_content: "Still nothing to see here.",
 
372
                funcLoad: function() {
 
373
                    load_called = true;
 
374
                }
 
375
            })
 
376
        ]
 
377
        var wizard = make_wizard({
 
378
            steps: wizard_steps
 
379
        });
 
380
        wizard.render();
 
381
        wizard.next();
 
382
 
 
383
        Assert.isTrue(
 
384
            load_called,
 
385
            "The funcLoad callback of the next step was not called.");
 
386
    },
 
387
 
 
388
    test_step_load_called_on_wizard_prev: function() {
 
389
        // When wizard.previous() is called, the previous Step's funcLoad
 
390
        // callback will be called.
 
391
        var load_called = false;
 
392
        var wizard_steps = [
 
393
            new Y.lazr.wizard.Step({
 
394
                form_content: "Nothing to see here.",
 
395
                funcLoad: function() {
 
396
                    load_called = true;
 
397
                }
 
398
            }),
 
399
            new Y.lazr.wizard.Step({
 
400
                form_content: "Still nothing to see here."
 
401
            })
 
402
        ]
 
403
        var wizard = make_wizard({
 
404
            steps: wizard_steps
 
405
        });
 
406
        wizard.render();
 
407
        wizard.next();
 
408
        load_called = false;
 
409
        wizard.previous();
 
410
 
 
411
        Assert.isTrue(
 
412
            load_called,
 
413
            "The funcLoad callback of the first step was not called.");
 
414
    },
 
415
 
 
416
    test_cant_go_back_when_at_first_step: function() {
 
417
        // When a wizard is on its first step, calling wizard.previous()
 
418
        // will raise an error.
 
419
        var wizard_steps = [
 
420
            new Y.lazr.wizard.Step({
 
421
                form_content: "Nothing to see here."
 
422
            })
 
423
        ]
 
424
        var wizard = make_wizard({
 
425
            steps: wizard_steps
 
426
        });
 
427
        wizard.render();
 
428
        wizard.previous();
 
429
    },
 
430
 
 
431
    test_cant_go_forward_when_at_last_step: function() {
 
432
        // When a wizard is on its last step, calling wizard.next()
 
433
        // will raise an error.
 
434
        var wizard_steps = [
 
435
            new Y.lazr.wizard.Step({
 
436
                form_content: "Nothing to see here."
 
437
            })
 
438
        ]
 
439
        var wizard = make_wizard({
 
440
            steps: wizard_steps
 
441
        });
 
442
        wizard.render();
 
443
        wizard.next();
 
444
    },
 
445
 
 
446
    test_hasNextStep_returns_true_with_next_step: function() {
 
447
        // Wizard.hasNextStep() will return True if there are more
 
448
        // steps after the current one.
 
449
        var wizard_steps = [
 
450
            new Y.lazr.wizard.Step({
 
451
                form_content: "Nothing to see here."
 
452
            }),
 
453
            new Y.lazr.wizard.Step({
 
454
                form_content: "Still nothing to see here."
 
455
            })
 
456
        ]
 
457
        var wizard = make_wizard({
 
458
            steps: wizard_steps
 
459
        });
 
460
        wizard.render();
 
461
 
 
462
        Assert.isTrue(
 
463
            wizard.hasNextStep(),
 
464
            "Wizard.hasNextStep() should return true.");
 
465
    },
 
466
 
 
467
    test_hasNextStep_returns_false_with_no_next_step: function() {
 
468
        // Wizard.hasNextStep() will return false if there are no more
 
469
        // steps after the current one.
 
470
        var wizard_steps = [
 
471
            new Y.lazr.wizard.Step({
 
472
                form_content: "Nothing to see here."
 
473
            })
 
474
        ]
 
475
        var wizard = make_wizard({
 
476
            steps: wizard_steps
 
477
        });
 
478
        wizard.render();
 
479
 
 
480
        Assert.isFalse(
 
481
            wizard.hasNextStep(),
 
482
            "Wizard.hasNextStep() should return false.");
 
483
    },
 
484
 
 
485
    test_hasPreviousStep_returns_true_with_prev_step: function() {
 
486
        // Wizard.hasPreviousStep() will return True if there are steps
 
487
        // before the current one.
 
488
        var wizard_steps = [
 
489
            new Y.lazr.wizard.Step({
 
490
                form_content: "Nothing to see here."
 
491
            }),
 
492
            new Y.lazr.wizard.Step({
 
493
                form_content: "Still nothing to see here."
 
494
            })
 
495
        ]
 
496
        var wizard = make_wizard({
 
497
            steps: wizard_steps
 
498
        });
 
499
        wizard.render();
 
500
        wizard.next();
 
501
 
 
502
        Assert.isTrue(
 
503
            wizard.hasPreviousStep(),
 
504
            "Wizard.hasPreviousStep() should return true.");
 
505
    },
 
506
 
 
507
    test_hasPreviousStep_returns_false_with_no_prev_step: function() {
 
508
        // Wizard.hasPreviousStep() will return false if there are no
 
509
        // steps before the current one.
 
510
        var wizard_steps = [
 
511
            new Y.lazr.wizard.Step({
 
512
                form_content: "Nothing to see here."
 
513
            })
 
514
        ]
 
515
        var wizard = make_wizard({
 
516
            steps: wizard_steps
 
517
        });
 
518
        wizard.render();
 
519
 
 
520
        Assert.isFalse(
 
521
            wizard.hasPreviousStep(),
 
522
            "Wizard.hasPreviousStep() should return false.");
 
523
   },
 
524
 
 
525
   test_stepChange_fired_on_step_change: function() {
 
526
        // Changing the step will fire a wizard:stepChange event.
 
527
        var stepChange_fired = false;
 
528
        var wizard_steps = [
 
529
            new Y.lazr.wizard.Step({
 
530
                form_content: "Nothing to see here."
 
531
            }),
 
532
            new Y.lazr.wizard.Step({
 
533
                form_content: "Still nothing to see here."
 
534
            })
 
535
        ]
 
536
        var wizard = make_wizard({
 
537
            steps: wizard_steps
 
538
        });
 
539
        wizard.on("wizard:stepChange", function() {
 
540
            stepChange_fired = true;
 
541
        });
 
542
        wizard.render();
 
543
        wizard.next();
 
544
 
 
545
        Assert.isTrue(
 
546
            stepChange_fired, "wizard:stepChange did not fire.");
 
547
   },
 
548
 
 
549
   test_addStep_adds_step: function() {
 
550
        // Wizard.addStep() adds a step to the Wizard.
 
551
        var wizard_steps = [
 
552
            new Y.lazr.wizard.Step({
 
553
                form_content: "Nothing to see here."
 
554
            })
 
555
        ]
 
556
        var wizard = make_wizard({
 
557
            steps: wizard_steps
 
558
        });
 
559
        wizard.render();
 
560
        // There's only one step at this point, so hasNextStep() returns
 
561
        // False.
 
562
        Assert.isFalse(
 
563
            wizard.hasNextStep(),
 
564
            "Wizard.hasNextStep() should return false.");
 
565
        wizard.addStep(new Y.lazr.wizard.Step({
 
566
            form_content: "Still nothing. Move along."
 
567
        }));
 
568
        Assert.isTrue(
 
569
            wizard.hasNextStep(),
 
570
            "Wizard.hasNextStep() should return true.");
 
571
   },
 
572
 
 
573
   test_destructor_deletes_steps: function() {
 
574
        // Wizard.destructor() deletes all the of the Wizard's Steps.
 
575
        var wizard_steps = [
 
576
            new Y.lazr.wizard.Step({
 
577
                form_content: "Nothing to see here."
 
578
            })
 
579
        ]
 
580
        var wizard = make_wizard({
 
581
            steps: wizard_steps
 
582
        });
 
583
        wizard.render();
 
584
        wizard.destructor();
 
585
 
 
586
        var steps = wizard.get("steps");
 
587
        Assert.areEqual(
 
588
            0, steps.length, "There should be no steps left.");
 
589
   }
 
590
 
 
591
 
 
592
}));
 
593
 
 
594
suite.add(new Y.Test.Case({
 
595
 
 
596
    name: 'wizard_data',
 
597
 
 
598
    test_submit_callback_called_on_submit: function() {
 
599
        // Set an expectation that the form_submit_callback will be
 
600
        // called with the correct data:
 
601
        var callback_called = false;
 
602
        var submit_callback = function(ignore){
 
603
            callback_called = true;
 
604
        };
 
605
        var wizard = make_wizard({
 
606
            steps: [
 
607
                new Y.lazr.wizard.Step({
 
608
                    form_content:
 
609
                        '<input type="text" name="field1" value="val1" />',
 
610
                })
 
611
            ],
 
612
            form_submit_callback: submit_callback
 
613
        });
 
614
        simulate(
 
615
            wizard.form_node,
 
616
            "input[type=submit]",
 
617
            'click');
 
618
 
 
619
        Assert.isTrue(
 
620
            callback_called,
 
621
            "The form_submit_callback should be called.");
 
622
        cleanup_wizard(wizard);
 
623
    },
 
624
 
 
625
    test_submit_with_callback_prevents_propagation: function() {
 
626
        // The onsubmit event is not propagated when user provides
 
627
        // a callback.
 
628
 
 
629
        var wizard = make_wizard({
 
630
            steps: [
 
631
                new Y.lazr.wizard.Step({
 
632
                    form_content:
 
633
                        '<input type="text" name="field1" value="val1" />',
 
634
                })
 
635
            ],
 
636
            form_submit_callback: function() {}
 
637
        });
 
638
 
 
639
        var event_was_propagated = false;
 
640
        var test = this;
 
641
        var onSubmit = function(e) {
 
642
            event_was_propagated = true;
 
643
            e.preventDefault();
 
644
        };
 
645
        Y.on('submit', onSubmit, wizard.form_node);
 
646
 
 
647
        simulate(wizard.form_node, "input[type=submit]", 'click');
 
648
 
 
649
        Assert.isFalse(
 
650
            event_was_propagated,
 
651
            "The onsubmit event should not be propagated.");
 
652
        cleanup_wizard(wizard);
 
653
    },
 
654
 
 
655
    test_submit_without_callback: function() {
 
656
        // The form should submit as a normal form if no callback
 
657
        // was provided.
 
658
        var wizard = make_wizard({
 
659
            steps: [
 
660
                new Y.lazr.wizard.Step({
 
661
                    form_content:
 
662
                        '<input type="text" name="field1" value="val1" />',
 
663
                })
 
664
            ],
 
665
        });
 
666
 
 
667
        var event_was_propagated = false;
 
668
        var test = this;
 
669
        var onSubmit = function(e) {
 
670
            event_was_propagated = true;
 
671
            e.preventDefault();
 
672
        };
 
673
 
 
674
        Y.on('submit', onSubmit, wizard.form_node);
 
675
 
 
676
        simulate(
 
677
            wizard.form_node,
 
678
            "input[type=submit]",
 
679
            'click');
 
680
        Assert.isTrue(event_was_propagated,
 
681
                      "The normal form submission event is propagated as " +
 
682
                      "normal when no callback is provided.");
 
683
        cleanup_wizard(wizard);
 
684
    },
 
685
 
 
686
    test_getFormData_returns_correct_data_for_simple_inputs: function() {
 
687
        // The getFormData method should return the values of simple
 
688
        // inputs correctly.
 
689
 
 
690
        var wizard = make_wizard({
 
691
            headerContent: 'Form for testing',
 
692
            steps: [
 
693
                new Y.lazr.wizard.Step({
 
694
                    form_content: [
 
695
                        'Here is an input: ',
 
696
                        '<input type="text" name="field1" value="val1" />',
 
697
                        '<input type="text" name="field2" value="val2" />',
 
698
                        '<input type="text" name="field3" value="val3" />'
 
699
                        ].join("")
 
700
                })
 
701
            ],
 
702
        });
 
703
        Assert.areEqual(
 
704
            '{field1 => [val1], field2 => [val2], field3 => [val3]}',
 
705
            Y.dump(wizard.getFormData()),
 
706
            "The getFormData method returns simple input data correctly.");
 
707
        cleanup_wizard(wizard);
 
708
    },
 
709
 
 
710
    test_getFormData_returns_inputs_nested_several_levels: function() {
 
711
        // The getFormData method should return the values of inputs
 
712
        // even when they are several levels deep in the form node
 
713
        var wizard = make_wizard({
 
714
            headerContent: 'Form for testing',
 
715
            steps: [
 
716
                new Y.lazr.wizard.Step({
 
717
                    form_content: [
 
718
                        'Here is an input: ',
 
719
                        '<div>',
 
720
                        '  <input type="text" name="field1" value="val1" />',
 
721
                        '  <div>',
 
722
                        '    <input type="text" name="field2" value="val2" ',
 
723
                        '    />',
 
724
                        '    <div>',
 
725
                        '      <input type="text" name="field3" ',
 
726
                        '        value="val3" />',
 
727
                        '    </div>',
 
728
                        '  </div>',
 
729
                        '</div>'
 
730
                    ].join("")
 
731
                })
 
732
            ]
 
733
        });
 
734
 
 
735
        Assert.areEqual(
 
736
            '{field1 => [val1], field2 => [val2], field3 => [val3]}',
 
737
            Y.dump(wizard.getFormData()),
 
738
            "The getFormData method returns simple input data correctly.");
 
739
        cleanup_wizard(wizard);
 
740
 
 
741
    },
 
742
 
 
743
}));
 
744
 
 
745
Y.lazr.testing.Runner.add(suite);
 
746
Y.lazr.testing.Runner.run();
 
747
 
 
748
});