How to use element.getAttribute method in Appium

Best JavaScript code snippet using appium

Run Appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Text.js

Source: Text.js Github

copy
1describe('Ext.field.Text', function() {
2    var field,
3    create = function(config) {
4        field = Ext.create('Ext.field.Text', config || {});
5    },
6    render = function() {
7        field.renderTo(Ext.getBody());
8    };
9
10    afterEach(function() {
11        if (field) {
12            field.destroy();
13            field = null;
14        }
15    });
16
17    describe('deprecated configurations + methods', function() {
18
19    });
20
21    describe("events", function() {
22        describe("change", function() {
23            it("should fire when you change the value from null", function() {
24                create();
25
26                var fired = false;
27
28                field.on('change', function() {
29                    fired = true;
30                }, this);
31
32                field.setValue('test');
33
34                expect(fired).toBeTruthy();
35            });
36
37            it("should fire when you change the value", function() {
38                create({
39                    value: 'test'
40                });
41
42                var fired = false;
43
44                field.on('change', function() {
45                    fired = true;
46                }, this);
47
48                field.setValue('test2');
49
50                expect(fired).toBeTruthy();
51            });
52
53            it("should not fire when you change the value", function() {
54                create({
55                    value: 'test'
56                });
57
58                var fired = false;
59
60                field.on('change', function() {
61                    fired = true;
62                }, this);
63
64                field.setValue('test');
65
66                expect(fired).toBeFalsy();
67            });
68        });
69    });
70
71    describe("configurations", function() {
72        describe("name", function() {
73            var defaultConfig = {
74                name: 'myname'
75            };
76
77            describe("configuration", function() {
78                it("should add the name attribute to the inputEl", function() {
79                    create(defaultConfig);
80                    render();
81                    expect(field.getComponent().inputElement.getAttribute('name')).toEqual('myname');
82                });
83            });
84
85            describe("method", function() {
86                describe("setting", function() {
87                    describe("before render", function() {
88                        it("should add the name attribute to the inputEl", function() {
89                            create();
90                            field.setName('myname');
91                            render();
92                            expect(field.getComponent().inputElement.getAttribute('name')).toEqual('myname');
93                        });
94                    });
95
96                    describe("after render", function() {
97                        it("should add the name attribute to the inputEl", function() {
98                            create();
99                            render();
100                            field.setName('myname');
101                            expect(field.getComponent().inputElement.getAttribute('name')).toEqual('myname');
102                        });
103                    });
104                });
105
106
107                describe("removing", function() {
108                    describe("before render", function() {
109                        it("should remove the name attribute from the inputEl", function() {
110                            create(defaultConfig);
111                            field.setName(null);
112                            render();
113                            expect(field.getComponent().inputElement.getAttribute('name')).toBeNull();
114                        });
115
116                    });
117
118                    describe("after render", function() {
119                        it("should remove the name attribute from the inputEl", function() {
120                            create(defaultConfig);
121                            render();
122                            field.setName(null);
123                            expect(field.getComponent().inputElement.getAttribute('name')).toBeNull();
124                        });
125
126                    });
127                });
128            });
129        });
130
131        describe("tabIndex", function() {
132           var defaultConfig = {
133               tabIndex: 10
134           };
135
136           describe("configuration", function() {
137                it("should add the tabindex attribute to the inputEl", function() {
138                    create(defaultConfig);
139                    render();
140                    expect(field.getComponent().inputElement.getAttribute('tabindex')).toEqual('10');
141                });
142            });
143
144            describe("method", function() {
145                describe("setting", function() {
146                    describe("before render", function() {
147                        it("should add the tabindex attribute to the inputEl", function() {
148                            create();
149                            field.setTabIndex(10);
150                            render();
151                            expect(field.getComponent().inputElement.getAttribute('tabindex')).toEqual('10');
152                        });
153                    });
154
155                    describe("after render", function() {
156                        it("should add the tabindex attribute to the inputEl", function() {
157                            create();
158                            render();
159                            field.setTabIndex(10);
160                            expect(field.getComponent().inputElement.getAttribute('tabindex')).toEqual('10');
161                        });
162                    });
163                });
164
165
166                describe("removing", function() {
167                    describe("before render", function() {
168                        it("should remove the tabindex attribute from the inputEl", function() {
169                            create(defaultConfig);
170                            field.setTabIndex(null);
171                            render();
172                            waits(10);
173                            runs(function() {
174                                expect(field.getComponent().inputElement.getAttribute('tabindex')).toBeNull();
175                            });
176                        });
177
178                    });
179
180                    describe("after render", function() {
181                        it("should remove the tabindex attribute from the inputEl", function() {
182                            create(defaultConfig);
183                            render();
184                            field.setTabIndex(null);
185
186                            expect(field.getComponent().inputElement.getAttribute('tabindex')).toBeNull();
187                        });
188
189                    });
190
191                });
192
193            });
194
195        });
196
197        describe("maxLength", function() {
198            var defaultConfig = {
199                maxLength: 10
200            };
201
202            describe("configuration", function() {
203                it("should add the maxlength attribute to the inputEl", function() {
204                    create(defaultConfig);
205                    render();
206                    expect(field.getComponent().inputElement.getAttribute('maxlength')).toEqual('10');
207                });
208            });
209
210            describe("method", function() {
211                describe("setting", function() {
212                    describe("before render", function() {
213                        it("should add the maxlength attribute to the inputEl", function() {
214                            create();
215                            field.setMaxLength(10);
216                            render();
217                            expect(field.getComponent().inputElement.getAttribute('maxlength')).toEqual('10');
218                        });
219                    });
220
221                    describe("after render", function() {
222                        it("should add the maxlength attribute to the inputEl", function() {
223                            create();
224                            render();
225                            field.setMaxLength(10);
226                            expect(field.getComponent().inputElement.getAttribute('maxlength')).toEqual('10');
227                        });
228                    });
229                });
230
231
232                describe("removing", function() {
233                    describe("before render", function() {
234                        it("should remove the maxlength attribute from the inputEl", function() {
235                            create(defaultConfig);
236                            field.setMaxLength(null);
237                            render();
238                            expect(field.getComponent().inputElement.getAttribute('maxlength')).toBeNull();
239                        });
240                    });
241
242                    describe("after render", function() {
243                        it("should remove the maxlength attribute from the inputEl", function() {
244                            create(defaultConfig);
245                            render();
246                            field.setMaxLength(null);
247                            expect(field.getComponent().inputElement.getAttribute('maxlength')).toBeNull();
248                        });
249                    });
250
251                });
252
253            });
254        });
255
256        describe("placeHolder", function() {
257            var defaultConfig = {
258                placeHolder: 'testing'
259            };
260
261            describe("configuration", function() {
262                it("should add the placeholder attribute to the inputEl", function() {
263                    create(defaultConfig);
264                    render();
265                    expect(field.getComponent().inputElement.getAttribute('placeholder')).toEqual('testing');
266                });
267            });
268
269            describe("method", function() {
270                describe("setting", function() {
271                    describe("before render", function() {
272                        it("should add the placeholder attribute to the inputEl", function() {
273                            create();
274                            field.setPlaceHolder('testing');
275                            render();
276                            expect(field.getComponent().inputElement.getAttribute('placeholder')).toEqual('testing');
277                        });
278                    });
279
280                    describe("after render", function() {
281                        it("should add the placeholder attribute to the inputEl", function() {
282                            create();
283                            render();
284                            field.setPlaceHolder('testing');
285                            expect(field.getComponent().inputElement.getAttribute('placeholder')).toEqual('testing');
286                        });
287                    });
288                });
289
290
291                describe("removing", function() {
292                    describe("before render", function() {
293                        it("should remove the placeholder attribute from the inputEl", function() {
294                            create(defaultConfig);
295                            field.setPlaceHolder(null);
296                            render();
297                            expect(field.getComponent().inputElement.getAttribute('placeholder')).toBeNull();
298                        });
299
300                    });
301
302                    describe("after render", function() {
303                        it("should remove the placeholder attribute from the inputEl", function() {
304                            create(defaultConfig);
305                            render();
306                            field.setPlaceHolder(null);
307                            expect(field.getComponent().inputElement.getAttribute('placeholder')).toBeNull();
308                        });
309                    });
310                });
311            });
312        });
313
314        describe("autoComplete", function() {
315            describe("using value 'on'", function() {
316                var defaultConfig = {
317                    autoComplete: 'on'
318                };
319
320                describe("configuration", function() {
321                    it("should add the autocomplete attribute to the inputEl", function() {
322                        create(defaultConfig);
323                        render();
324                        expect(field.getComponent().inputElement.getAttribute('autocomplete')).toEqual('on');
325                    });
326                });
327
328                describe("method", function() {
329                    describe("setting", function() {
330                        describe("before render", function() {
331                            it("should add the autocomplete attribute to the inputEl", function() {
332                                create();
333                                field.setAutoComplete('on');
334                                render();
335                                expect(field.getComponent().inputElement.getAttribute('autocomplete')).toEqual('on');
336                            });
337                        });
338
339                        describe("after render", function() {
340                            it("should add the autocomplete attribute to the inputEl", function() {
341                                create();
342                                render();
343                                field.setAutoComplete('on');
344                                expect(field.getComponent().inputElement.getAttribute('autocomplete')).toEqual('on');
345                            });
346                        });
347                    });
348
349
350                    describe("removing", function() {
351                        describe("before render", function() {
352                            it("should remove the autocomplete attribute from the inputEl", function() {
353                                create(defaultConfig);
354                                field.setAutoComplete(null);
355                                render();
356                                expect(field.getComponent().inputElement.getAttribute('autocomplete')).toBe('off');
357                            });
358
359                        });
360
361                        describe("after render", function() {
362                            it("should remove the autocomplete attribute from the inputEl", function() {
363                                create(defaultConfig);
364                                render();
365                                field.setAutoComplete(null);
366                                expect(field.getComponent().inputElement.getAttribute('autocomplete')).toBe('off');
367                            });
368                        });
369                    });
370                });
371            });
372
373            describe("using value true", function() {
374                var defaultConfig = {
375                    autoComplete: true
376                };
377
378                describe("configuration", function() {
379                    it("should add the autocomplete attribute to the inputEl", function() {
380                        create(defaultConfig);
381                        render();
382                        expect(field.getComponent().inputElement.getAttribute('autocomplete')).toEqual('on');
383                    });
384                });
385
386                describe("method", function() {
387                    describe("setting", function() {
388                        describe("before render", function() {
389                            it("should add the autocomplete attribute to the inputEl", function() {
390                                create();
391                                field.setAutoComplete(true);
392                                render();
393                                expect(field.getComponent().inputElement.getAttribute('autocomplete')).toEqual('on');
394                            });
395                        });
396
397                        describe("after render", function() {
398                            it("should add the autocomplete attribute to the inputEl", function() {
399                                create();
400                                render();
401                                field.setAutoComplete(true);
402                                expect(field.getComponent().inputElement.getAttribute('autocomplete')).toEqual('on');
403                            });
404                        });
405                    });
406
407
408                    describe("removing", function() {
409                        describe("before render", function() {
410                            it("should remove the autocomplete attribute from the inputEl", function() {
411                                create(defaultConfig);
412                                field.setAutoComplete(null);
413                                render();
414                                expect(field.getComponent().inputElement.getAttribute('autocomplete')).toBe('off');
415                            });
416
417                        });
418
419                        describe("after render", function() {
420                            it("should remove the autocomplete attribute from the inputEl", function() {
421                                create(defaultConfig);
422                                render();
423                                field.setAutoComplete(null);
424                                expect(field.getComponent().inputElement.getAttribute('autocomplete')).toBe('off');
425                            });
426                        });
427                    });
428                });
429            });
430
431            describe("using value 'off'", function() {
432                var defaultConfig = {
433                    autoComplete: 'off'
434                };
435
436                describe("configuration", function() {
437                    it("should add the autocomplete attribute to the inputEl", function() {
438                        create(defaultConfig);
439                        render();
440                        expect(field.getComponent().inputElement.getAttribute('autocomplete')).toEqual('off');
441                    });
442                });
443
444                describe("method", function() {
445                    describe("setting", function() {
446                        describe("before render", function() {
447                            it("should add the autocomplete attribute to the inputEl", function() {
448                                create();
449                                field.setAutoComplete('off');
450                                render();
451                                expect(field.getComponent().inputElement.getAttribute('autocomplete')).toEqual('off');
452                            });
453                        });
454                        describe("after render", function() {
455                            it("should add the autocomplete attribute to the inputEl", function() {
456                                create();
457                                render();
458                                field.setAutoComplete('off');
459                                expect(field.getComponent().inputElement.getAttribute('autocomplete')).toEqual('off');
460                            });
461                        });
462                    });
463                    describe("removing", function() {
464                        describe("before render", function() {
465                            it("should remove the autocomplete attribute from the inputEl", function() {
466                                create(defaultConfig);
467                                field.setAutoComplete(null);
468                                render();
469                                expect(field.getComponent().inputElement.getAttribute('autocomplete')).toBe('off');
470                            });
471
472                        });
473                        describe("after render", function() {
474                            it("should remove the autocomplete attribute from the inputEl", function() {
475                                create(defaultConfig);
476                                render();
477                                field.setAutoComplete(null);
478                                expect(field.getComponent().inputElement.getAttribute('autocomplete')).toBe('off');
479                            });
480                        });
481                    });
482                });
483            });
484
485            describe("using value false", function() {
486                var defaultConfig = {
487                    autoComplete: false
488                };
489
490                describe("configuration", function() {
491                    it("should add the autocomplete attribute to the inputEl", function() {
492                        create(defaultConfig);
493                        render();
494                        expect(field.getComponent().inputElement.getAttribute('autocomplete')).toEqual('off');
495                    });
496                });
497
498                describe("method", function() {
499                    describe("setting", function() {
500                        describe("before render", function() {
501                            it("should add the autocomplete attribute to the inputEl", function() {
502                                create();
503                                field.setAutoComplete(false);
504                                render();
505                                expect(field.getComponent().inputElement.getAttribute('autocomplete')).toEqual('off');
506                            });
507                        });
508
509                        describe("after render", function() {
510                            it("should add the autocomplete attribute to the inputEl", function() {
511                                create();
512                                render();
513                                field.setAutoComplete(false);
514                                expect(field.getComponent().inputElement.getAttribute('autocomplete')).toEqual('off');
515                            });
516                        });
517                    });
518
519
520                    describe("removing", function() {
521                        describe("before render", function() {
522                            it("should remove the autocomplete attribute from the inputEl", function() {
523                                create(defaultConfig);
524                                field.setAutoComplete(null);
525                                render();
526                                expect(field.getComponent().inputElement.getAttribute('autocomplete')).toBe('off');
527                            });
528
529                        });
530
531                        describe("after render", function() {
532                            it("should remove the autocomplete attribute from the inputEl", function() {
533                                create(defaultConfig);
534                                render();
535                                field.setAutoComplete(null);
536                                expect(field.getComponent().inputElement.getAttribute('autocomplete')).toBe('off');
537                            });
538                        });
539                    });
540                });
541            });
542        });
543
544        describe("autoCapitalize", function() {
545            describe("using value 'on'", function() {
546                var defaultConfig = {
547                    autoCapitalize: 'on'
548                };
549
550                describe("configuration", function() {
551                    it("should add the autocapitalize attribute to the inputEl", function() {
552                        create(defaultConfig);
553                        render();
554                        expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toEqual('on');
555                    });
556                });
557
558                describe("method", function() {
559                    describe("setting", function() {
560                        describe("before render", function() {
561                            it("should add the autocapitalize attribute to the inputEl", function() {
562                                create();
563                                field.setAutoCapitalize('on');
564                                render();
565                                expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toEqual('on');
566                            });
567                        });
568
569                        describe("after render", function() {
570                            it("should add the autocapitalize attribute to the inputEl", function() {
571                                create();
572                                render();
573                                field.setAutoCapitalize('on');
574                                expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toEqual('on');
575                            });
576                        });
577                    });
578
579
580                    describe("removing", function() {
581                        describe("before render", function() {
582                            it("should remove the autocapitalize attribute from the inputEl", function() {
583                                create(defaultConfig);
584                                field.setAutoCapitalize(null);
585                                render();
586                                expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toBe('off');
587                            });
588
589                        });
590
591                        describe("after render", function() {
592                            it("should remove the autocapitalize attribute from the inputEl", function() {
593                                create(defaultConfig);
594                                render();
595                                field.setAutoCapitalize(null);
596                                expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toBe('off');
597                            });
598                        });
599                    });
600                });
601            });
602
603            describe("using value true", function() {
604                var defaultConfig = {
605                    autoCapitalize: true
606                };
607
608                describe("configuration", function() {
609                    it("should add the autocapitalize attribute to the inputEl", function() {
610                        create(defaultConfig);
611                        render();
612                        expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toEqual('on');
613                    });
614                });
615
616                describe("method", function() {
617                    describe("setting", function() {
618                        describe("before render", function() {
619                            it("should add the autocapitalize attribute to the inputEl", function() {
620                                create();
621                                field.setAutoCapitalize(true);
622                                render();
623                                expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toEqual('on');
624                            });
625                        });
626
627                        describe("after render", function() {
628                            it("should add the autocapitalize attribute to the inputEl", function() {
629                                create();
630                                render();
631                                field.setAutoCapitalize(true);
632                                expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toEqual('on');
633                            });
634                        });
635                    });
636
637
638                    describe("removing", function() {
639                        describe("before render", function() {
640                            it("should remove the autocapitalize attribute from the inputEl", function() {
641                                create(defaultConfig);
642                                field.setAutoCapitalize(null);
643                                render();
644                                expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toBe('off');
645                            });
646
647                        });
648
649                        describe("after render", function() {
650                            it("should remove the autocapitalize attribute from the inputEl", function() {
651                                create(defaultConfig);
652                                render();
653                                field.setAutoCapitalize(null);
654                                expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toBe('off');
655                            });
656                        });
657                    });
658                });
659            });
660
661            describe("using value 'off'", function() {
662                var defaultConfig = {
663                    autoCapitalize: 'off'
664                };
665
666                describe("configuration", function() {
667                    it("should add the autocapitalize attribute to the inputEl", function() {
668                        create(defaultConfig);
669                        render();
670                        expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toEqual('off');
671                    });
672                });
673
674                describe("method", function() {
675                    describe("setting", function() {
676                        describe("before render", function() {
677                            it("should add the autocapitalize attribute to the inputEl", function() {
678                                create();
679                                field.setAutoCapitalize('off');
680                                render();
681                                expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toEqual('off');
682                            });
683                        });
684                        describe("after render", function() {
685                            it("should add the autocapitalize attribute to the inputEl", function() {
686                                create();
687                                render();
688                                field.setAutoCapitalize('off');
689                                expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toEqual('off');
690                            });
691                        });
692                    });
693                    describe("removing", function() {
694                        describe("before render", function() {
695                            it("should remove the autocapitalize attribute from the inputEl", function() {
696                                create(defaultConfig);
697                                field.setAutoCapitalize(null);
698                                render();
699                                expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toBe('off');
700                            });
701
702                        });
703                        describe("after render", function() {
704                            it("should remove the autocapitalize attribute from the inputEl", function() {
705                                create(defaultConfig);
706                                render();
707                                field.setAutoCapitalize(null);
708                                expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toBe('off');
709                            });
710                        });
711                    });
712                });
713            });
714
715            describe("using value false", function() {
716                var defaultConfig = {
717                    autoCapitalize: false
718                };
719
720                describe("configuration", function() {
721                    it("should add the autocapitalize attribute to the inputEl", function() {
722                        create(defaultConfig);
723                        render();
724                        expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toEqual('off');
725                    });
726                });
727
728                describe("method", function() {
729                    describe("setting", function() {
730                        describe("before render", function() {
731                            it("should add the autocapitalize attribute to the inputEl", function() {
732                                create();
733                                field.setAutoCapitalize(false);
734                                render();
735                                expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toEqual('off');
736                            });
737                        });
738
739                        describe("after render", function() {
740                            it("should add the autocapitalize attribute to the inputEl", function() {
741                                create();
742                                render();
743                                field.setAutoCapitalize(false);
744                                expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toEqual('off');
745                            });
746                        });
747                    });
748
749
750                    describe("removing", function() {
751                        describe("before render", function() {
752                            it("should remove the autocapitalize attribute from the inputEl", function() {
753                                create(defaultConfig);
754                                field.setAutoCapitalize(null);
755                                render();
756                                expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toBe('off');
757                            });
758
759                        });
760
761                        describe("after render", function() {
762                            it("should remove the autocapitalize attribute from the inputEl", function() {
763                                create(defaultConfig);
764                                render();
765                                field.setAutoCapitalize(null);
766                                expect(field.getComponent().inputElement.getAttribute('autocapitalize')).toBe('off');
767                            });
768                        });
769                    });
770                });
771            });
772        });
773
774
775        describe("autoCorrect", function() {
776            describe("using value 'on'", function() {
777                var defaultConfig = {
778                    autoCorrect: 'on'
779                };
780
781                describe("configuration", function() {
782                    it("should add the autocorrect attribute to the inputEl", function() {
783                        create(defaultConfig);
784                        render();
785                        expect(field.getComponent().inputElement.getAttribute('autocorrect')).toEqual('on');
786                    });
787                });
788
789                describe("method", function() {
790                    describe("setting", function() {
791                        describe("before render", function() {
792                            it("should add the autocorrect attribute to the inputEl", function() {
793                                create();
794                                field.setAutoCorrect('on');
795                                render();
796                                expect(field.getComponent().inputElement.getAttribute('autocorrect')).toEqual('on');
797                            });
798                        });
799
800                        describe("after render", function() {
801                            it("should add the autocorrect attribute to the inputEl", function() {
802                                create();
803                                render();
804                                field.setAutoCorrect('on');
805                                expect(field.getComponent().inputElement.getAttribute('autocorrect')).toEqual('on');
806                            });
807                        });
808                    });
809
810
811                    describe("removing", function() {
812                        describe("before render", function() {
813                            it("should remove the autocorrect attribute from the inputEl", function() {
814                                create(defaultConfig);
815                                field.setAutoCorrect(null);
816                                render();
817                                expect(field.getComponent().inputElement.getAttribute('autocorrect')).toBe('off');
818                            });
819
820                        });
821
822                        describe("after render", function() {
823                            it("should remove the autocorrect attribute from the inputEl", function() {
824                                create(defaultConfig);
825                                render();
826                                field.setAutoCorrect(null);
827                                expect(field.getComponent().inputElement.getAttribute('autocorrect')).toBe('off');
828                            });
829                        });
830                    });
831                });
832            });
833
834            describe("using value true", function() {
835                var defaultConfig = {
836                    autoCorrect: true
837                };
838
839                describe("configuration", function() {
840                    it("should add the autocorrect attribute to the inputEl", function() {
841                        create(defaultConfig);
842                        render();
843                        expect(field.getComponent().inputElement.getAttribute('autocorrect')).toEqual('on');
844                    });
845                });
846
847                describe("method", function() {
848                    describe("setting", function() {
849                        describe("before render", function() {
850                            it("should add the autocorrect attribute to the inputEl", function() {
851                                create();
852                                field.setAutoCorrect(true);
853                                render();
854                                expect(field.getComponent().inputElement.getAttribute('autocorrect')).toEqual('on');
855                            });
856                        });
857
858                        describe("after render", function() {
859                            it("should add the autocorrect attribute to the inputEl", function() {
860                                create();
861                                render();
862                                field.setAutoCorrect(true);
863                                expect(field.getComponent().inputElement.getAttribute('autocorrect')).toEqual('on');
864                            });
865                        });
866                    });
867
868
869                    describe("removing", function() {
870                        describe("before render", function() {
871                            it("should remove the autocorrect attribute from the inputEl", function() {
872                                create(defaultConfig);
873                                field.setAutoCorrect(null);
874                                render();
875                                expect(field.getComponent().inputElement.getAttribute('autocorrect')).toBe('off');
876                            });
877
878                        });
879
880                        describe("after render", function() {
881                            it("should remove the autocorrect attribute from the inputEl", function() {
882                                create(defaultConfig);
883                                render();
884                                field.setAutoCorrect(null);
885                                expect(field.getComponent().inputElement.getAttribute('autocorrect')).toBe('off');
886                            });
887                        });
888                    });
889                });
890            });
891
892            describe("using value 'off'", function() {
893                var defaultConfig = {
894                    autoCorrect: 'off'
895                };
896
897                describe("configuration", function() {
898                    it("should add the autocorrect attribute to the inputEl", function() {
899                        create(defaultConfig);
900                        render();
901                        expect(field.getComponent().inputElement.getAttribute('autocorrect')).toEqual('off');
902                    });
903                });
904
905                describe("method", function() {
906                    describe("setting", function() {
907                        describe("before render", function() {
908                            it("should add the autocorrect attribute to the inputEl", function() {
909                                create();
910                                field.setAutoCorrect('off');
911                                render();
912                                expect(field.getComponent().inputElement.getAttribute('autocorrect')).toEqual('off');
913                            });
914                        });
915                        describe("after render", function() {
916                            it("should add the autocorrect attribute to the inputEl", function() {
917                                create();
918                                render();
919                                field.setAutoCorrect('off');
920                                expect(field.getComponent().inputElement.getAttribute('autocorrect')).toEqual('off');
921                            });
922                        });
923                    });
924                    describe("removing", function() {
925                        describe("before render", function() {
926                            it("should remove the autocorrect attribute from the inputEl", function() {
927                                create(defaultConfig);
928                                field.setAutoCorrect(null);
929                                render();
930                                expect(field.getComponent().inputElement.getAttribute('autocorrect')).toBe('off');
931                            });
932
933                        });
934                        describe("after render", function() {
935                            it("should remove the autocorrect attribute from the inputEl", function() {
936                                create(defaultConfig);
937                                render();
938                                field.setAutoCorrect(null);
939                                expect(field.getComponent().inputElement.getAttribute('autocorrect')).toBe('off');
940                            });
941                        });
942                    });
943                });
944            });
945
946            describe("using value false", function() {
947                var defaultConfig = {
948                    autoCorrect: false
949                };
950
951                describe("configuration", function() {
952                    it("should add the autocorrect attribute to the inputEl", function() {
953                        create(defaultConfig);
954                        render();
955                        expect(field.getComponent().inputElement.getAttribute('autocorrect')).toEqual('off');
956                    });
957                });
958
959                describe("method", function() {
960                    describe("setting", function() {
961                        describe("before render", function() {
962                            it("should add the autocorrect attribute to the inputEl", function() {
963                                create();
964                                field.setAutoCorrect(false);
965                                render();
966                                expect(field.getComponent().inputElement.getAttribute('autocorrect')).toEqual('off');
967                            });
968                        });
969
970                        describe("after render", function() {
971                            it("should add the autocorrect attribute to the inputEl", function() {
972                                create();
973                                render();
974                                field.setAutoCorrect(false);
975                                expect(field.getComponent().inputElement.getAttribute('autocorrect')).toEqual('off');
976                            });
977                        });
978                    });
979
980
981                    describe("removing", function() {
982                        describe("before render", function() {
983                            it("should remove the autocorrect attribute from the inputEl", function() {
984                                create(defaultConfig);
985                                field.setAutoCorrect(null);
986                                render();
987                                expect(field.getComponent().inputElement.getAttribute('autocorrect')).toBe('off');
988                            });
989
990                        });
991
992                        describe("after render", function() {
993                            it("should remove the autocorrect attribute from the inputEl", function() {
994                                create(defaultConfig);
995                                render();
996                                field.setAutoCorrect(null);
997                                expect(field.getComponent().inputElement.getAttribute('autocorrect')).toBe('off');
998                            });
999                        });
1000                    });
1001                });
1002            });
1003        });
1004    });
1005
1006    describe("methods", function() {
1007        describe("reset", function() {
1008            beforeEach(function () {
1009                create({
1010                    value: 'foo'
1011                });
1012                render();
1013                field.setValue('foobar');
1014            });
1015
1016            it("should update the input field element", function () {
1017                field.reset();
1018
1019                expect(field.getComponent().input.dom.value).toBe('foo');
1020            });
1021
1022            it("should synchronize the value of the component with the field", function () {
1023                field.reset();
1024
1025                expect(field.getValue()).toBe('foo');
1026                expect(field.getComponent().getValue()).toBe('foo');
1027            });
1028        });
1029    });
1030});
1031
Full Screen

