~ubuntu-branches/ubuntu/quantal/maas/quantal-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/docs/test/test-async-test.html

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html>
2
 
<html lang="en">
3
 
<head>
4
 
    <meta charset="utf-8">
5
 
    <title>Example: Asynchronous Testing</title>
6
 
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
7
 
    <link rel="stylesheet" href="../assets/css/main.css">
8
 
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
9
 
    <script src="../../build/yui/yui-min.js"></script>
10
 
</head>
11
 
<body>
12
 
 
13
 
<div id="doc">
14
 
    <h1>Example: Asynchronous Testing</h1>
15
 
 
16
 
    
17
 
        <a href="#toc" class="jump">Jump to Table of Contents</a>
18
 
    
19
 
 
20
 
    <div class="yui3-g">
21
 
        <div id="main" class="yui3-u">
22
 
            <div class="content"><div class="intro">
23
 
    <p>This example shows how to create an asynchronous test with the YUI Test framework for testing browser-based JavaScript code.
24
 
      A <code>Y.Test.Case</code> object is created with a test that waits for a
25
 
      few seconds before continuing. The <code>Y.Test.Runner</code>
26
 
      is then used to run the tests once the page has loaded.</p>
27
 
</div>
28
 
 
29
 
<div class="example yui3-skin-sam">
30
 
    <style scoped>
31
 
    #testLogger {
32
 
        margin-bottom: 1em;
33
 
    }
34
 
 
35
 
    #testLogger .yui3-console .yui3-console-title {
36
 
        border: 0 none;
37
 
        color: #000;
38
 
        font-size: 13px;
39
 
        font-weight: bold;
40
 
        margin: 0;
41
 
        text-transform: none;
42
 
    }
43
 
    #testLogger .yui3-console .yui3-console-entry-meta {
44
 
        margin: 0;
45
 
    }
46
 
 
47
 
    .yui3-skin-sam .yui3-console-entry-pass .yui3-console-entry-cat {
48
 
        background: #070;
49
 
        color: #fff;
50
 
    }
51
 
    </style>
52
 
 
53
 
    <div id="testLogger"></div>
54
 
 
55
 
<script>
56
 
YUI().use('node', 'console', 'test',function (Y) {
57
 
 
58
 
    Y.namespace("example.test");
59
 
 
60
 
    Y.example.test.AsyncTestCase = new Y.Test.Case({
61
 
 
62
 
        //name of the test case - if not provided, one is auto-generated
63
 
        name : "Asynchronous Tests",
64
 
 
65
 
        //---------------------------------------------------------------------
66
 
        // setUp and tearDown methods - optional
67
 
        //---------------------------------------------------------------------
68
 
 
69
 
        /*
70
 
         * Sets up data that is needed by each test.
71
 
         */
72
 
        setUp : function () {
73
 
            this.data = {
74
 
                name: "test",
75
 
                year: 2007,
76
 
                beta: true
77
 
            };
78
 
        },
79
 
 
80
 
        /*
81
 
         * Cleans up everything that was created by setUp().
82
 
         */
83
 
        tearDown : function () {
84
 
            delete this.data;
85
 
        },
86
 
 
87
 
        //---------------------------------------------------------------------
88
 
        // Test methods - names must begin with "test"
89
 
        //---------------------------------------------------------------------
90
 
 
91
 
        testWait : function (){
92
 
            var Assert = Y.Assert;
93
 
 
94
 
            //do some assertions now
95
 
            Assert.isTrue(this.data.beta);
96
 
            Assert.isNumber(this.data.year);
97
 
 
98
 
            //wait five seconds and do some more
99
 
            this.wait(function(){
100
 
 
101
 
                Assert.isString(this.data.name);
102
 
 
103
 
            }, 5000);
104
 
 
105
 
        }
106
 
 
107
 
    });
108
 
 
109
 
    //create the console
110
 
    var r = new Y.Console({
111
 
        newestOnTop : false,
112
 
        style: 'block' // to anchor in the example content
113
 
    });
114
 
 
115
 
    r.render('#testLogger');
116
 
 
117
 
    Y.Test.Runner.add(Y.example.test.AsyncTestCase);
118
 
 
119
 
    //run the tests
120
 
    Y.Test.Runner.run();
121
 
});
122
 
 
123
 
