-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1a6a00
commit cfda0b3
Showing
6 changed files
with
159 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {FormToObject} from "../../src/FormToObject"; | ||
|
||
describe('settings', () => { | ||
describe('phpStyleMultipleSelects', () => { | ||
it('when true, should return "multiple" key and array as value', () => { | ||
const $formEl = document.createElement('form'); | ||
const $formInner = document.createElement('div'); | ||
$formInner.innerHTML = ` | ||
<select name="multiple[]" multiple> | ||
<option value="a" selected>a</option> | ||
<option value="b" selected>b</option> | ||
</select> | ||
`; | ||
$formEl.appendChild($formInner); | ||
|
||
const formToObject = new FormToObject($formEl, { phpStyleMultipleSelects: true }); | ||
const result = formToObject.convertToObj(); | ||
|
||
expect(result).toEqual({"multiple": ["a", "b"]}); | ||
}); | ||
|
||
it('when false, should return "multiple" key and multi-array as value', () => { | ||
const $formEl = document.createElement('form'); | ||
const $formInner = document.createElement('div'); | ||
$formInner.innerHTML = ` | ||
<select name="multiple[]" multiple> | ||
<option value="a" selected>a</option> | ||
<option value="b" selected>b</option> | ||
</select> | ||
`; | ||
$formEl.appendChild($formInner); | ||
|
||
const formToObject = new FormToObject($formEl, { phpStyleMultipleSelects: false }); | ||
const result = formToObject.convertToObj(); | ||
|
||
expect(result).toEqual({"multiple": [["a", "b"]]}); | ||
}); | ||
|
||
// Note: this is a forced example. | ||
it('when false, should return "multiple" key and multi-arrays as value', () => { | ||
const $formEl = document.createElement('form'); | ||
const $formInner = document.createElement('div'); | ||
$formInner.innerHTML = ` | ||
<select name="multiple[]" multiple> | ||
<option value="a" selected>a</option> | ||
<option value="b" selected>b</option> | ||
</select> | ||
<select name="multiple[]" multiple> | ||
<option value="c" selected>c</option> | ||
<option value="d" selected>d</option> | ||
</select> | ||
`; | ||
$formEl.appendChild($formInner); | ||
|
||
const formToObject = new FormToObject($formEl, { phpStyleMultipleSelects: false }); | ||
const result = formToObject.convertToObj(); | ||
|
||
expect(result).toEqual({"multiple": [["a", "b"], ["c", "d"]]}); | ||
}); | ||
|
||
}); | ||
}); |