jaxon-php /
jaxon-mono
| 1 | const jq = require('jquery'); |
||
| 2 | const { |
||
| 3 | cmd: { node }, |
||
| 4 | utils: { dom, form, types }, |
||
| 5 | parser: { query }, |
||
| 6 | } = require('../dist/jaxon.module'); |
||
| 7 | |||
| 8 | // Init the selector library. |
||
| 9 | query.jq = jq; |
||
|
0 ignored issues
–
show
|
|||
| 10 | |||
| 11 | test('Test empty form', () => { |
||
| 12 | document.body.innerHTML = ` |
||
| 13 | <div id="wrapper"> |
||
| 14 | <form id="test_form"> |
||
| 15 | </form> |
||
| 16 | </div>`; |
||
| 17 | |||
| 18 | const formValues = form.getValues('test_form'); |
||
|
0 ignored issues
–
show
The variable
form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 19 | |||
| 20 | expect(types.of(formValues)).toBe('object'); |
||
|
0 ignored issues
–
show
The variable
types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 21 | expect(Object.keys(formValues).length).toBe(0); |
||
| 22 | }); |
||
| 23 | |||
| 24 | test('Test form without id', () => { |
||
| 25 | document.body.innerHTML = ` |
||
| 26 | <div id="wrapper"> |
||
| 27 | <form> |
||
| 28 | </form> |
||
| 29 | </div>`; |
||
| 30 | |||
| 31 | const formValues = form.getValues('test_form'); |
||
|
0 ignored issues
–
show
The variable
form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 32 | |||
| 33 | expect(types.of(formValues)).toBe('object'); |
||
|
0 ignored issues
–
show
The variable
types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 34 | expect(Object.keys(formValues).length).toBe(0); |
||
| 35 | }); |
||
| 36 | |||
| 37 | test('Test form with multiple select in simple var', () => { |
||
| 38 | // Fix: https://github.com/jaxon-php/jaxon-core/issues/128 |
||
| 39 | document.body.innerHTML = ` |
||
| 40 | <div id="wrapper"> |
||
| 41 | <form id="test_form"> |
||
| 42 | <select multiple="multiple" name="multiselect"> |
||
| 43 | <option value="1" selected>Value 1</option> |
||
| 44 | <option value="2" selected>Value 2</option> |
||
| 45 | <option value="3">Value 3</option> |
||
| 46 | </select> |
||
| 47 | </form> |
||
| 48 | </div>`; |
||
| 49 | |||
| 50 | const formValues = form.getValues('test_form'); |
||
|
0 ignored issues
–
show
The variable
form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 51 | |||
| 52 | expect(types.of(formValues)).toBe('object'); |
||
|
0 ignored issues
–
show
The variable
types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 53 | expect(types.of(formValues.multiselect)).toBe('string'); |
||
| 54 | expect(formValues.multiselect).toBe('2'); |
||
| 55 | }); |
||
| 56 | |||
| 57 | test('Test assign command on multiple select in simple var', () => { |
||
| 58 | // Fix: https://github.com/jaxon-php/jaxon-js/issues/29 |
||
| 59 | document.body.innerHTML = ` |
||
| 60 | <div id="wrapper"> |
||
| 61 | <form id="test_form"> |
||
| 62 | <select id="multiselect" multiple="multiple" name="multiselect"> |
||
| 63 | <option value="1">Value 1</option> |
||
| 64 | <option value="2">Value 2</option> |
||
| 65 | <option value="3">Value 3</option> |
||
| 66 | </select> |
||
| 67 | </form> |
||
| 68 | </div>`; |
||
| 69 | |||
| 70 | const formValues0 = form.getValues('test_form'); |
||
|
0 ignored issues
–
show
The variable
form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 71 | |||
| 72 | expect(types.of(formValues0)).toBe('object'); |
||
|
0 ignored issues
–
show
The variable
types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 73 | expect(formValues0.multiselect).toBe(undefined); |
||
| 74 | |||
| 75 | node.assign({ |
||
|
0 ignored issues
–
show
The variable
node seems to be never declared. If this is a global, consider adding a /** global: node */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 76 | attr: 'options[0].selected', |
||
| 77 | value: 'true', |
||
| 78 | }, { |
||
| 79 | target: dom.$('multiselect'), |
||
|
0 ignored issues
–
show
The variable
dom seems to be never declared. If this is a global, consider adding a /** global: dom */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 80 | }); |
||
| 81 | const formValues1 = form.getValues('test_form'); |
||
| 82 | |||
| 83 | expect(types.of(formValues1)).toBe('object'); |
||
| 84 | expect(types.of(formValues1.multiselect)).toBe('string'); |
||
| 85 | expect(formValues1.multiselect).toBe('1'); |
||
| 86 | |||
| 87 | node.assign({ |
||
| 88 | attr: 'options[1].selected', |
||
| 89 | value: 'true', |
||
| 90 | }, { |
||
| 91 | target: dom.$('multiselect'), |
||
| 92 | }); |
||
| 93 | const formValues2 = form.getValues('test_form'); |
||
| 94 | |||
| 95 | expect(types.of(formValues2)).toBe('object'); |
||
| 96 | expect(types.of(formValues2.multiselect)).toBe('string'); |
||
| 97 | expect(formValues2.multiselect).toBe('2'); |
||
| 98 | }); |
||
| 99 | |||
| 100 | test('Test form with multiple select in array var', () => { |
||
| 101 | // Fix: https://github.com/jaxon-php/jaxon-core/issues/128 |
||
| 102 | document.body.innerHTML = ` |
||
| 103 | <div id="wrapper"> |
||
| 104 | <form id="test_form"> |
||
| 105 | <select multiple="multiple" name="multiselect[]"> |
||
| 106 | <option value="1" selected>Value 1</option> |
||
| 107 | <option value="2" selected>Value 2</option> |
||
| 108 | <option value="3">Value 3</option> |
||
| 109 | </select> |
||
| 110 | </form> |
||
| 111 | </div>`; |
||
| 112 | |||
| 113 | const formValues = form.getValues('test_form'); |
||
|
0 ignored issues
–
show
The variable
form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 114 | |||
| 115 | expect(types.of(formValues)).toBe('object'); |
||
|
0 ignored issues
–
show
The variable
types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 116 | expect(types.of(formValues.multiselect)).toBe('array'); |
||
| 117 | expect(formValues.multiselect.length).toBe(2); |
||
| 118 | expect(formValues.multiselect[0]).toBe('1'); |
||
| 119 | expect(formValues.multiselect[1]).toBe('2'); |
||
| 120 | }); |
||
| 121 | |||
| 122 | test('Test assign command on multiple select in array var', () => { |
||
| 123 | // Fix: https://github.com/jaxon-php/jaxon-js/issues/29 |
||
| 124 | document.body.innerHTML = ` |
||
| 125 | <div id="wrapper"> |
||
| 126 | <form id="test_form"> |
||
| 127 | <select id="multiselect" multiple="multiple" name="multiselect[]"> |
||
| 128 | <option value="1">Value 1</option> |
||
| 129 | <option value="2">Value 2</option> |
||
| 130 | <option value="3">Value 3</option> |
||
| 131 | </select> |
||
| 132 | </form> |
||
| 133 | </div>`; |
||
| 134 | |||
| 135 | const formValues0 = form.getValues('test_form'); |
||
|
0 ignored issues
–
show
The variable
form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 136 | |||
| 137 | expect(types.of(formValues0)).toBe('object'); |
||
|
0 ignored issues
–
show
The variable
types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 138 | expect(types.of(formValues0.multiselect)).toBe('array'); |
||
| 139 | expect(formValues0.multiselect.length).toBe(0); |
||
| 140 | |||
| 141 | node.assign({ |
||
|
0 ignored issues
–
show
The variable
node seems to be never declared. If this is a global, consider adding a /** global: node */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 142 | attr: 'options[0].selected', |
||
| 143 | value: 'true', |
||
| 144 | }, { |
||
| 145 | target: dom.$('multiselect'), |
||
|
0 ignored issues
–
show
The variable
dom seems to be never declared. If this is a global, consider adding a /** global: dom */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 146 | }); |
||
| 147 | const formValues1 = form.getValues('test_form'); |
||
| 148 | |||
| 149 | expect(types.of(formValues1)).toBe('object'); |
||
| 150 | expect(types.of(formValues1.multiselect)).toBe('array'); |
||
| 151 | expect(formValues1.multiselect.length).toBe(1); |
||
| 152 | expect(formValues1.multiselect[0]).toBe('1'); |
||
| 153 | |||
| 154 | node.assign({ |
||
| 155 | attr: 'options[1].selected', |
||
| 156 | value: 'true', |
||
| 157 | }, { |
||
| 158 | target: dom.$('multiselect'), |
||
| 159 | }); |
||
| 160 | const formValues2 = form.getValues('test_form'); |
||
| 161 | |||
| 162 | expect(types.of(formValues2)).toBe('object'); |
||
| 163 | expect(types.of(formValues2.multiselect)).toBe('array'); |
||
| 164 | expect(formValues2.multiselect.length).toBe(2); |
||
| 165 | expect(formValues2.multiselect[0]).toBe('1'); |
||
| 166 | expect(formValues2.multiselect[1]).toBe('2'); |
||
| 167 | }); |
||
| 168 | |||
| 169 | test('Test multiple select in nested array var', () => { |
||
| 170 | // Fix: https://github.com/jaxon-php/jaxon-js/issues/29 |
||
| 171 | document.body.innerHTML = ` |
||
| 172 | <div id="wrapper"> |
||
| 173 | <form id="test_form"> |
||
| 174 | <select id="multiselect" multiple="multiple" name="user[roles][]"> |
||
| 175 | <option value="1" selected>Value 1</option> |
||
| 176 | <option value="2">Value 2</option> |
||
| 177 | <option value="3" selected>Value 3</option> |
||
| 178 | </select> |
||
| 179 | </form> |
||
| 180 | </div>`; |
||
| 181 | |||
| 182 | const formValues = form.getValues('test_form'); |
||
|
0 ignored issues
–
show
The variable
form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 183 | |||
| 184 | expect(types.of(formValues)).toBe('object'); |
||
|
0 ignored issues
–
show
The variable
types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 185 | expect(types.of(formValues.user)).toBe('object'); |
||
| 186 | expect(types.of(formValues.user.roles)).toBe('array'); |
||
| 187 | expect(formValues.user.roles.length).toBe(2); |
||
| 188 | expect(formValues.user.roles[0]).toBe('1'); |
||
| 189 | expect(formValues.user.roles[1]).toBe('3'); |
||
| 190 | }); |
||
| 191 | |||
| 192 | test('Test form with names into brackets', () => { |
||
| 193 | document.body.innerHTML = ` |
||
| 194 | <div id="wrapper"> |
||
| 195 | <form id="test_form"> |
||
| 196 | <input name="user[name]" value="John Doe" /> |
||
| 197 | <input name="user[email]" value="[email protected]" /> |
||
| 198 | <input name="user[website]" value="john.doe.website.com" /> |
||
| 199 | </form> |
||
| 200 | </div>`; |
||
| 201 | |||
| 202 | const formValues = form.getValues('test_form'); |
||
|
0 ignored issues
–
show
The variable
form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 203 | |||
| 204 | expect(types.of(formValues)).toBe('object'); |
||
|
0 ignored issues
–
show
The variable
types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 205 | expect(types.of(formValues.user)).toBe('object'); |
||
| 206 | expect(Object.keys(formValues.user).length).toBe(3); |
||
| 207 | expect(formValues.user.name).toBe('John Doe'); |
||
| 208 | expect(formValues.user.email).toBe('[email protected]'); |
||
| 209 | expect(formValues.user.website).toBe('john.doe.website.com'); |
||
| 210 | }); |
||
| 211 | |||
| 212 | test('Test form with names into multiple brackets', () => { |
||
| 213 | document.body.innerHTML = ` |
||
| 214 | <div id="wrapper"> |
||
| 215 | <form id="test_form"> |
||
| 216 | <input name="user[name][first]" value="John" /> |
||
| 217 | <input name="user[name][last]" value="Doe" /> |
||
| 218 | <input name="user[email]" value="[email protected]" /> |
||
| 219 | <input name="user[website]" value="john.doe.website.com" /> |
||
| 220 | </form> |
||
| 221 | </div>`; |
||
| 222 | |||
| 223 | const formValues = form.getValues('test_form'); |
||
|
0 ignored issues
–
show
The variable
form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 224 | |||
| 225 | expect(types.of(formValues)).toBe('object'); |
||
|
0 ignored issues
–
show
The variable
types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 226 | expect(types.of(formValues.user)).toBe('object'); |
||
| 227 | expect(Object.keys(formValues.user).length).toBe(3); |
||
| 228 | expect(types.of(formValues.user.name)).toBe('object'); |
||
| 229 | expect(Object.keys(formValues.user.name).length).toBe(2); |
||
| 230 | expect(formValues.user.name.first).toBe('John'); |
||
| 231 | expect(formValues.user.name.last).toBe('Doe'); |
||
| 232 | expect(formValues.user.email).toBe('[email protected]'); |
||
| 233 | expect(formValues.user.website).toBe('john.doe.website.com'); |
||
| 234 | }); |
||
| 235 | |||
| 236 | test('Test form with array field', () => { |
||
| 237 | document.body.innerHTML = ` |
||
| 238 | <div id="wrapper"> |
||
| 239 | <form id="test_form"> |
||
| 240 | <input name="values[]" value="First value" /> |
||
| 241 | <input name="values[]" value="Second value" /> |
||
| 242 | <input name="values[]" value="Third value" /> |
||
| 243 | </form> |
||
| 244 | </div>`; |
||
| 245 | |||
| 246 | const formValues = form.getValues('test_form'); |
||
|
0 ignored issues
–
show
The variable
form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 247 | |||
| 248 | expect(types.of(formValues)).toBe('object'); |
||
|
0 ignored issues
–
show
The variable
types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 249 | expect(types.of(formValues.values)).toBe('array'); |
||
| 250 | expect(Object.keys(formValues.values).length).toBe(3); |
||
| 251 | expect(formValues.values[0]).toBe('First value'); |
||
| 252 | expect(formValues.values[1]).toBe('Second value'); |
||
| 253 | expect(formValues.values[2]).toBe('Third value'); |
||
| 254 | }); |
||
| 255 | |||
| 256 | test('Test form with object with array field', () => { |
||
| 257 | document.body.innerHTML = ` |
||
| 258 | <div id="wrapper"> |
||
| 259 | <form id="test_form"> |
||
| 260 | <input name="user[roles][]" value="First role" /> |
||
| 261 | <input name="user[perms][]" value="First perm" /> |
||
| 262 | <input name="user[roles][]" value="Second role" /> |
||
| 263 | <input name="user[perms][]" value="Second perm" /> |
||
| 264 | </form> |
||
| 265 | </div>`; |
||
| 266 | |||
| 267 | const formValues = form.getValues('test_form'); |
||
|
0 ignored issues
–
show
The variable
form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 268 | |||
| 269 | expect(types.of(formValues)).toBe('object'); |
||
|
0 ignored issues
–
show
The variable
types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 270 | expect(types.of(formValues.user)).toBe('object'); |
||
| 271 | expect(types.of(formValues.user.roles)).toBe('array'); |
||
| 272 | expect(types.of(formValues.user.perms)).toBe('array'); |
||
| 273 | expect(Object.keys(formValues.user.roles).length).toBe(2); |
||
| 274 | expect(Object.keys(formValues.user.perms).length).toBe(2); |
||
| 275 | expect(formValues.user.roles[0]).toBe('First role'); |
||
| 276 | expect(formValues.user.roles[1]).toBe('Second role'); |
||
| 277 | expect(formValues.user.perms[0]).toBe('First perm'); |
||
| 278 | expect(formValues.user.perms[1]).toBe('Second perm'); |
||
| 279 | }); |
||
| 280 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.