</script>
124
 
 
125
 
</div>
126
 
 
127
 
<h2 class="first" id="asynchronous-test-example">Asynchronous Test Example</h2>
128
 
 
129
 
<p>This example begins by creating a namespace:</p>
130
 
<pre class="code prettyprint">Y.namespace(&quot;example.test&quot;);</pre>
131
 
 
132
 
<p>This namespace serves as the core object upon which others will be added (to prevent creating global objects).</p>
133
 
 
134
 
<h3 id="creating-the-testcase">Creating the TestCase</h3>
135
 
 
136
 
<p>The first step is to create a new <code>Y.Test.Case</code> object called <code>AsyncTestCase</code>.
137
 
  To do so, using the <code>Y.Test.Case</code> constructor and pass in an object literal containing information about the tests to be run:</p>
138
 
<pre class="code prettyprint">Y.example.test.AsyncTestCase = new Y.Test.Case({
139
 
 
140
 
    &#x2F;&#x2F;name of the test case - if not provided, one is auto-generated
141
 
    name : &quot;Asynchronous Tests&quot;,
142
 
 
143
 
    &#x2F;&#x2F;---------------------------------------------------------------------
144
 
    &#x2F;&#x2F; setUp and tearDown methods - optional
145
 
    &#x2F;&#x2F;---------------------------------------------------------------------
146
 
 
147
 
    &#x2F;*
148
 
     * Sets up data that is needed by each test.
149
 
     *&#x2F;
150
 
    setUp : function () {
151
 
        this.data = {
152
 
            name: &quot;test&quot;,
153
 
            year: 2007,
154
 
            beta: true
155
 
        };
156
 
    },
157
 
 
158
 
    &#x2F;*
159
 
     * Cleans up everything that was created by setUp().
160
 
     *&#x2F;
161
 
    tearDown : function () {
162
 
        delete this.data;
163
 
    },
164
 
 
165
 
    &#x2F;&#x2F;---------------------------------------------------------------------
166
 
    &#x2F;&#x2F; Test methods - names must begin with &quot;test&quot;
167
 
    &#x2F;&#x2F;---------------------------------------------------------------------
168
 
 
169
 
    testWait : function (){
170
 
        var Assert = Y.Assert;
171
 
 
172
 
        &#x2F;&#x2F;do some assertions now
173
 
        Assert.isTrue(this.data.beta);
174
 
        Assert.isNumber(this.data.year);
175
 
 
176
 
        &#x2F;&#x2F;wait five seconds and do some more
177
 
        this.wait(function(){
178
 
 
179
 
            Assert.isString(this.data.name);
180
 
 
181
 
        }, 5000);
182
 
 
183
 
    }
184
 
 
185
 
});</pre>
186
 
 
187
 
<p>The object literal passed into the constructor contains two different sections. The first section contains the <code>name</code> property,
188
 
  which is used to determine which <code>Y.Test.Case</code> is being executed. A name is necessary, so one is generated if it isn't specified.</p>
189
 
<p>Next, the <code>setUp()</code> and <code>tearDown()</code> methods are included. The <code>setUp()</code> method is used in a <code>Y.Test.Case</code>
190
 
  to set up data that may be needed for tests to be completed. This method is called immediately before each test is executed. For this example,
191
 
  <code>setUp()</code> creates a data object. The <code>tearDown()</code> is responsible for undoing what was done in <code>setUp()</code>. It is
192
 
  run immediately after each test is run and, in this case, deletes the data object that was created by <code>setUp</code>. These methods are optional.</p>
193
 
<p>The second section contains the actual tests to be run. The only test is <code>testWait()</code>, which demonstrates using
194
 
  the <code>wait()</code> method to delay test execution. There are two arguments passed in: a function to run once the test resumes
