aboutsummaryrefslogtreecommitdiff
path: root/engine/js/tests/ElggAjaxOptionsTest.js
blob: 8a2b7f574bdffd798655eb3f79078dd6f095edc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
 * Tests elgg.ajax.handleOptions() with all of the possible valid inputs
 */
ElggAjaxOptionsTest = TestCase("ElggAjaxOptionsTest");

ElggAjaxOptionsTest.prototype.testHandleOptionsAcceptsNoArgs = function() {
	assertNotUndefined(elgg.ajax.handleOptions());
};

ElggAjaxOptionsTest.prototype.testHandleOptionsAcceptsUrl = function() {
	var url = 'url',
		result = elgg.ajax.handleOptions(url);
	
	assertEquals(url, result.url);
};

ElggAjaxOptionsTest.prototype.testHandleOptionsAcceptsDataOnly = function() {
	var options = {},
		result = elgg.ajax.handleOptions(options);
	
	assertEquals(options, result.data);
};

ElggAjaxOptionsTest.prototype.testHandleOptionsAcceptsOptions = function() {
	var options = {data:{arg:1}},
		result = elgg.ajax.handleOptions(options);
	
	assertEquals(options, result);
	
	function func() {}
	options = {success: func};
	result = elgg.ajax.handleOptions(options);
	
	assertEquals(options, result);
};

ElggAjaxOptionsTest.prototype.testHandleOptionsAcceptsUrlThenDataOnly = function() {
	var url = 'url',
		options = {arg:1},
		result = elgg.ajax.handleOptions(url, options);
	
	assertEquals(url, result.url);
	assertEquals(options, result.data);
};

ElggAjaxOptionsTest.prototype.testHandleOptionsAcceptsUrlThenSuccessOnly = function() {
	var url = 'url',
	success = function() {},
	result = elgg.ajax.handleOptions(url, success);
	
	assertEquals(url, result.url);
	assertEquals(success, result.success);
};

ElggAjaxOptionsTest.prototype.testHandleOptionsAcceptsUrlThenOptions = function() {
	var url = 'url',
	options = {data:{arg:1}},
	result = elgg.ajax.handleOptions(url, options);
	
	assertEquals(url, result.url);
	assertEquals(options.data, result.data);
};