1
1
/* Copyright (c) 2011, Canonical Ltd. All rights reserved. */
3
YUI().use('lp.testing.runner', 'lp.testing.iorecorder', 'test', 'console',
3
YUI().use('lp.testing.runner', 'lp.testing.mockio', 'test', 'console',
4
4
'lp.client', 'escape', function(Y) {
6
6
var Assert = Y.Assert; // For easy access to isTrue(), etc.
30
30
normalize("api/devel/foo/bar"), "/api/devel/foo/bar");
33
test_get_io_provider__default: function() {
34
var undefined_provider,
35
io_provider = Y.lp.client.get_io_provider(undefined_provider);
36
Assert.areSame(Y, io_provider);
39
test_get_io_provider__mockio: function() {
40
// If a mock provider is provided, it is picked as the io_provider.
41
var mockio = new Y.lp.testing.mockio.MockIo(),
42
io_provider = Y.lp.client.get_io_provider(mockio);
43
Assert.areSame(mockio, io_provider);
46
test_get_configured_io_provider__default: function() {
47
// If no io_provider is configured, Y is the io_provider.
48
var io_provider = Y.lp.client.get_configured_io_provider({});
49
Assert.areSame(Y, io_provider);
52
test_get_configured_io_provider__default_undefined: function() {
53
// If no configuration is provided, Y is the io_provider.
54
var io_provider = Y.lp.client.get_configured_io_provider();
55
Assert.areSame(Y, io_provider);
58
test_get_configured_io_provider__mockio: function() {
59
// If an io_provider is configured, it is picked as the io_provider.
60
var mockio = new Y.lp.testing.mockio.MockIo(),
61
io_provider = Y.lp.client.get_configured_io_provider(
62
{io_provider: mockio});
63
Assert.areSame(mockio, io_provider);
66
test_get_configured_io_provider__different_key: function() {
67
// The io_provider can be stored with a different key.
68
var mockio = new Y.lp.testing.mockio.MockIo(),
69
io_provider = Y.lp.client.get_configured_io_provider(
70
{my_io: mockio}, 'my_io');
71
Assert.areSame(mockio, io_provider);
33
74
test_append_qs: function() {
35
76
qs = Y.lp.client.append_qs(qs, "Pöllä", "Perelló");
74
115
Assert.areEqual(expected, actual);
76
117
test_load_model: function(){
77
var recorder = new Y.lp.testing.iorecorder.IORecorder();
78
Assert.areEqual(0, recorder.requests.length);
118
var mockio = new Y.lp.testing.mockio.MockIo();
119
Assert.areEqual(0, mockio.requests.length);
81
io: Y.bind(recorder.do_io, recorder),
83
124
success: Y.bind(mylist.push, mylist)
87
128
var client = new Y.lp.client.Launchpad();
88
129
var context = new Y.lp.client.Entry(client, entry_repr, null);
89
130
Y.lp.client.load_model(context, '+myview', config);
90
var request = recorder.requests[0];
91
Assert.areEqual('/context/+myview/++model++', request.url);
93
'{"boolean": true, "entry": {"resource_type_link": "foo"}}',
94
{'Content-Type': 'application/json'});
132
'/context/+myview/++model++', mockio.last_request.url);
135
'{"boolean": true, "entry": {"resource_type_link": "foo"}}',
136
responseHeaders: {'Content-Type': 'application/json'}
95
138
var result = mylist[0];
96
139
Assert.areSame(true, result.boolean);
97
140
Assert.isInstanceOf(Y.lp.client.Entry, result.entry);
125
168
Y.Assert.areNotSame(foo, bar);
127
170
test_wrap_resource_creates_mapping: function() {
128
// wrap_resource creates new mappings, rather than reusing the existing
171
// wrap_resource creates new mappings, rather than reusing the
130
173
var foo = {a: 'b'};
131
174
var bar = new Y.lp.client.Launchpad().wrap_resource(null, foo);
132
175
Y.Assert.areNotSame(foo, bar);
294
337
setUp: function() {
295
338
this.client = new Y.lp.client.Launchpad();
296
339
this.args=[this.client, null, this._on_success, false];
297
this.response = new Y.lp.testing.iorecorder.MockHttpResponse();
340
this.response = new Y.lp.testing.mockio.MockHttpResponse();
298
341
this.response.setResponseHeader('Content-Type', 'application/json');