~bac/juju-gui/trunkcopy

« back to all changes in this revision

Viewing changes to lib/yui/tests/datasource/tests/datasource-jsonschema-tests.js

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
YUI.add('datasource-jsonschema-tests', function(Y) {
2
 
 
3
 
var Assert = Y.Assert,
4
 
 
5
 
    suite = new Y.Test.Suite("Plugin.DataSourceJSONSchema Test Suite"),
6
 
 
7
 
    jsonData = '{"ResultSet":{"Result":[{"Title":"1"},{"Title":"2"},{"Title":"3"},{"Title":"4"},{"Title":"5"},{"Title":"6"},{"Title":"7"},{"Title":"8"},{"Title":"9"},{"Title":"10"}]}}';
8
 
 
9
 
 
10
 
suite.add(new Y.Test.Case({
11
 
    name: "DataSource JSONSchema Plugin Tests",
12
 
 
13
 
    testJSONSchema: function() {
14
 
        var ds = new Y.DataSource.Local({ source: jsonData }),
15
 
            request = null, response;
16
 
 
17
 
        ds.plug(Y.Plugin.DataSourceJSONSchema, {
18
 
            schema: {
19
 
                resultListLocator: "ResultSet.Result",
20
 
                resultFields: ["Title"]
21
 
            }
22
 
        });
23
 
 
24
 
        ds.sendRequest({
25
 
            callback: {
26
 
                success: function (e) {
27
 
                    request  = e.request;
28
 
                    response = e.response;
29
 
                }
30
 
            }
31
 
        });
32
 
 
33
 
        Assert.isUndefined(request, "Expected undefined request.");
34
 
        Assert.isObject(response, "Expected normalized response object.");
35
 
        Assert.isArray(response.results, "Expected results array.");
36
 
        Assert.areSame(10, response.results.length, "Expected 10 results.");
37
 
        Assert.isNotUndefined(response.results[0].Title, "Expected Title property");
38
 
    },
39
 
 
40
 
    testSchemaError: function() {
41
 
        var ds = new Y.DataSource.Local({ source: jsonData }),
42
 
            request = null, response, error;
43
 
 
44
 
        ds.plug(Y.Plugin.DataSourceJSONSchema);
45
 
 
46
 
        ds.sendRequest({
47
 
            callback: {
48
 
                failure: function (e) {
49
 
                    response = e.response;
50
 
                    error    = e.error;
51
 
                }
52
 
            }
53
 
        });
54
 
 
55
 
        Assert.isObject(response, "Expected normalized response object.");
56
 
        Assert.isObject(error, "Expected response error.");
57
 
    }
58
 
}));
59
 
 
60
 
Y.Test.Runner.add(suite);
61
 
 
62
 
 
63
 
}, '@VERSION@' ,{requires:['datasource-jsonschema', 'test']});