author | Julien Cristau <julien.cristau@logilab.fr> |
Mon, 18 May 2015 20:00:06 +0200 | |
changeset 10436 | 6493c8bf521d |
parent 10431 | 7628a14d2209 |
permissions | -rw-r--r-- |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
1 |
$(document).ready(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
2 |
|
10428
c961a301a90b
[devtools] qunit: stop using global variables
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10427
diff
changeset
|
3 |
QUnit.module("ajax", { |
5950
f84dba9b8eca
[test] fix test_ajax js tests. We have to mock some of our js functions / variables (e.g. _ or pageid) in the test environment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5743
diff
changeset
|
4 |
setup: function() { |
f84dba9b8eca
[test] fix test_ajax js tests. We have to mock some of our js functions / variables (e.g. _ or pageid) in the test environment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5743
diff
changeset
|
5 |
this.scriptsLength = $('head script[src]').length-1; |
6214
e03808843325
[javascript] fix test_ajax.js implementation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5950
diff
changeset
|
6 |
this.cssLength = $('head link[rel=stylesheet]').length-1; |
e03808843325
[javascript] fix test_ajax.js implementation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5950
diff
changeset
|
7 |
// re-initialize cw loaded cache so that each tests run in a |
e03808843325
[javascript] fix test_ajax.js implementation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5950
diff
changeset
|
8 |
// clean environment, have a lookt at _loadAjaxHtmlHead implementation |
e03808843325
[javascript] fix test_ajax.js implementation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5950
diff
changeset
|
9 |
// in cubicweb.ajax.js for more information. |
10416
6e5e1617e1cd
[web/test] Fix reset of loaded JS/CSS files
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10413
diff
changeset
|
10 |
cw.loaded_scripts = []; |
6e5e1617e1cd
[web/test] Fix reset of loaded JS/CSS files
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10413
diff
changeset
|
11 |
cw.loaded_links = []; |
5950
f84dba9b8eca
[test] fix test_ajax js tests. We have to mock some of our js functions / variables (e.g. _ or pageid) in the test environment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5743
diff
changeset
|
12 |
}, |
f84dba9b8eca
[test] fix test_ajax js tests. We have to mock some of our js functions / variables (e.g. _ or pageid) in the test environment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5743
diff
changeset
|
13 |
teardown: function() { |
10419
5edd38e3205f
[web/test] Fix remaining JS tests (closes #5533303)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10418
diff
changeset
|
14 |
$('head script[src]:lt(' + ($('head script[src]').length - 1 - this.scriptsLength) + ')').remove(); |
5950
f84dba9b8eca
[test] fix test_ajax js tests. We have to mock some of our js functions / variables (e.g. _ or pageid) in the test environment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5743
diff
changeset
|
15 |
$('head link[rel=stylesheet]:gt(' + this.cssLength + ')').remove(); |
f84dba9b8eca
[test] fix test_ajax js tests. We have to mock some of our js functions / variables (e.g. _ or pageid) in the test environment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5743
diff
changeset
|
16 |
} |
f84dba9b8eca
[test] fix test_ajax js tests. We have to mock some of our js functions / variables (e.g. _ or pageid) in the test environment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5743
diff
changeset
|
17 |
}); |
f84dba9b8eca
[test] fix test_ajax js tests. We have to mock some of our js functions / variables (e.g. _ or pageid) in the test environment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5743
diff
changeset
|
18 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
19 |
function jsSources() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
20 |
return $.map($('head script[src]'), function(script) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
21 |
return script.getAttribute('src'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
22 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
23 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
24 |
|
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
25 |
QUnit.test('test simple h1 inclusion (ajax_url0.html)', function (assert) { |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
26 |
assert.expect(3); |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
27 |
assert.equal($('#qunit-fixture').children().length, 0); |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
28 |
var done = assert.async(); |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
29 |
$('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url0.html') |
10417
59bf206996c8
[web/test] stop calling loadxhtml with a form.callback
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10416
diff
changeset
|
30 |
.addCallback(function() { |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
31 |
try { |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
32 |
assert.equal($('#qunit-fixture').children().length, 1); |
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
33 |
assert.equal($('#qunit-fixture h1').html(), 'Hello'); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
34 |
} finally { |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
35 |
done(); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
36 |
}; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
37 |
} |
10417
59bf206996c8
[web/test] stop calling loadxhtml with a form.callback
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10416
diff
changeset
|
38 |
); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
39 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
40 |
|
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
41 |
QUnit.test('test simple html head inclusion (ajax_url1.html)', function (assert) { |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
42 |
assert.expect(6); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
43 |
var scriptsIncluded = jsSources(); |
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
44 |
assert.equal(jQuery.inArray('http://foo.js', scriptsIncluded), - 1); |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
45 |
var done = assert.async(); |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
46 |
$('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url1.html') |
10417
59bf206996c8
[web/test] stop calling loadxhtml with a form.callback
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10416
diff
changeset
|
47 |
.addCallback(function() { |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
48 |
try { |
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
49 |
var origLength = scriptsIncluded.length; |
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
50 |
scriptsIncluded = jsSources(); |
10419
5edd38e3205f
[web/test] Fix remaining JS tests (closes #5533303)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10418
diff
changeset
|
51 |
// check that foo.js has been prepended to <head> |
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
52 |
assert.equal(scriptsIncluded.length, origLength + 1); |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
53 |
assert.equal(scriptsIncluded.indexOf('http://foo.js'), 0); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
54 |
// check that <div class="ajaxHtmlHead"> has been removed |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
55 |
assert.equal($('#qunit-fixture').children().length, 1); |
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
56 |
assert.equal($('div.ajaxHtmlHead').length, 0); |
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
57 |
assert.equal($('#qunit-fixture h1').html(), 'Hello'); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
58 |
} finally { |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
59 |
done(); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
60 |
}; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
61 |
} |
10417
59bf206996c8
[web/test] stop calling loadxhtml with a form.callback
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10416
diff
changeset
|
62 |
); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
63 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
64 |
|
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
65 |
QUnit.test('test addCallback', function (assert) { |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
66 |
assert.expect(3); |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
67 |
assert.equal($('#qunit-fixture').children().length, 0); |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
68 |
var done = assert.async(); |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
69 |
var d = $('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url0.html'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
70 |
d.addCallback(function() { |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
71 |
try { |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
72 |
assert.equal($('#qunit-fixture').children().length, 1); |
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
73 |
assert.equal($('#qunit-fixture h1').html(), 'Hello'); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
74 |
} finally { |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
75 |
done(); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
76 |
}; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
77 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
78 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
79 |
|
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
80 |
QUnit.test('test callback after synchronous request', function (assert) { |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
81 |
assert.expect(1); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
82 |
var deferred = new Deferred(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
83 |
var result = jQuery.ajax({ |
10413
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8879
diff
changeset
|
84 |
url: BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url0.html', |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
85 |
async: false, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
86 |
beforeSend: function(xhr) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
87 |
deferred._req = xhr; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
88 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
89 |
success: function(data, status) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
90 |
deferred.success(data); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
91 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
92 |
}); |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
93 |
var done = assert.async(); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
94 |
deferred.addCallback(function() { |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
95 |
try { |
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
96 |
// add an assertion to ensure the callback is executed |
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
97 |
assert.ok(true, "callback is executed"); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
98 |
} finally { |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
99 |
done(); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
100 |
}; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
101 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
102 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
103 |
|
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
104 |
QUnit.test('test addCallback with parameters', function (assert) { |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
105 |
assert.expect(3); |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
106 |
assert.equal($('#qunit-fixture').children().length, 0); |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
107 |
var done = assert.async(); |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
108 |
var d = $('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url0.html'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
109 |
d.addCallback(function(data, req, arg1, arg2) { |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
110 |
try { |
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
111 |
assert.equal(arg1, 'Hello'); |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
112 |
assert.equal(arg2, 'world'); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
113 |
} finally { |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
114 |
done(); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
115 |
}; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
116 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
117 |
'Hello', 'world'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
118 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
119 |
|
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
120 |
QUnit.test('test callback after synchronous request with parameters', function (assert) { |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
121 |
assert.expect(3); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
122 |
var deferred = new Deferred(); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
123 |
deferred.addCallback(function(data, req, arg1, arg2) { |
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
124 |
// add an assertion to ensure the callback is executed |
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
125 |
try { |
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
126 |
assert.ok(true, "callback is executed"); |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
127 |
assert.equal(arg1, 'Hello'); |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
128 |
assert.equal(arg2, 'world'); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
129 |
} finally { |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
130 |
done(); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
131 |
}; |
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
132 |
}, |
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
133 |
'Hello', 'world'); |
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
134 |
deferred.addErrback(function() { |
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
135 |
// throw an exception to start errback chain |
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
136 |
try { |
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
137 |
throw this._error; |
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
138 |
} finally { |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
139 |
done(); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
140 |
}; |
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
141 |
}); |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
142 |
var done = assert.async(); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
143 |
var result = jQuery.ajax({ |
10413
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8879
diff
changeset
|
144 |
url: BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url0.html', |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
145 |
async: false, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
146 |
beforeSend: function(xhr) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
147 |
deferred._req = xhr; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
148 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
149 |
success: function(data, status) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
150 |
deferred.success(data); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
151 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
152 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
153 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
154 |
|
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
155 |
QUnit.test('test addErrback', function (assert) { |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
156 |
assert.expect(1); |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
157 |
var done = assert.async(); |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
158 |
var d = $('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/nonexistent.html'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
159 |
d.addCallback(function() { |
10418
e1076102bd84
[web/test] Stop testing that exceptions raised in Deferred callbacks call errback
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10417
diff
changeset
|
160 |
// should not be executed |
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
161 |
assert.ok(false, "callback is executed"); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
162 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
163 |
d.addErrback(function() { |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
164 |
try { |
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
165 |
assert.ok(true, "errback is executed"); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
166 |
} finally { |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
167 |
done(); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
168 |
}; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
169 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
170 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
171 |
|
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
172 |
QUnit.test('test callback execution order', function (assert) { |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
173 |
assert.expect(3); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
174 |
var counter = 0; |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
175 |
var done = assert.async(); |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
176 |
var d = $('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url0.html'); |
10417
59bf206996c8
[web/test] stop calling loadxhtml with a form.callback
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10416
diff
changeset
|
177 |
d.addCallback(function() { |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
178 |
assert.equal(++counter, 1); // should be executed first |
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
179 |
}); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
180 |
d.addCallback(function() { |
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
181 |
assert.equal(++counter, 2); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
182 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
183 |
d.addCallback(function() { |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
184 |
try { |
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
185 |
assert.equal(++counter, 3); |
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
186 |
} finally { |
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
187 |
done(); |
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
188 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
189 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
190 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
191 |
|
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
192 |
QUnit.test('test already included resources are ignored (ajax_url1.html)', function (assert) { |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
193 |
assert.expect(10); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
194 |
var scriptsIncluded = jsSources(); |
6215
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6214
diff
changeset
|
195 |
// NOTE: |
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
196 |
assert.equal(jQuery.inArray('http://foo.js', scriptsIncluded), -1); |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
197 |
assert.equal($('head link').length, 1); |
5743
4a0600664f85
Use the qunit automatic launcher for existing testcase.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
5658
diff
changeset
|
198 |
/* use endswith because in pytest context we have an absolute path */ |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
199 |
assert.ok($('head link').attr('href').endswith('/qunit.css'), 'qunit.css is loaded'); |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
200 |
var done = assert.async(); |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
201 |
$('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url1.html') |
10417
59bf206996c8
[web/test] stop calling loadxhtml with a form.callback
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10416
diff
changeset
|
202 |
.addCallback(function() { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
203 |
var origLength = scriptsIncluded.length; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
204 |
scriptsIncluded = jsSources(); |
6215
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6214
diff
changeset
|
205 |
try { |
5950
f84dba9b8eca
[test] fix test_ajax js tests. We have to mock some of our js functions / variables (e.g. _ or pageid) in the test environment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5743
diff
changeset
|
206 |
// check that foo.js has been inserted in <head> |
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
207 |
assert.equal(scriptsIncluded.length, origLength + 1); |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
208 |
assert.equal(scriptsIncluded.indexOf('http://foo.js'), 0); |
5950
f84dba9b8eca
[test] fix test_ajax js tests. We have to mock some of our js functions / variables (e.g. _ or pageid) in the test environment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5743
diff
changeset
|
209 |
// check that <div class="ajaxHtmlHead"> has been removed |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
210 |
assert.equal($('#qunit-fixture').children().length, 1); |
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
211 |
assert.equal($('div.ajaxHtmlHead').length, 0); |
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
212 |
assert.equal($('#qunit-fixture h1').html(), 'Hello'); |
5950
f84dba9b8eca
[test] fix test_ajax js tests. We have to mock some of our js functions / variables (e.g. _ or pageid) in the test environment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5743
diff
changeset
|
213 |
// qunit.css is not added twice |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
214 |
assert.equal($('head link').length, 1); |
5950
f84dba9b8eca
[test] fix test_ajax js tests. We have to mock some of our js functions / variables (e.g. _ or pageid) in the test environment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5743
diff
changeset
|
215 |
/* use endswith because in pytest context we have an absolute path */ |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
216 |
assert.ok($('head link').attr('href').endswith('/qunit.css'), 'qunit.css is loaded'); |
5950
f84dba9b8eca
[test] fix test_ajax js tests. We have to mock some of our js functions / variables (e.g. _ or pageid) in the test environment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5743
diff
changeset
|
217 |
} finally { |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
218 |
done(); |
6215
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6214
diff
changeset
|
219 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
220 |
} |
10417
59bf206996c8
[web/test] stop calling loadxhtml with a form.callback
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10416
diff
changeset
|
221 |
); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
222 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
223 |
|
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
224 |
QUnit.test('test synchronous request loadRemote', function (assert) { |
10413
22a89d0f4143
[devtools] Serve JS tests over HTTP (closes #5533285)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8879
diff
changeset
|
225 |
var res = loadRemote(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajaxresult.json', {}, |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
226 |
'GET', true); |
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
227 |
assert.deepEqual(res, ['foo', 'bar']); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
228 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
229 |
|
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
230 |
QUnit.test('test event on CubicWeb', function (assert) { |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
231 |
assert.expect(1); |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
232 |
var done = assert.async(); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
233 |
var events = null; |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
234 |
$(CubicWeb).bind('server-response', function() { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
235 |
// check that server-response event on CubicWeb is triggered |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
236 |
events = 'CubicWeb'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
237 |
}); |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
238 |
$('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url0.html') |
10417
59bf206996c8
[web/test] stop calling loadxhtml with a form.callback
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10416
diff
changeset
|
239 |
.addCallback(function() { |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
240 |
try { |
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
241 |
assert.equal(events, 'CubicWeb'); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
242 |
} finally { |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
243 |
done(); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
244 |
}; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
245 |
} |
10417
59bf206996c8
[web/test] stop calling loadxhtml with a form.callback
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10416
diff
changeset
|
246 |
); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
247 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
248 |
|
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
249 |
QUnit.test('test event on node', function (assert) { |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
250 |
assert.expect(3); |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
251 |
var done = assert.async(); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
252 |
var nodes = []; |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
253 |
$('#qunit-fixture').bind('server-response', function() { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
254 |
nodes.push('node'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
255 |
}); |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
256 |
$(CubicWeb).bind('server-response', function() { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
257 |
nodes.push('CubicWeb'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
258 |
}); |
10431
7628a14d2209
[web/test] Use shorter $() instead of jQuery()
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10430
diff
changeset
|
259 |
$('#qunit-fixture').loadxhtml(BASE_URL + 'cwsoftwareroot/web/test/jstests/ajax_url0.html') |
10417
59bf206996c8
[web/test] stop calling loadxhtml with a form.callback
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10416
diff
changeset
|
260 |
.addCallback(function() { |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
261 |
try { |
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
262 |
assert.equal(nodes.length, 2); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
263 |
// check that server-response event on CubicWeb is triggered |
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
264 |
// only once and event server-response on node is triggered |
10429
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
265 |
assert.equal(nodes[0], 'CubicWeb'); |
98ea2b865210
[devtools] qunit: use new assert APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10428
diff
changeset
|
266 |
assert.equal(nodes[1], 'node'); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
267 |
} finally { |
10430
2b1ea3e8e080
[devtools] qunit: use new async testing APIs
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10429
diff
changeset
|
268 |
done(); |
8879
982a49239420
[web] move qunit test back into web and fix the hanging
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7363
diff
changeset
|
269 |
}; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
270 |
} |
10417
59bf206996c8
[web/test] stop calling loadxhtml with a form.callback
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10416
diff
changeset
|
271 |
); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
272 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
273 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
274 |