Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Commit

Permalink
test(formData): MPE unit tests
Browse files Browse the repository at this point in the history
closes #42
  • Loading branch information
rnicholus committed Jan 16, 2015
1 parent ae52294 commit 0408f5c
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/ajax-form-tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,49 @@
</select>
</form>

<form is="ajax-form" id="formDataForm" method="post" action="test" enctype="multipart/form-data">
<input name="test1" type="text" value="foobar"/>
<input name="test2" type="text"/>
<input name="test3" type="text"/>

<my-ce1 id="formdatace" name="ce1name"></my-ce1>
<my-ce2></my-ce2>

<select name="select1">
<option value="foo">foo</option>
<option value="bar" selected>bar</option>
</select>

<select name="select3">
<optgroup label="one">
<option value="foo">foo</option>
<option value="bar">bar</option>
</optgroup>
<optgroup label="two">
<option value="fizz" selected>fizz</option>
<option value="buzz">buzz</option>
</optgroup>
</select>
</form>

<script>
var typicalForm = document.querySelector('#typicalForm'),
requiredFileInputForm = document.querySelector('#requiredFileInputForm'),
jsonForm = document.querySelector('#jsonForm'),
formDataForm = document.querySelector('#formDataForm'),
xhr, requests;

document.querySelector('#typicalce').value = 'ce1value';
document.querySelector('#jsonce').value = 'ce1value';
document.querySelector('#formdatace').value = 'ce1value';

describe('Validate environment', function() {
it('Make sure Polymer and ajax-form are alive', function() {
expect(ajaxForm).to.exist;
expect(typicalForm).to.exist;
expect(requiredFileInputForm).to.exist;
expect(jsonForm).to.exist;
expect(formDataForm).to.exist;
expect(Polymer).to.exist;
});
});
Expand Down Expand Up @@ -247,6 +275,34 @@
});
});

describe('multipart/form-data encoding', function() {
var realFormData = window.FormData,
appendedData = {};

beforeEach(function() {
window.FormData.prototype.append = function(key, val) {
appendedData[key] = val;
}
});

afterEach(function() {
window.FormData = realFormData;
appendedData = {};
});

it('encodes the form fields and includes them in the payload', function() {
ajaxForm.domReady.call(formDataForm);
formDataForm.submit();

expect(JSON.stringify(appendedData)).to.equal(JSON.stringify({
test1:'foobar',
select1:'bar',
select3:'fizz',
ce1name:'ce1value'
}));
});
});

describe('Submit data modification', function() {
it('Allows JSON encoded data to be augmented before it is submitted', function() {
var submittedListener = function(event) {
Expand Down

0 comments on commit 0408f5c

Please sign in to comment.