GmlRectifiedGrid.js

Source: GmlRectifiedGrid.js Github

copy
1/*
2 * Copyright 2003-2006, 2009, 2017, United States Government, as represented by the Administrator of the
3 * National Aeronautics and Space Administration. All rights reserved.
4 *
5 * The NASAWorldWind/WebWorldWind platform is licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/**
18 * @exports GmlRectifiedGrid
19 */
20define([
21        '../../error/ArgumentError',
22        '../../util/Logger'
23    ],
24    function (ArgumentError,
25              Logger) {
26        "use strict";
27
28        var GmlRectifiedGrid = function (element) {
29            if (!element) {
30                throw new ArgumentError(
31                    Logger.logMessage(Logger.LEVEL_SEVERE, "GmlRectifiedGrid", "constructor", "missingDom"));
32            }
33
34            this.assembleElement(element);
35        };
36
37        // Internal. Intentionally not documented.
38        GmlRectifiedGrid.prototype.assembleElement = function (element) {
39            var children = element.children || element.childNodes;
40
41            this.captureAttributes(element);
42
43            for (var c = 0; c < children.length; c++) {
44                var child = children[c];
45
46                if (child.localName === "description") {
47                    this.description = child.textContent;
48                } else if (child.localName === "descriptionReference") {
49                    this.descriptionReference = child.getAttribute("xlink:href");
50                } else if (child.localName === "identifier") {
51                    this.identifier = child.textContent;
52                } else if (child.localName === "name") {
53                    this.names = this.names || [];
54                    this.names.push(child.textContent);
55                } else if (child.localName === "limits") {
56                    this.limits = this.assembleLimits(child);
57                } else if (child.localName === "axisLabels") {
58                    this.axisLabels = child.textContent.split(/\s+/);
59                } else if (child.localName === "axisName") {
60                    this.axisNames = this.axisNames || [];
61                    this.axisNames.push(child.textContent);
62                } else if (child.localName === "origin") {
63                    this.origin = this.assembleOrigin(child);
64                } else if (child.localName === "offsetVector") {
65                    this.offsetVector = this.offsetVector || [];
66                    this.offsetVector.push(this.assembleOffsetVector(child));
67                }
68            }
69        };
70
71        // Internal. Intentionally not documented.
72        GmlRectifiedGrid.prototype.captureAttributes = function (element) {
73            this.id = element.getAttribute("gml:id");
74            this.srsName = element.getAttribute("srsName");
75            this.srsDimension = element.getAttribute("srsDimension");
76            this.axisLabels = element.getAttribute("axisLabels");
77            if (this.axisLabels) {
78                this.axisLabels = this.axisLabels.split(/\s+/);
79            }
80            this.uomLabels = element.getAttribute("uomLabels");
81            if (this.uomLabels) {
82                this.uomLabels = this.uomLabels.split(/\s+/);
83            }
84            this.dimension = parseInt(element.getAttribute("dimension"));
85        };
86
87        // Internal. Intentionally not documented.
88        GmlRectifiedGrid.prototype.assembleLimits = function (element) {
89            var children = element.children || element.childNodes;
90
91            for (var c = 0; c < children.length; c++) {
92                var child = children[c];
93
94                if (child.localName === "GridEnvelope") {
95                    return this.assembleGridEnvelope(child);
96                }
97            }
98        };
99
100        // Internal. Intentionally not documented.
101        GmlRectifiedGrid.prototype.assembleGridEnvelope = function (element) {
102            var children = element.children || element.childNodes, envelop = {};
103
104            for (var c = 0; c < children.length; c++) {
105                var child = children[c];
106                envelop[child.localName] = child.textContent.split(/\s+/);
107            }
108
109            return envelop;
110        };
111
112        // Internal. Intentionally not documented.
113        GmlRectifiedGrid.prototype.assembleOrigin = function (element) {
114            var origin = {};
115            origin.type = element.getAttribute("xlink:type");
116            origin.href = element.getAttribute("xlink:href");
117            origin.role = element.getAttribute("xlink:role");
118            origin.arcrole = element.getAttribute("xlink:arcrole");
119            origin.title = element.getAttribute("xlink:title");
120            origin.show = element.getAttribute("xlink:show");
121            origin.actuate = element.getAttribute("xlink:actuate");
122            origin.nilReason = element.getAttribute("nilReason");
123            origin.remoteSchema = element.getAttribute("gml:remoteSchema");
124            origin.owns = element.getAttribute("owns");
125
126            var children = element.children || element.childNodes;
127
128            for (var c = 0; c < children.length; c++) {
129                var child = children[c];
130
131                if (child.localName === "Point") {
132                    origin.point = this.assemblePoint(child);
133                } else if (child.localName === "pos") {
134                    origin.pos = this.assemblePos(child);
135                }
136            }
137
138            return origin;
139        };
140
141        // Internal. Intentionally not documented.
142        GmlRectifiedGrid.prototype.assemblePoint = function (element) {
143            var point = {}, pos = {};
144            point.id = element.getAttribute("gml:id");
145            point.srsName = element.getAttribute("srsName");
146            point.srsDimension = element.getAttribute("srsDimension");
147            point.axisLabels = element.getAttribute("axisLabels");
148            if (point.axisLabels) {
149                point.axisLabels = point.axisLabels.split(/\s+/);
150            }
151            point.uomLabels = element.getAttribute("uomLabels");
152            if (point.uomLabels) {
153                point.uomLabels = point.uomLabels.split(/\s+/);
154            }
155
156            var children = element.children || element.childNodes;
157
158            for (var c = 0; c < children.length; c++) {
159                var child = children[c];
160
161                if (child.localName === "description") {
162                    point.description = child.textContent;
163                } else if (child.localName === "descriptionReference") {
164                    point.descriptionReference = this.assembleOrigin(child);
165                } else if (child.localName === "identifier") {
166                    point.identifier = child.textContent;
167                } else if (child.localName === "name") {
168                    point.name = child.textContent;
169                } else if (child.localName === "pos") {
170                    point.pos = this.assemblePos(child);
171                }
172            }
173
174            return point;
175        };
176
177        // Internal. Intentionally not documented.
178        GmlRectifiedGrid.prototype.assemblePos = function (child) {
179            var pos = {};
180            pos.srsName = child.getAttribute("srsName");
181            pos.srsDimension = parseInt(child.getAttribute("srsDimension"));
182            pos.axisLabels = child.getAttribute("axisLabels");
183            if (pos.axisLabels) {
184                pos.axisLabels = pos.axisLabels.split(/\s+/);
185            }
186            pos.uomLabels = child.getAttribute("uomLabels");
187            if (pos.uomLabels) {
188                pos.uomLabels = pos.uomLabels.split(/\s+/);
189            }
190            pos.pos = child.textContent;
191            if (pos.pos) {
192                pos.pos = pos.pos.split(/\s+/);
193                for (var p = 0; p < pos.pos.length; p++) {
194                    pos.pos[p] = parseFloat(pos.pos[p]);
195                }
196            }
197
198            return pos;
199        };
200
201        // Internal. Intentionally not documented.
202        GmlRectifiedGrid.prototype.assembleOffsetVector = function (element) {
203            var children = element.children || element.childNodes, offsetVector = {}, rawValues;
204
205            // Collect and store associated attributes
206            offsetVector.srsName = element.getAttribute("srsName");
207            offsetVector.srsDimension = parseInt(element.getAttribute("srsDimension"));
208            offsetVector.axisLabels = element.getAttribute("axisLabels");
209            if (offsetVector.axisLabels) {
210                offsetVector.axisLabels = offsetVector.axisLabels.split(/\s+/);
211            }
212            offsetVector.uomLabels = element.getAttribute("uomLabels");
213            if (offsetVector.uomLabels) {
214                offsetVector.uomLabels = offsetVector.uomLabels.split(/\s+/);
215            }
216
217            rawValues = element.textContent.split(/\s+/);
218            offsetVector.values = [];
219            for (var i = 0; i < rawValues.length; i++) {
220                offsetVector.values.push(parseFloat(rawValues[i]));
221            }
222
223            return offsetVector;
224        };
225
226        return GmlRectifiedGrid;
227    });
228
Full Screen

