migrated knockout asset to bower
[openemr.git] / public / assets / knockout-2-2-1 / spec / jsonPostingBehaviors.js
blobd398b5f4f1d766fc8ac0236ea641f57998decc55
1 describe('JSON posting', {
2     'Should stringify and post the supplied data to a supplied URL': function () {
3         var submittedForm;
4         ko.utils.postJson('http://example.com/some/url', {myModel : {a : 1}}, { submitter : function(x) { submittedForm = x } });
6         value_of(submittedForm.action).should_be('http://example.com/some/url');
7         var input = submittedForm.childNodes[0];
8         value_of(input.tagName).should_be('INPUT');
9         value_of(input.name).should_be('myModel');
10         value_of(input.value).should_be('{"a":1}');
11     },
13     'Given an existing form, should take the URL from the form\'s \'action\' attribute': function() {
14         var existingForm = document.createElement("FORM");
15         existingForm.action = 'http://example.com/blah';
17         var submittedForm;
18         ko.utils.postJson(existingForm, {myModel : {a : 1}}, { submitter : function(x) { submittedForm = x } });
20         value_of(submittedForm.action).should_be('http://example.com/blah');
21     },
23     'Given an existing form, should include any requested field values from that form': function() {
24         var existingForm = document.createElement("FORM");
25         existingForm.innerHTML = '<input name="someField" value="myValue"/><input name="anotherField" value="unwantedValue"/>';
27         var submittedForm;
28         ko.utils.postJson(existingForm, {myModel : {a : 1}}, { includeFields : ['someField'], submitter : function(x) { submittedForm = x } });
30         value_of(ko.utils.getFormFields(submittedForm, 'someField')[0].value).should_be('myValue');
31         value_of(ko.utils.getFormFields(submittedForm, 'anotherField').length).should_be(0);
32         },
34         'Given an existing form, should include Rails and ASP.NET MVC auth tokens by default' : function() {
35         var existingForm = document.createElement("FORM");
36         existingForm.innerHTML = '<input name="__RequestVerificationToken_Lr4e" value="wantedval1"/>'
37                                                    + '<input name="__RequestVe" value="unwantedval"/>'
38                                                    + '<input name="authenticity_token" value="wantedval2"/>';
40         var submittedForm;
41         ko.utils.postJson(existingForm, {myModel : {a : 1}}, { submitter : function(x) { submittedForm = x } });
43         value_of(ko.utils.getFormFields(submittedForm, '__RequestVerificationToken_Lr4e')[0].value).should_be('wantedval1');
44         value_of(ko.utils.getFormFields(submittedForm, '__RequestVe').length).should_be(0);
45         value_of(ko.utils.getFormFields(submittedForm, 'authenticity_token')[0].value).should_be('wantedval2');
46         }
47 });