thin_man 0.19.6 → 0.19.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/debug_logger.js +12 -2
- data/app/assets/javascripts/thin_man.js +937 -931
- data/lib/thin_man/ajax_helper.rb +4 -1
- data/lib/thin_man/version.rb +1 -1
- data/test/javascript/karma.conf.js +44 -49
- data/test/javascript/spec/thinManSpec.js +224 -254
- data/test/thin_man_test.rb +6 -1
- metadata +2 -2
data/lib/thin_man/ajax_helper.rb
CHANGED
@@ -29,7 +29,8 @@ module ThinMan
|
|
29
29
|
sub_class: nil, insert_method: nil, empty_on_success: nil, remove_on_success: nil,
|
30
30
|
http_method: nil, no_mouse_click: nil, progress_target: nil,
|
31
31
|
progress_color: nil, mask_target: nil, mask_message: nil,
|
32
|
-
sequence_group: nil, sequence_number: nil
|
32
|
+
sequence_group: nil, sequence_number: nil,
|
33
|
+
search_path: nil, search_params: nil)
|
33
34
|
ajax_options = {
|
34
35
|
'data-ajax-link-now' => true,
|
35
36
|
'data-ajax-target' => target
|
@@ -46,6 +47,8 @@ module ThinMan
|
|
46
47
|
ajax_options.merge!('data-mask-message' => mask_message) if mask_message.present?
|
47
48
|
ajax_options.merge!('data-sequence-group' => sequence_group) if sequence_group.present?
|
48
49
|
ajax_options.merge!('data-sequence-number' => sequence_number) if sequence_number.present?
|
50
|
+
ajax_options.merge!('data-search-path' => search_path) if search_path.present?
|
51
|
+
ajax_options.merge!('data-search-params' => search_params) if search_params.present?
|
49
52
|
link_to(name,
|
50
53
|
options,
|
51
54
|
html_options.merge(ajax_options))
|
data/lib/thin_man/version.rb
CHANGED
@@ -2,75 +2,70 @@
|
|
2
2
|
// Generated on Thu Sep 10 2015 16:43:39 GMT-0500 (COT)
|
3
3
|
|
4
4
|
module.exports = function(config) {
|
5
|
-
|
5
|
+
config.set({
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
// base path that will be used to resolve all patterns (eg. files, exclude)
|
8
|
+
basePath: '',
|
9
9
|
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
// frameworks to use
|
12
|
+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
13
|
+
frameworks: ['jasmine-ajax', 'jasmine', 'requirejs'],
|
14
14
|
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
// list of files / patterns to load in the browser
|
17
|
+
files: [
|
18
|
+
'test-main.js',
|
19
|
+
{pattern: 'jquery.js'},
|
20
|
+
{pattern: 'jasmine-fixture.js'},
|
21
|
+
{pattern: '../../app/assets/javascripts/thin_man.js'},
|
22
|
+
{pattern: '../../app/assets/javascripts/debug_logger.js'},
|
23
|
+
{pattern: 'spec/helpers/*.js'},
|
24
|
+
{pattern: 'spec/**/*Spec.js', included: false}
|
25
|
+
],
|
26
26
|
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
// list of files to exclude
|
29
|
+
exclude: [
|
30
|
+
],
|
30
31
|
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
// preprocess matching files before serving them to the browser
|
34
|
+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
35
|
+
preprocessors: {
|
36
|
+
},
|
35
37
|
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
// test results reporter to use
|
40
|
+
// possible values: 'dots', 'progress'
|
41
|
+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
42
|
+
reporters: ['spec'],
|
41
43
|
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
+
// web server port
|
46
|
+
port: 9876,
|
45
47
|
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
+
// enable / disable colors in the output (reporters and logs)
|
50
|
+
colors: true,
|
49
51
|
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
// level of logging
|
54
|
+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
55
|
+
logLevel: config.LOG_INFO,
|
54
56
|
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
+
// enable / disable watching file and executing tests whenever any file changes
|
59
|
+
autoWatch: false,
|
58
60
|
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
// customLaunchers: {
|
64
|
-
// 'PhantomJS_custom': {
|
65
|
-
// base: 'PhantomJS',
|
66
|
-
// debug: true,
|
67
|
-
// },
|
68
|
-
// },
|
69
|
-
// browsers: ['Chrome'],
|
62
|
+
// start these browsers
|
63
|
+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
64
|
+
browsers: ['PhantomJS'],
|
70
65
|
|
71
66
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
}
|
67
|
+
// Continuous Integration mode
|
68
|
+
// if true, Karma captures browsers, runs the tests and exits
|
69
|
+
singleRun: true
|
70
|
+
})
|
71
|
+
}
|
@@ -1,272 +1,242 @@
|
|
1
|
-
describe("thin_man", function()
|
1
|
+
describe("thin_man", function(){
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
function getAjaxArg(arg_name){
|
4
|
+
return $.ajax.calls.argsFor(0)[0][arg_name];
|
5
|
+
}
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
describe("Base class", function(){
|
8
|
+
beforeAll(function(){
|
9
|
+
jasmine.Ajax.install();
|
10
|
+
jasmine.clock().install();
|
11
|
+
});
|
12
|
+
|
13
|
+
describe(".ajaxSuccess", function(){
|
14
|
+
var $link, $target, thin;
|
15
|
+
|
16
|
+
beforeEach(function(){
|
17
|
+
$link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"]');
|
18
|
+
$target = affix('#test_dom_id');
|
19
|
+
thin = new thin_man.AjaxLinkSubmission($link);
|
20
|
+
});
|
21
|
+
|
22
|
+
it("Add result to the target", function(){
|
23
|
+
thin.ajaxSuccess({ html: "Hello" }, 'success', TestResponses.success)
|
24
|
+
expect($target.html()).toEqual("Hello")
|
25
|
+
});
|
26
|
+
|
27
|
+
it("focus on first element", function(){
|
28
|
+
var form = '<form><input type="text"><textarea>dummy</textarea></form>'
|
29
|
+
thin.ajaxSuccess(form, 'success', TestResponses.success)
|
30
|
+
expect($target.html()).toEqual(form);
|
31
|
+
expect($("[type='text']").length).toEqual(1);
|
32
|
+
//Check if it's focused
|
33
|
+
expect($("[type='text']").get(0)).toBe(document.activeElement);
|
34
|
+
});
|
35
|
+
|
36
|
+
it("empties the target if there is no html in the json", function(){
|
37
|
+
$target.html('Remove me.')
|
38
|
+
thin.ajaxSuccess({flash_message: 'Successfully moved the widget.'}, 'success', TestResponses.success)
|
39
|
+
expect($target.html()).toEqual('')
|
40
|
+
})
|
41
|
+
|
42
|
+
it("handles success with no target", function(){
|
43
|
+
$no_target_link = affix('a[data-ajax-link="true"][data-ajax-target=""]');
|
44
|
+
thin = new thin_man.AjaxLinkSubmission($no_target_link);
|
45
|
+
thin.ajaxSuccess({flash_message: 'Success'},'success', TestResponses.success)
|
46
|
+
})
|
47
|
+
});
|
48
|
+
|
49
|
+
describe(".ajaxComplete", function(){
|
50
|
+
var $link, thin;
|
12
51
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
thin.ajaxSuccess({ html: "Hello" }, 'success', TestResponses.success)
|
24
|
-
expect($target.html()).toEqual("Hello")
|
25
|
-
});
|
26
|
-
|
27
|
-
it("focus on first element", function() {
|
28
|
-
var form = '<form><input type="text"><textarea>dummy</textarea></form>'
|
29
|
-
thin.ajaxSuccess(form, 'success', TestResponses.success)
|
30
|
-
expect($target.html()).toEqual(form);
|
31
|
-
expect($("[type='text']").length).toEqual(1);
|
32
|
-
//Check if it's focused
|
33
|
-
expect($("[type='text']").get(0)).toBe(document.activeElement);
|
34
|
-
});
|
35
|
-
|
36
|
-
it("empties the target if there is no html in the json", function() {
|
37
|
-
$target.html('Remove me.')
|
38
|
-
thin.ajaxSuccess({ flash_message: 'Successfully moved the widget.' }, 'success', TestResponses.success)
|
39
|
-
expect($target.html()).toEqual('')
|
40
|
-
})
|
41
|
-
|
42
|
-
it("handles success with no target", function() {
|
43
|
-
$no_target_link = affix('a[data-ajax-link="true"][data-ajax-target=""]');
|
44
|
-
thin = new thin_man.AjaxLinkSubmission($no_target_link);
|
45
|
-
thin.ajaxSuccess({ flash_message: 'Success' }, 'success', TestResponses.success)
|
46
|
-
})
|
52
|
+
beforeEach(function(){
|
53
|
+
$link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"] #test_dom_id');
|
54
|
+
affix('[data-thin-man-flash-template] [data-thin-man-flash-content]');
|
55
|
+
thin = new thin_man.AjaxLinkSubmission($link);
|
56
|
+
});
|
57
|
+
|
58
|
+
describe("Display flash message", function(){
|
59
|
+
it("successfully response", function(){
|
60
|
+
thin.ajaxComplete(TestResponses.success);
|
61
|
+
expect(thin.flash.flash_content.text()).toMatch('successfully response');
|
47
62
|
});
|
48
63
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
beforeEach(function() {
|
53
|
-
$link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"] #test_dom_id');
|
54
|
-
affix('[data-thin-man-flash-template] [data-thin-man-flash-content]');
|
55
|
-
thin = new thin_man.AjaxLinkSubmission($link);
|
56
|
-
});
|
57
|
-
|
58
|
-
describe("Display flash message", function() {
|
59
|
-
it("successfully response", function() {
|
60
|
-
thin.ajaxComplete(TestResponses.success);
|
61
|
-
expect(thin.flash.flash_content.text()).toMatch('successfully response');
|
62
|
-
});
|
63
|
-
|
64
|
-
it("error response", function() {
|
65
|
-
thin.ajaxComplete(TestResponses.error);
|
66
|
-
expect(thin.flash.flash_content.text()).toMatch('error response');
|
67
|
-
});
|
68
|
-
});
|
69
|
-
|
70
|
-
it("fade out if flash_persist is false", function() {
|
71
|
-
spyOn($.fn, 'fadeOut');
|
72
|
-
thin.ajaxComplete(TestResponses.success);
|
73
|
-
jasmine.clock().tick(2000);
|
74
|
-
expect($.fn.fadeOut).toHaveBeenCalled();
|
75
|
-
});
|
64
|
+
it("error response", function(){
|
65
|
+
thin.ajaxComplete(TestResponses.error);
|
66
|
+
expect(thin.flash.flash_content.text()).toMatch('error response');
|
76
67
|
});
|
68
|
+
});
|
69
|
+
|
70
|
+
it("fade out if flash_persist is false", function(){
|
71
|
+
spyOn($.fn, 'fadeOut');
|
72
|
+
thin.ajaxComplete(TestResponses.success);
|
73
|
+
jasmine.clock().tick(2000);
|
74
|
+
expect($.fn.fadeOut).toHaveBeenCalled();
|
75
|
+
});
|
76
|
+
});
|
77
77
|
|
78
|
-
|
79
|
-
|
78
|
+
describe(".ajaxError", function(){
|
79
|
+
var $link, thin;
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
81
|
+
beforeEach(function(){
|
82
|
+
$link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"]');
|
83
|
+
$target = affix('#test_dom_id');
|
84
|
+
thin = new thin_man.AjaxLinkSubmission($link);
|
85
|
+
});
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
87
|
+
it('as a string', function(){
|
88
|
+
thin.ajaxError(TestResponses.conflictString);
|
89
|
+
expect($('#test_dom_id').html()).toMatch('conflict string response');
|
90
|
+
});
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
it('as an object', function(){
|
93
|
+
thin.ajaxError(TestResponses.conflict);
|
94
|
+
expect($('#test_dom_id').html()).toMatch('Required field');
|
95
|
+
});
|
96
96
|
|
97
|
-
});
|
98
97
|
});
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
it("fires grouped links in sequence", function() {
|
113
|
-
var $link_zero = affix('a[data-ajax-link-now="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-sequence-group="test_group"][data-sequence-number="0"]');
|
114
|
-
var $link_one = affix('a[data-ajax-link-now="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-sequence-group="test_group"][data-sequence-number="1"]');
|
115
|
-
var $link_two = affix('a[data-ajax-link-now="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-sequence-group="test_group"][data-sequence-number="2"]');
|
116
|
-
zero = new thin_man.AjaxLinkSubmission($link_zero)
|
117
|
-
one = new thin_man.AjaxLinkSubmission($link_one)
|
118
|
-
two = new thin_man.AjaxLinkSubmission($link_two)
|
119
|
-
expect(thin_man.hasOwnProperty('link_groups')).toEqual(true)
|
120
|
-
spyOn(one, 'fire')
|
121
|
-
spyOn(two, 'fire')
|
122
|
-
zero.ajaxComplete()
|
123
|
-
expect(one.fire).toHaveBeenCalled();
|
124
|
-
expect(two.fire).not.toHaveBeenCalled();
|
125
|
-
one.ajaxComplete()
|
126
|
-
expect(one.fire.calls.count()).toEqual(1);
|
127
|
-
expect(two.fire).toHaveBeenCalled();
|
128
|
-
})
|
98
|
+
});
|
99
|
+
|
100
|
+
describe("AjaxLinkSubmission", function(){
|
101
|
+
it("submits an ajax call with options", function(){
|
102
|
+
var $link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-return-type="json"]');
|
103
|
+
thin_man.AjaxLinkSubmission($link)
|
104
|
+
spyOn($, 'ajax');
|
105
|
+
$link.click();
|
106
|
+
expect($.ajax).toHaveBeenCalled();
|
107
|
+
expect(getAjaxArg("url")).toMatch("/url");
|
108
|
+
expect(getAjaxArg("type")).toMatch("PATCH");
|
109
|
+
expect(getAjaxArg("datatype")).toMatch("json");
|
110
|
+
expect(thin_man.hasOwnProperty('link_groups')).toEqual(false)
|
129
111
|
});
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
112
|
+
|
113
|
+
it("submits an ajax call with search params and path", function(){
|
114
|
+
var $link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"][href="/url"][data-return-type="json"][data-search-params="search_params"][data-search-path="/search_path"]');
|
115
|
+
thin_man.AjaxLinkSubmission($link)
|
116
|
+
spyOn($, 'ajax');
|
117
|
+
$link.click();
|
118
|
+
expect($.ajax).toHaveBeenCalled();
|
119
|
+
expect(getAjaxArg("url")).toEqual('/search_path?search_params');
|
120
|
+
});
|
121
|
+
|
122
|
+
it("fires grouped links in sequence", function(){
|
123
|
+
var $link_zero = affix('a[data-ajax-link-now="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-sequence-group="test_group"][data-sequence-number="0"]');
|
124
|
+
var $link_one = affix('a[data-ajax-link-now="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-sequence-group="test_group"][data-sequence-number="1"]');
|
125
|
+
var $link_two = affix('a[data-ajax-link-now="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-sequence-group="test_group"][data-sequence-number="2"]');
|
126
|
+
zero = new thin_man.AjaxLinkSubmission($link_zero)
|
127
|
+
one = new thin_man.AjaxLinkSubmission($link_one)
|
128
|
+
two = new thin_man.AjaxLinkSubmission($link_two)
|
129
|
+
expect(thin_man.hasOwnProperty('link_groups')).toEqual(true)
|
130
|
+
spyOn(one,'fire')
|
131
|
+
spyOn(two,'fire')
|
132
|
+
zero.ajaxComplete()
|
133
|
+
expect(one.fire).toHaveBeenCalled();
|
134
|
+
expect(two.fire).not.toHaveBeenCalled();
|
135
|
+
one.ajaxComplete()
|
136
|
+
expect(one.fire.calls.count()).toEqual(1);
|
137
|
+
expect(two.fire).toHaveBeenCalled();
|
138
|
+
})
|
139
|
+
});
|
140
|
+
describe("DeleteLink", function(){
|
141
|
+
it("submits an ajax delete call with options", function(){
|
142
|
+
var $link = affix('a[data-ajax-delete="true"][data-ajax-target="#test_dom_id"][href="/url"]');
|
143
|
+
var delete_link = new thin_man.DeleteLink($link)
|
144
|
+
spyOn($, 'ajax');
|
145
|
+
$link.click();
|
146
|
+
expect($.ajax).toHaveBeenCalled();
|
147
|
+
expect(delete_link.getAjaxType()).toEqual('DELETE')
|
148
|
+
expect(delete_link.getAjaxUrl()).toEqual('/url')
|
149
|
+
expect(delete_link.trigger).toEqual($link)
|
150
|
+
})
|
151
|
+
});
|
152
|
+
describe("AjaxFormSubmission", function(){
|
153
|
+
it("submits an ajax call with options", function(){
|
154
|
+
var $form = affix('form[data-ajax-form="true"][method="PATCH"][action="/url"]');
|
155
|
+
$form.affix('input[type="text"][name="name"][value="Jon Snow"]')
|
156
|
+
thin_man.AjaxFormSubmission($form)
|
157
|
+
spyOn($, 'ajax');
|
158
|
+
$form.submit();
|
159
|
+
expect($.ajax).toHaveBeenCalled();
|
160
|
+
expect(getAjaxArg("url")).toMatch("/url");
|
161
|
+
expect(getAjaxArg("type")).toMatch("PATCH");
|
162
|
+
expect(getAjaxArg("datatype")).toMatch("html");
|
181
163
|
});
|
182
|
-
describe("AjaxFormSubmission", function() {
|
183
|
-
it("submits an ajax call with options", function() {
|
184
|
-
var $form = affix('form[data-ajax-form="true"][method="PATCH"][action="/url"]');
|
185
|
-
$form.affix('input[type="text"][name="name"][value="Jon Snow"]')
|
186
|
-
thin_man.AjaxFormSubmission($form)
|
187
|
-
spyOn($, 'ajax');
|
188
|
-
$form.submit();
|
189
|
-
expect($.ajax).toHaveBeenCalled();
|
190
|
-
expect(getAjaxArg("url")).toMatch("/url");
|
191
|
-
expect(getAjaxArg("type")).toMatch("PATCH");
|
192
|
-
expect(getAjaxArg("datatype")).toMatch("html");
|
193
|
-
});
|
194
|
-
|
195
|
-
describe("GET request", function() {
|
196
|
-
var $form;
|
197
|
-
|
198
|
-
beforeEach(function() {
|
199
|
-
$form = affix('form[data-ajax-form="true"][action="/url"][method="GET"]');
|
200
|
-
});
|
201
|
-
|
202
|
-
it("serialize data", function() {
|
203
|
-
$form.affix('input[type="text"][name="name"][value="Jon Snow"]');
|
204
|
-
var thin = new thin_man.AjaxFormSubmission($form);
|
205
|
-
spyOn($, 'ajax');
|
206
|
-
$form.submit();
|
207
|
-
expect($.ajax).toHaveBeenCalled();
|
208
|
-
expect(thin.ajax_options.data).toEqual([{ name: 'name', value: 'Jon Snow' }, { name: 'thin_man_submitter', value: 'link_now' }]);
|
209
|
-
});
|
210
|
-
|
211
|
-
it(".getProcessData", function() {
|
212
|
-
var thin = new thin_man.AjaxFormSubmission($form)
|
213
|
-
expect(thin.getProcessData()).toBe(true);
|
214
|
-
});
|
215
|
-
|
216
|
-
it(".sendContentType", function() {
|
217
|
-
var thin = new thin_man.AjaxFormSubmission($form)
|
218
|
-
expect(thin.sendContentType()).toBe(true);
|
219
|
-
});
|
220
|
-
});
|
221
164
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
165
|
+
describe("GET request", function(){
|
166
|
+
var $form;
|
167
|
+
|
168
|
+
beforeEach(function() {
|
169
|
+
$form = affix('form[data-ajax-form="true"][action="/url"][method="GET"]');
|
170
|
+
});
|
171
|
+
|
172
|
+
it("serialize data", function(){
|
173
|
+
$form.affix('input[type="text"][name="name"][value="Jon Snow"]');
|
174
|
+
var thin = new thin_man.AjaxFormSubmission($form);
|
175
|
+
spyOn($, 'ajax');
|
176
|
+
$form.submit();
|
177
|
+
expect($.ajax).toHaveBeenCalled();
|
178
|
+
expect(thin.ajax_options.data).toEqual([{ name: 'name', value: 'Jon Snow' },{name: 'thin_man_submitter', value: 'link_now'}]);
|
179
|
+
});
|
180
|
+
|
181
|
+
it(".getProcessData", function(){
|
182
|
+
var thin = new thin_man.AjaxFormSubmission($form)
|
183
|
+
expect(thin.getProcessData()).toBe(true);
|
184
|
+
});
|
185
|
+
|
186
|
+
it(".sendContentType", function(){
|
187
|
+
var thin = new thin_man.AjaxFormSubmission($form)
|
188
|
+
expect(thin.sendContentType()).toBe(true);
|
189
|
+
});
|
190
|
+
});
|
245
191
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
});
|
192
|
+
describe("POST/PATCH/DELETE request", function(){
|
193
|
+
var $form;
|
194
|
+
beforeEach(function(){
|
195
|
+
$form = affix('form[data-ajax-form="true"][action="/url"]');
|
196
|
+
});
|
197
|
+
|
198
|
+
it("Set data in a FormData object", function(){
|
199
|
+
thin_man.AjaxFormSubmission($form)
|
200
|
+
spyOn($, 'ajax');
|
201
|
+
$form.submit();
|
202
|
+
expect(getAjaxArg("data")).toEqual(jasmine.any(FormData));
|
203
|
+
});
|
204
|
+
|
205
|
+
it(".getProcessData", function(){
|
206
|
+
var thin = new thin_man.AjaxFormSubmission($form)
|
207
|
+
expect(thin.getProcessData()).toBe(false);
|
208
|
+
});
|
209
|
+
|
210
|
+
it(".sendContentType", function(){
|
211
|
+
var thin = new thin_man.AjaxFormSubmission($form)
|
212
|
+
expect(thin.sendContentType()).toBe(false);
|
213
|
+
});
|
214
|
+
});
|
270
215
|
|
216
|
+
describe("Log", function(){
|
217
|
+
beforeEach(function(){
|
218
|
+
spyOn(console, 'log');
|
219
|
+
});
|
220
|
+
|
221
|
+
it("Don't show a warning with a valid target", function(){
|
222
|
+
$link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"]');
|
223
|
+
$target = affix('#test_dom_id');
|
224
|
+
thin = new thin_man.AjaxLinkSubmission($link);
|
225
|
+
expect(console.log).not.toHaveBeenCalled();
|
226
|
+
});
|
227
|
+
|
228
|
+
it("Show a warning when target not found", function(){
|
229
|
+
$link = affix('a[data-ajax-link="true"][data-ajax-target="#not_valid_target"]');
|
230
|
+
thin = new thin_man.AjaxLinkSubmission($link);
|
231
|
+
expect(console.log).toHaveBeenCalledWith('Warning! Thin Man selector #not_valid_target not found');
|
232
|
+
});
|
233
|
+
|
234
|
+
it("Show a warning when target not provided", function(){
|
235
|
+
$link = affix('a[data-ajax-link="true"]');
|
236
|
+
thin = new thin_man.AjaxLinkSubmission($link);
|
237
|
+
expect(console.log).toHaveBeenCalledWith('Warning! Thin Man selector not given');
|
238
|
+
});
|
271
239
|
});
|
272
|
-
|
240
|
+
|
241
|
+
});
|
242
|
+
});
|