195
 
  and the number of milliseconds to wait before running this function (same basic format as <code>setTimeout()</code>). When
196
 
  the test resumes, the function is executed in the context of the <code>Y.Test.Case</code> object, meaning that it still has
197
 
  access to all of the same data as the test that called <code>wait()</code>, including properties and methods on the <code>Y.Test.Case</code>
198
 
  itself. This example shows the anonymous function using both the <code>Y.Assert</code> object and the <code>data</code> property
199
 
  of the <code>Y.Test.Case</code>.</p>
200
 
 
201
 
<h3 id="running-the-tests">Running the tests</h3>
202
 
 
203
 
<p>With all of the tests defined, the last step is to run them:</p>
204
 
 
205
 
<pre class="code prettyprint">&#x2F;&#x2F;create the console
206
 
var r = new Y.Console({
207
 
    verbose : true,
208
 
    newestOnTop : false
209
 
});
210
 
 
211
 
r.render(&#x27;#testLogger&#x27;);
212
 
 
213
 
&#x2F;&#x2F;add the test suite to the runner&#x27;s queue
214
 
Y.Test.Runner.add(Y.example.test.AsyncTestCase);
215
 
 
216
 
&#x2F;&#x2F;run the tests
217
 
Y.Test.Runner.run();</pre>
218
 
 
219
 
 
220
 
<p>Before running the tests, it's necessary to create a <code>Y.Console</code> object to display the results (otherwise the tests would run
221
 
  but you wouldn't see the results). After that, the <code>Y.Test.Runner</code> is loaded with the <code>Y.Test.Case</code> object by calling
222
 
  <code>add()</code> (any number of <code>Y.Test.Case</code> and <code>TestSuite</code> objects can be added to a <code>TestRunner</code>,
223
 
  this example only adds one for simplicity). The very last step is to call <code>run()</code>, which begins executing the tests in its
224
 
  queue and displays the results in the <code>Y.Console</code>.</p>
225
 
 
226
 
<h2 id="complete-example-source">Complete Example Source</h2>
227
 
 
228
 
<pre class="code prettyprint">&lt;div id=&quot;testLogger&quot;&gt;&lt;&#x2F;div&gt;
229
 
 
230
 
&lt;script&gt;
231
 
YUI().use(&#x27;node&#x27;, &#x27;console&#x27;, &#x27;test&#x27;,function (Y) {
232
 
 
233
 
    Y.namespace(&quot;example.test&quot;);
234
 
 
235
 
    Y.example.test.AsyncTestCase = new Y.Test.Case({
236
 
 
237
 
        &#x2F;&#x2F;name of the test case - if not provided, one is auto-generated
238
 
        name : &quot;Asynchronous Tests&quot;,
239
 
 
240
 
        &#x2F;&#x2F;---------------------------------------------------------------------
241
 
        &#x2F;&#x2F; setUp and tearDown methods - optional
242
 
        &#x2F;&#x2F;---------------------------------------------------------------------
243
 
 
244
 
        &#x2F;*
245
 
         * Sets up data that is needed by each test.
246
 
         *&#x2F;
247
 
        setUp : function () {
248
 
            this.data = {
249
 
                name: &quot;test&quot;,
250
 
                year: 2007,
251
 
                beta: true
252
 
            };
253
 
        },
254
 
 
255
 
        &#x2F;*
256
 
         * Cleans up everything that was created by setUp().
257
 
         *&#x2F;
258
 
        tearDown : function () {
259
 
            delete this.data;
260
 
        },
261
 
 
262
 
        &#x2F;&#x2F;---------------------------------------------------------------------
263
 
        &#x2F;&#x2F; Test methods - names must begin with &quot;test&quot;
264
 
        &#x2F;&#x2F;---------------------------------------------------------------------
265
 
 
266
 
        testWait : function (){
267
 
            var Assert = Y.Assert;
268
 
 
269
 
            &#x2F;&#x2F;do some assertions now
270
 
            Assert.isTrue(this.data.beta);
271
 
            Assert.isNumber(this.data.year);
272
 
 
273
 
            &#x2F;&#x2F;wait five seconds and do some more
274
 
            this.wait(function(){
275
 
 
276
 
                Assert.isString(this.data.name);
277
 
 
278
 
            }, 5000);
279
 
 
280
 
        }
281
 
 
282
 
    });
283
 
 
284
 
    &#x2F;&#x2F;create the console
285
 
    var r = new Y.Console({
286
 
        newestOnTop : false,
287
 
        style: &#x27;block&#x27; &#x2F;&#x2F; to anchor in the example content
288
 
    });
289
 
 
290
 
    r.render(&#x27;#testLogger&#x27;);
291
 
 
292
 
    Y.Test.Runner.add(Y.example.test.AsyncTestCase);
293
 
 
294
 
    &#x2F;&#x2F;run the tests
295
 
    Y.Test.Runner.run();
296
 
});
297
 
 
298
 
&lt;&#x2F;script&gt;</pre>
299
 
 
300
 
</div>
301
 
        </div>
302
 
 
303
 
        <div id="sidebar" class="yui3-u">
304
 
            
305
 
                <div id="toc" class="sidebox">
306
 
                    <div class="hd">
307
 
                        <h2 class="no-toc">Table of Contents</h2>
308
 
                    </div>
309
 
 
310
 
                    <div class="bd">
311
 
                        <ul class="toc">
312
 
<li>
313
 
<a href="#asynchronous-test-example">Asynchronous Test Example</a>
314
 
<ul class="toc">
315
 
<li>
316
 
<a href="#creating-the-testcase">Creating the TestCase</a>
317
 
</li>
318
 
<li>
319
 
<a href="#running-the-tests">Running the tests</a>
320
 
</li>
321
 
</ul>
322
 
</li>
323
 
<li>
324
 
<a href="#complete-example-source">Complete Example Source</a>
325
 
</li>
326
 
</ul>
327
 
                    </div>
328
 
                </div>
329
 
            
330
 
 
331
 
            
332
 
                <div class="sidebox">
333
 
                    <div class="hd">
334
 
                        <h2 class="no-toc">Examples</h2>
335
 
                    </div>
336
 
 
337
 
                    <div class="bd">
338
 
                        <ul class="examples">
339
 
                            
340
 
                                
341
 
                                    <li data-description="Demonstrates basic usage of YUI Test for setting up and running tests.">
342
 
                                        <a href="test-simple-example.html">Simple Testing Example</a>
343
 
                                    </li>
344
 
                                
345
 
                            
346
 
                                
347
 
                                    <li data-description="Demonstrates how to use advanced testing features such as defining tests that should fail, tests that should be ignored, and tests that should throw an error.">
348
 
                                        <a href="test-advanced-test-options.html">Advanced Test Options</a>
349
 
                                    </li>
350
 
                                
351
 
                            
352
 
                                
353
 
                                    <li data-description="Demonstrates how to use the ArrayAssert object to test array data.">
354
 
                                        <a href="test-array-tests.html">Array Processing</a>
355
 
                                    </li>
356
 
                                
357
 
                            
358
 
                                
359
 
                                    <li data-description="Demonstrates basic asynchronous tests.">
360
 
                                        <a href="test-async-test.html">Asynchronous Testing</a>
361
 
                                    </li>
362
 
                                
363
 
                            
364
 
                                
365
 
                                    <li data-description="Demonstrates using events with asynchronous tests.">
366
 
                                        <a href="test-async-event-tests.html">Asynchronous Event Testing</a>
367
 
                                    </li>
368
 
                                
369
 
                            
370
 
                        </ul>
371
 
                    </div>
372
 
                </div>
373
 
            
374
 
 
375
 
            
376
 
        </div>
377
 
    </div>
378
 
</div>
379
 
 
380
 
<script src="../assets/vendor/prettify/prettify-min.js"></script>
381
 
<script>prettyPrint();</script>
382
 
 
383
 
</body>
384
 
</html>