1
1
describe ( 'autocomplete-matches' , function ( ) {
2
2
'use strict' ;
3
3
var fixture = document . getElementById ( 'fixture' ) ;
4
+ var queryFixture = axe . testUtils . queryFixture ;
4
5
var rule = axe . _audit . rules . find ( function ( rule ) {
5
6
return rule . id === 'autocomplete-valid' ;
6
7
} ) ;
@@ -14,105 +15,88 @@ describe('autocomplete-matches', function() {
14
15
} ) ;
15
16
16
17
it ( 'returns true for input elements' , function ( ) {
17
- var elm = document . createElement ( 'input' ) ;
18
- elm . setAttribute ( 'autocomplete' , 'foo' ) ;
19
- fixture . appendChild ( elm ) ;
20
- assert . isTrue ( rule . matches ( elm ) ) ;
18
+ var vNode = queryFixture ( '<input id="target" autocomplete="foo">' ) ;
19
+ assert . isTrue ( rule . matches ( null , vNode ) ) ;
21
20
} ) ;
22
21
23
22
it ( 'returns true for select elements' , function ( ) {
24
- var elm = document . createElement ( 'select' ) ;
25
- elm . setAttribute ( 'autocomplete' , 'foo' ) ;
26
- fixture . appendChild ( elm ) ;
27
- assert . isTrue ( rule . matches ( elm ) ) ;
23
+ var vNode = queryFixture ( '<select id="target" autocomplete="foo">' ) ;
24
+ assert . isTrue ( rule . matches ( null , vNode ) ) ;
28
25
} ) ;
29
26
30
27
it ( 'returns true for textarea elements' , function ( ) {
31
- var elm = document . createElement ( 'textarea' ) ;
32
- elm . setAttribute ( 'autocomplete' , 'foo' ) ;
33
- fixture . appendChild ( elm ) ;
34
- assert . isTrue ( rule . matches ( elm ) ) ;
28
+ var vNode = queryFixture ( '<textarea id="target" autocomplete="foo">' ) ;
29
+ assert . isTrue ( rule . matches ( null , vNode ) ) ;
35
30
} ) ;
36
31
37
32
it ( 'returns false for buttons elements' , function ( ) {
38
- var elm = document . createElement ( 'button' ) ;
39
- elm . setAttribute ( 'autocomplete' , 'foo' ) ;
40
- fixture . appendChild ( elm ) ;
41
- assert . isFalse ( rule . matches ( elm ) ) ;
33
+ var vNode = queryFixture ( '<button id="target" autocomplete="foo">' ) ;
34
+ assert . isFalse ( rule . matches ( null , vNode ) ) ;
42
35
} ) ;
43
36
44
37
it ( 'should return false for non-form field elements' , function ( ) {
45
- var elm = document . createElement ( 'div' ) ;
46
- elm . setAttribute ( 'autocomplete' , 'foo' ) ;
47
- fixture . appendChild ( elm ) ;
48
- assert . isFalse ( rule . matches ( elm ) ) ;
38
+ var vNode = queryFixture ( '<div id="target" autocomplete="foo">' ) ;
39
+ assert . isFalse ( rule . matches ( null , vNode ) ) ;
49
40
} ) ;
50
41
51
42
it ( 'returns false for input buttons' , function ( ) {
52
43
[ 'reset' , 'submit' , 'button' ] . forEach ( function ( type ) {
53
- var elm = document . createElement ( 'input' ) ;
54
- elm . setAttribute ( 'autocomplete' , 'foo' ) ;
55
- elm . type = type ;
56
- fixture . appendChild ( elm ) ;
57
- assert . isFalse ( rule . matches ( elm ) ) ;
44
+ var vNode = queryFixture (
45
+ '<input id="target" type="' + type + '" autocomplete="foo">'
46
+ ) ;
47
+ assert . isFalse ( rule . matches ( null , vNode ) ) ;
58
48
} ) ;
59
49
} ) ;
60
50
61
51
it ( 'returns false for elements with an empty autocomplete' , function ( ) {
62
- var elm = document . createElement ( 'input' ) ;
63
- elm . setAttribute ( 'autocomplete' , ' ' ) ;
64
- fixture . appendChild ( elm ) ;
65
- assert . isFalse ( rule . matches ( elm ) ) ;
52
+ var vNode = queryFixture ( '<input id="target" autocomplete=" ">' ) ;
53
+ assert . isFalse ( rule . matches ( null , vNode ) ) ;
66
54
} ) ;
67
55
68
56
it ( 'returns false for intput[type=hidden]' , function ( ) {
69
- var elm = document . createElement ( 'input' ) ;
70
- elm . setAttribute ( 'autocomplete' , 'foo' ) ;
71
- elm . type = 'hidden' ;
72
- fixture . appendChild ( elm ) ;
73
- assert . isFalse ( rule . matches ( elm ) ) ;
57
+ var vNode = queryFixture (
58
+ '<input id="target" type="hidden" autocomplete="foo">'
59
+ ) ;
60
+ assert . isFalse ( rule . matches ( null , vNode ) ) ;
74
61
} ) ;
75
62
76
63
it ( 'returns false for disabled fields' , function ( ) {
77
64
[ 'input' , 'select' , 'textarea' ] . forEach ( function ( tagName ) {
78
- var elm = document . createElement ( tagName ) ;
79
- elm . setAttribute ( 'autocomplete' , 'foo' ) ;
80
- elm . disabled = true ;
81
- fixture . appendChild ( elm ) ;
82
- assert . isFalse ( rule . matches ( elm ) ) ;
65
+ var vNode = queryFixture (
66
+ '<' + tagName + ' id="target" disabled autocomplete="foo">'
67
+ ) ;
68
+ assert . isFalse ( rule . matches ( null , vNode ) ) ;
83
69
} ) ;
84
70
} ) ;
85
71
86
72
it ( 'returns false for aria-disabled=true fields' , function ( ) {
87
73
[ 'input' , 'select' , 'textarea' ] . forEach ( function ( tagName ) {
88
- var elm = document . createElement ( tagName ) ;
89
- elm . setAttribute ( 'autocomplete' , 'foo' ) ;
90
- elm . setAttribute ( 'aria-disabled' , 'true' ) ;
91
- fixture . appendChild ( elm ) ;
92
- assert . isFalse ( rule . matches ( elm ) ) ;
74
+ var vNode = queryFixture (
75
+ '<' + tagName + ' id="target" aria-disabled="true" autocomplete="foo">'
76
+ ) ;
77
+ assert . isFalse ( rule . matches ( null , vNode ) ) ;
93
78
} ) ;
94
79
} ) ;
95
80
96
81
it ( 'returns true for aria-disabled=false fields' , function ( ) {
97
82
[ 'input' , 'select' , 'textarea' ] . forEach ( function ( tagName ) {
98
- var elm = document . createElement ( tagName ) ;
99
- elm . setAttribute ( 'autocomplete' , 'foo' ) ;
100
- elm . setAttribute ( 'aria-disabled' , 'false' ) ;
101
- fixture . appendChild ( elm ) ;
102
- assert . isTrue ( rule . matches ( elm ) ) ;
83
+ var vNode = queryFixture (
84
+ '<' + tagName + ' id="target" aria-disabled="false" autocomplete="foo">'
85
+ ) ;
86
+ assert . isTrue ( rule . matches ( null , vNode ) ) ;
103
87
} ) ;
104
88
} ) ;
105
89
106
90
it ( 'returns false for non-widget roles with tabindex=-1' , function ( ) {
107
91
var nonWidgetRoles = [ 'application' , 'fakerole' , 'main' ] ;
108
92
nonWidgetRoles . forEach ( function ( role ) {
109
- var elm = document . createElement ( 'input' ) ;
110
- elm . setAttribute ( 'autocomplete' , 'foo' ) ;
111
- elm . setAttribute ( ' role' , role ) ;
112
- elm . setAttribute ( 'tabindex' , '-1' ) ;
113
- fixture . appendChild ( elm ) ;
93
+ var vNode = queryFixture (
94
+ '<input id="target" role="' +
95
+ role +
96
+ '" tabindex="-1" autocomplete="foo">'
97
+ ) ;
114
98
assert . isFalse (
115
- rule . matches ( elm ) ,
99
+ rule . matches ( null , vNode ) ,
116
100
'Expect role=' + role + ' to be ignored when it has tabindex=-1'
117
101
) ;
118
102
} ) ;
@@ -121,36 +105,30 @@ describe('autocomplete-matches', function() {
121
105
it ( 'returns true for form fields with a widget role with tabindex=-1' , function ( ) {
122
106
var nonWidgetRoles = [ 'button' , 'menuitem' , 'slider' ] ;
123
107
nonWidgetRoles . forEach ( function ( role ) {
124
- var elm = document . createElement ( 'input' ) ;
125
- elm . setAttribute ( 'autocomplete' , 'foo' ) ;
126
- elm . setAttribute ( ' role' , role ) ;
127
- elm . setAttribute ( 'tabindex' , '-1' ) ;
128
- fixture . appendChild ( elm ) ;
129
- assert . isTrue ( rule . matches ( elm ) ) ;
108
+ var vNode = queryFixture (
109
+ '<input id="target" role="' +
110
+ role +
111
+ '" tabindex="-1" autocomplete="foo">'
112
+ ) ;
113
+ assert . isTrue ( rule . matches ( null , vNode ) ) ;
130
114
} ) ;
131
115
} ) ;
132
116
133
117
it ( 'returns true for form fields with tabindex=-1' , function ( ) {
134
118
[ 'input' , 'select' , 'textarea' ] . forEach ( function ( tagName ) {
135
- var elm = document . createElement ( tagName ) ;
136
- elm . setAttribute ( 'autocomplete' , 'foo' ) ;
137
- elm . setAttribute ( 'tabindex' , - 1 ) ;
138
- fixture . appendChild ( elm ) ;
139
- assert . isTrue ( rule . matches ( elm ) ) ;
119
+ var vNode = queryFixture (
120
+ '<' + tagName + ' id="target" tabindex="-1" autocomplete="foo">'
121
+ ) ;
122
+ assert . isTrue ( rule . matches ( null , vNode ) ) ;
140
123
} ) ;
141
124
} ) ;
142
125
143
126
it ( 'returns false for off screen and hidden form fields with tabindex=-1' , function ( ) {
144
- var elm = document . createElement ( 'input' ) ;
145
- elm . setAttribute ( 'autocomplete' , 'foo' ) ;
146
- elm . setAttribute ( 'tabindex' , - 1 ) ;
147
- elm . setAttribute ( 'style' , 'position:absolute; top:-9999em' ) ;
148
-
149
- var parent = document . createElement ( 'div' ) ;
150
- parent . appendChild ( elm ) ;
151
- parent . setAttribute ( 'aria-hidden' , 'true' ) ;
152
-
153
- fixture . appendChild ( parent ) ;
154
- assert . isFalse ( rule . matches ( elm ) ) ;
127
+ var vNode = queryFixture (
128
+ '<div aria-hidden="true">' +
129
+ '<input id="target" tabindex="-1" style="position:absolute; top:-9999em" autocomplete="foo">' +
130
+ '</div>'
131
+ ) ;
132
+ assert . isFalse ( rule . matches ( null , vNode ) ) ;
155
133
} ) ;
156
134
} ) ;
0 commit comments