jquery.unobtrusive-ajax.js

Source: jquery.unobtrusive-ajax.js Github

copy
1/*!
2** Unobtrusive Ajax support library for jQuery
3** Copyright (C) Microsoft Corporation. All rights reserved.
4*/
5
6/*jslint white: true, browser: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: false */
7/*global window: false, jQuery: false */
8
9(function ($) {
10    var data_click = "unobtrusiveAjaxClick",
11        data_validation = "unobtrusiveValidation";
12
13    function getFunction(code, argNames) {
14        var fn = window, parts = (code || "").split(".");
15        while (fn && parts.length) {
16            fn = fn[parts.shift()];
17        }
18        if (typeof (fn) === "function") {
19            return fn;
20        }
21        argNames.push(code);
22        return Function.constructor.apply(null, argNames);
23    }
24
25    function isMethodProxySafe(method) {
26        return method === "GET" || method === "POST";
27    }
28
29    function asyncOnBeforeSend(xhr, method) {
30        if (!isMethodProxySafe(method)) {
31            xhr.setRequestHeader("X-HTTP-Method-Override", method);
32        }
33    }
34
35    function asyncOnSuccess(element, data, contentType) {
36        var mode;
37
38        if (contentType.indexOf("application/x-javascript") !== -1) {  // jQuery already executes JavaScript for us
39            return;
40        }
41
42        mode = (element.getAttribute("data-ajax-mode") || "").toUpperCase();
43        $(element.getAttribute("data-ajax-update")).each(function (i, update) {
44            var top;
45
46            switch (mode) {
47            case "BEFORE":
48                top = update.firstChild;
49                $("<div />").html(data).contents().each(function () {
50                    update.insertBefore(this, top);
51                });
52                break;
53            case "AFTER":
54                $("<div />").html(data).contents().each(function () {
55                    update.appendChild(this);
56                });
57                break;
58            default:
59                $(update).html(data);
60                break;
61            }
62        });
63    }
64
65    function asyncRequest(element, options) {
66        var confirm, loading, method, duration;
67
68        confirm = element.getAttribute("data-ajax-confirm");
69        if (confirm && !window.confirm(confirm)) {
70            return;
71        }
72
73        loading = $(element.getAttribute("data-ajax-loading"));
74        duration = element.getAttribute("data-ajax-loading-duration") || 0;
75
76        $.extend(options, {
77            type: element.getAttribute("data-ajax-method") || undefined,
78            url: element.getAttribute("data-ajax-url") || undefined,
79            beforeSend: function (xhr) {
80                var result;
81                asyncOnBeforeSend(xhr, method);
82                result = getFunction(element.getAttribute("data-ajax-begin"), ["xhr"]).apply(this, arguments);
83                if (result !== false) {
84                    loading.show(duration);
85                }
86                return result;
87            },
88            complete: function () {
89                loading.hide(duration);
90                getFunction(element.getAttribute("data-ajax-complete"), ["xhr", "status"]).apply(this, arguments);
91            },
92            success: function (data, status, xhr) {
93                asyncOnSuccess(element, data, xhr.getResponseHeader("Content-Type") || "text/html");
94                getFunction(element.getAttribute("data-ajax-success"), ["data", "status", "xhr"]).apply(this, arguments);
95            },
96            error: getFunction(element.getAttribute("data-ajax-failure"), ["xhr", "status", "error"])
97        });
98
99        options.data.push({ name: "X-Requested-With", value: "XMLHttpRequest" });
100
101        method = options.type.toUpperCase();
102        if (!isMethodProxySafe(method)) {
103            options.type = "POST";
104            options.data.push({ name: "X-HTTP-Method-Override", value: method });
105        }
106
107        $.ajax(options);
108    }
109
110    function validate(form) {
111        var validationInfo = $(form).data(data_validation);
112        return !validationInfo || !validationInfo.validate || validationInfo.validate();
113    }
114
115    $(document).on("click", "a[data-ajax=true]", function (evt) {
116        evt.preventDefault();
117        asyncRequest(this, {
118            url: this.href,
119            type: "GET",
120            data: []
121        });
122    });
123
124    $(document).on("click", "form[data-ajax=true] input[type=image]", function (evt) {
125        var name = evt.target.name,
126            $target = $(evt.target),
127            form = $target.parents("form")[0],
128            offset = $target.offset();
129
130        $(form).data(data_click, [
131            { name: name + ".x", value: Math.round(evt.pageX - offset.left) },
132            { name: name + ".y", value: Math.round(evt.pageY - offset.top) }
133        ]);
134
135        setTimeout(function () {
136            $(form).removeData(data_click);
137        }, 0);
138    });
139
140    $(document).on("click", "form[data-ajax=true] :submit", function (evt) {
141        var name = evt.target.name,
142            form = $(evt.target).parents("form")[0];
143
144        $(form).data(data_click, name ? [{ name: name, value: evt.target.value }] : []);
145
146        setTimeout(function () {
147            $(form).removeData(data_click);
148        }, 0);
149    });
150
151    $(document).on("submit", "form[data-ajax=true]", function (evt) {
152        var clickInfo = $(this).data(data_click) || [];
153        evt.preventDefault();
154        if (!validate(this)) {
155            return;
156        }
157        asyncRequest(this, {
158            url: this.action,
159            type: this.method || "GET",
160            data: clickInfo.concat($(this).serializeArray())
161        });
162    });
163}(jQuery));
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)