corrade-nucleus-nucleons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | (function(){ |
2 | |||
3 | 'use strict'; |
||
4 | |||
5 | /**
|
||
6 | * Input elements tests.
|
||
7 | *
|
||
8 | */ |
||
9 | describe('An HTML form with a text field', function () { |
||
10 | |||
11 | beforeEach(function () { |
||
12 | var html = '<form id="newForm">' + |
||
13 | '<input type="text" name="name" value="Serban">' + |
||
14 | '</form>'; |
||
15 | var $newForm = document.createElement('div'); |
||
16 | $newForm.id = 'fixtures'; |
||
17 | $newForm.innerHTML = html; |
||
18 | document.body.appendChild($newForm); |
||
19 | }); |
||
20 | |||
21 | afterEach(function () { |
||
22 | document.body.removeChild(document.getElementById('fixtures')); |
||
23 | }); |
||
24 | |||
25 | it('searched by a valid element string should return an object', function(){ |
||
26 | expect(formToObject('newForm')).toEqual({'name':'Serban'}); |
||
27 | }); |
||
28 | |||
29 | it('searched by a valid DOM element should return an object', function(){ |
||
30 | expect(formToObject(document.getElementById('newForm'))) |
||
31 | .toEqual({'name':'Serban'}); |
||
32 | }); |
||
33 | |||
34 | }); |
||
35 | |||
36 | describe('An HTML form with a color field', function(){ |
||
37 | |||
38 | beforeEach(function () { |
||
39 | var html = '<form id="newForm">' + |
||
40 | '<input type="color" name="myColor" value="#ff0000">' + |
||
41 | '</form>'; |
||
42 | var $newForm = document.createElement('div'); |
||
43 | $newForm.id = 'fixtures'; |
||
44 | $newForm.innerHTML = html; |
||
45 | document.body.appendChild($newForm); |
||
46 | }); |
||
47 | |||
48 | afterEach(function () { |
||
49 | document.body.removeChild(document.getElementById('fixtures')); |
||
50 | }); |
||
51 | |||
52 | it('should return an object', function(){ |
||
53 | expect(formToObject('newForm')).toEqual({'myColor':'#ff0000'}); |
||
54 | }); |
||
55 | |||
56 | }); |
||
57 | |||
58 | describe('An HTML form with a date field', function(){ |
||
59 | |||
60 | beforeEach(function () { |
||
61 | var html = '<form id="newForm">' + |
||
62 | '<input type="date" name="bday" value="2012-07-17">' + |
||
63 | '</form>'; |
||
64 | var $newForm = document.createElement('div'); |
||
65 | $newForm.id = 'fixtures'; |
||
66 | $newForm.innerHTML = html; |
||
67 | document.body.appendChild($newForm); |
||
68 | }); |
||
69 | |||
70 | afterEach(function () { |
||
71 | document.body.removeChild(document.getElementById('fixtures')); |
||
72 | }); |
||
73 | |||
74 | it('should return an object', function(){ |
||
75 | expect(formToObject('newForm')).toEqual({'bday':'2012-07-17'}); |
||
76 | }); |
||
77 | |||
78 | }); |
||
79 | |||
80 | describe('An HTML form with a datetime field', function(){ |
||
81 | |||
82 | beforeEach(function () { |
||
83 | var html = '<form id="newForm">' + |
||
84 | '<input type="datetime" name="bdaytime" value="2012-07-17 08:57:00">' + |
||
85 | '</form>'; |
||
86 | var $newForm = document.createElement('div'); |
||
87 | $newForm.id = 'fixtures'; |
||
88 | $newForm.innerHTML = html; |
||
89 | document.body.appendChild($newForm); |
||
90 | }); |
||
91 | |||
92 | afterEach(function () { |
||
93 | document.body.removeChild(document.getElementById('fixtures')); |
||
94 | }); |
||
95 | |||
96 | it('should return an object', function(){ |
||
97 | expect(formToObject('newForm')).toEqual({'bdaytime':'2012-07-17 08:57:00'}); |
||
98 | }); |
||
99 | |||
100 | }); |
||
101 | |||
102 | describe('An HTML form with a datetime-local field', function(){ |
||
103 | |||
104 | beforeEach(function () { |
||
105 | var html = '<form id="newForm">' + |
||
106 | '<input type="datetime-local" name="bdaytimeLocal" value="2014-08-30T02:03">' + |
||
107 | '</form>'; |
||
108 | var $newForm = document.createElement('div'); |
||
109 | $newForm.id = 'fixtures'; |
||
110 | $newForm.innerHTML = html; |
||
111 | document.body.appendChild($newForm); |
||
112 | }); |
||
113 | |||
114 | afterEach(function () { |
||
115 | document.body.removeChild(document.getElementById('fixtures')); |
||
116 | }); |
||
117 | |||
118 | it('should return an object', function(){ |
||
119 | expect(formToObject('newForm')).toEqual({'bdaytimeLocal':'2014-08-30T02:03'}); |
||
120 | }); |
||
121 | |||
122 | }); |
||
123 | |||
124 | describe('An HTML form with an email field', function(){ |
||
125 | |||
126 | beforeEach(function () { |
||
127 | var html = '<form id="newForm">' + |
||
128 | '<input type="email" name="email" value="serbanghita@gmail.com" placeholder="you@email.com">' + |
||
129 | '</form>'; |
||
130 | var $newForm = document.createElement('div'); |
||
131 | $newForm.id = 'fixtures'; |
||
132 | $newForm.innerHTML = html; |
||
133 | document.body.appendChild($newForm); |
||
134 | }); |
||
135 | |||
136 | afterEach(function () { |
||
137 | document.body.removeChild(document.getElementById('fixtures')); |
||
138 | }); |
||
139 | |||
140 | it('should return an object', function(){ |
||
141 | expect(formToObject('newForm')).toEqual({'email':'serbanghita@gmail.com'}); |
||
142 | }); |
||
143 | |||
144 | }); |
||
145 | |||
146 | describe('An HTML form with a month field', function(){ |
||
147 | |||
148 | beforeEach(function () { |
||
149 | var html = '<form id="newForm">' + |
||
150 | '<input type="month" name="bdaymonth" value="2014-07" placeholder="July, 2014">' + |
||
151 | '</form>'; |
||
152 | var $newForm = document.createElement('div'); |
||
153 | $newForm.id = 'fixtures'; |
||
154 | $newForm.innerHTML = html; |
||
155 | document.body.appendChild($newForm); |
||
156 | }); |
||
157 | |||
158 | afterEach(function () { |
||
159 | document.body.removeChild(document.getElementById('fixtures')); |
||
160 | }); |
||
161 | |||
162 | it('should return an object', function(){ |
||
163 | expect(formToObject('newForm')).toEqual({'bdaymonth':'2014-07'}); |
||
164 | }); |
||
165 | |||
166 | }); |
||
167 | |||
168 | describe('An HTML form with a number field', function(){ |
||
169 | |||
170 | beforeEach(function () { |
||
171 | var html = '<form id="newForm">' + |
||
172 | '<input type="number" name="quantity" min="1" max="5" value="4">' + |
||
173 | '</form>'; |
||
174 | var $newForm = document.createElement('div'); |
||
175 | $newForm.id = 'fixtures'; |
||
176 | $newForm.innerHTML = html; |
||
177 | document.body.appendChild($newForm); |
||
178 | }); |
||
179 | |||
180 | afterEach(function () { |
||
181 | document.body.removeChild(document.getElementById('fixtures')); |
||
182 | }); |
||
183 | |||
184 | it('should return an object', function(){ |
||
185 | expect(formToObject('newForm')).toEqual({'quantity':'4'}); |
||
186 | }); |
||
187 | |||
188 | }); |
||
189 | |||
190 | describe('An HTML form with a range field', function(){ |
||
191 | |||
192 | beforeEach(function () { |
||
193 | var html = '<form id="newForm">' + |
||
194 | '<input type="range" name="points" min="1" max="10" value="9">' + |
||
195 | '</form>'; |
||
196 | var $newForm = document.createElement('div'); |
||
197 | $newForm.id = 'fixtures'; |
||
198 | $newForm.innerHTML = html; |
||
199 | document.body.appendChild($newForm); |
||
200 | }); |
||
201 | |||
202 | afterEach(function () { |
||
203 | document.body.removeChild(document.getElementById('fixtures')); |
||
204 | }); |
||
205 | |||
206 | it('should return an object', function(){ |
||
207 | expect(formToObject('newForm')).toEqual({'points':'9'}); |
||
208 | }); |
||
209 | |||
210 | }); |
||
211 | |||
212 | describe('An HTML form with a search field', function(){ |
||
213 | |||
214 | beforeEach(function () { |
||
215 | var html = '<form id="newForm">' + |
||
216 | '<input type="search" name="googlesearch" value="javascript form to object">' + |
||
217 | '</form>'; |
||
218 | var $newForm = document.createElement('div'); |
||
219 | $newForm.id = 'fixtures'; |
||
220 | $newForm.innerHTML = html; |
||
221 | document.body.appendChild($newForm); |
||
222 | }); |
||
223 | |||
224 | afterEach(function () { |
||
225 | document.body.removeChild(document.getElementById('fixtures')); |
||
226 | }); |
||
227 | |||
228 | it('should return an object', function(){ |
||
229 | expect(formToObject('newForm')).toEqual({'googlesearch':'javascript form to object'}); |
||
230 | }); |
||
231 | |||
232 | }); |
||
233 | |||
234 | describe('An HTML form with a tel field', function(){ |
||
235 | |||
236 | beforeEach(function () { |
||
237 | var html = '<form id="newForm">' + |
||
238 | '<input type="tel" name="yourPhoneNo" value="+40.737.10.01.10">' + |
||
239 | '</form>'; |
||
240 | var $newForm = document.createElement('div'); |
||
241 | $newForm.id = 'fixtures'; |
||
242 | $newForm.innerHTML = html; |
||
243 | document.body.appendChild($newForm); |
||
244 | }); |
||
245 | |||
246 | afterEach(function () { |
||
247 | document.body.removeChild(document.getElementById('fixtures')); |
||
248 | }); |
||
249 | |||
250 | it('should return an object', function(){ |
||
251 | expect(formToObject('newForm')).toEqual({'yourPhoneNo':'+40.737.10.01.10'}); |
||
252 | }); |
||
253 | |||
254 | }); |
||
255 | |||
256 | describe('An HTML form with a time field', function(){ |
||
257 | |||
258 | beforeEach(function () { |
||
259 | var html = '<form id="newForm">' + |
||
260 | '<input type="time" name="usrTime" value="22:07">' + |
||
261 | '</form>'; |
||
262 | var $newForm = document.createElement('div'); |
||
263 | $newForm.id = 'fixtures'; |
||
264 | $newForm.innerHTML = html; |
||
265 | document.body.appendChild($newForm); |
||
266 | }); |
||
267 | |||
268 | afterEach(function () { |
||
269 | document.body.removeChild(document.getElementById('fixtures')); |
||
270 | }); |
||
271 | |||
272 | it('should return an object', function(){ |
||
273 | expect(formToObject('newForm')).toEqual({'usrTime':'22:07'}); |
||
274 | }); |
||
275 | |||
276 | }); |
||
277 | |||
278 | describe('An HTML form with an url field', function(){ |
||
279 | |||
280 | beforeEach(function () { |
||
281 | var html = '<form id="newForm">' + |
||
282 | '<input type="url" name="homepage" value="http://google.com.ro">' + |
||
283 | '</form>'; |
||
284 | var $newForm = document.createElement('div'); |
||
285 | $newForm.id = 'fixtures'; |
||
286 | $newForm.innerHTML = html; |
||
287 | document.body.appendChild($newForm); |
||
288 | }); |
||
289 | |||
290 | afterEach(function () { |
||
291 | document.body.removeChild(document.getElementById('fixtures')); |
||
292 | }); |
||
293 | |||
294 | it('should return an object', function(){ |
||
295 | expect(formToObject('newForm')).toEqual({'homepage':'http://google.com.ro'}); |
||
296 | }); |
||
297 | |||
298 | }); |
||
299 | |||
300 | describe('An HTML form with a week field', function(){ |
||
301 | |||
302 | beforeEach(function () { |
||
303 | var html = '<form id="newForm">' + |
||
304 | '<input type="week" name="yearWeek" value="2016-W02">' + |
||
305 | '</form>'; |
||
306 | var $newForm = document.createElement('div'); |
||
307 | $newForm.id = 'fixtures'; |
||
308 | $newForm.innerHTML = html; |
||
309 | document.body.appendChild($newForm); |
||
310 | }); |
||
311 | |||
312 | afterEach(function () { |
||
313 | document.body.removeChild(document.getElementById('fixtures')); |
||
314 | }); |
||
315 | |||
316 | it('should return an object', function(){ |
||
317 | expect(formToObject('newForm')).toEqual({'yearWeek':'2016-W02'}); |
||
318 | }); |
||
319 | |||
320 | }); |
||
321 | |||
322 | describe('An HTML from with a hidden field', function(){ |
||
323 | |||
324 | beforeEach(function () { |
||
325 | var html = '<form id="newForm">' + |
||
326 | '<input type="hidden" name="token" value="123-456-789">' + |
||
327 | '</form>'; |
||
328 | var $newForm = document.createElement('div'); |
||
329 | $newForm.id = 'fixtures'; |
||
330 | $newForm.innerHTML = html; |
||
331 | document.body.appendChild($newForm); |
||
332 | }); |
||
333 | |||
334 | afterEach(function () { |
||
335 | document.body.removeChild(document.getElementById('fixtures')); |
||
336 | }); |
||
337 | |||
338 | it('should return an object', function(){ |
||
339 | expect(formToObject('newForm')).toEqual({'token':'123-456-789'}); |
||
340 | }); |
||
341 | |||
342 | }); |
||
343 | |||
344 | |||
345 | /**
|
||
346 | * Multiple input elements tests
|
||
347 | *
|
||
348 | */ |
||
349 | describe('An HTML form with multiple input fields', function(){ |
||
350 | |||
351 | beforeEach(function () { |
||
352 | var html = '<form id="newForm">' + |
||
353 | '<input type="text" name="name" value="Serban">' + |
||
354 | '<input type="color" name="myColor" value="#ff0000">' + |
||
355 | '<input type="date" name="bday" value="2012-07-17">' + |
||
356 | '<input type="datetime" name="bdaytime" value="2012-07-17 08:57:00">' + |
||
357 | '<input type="datetime-local" name="bdaytimeLocal" value="2014-08-30T02:03">' + |
||
358 | '<input type="email" name="email" value="serbanghita@gmail.com" placeholder="you@email.com">' + |
||
359 | '<input type="month" name="bdaymonth" value="2014-07" placeholder="July, 2014">' + |
||
360 | '<input type="number" name="quantity" min="1" max="5" value="4">' + |
||
361 | '<input type="range" name="points" min="1" max="10" value="9">' + |
||
362 | '<input type="search" name="googlesearch" value="javascript form to object">' + |
||
363 | '<input type="tel" name="yourPhoneNo" value="+40.737.10.01.10">' + |
||
364 | '<input type="time" name="usrTime" value="22:07">' + |
||
365 | '<input type="url" name="homepage" value="http://google.com.ro">' + |
||
366 | '<input type="week" name="yearWeek" value="2016-W02">' + |
||
367 | '<input type="week" name="yearWeek" value="2016-W02">' + |
||
368 | '</form>'; |
||
369 | var $newForm = document.createElement('div'); |
||
370 | $newForm.id = 'fixtures'; |
||
371 | $newForm.innerHTML = html; |
||
372 | document.body.appendChild($newForm); |
||
373 | }); |
||
374 | |||
375 | afterEach(function () { |
||
376 | document.body.removeChild(document.getElementById('fixtures')); |
||
377 | }); |
||
378 | |||
379 | it('should return an object containing all the fields names and respective values', function(){ |
||
380 | expect(formToObject('newForm')).toEqual({ |
||
381 | 'name':'Serban', |
||
382 | 'myColor':'#ff0000', |
||
383 | 'bday':'2012-07-17', |
||
384 | 'bdaytime':'2012-07-17 08:57:00', |
||
385 | 'bdaytimeLocal':'2014-08-30T02:03', |
||
386 | 'email':'serbanghita@gmail.com', |
||
387 | 'bdaymonth':'2014-07', |
||
388 | 'quantity':'4', |
||
389 | 'points':'9', |
||
390 | 'googlesearch':'javascript form to object', |
||
391 | 'yourPhoneNo':'+40.737.10.01.10', |
||
392 | 'usrTime':'22:07', |
||
393 | 'homepage':'http://google.com.ro', |
||
394 | 'yearWeek':'2016-W02' |
||
395 | }); |
||
396 | }); |
||
397 | |||
398 | }); |
||
399 | |||
400 | |||
401 | })(); |