Moving the easing check logic to the fx function, since Interface was overwriting...
[jquery.git] / src / selector / selectorTest.js
1 module("selector");
2
3 test("element", function() {
4         expect(9);
5         ok( $("*").size() >= 30, "Select all" );
6         t( "Element Selector", "div", ["main","foo"] );
7         t( "Element Selector", "body", ["body"] );
8         t( "Element Selector", "html", ["html"] );
9         t( "Parent Element", "div div", ["foo"] );
10         ok( $("param", "#object1").length == 2, "Object/param as context" );
11         
12         ok( $("#length").length, '<input name="length"> cannot be found under IE, see #945' );
13         ok( $("#lengthtest input").length, '<input name="length"> cannot be found under IE, see #945' );
14
15         t( "Element Selector with underscore", "foo_bar", ["foobar"] );
16 });
17
18 test("broken", function() {
19         expect(7);
20         t( "Broken Selector", "[", [] );
21         t( "Broken Selector", "(", [] );
22         t( "Broken Selector", "{", [] );
23         t( "Broken Selector", "<", [] );
24         t( "Broken Selector", "()", [] );
25         t( "Broken Selector", "<>", [] );
26         t( "Broken Selector", "{}", [] );
27 });
28
29 test("id", function() {
30         expect(24);
31         t( "ID Selector", "#body", ["body"] );
32         t( "ID Selector w/ Element", "body#body", ["body"] );
33         t( "ID Selector w/ Element", "ul#first", [] );
34         t( "ID selector with existing ID descendant", "#firstp #simon1", ["simon1"] );
35         t( "ID selector with non-existant descendant", "#firstp #foobar", [] );
36         t( "ID selector using UTF8", "#台北Táiběi", ["台北Táiběi"] );
37         t( "Multiple ID selectors using UTF8", "#台北Táiběi, #台北", ["台北Táiběi","台北"] );
38         t( "Descendant ID selector using UTF8", "div #台北", ["台北"] );
39         t( "Child ID selector using UTF8", "form > #台北", ["台北"] );
40         
41         t( "Escaped ID", "#foo\\:bar", ["foo:bar"] );
42         t( "Escaped ID", "#test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
43         t( "Descendant escaped ID", "div #foo\\:bar", ["foo:bar"] );
44         t( "Descendant escaped ID", "div #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
45         t( "Child escaped ID", "form > #foo\\:bar", ["foo:bar"] );
46         t( "Child escaped ID", "form > #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
47         
48         t( "ID Selector, child ID present", "#form > #radio1", ["radio1"] );  // bug #267
49         t( "ID Selector, not an ancestor ID", "#form  #first", [] );
50         t( "ID Selector, not a child ID", "#form > #option1a", [] );
51         
52         t( "All Children of ID", "#foo/*", ["sndp", "en", "sap"] );
53         t( "All Children of ID with no children", "#firstUL/*", [] );
54         
55         $('<a name="tName1">tName1 A</a><a name="tName2">tName2 A</a><div id="tName1">tName1 Div</div>').appendTo('#main');
56         ok( $("#tName1")[0].id == 'tName1', "ID selector with same value for a name attribute" );
57         ok( $("#tName2").length == 0, "ID selector non-existing but name attribute on an A tag" );
58         t( "ID Selector on Form with an input that has a name of 'id'", "#lengthtest", ["lengthtest"] );
59         
60         t( "ID selector with non-existant ancestor", "#asdfasdf #foobar", [] ); // bug #986
61 });
62
63 test("class", function() {
64         expect(16);
65         t( "Class Selector", ".blog", ["mark","simon"] );
66         t( "Class Selector", ".blog.link", ["simon"] );
67         t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
68         t( "Parent Class Selector", "p .blog", ["mark","simon"] );
69         
70         t( "Class selector using UTF8", ".台北Táiběi", ["utf8class1"] );
71         t( "Class selector using UTF8", ".台北", ["utf8class1","utf8class2"] );
72         t( "Class selector using UTF8", ".台北Táiběi.台北", ["utf8class1"] );
73         t( "Class selector using UTF8", ".台北Táiběi, .台北", ["utf8class1","utf8class2"] );
74         t( "Descendant class selector using UTF8", "div .台北Táiběi", ["utf8class1"] );
75         t( "Child class selector using UTF8", "form > .台北Táiběi", ["utf8class1"] );
76         
77         t( "Escaped Class", ".foo\\:bar", ["foo:bar"] );
78         t( "Escaped Class", ".test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
79         t( "Descendant scaped Class", "div .foo\\:bar", ["foo:bar"] );
80         t( "Descendant scaped Class", "div .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
81         t( "Child escaped Class", "form > .foo\\:bar", ["foo:bar"] );
82         t( "Child escaped Class", "form > .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
83 });
84
85 test("multiple", function() {
86         expect(4);
87         t( "Comma Support", "a.blog, div", ["mark","simon","main","foo"] );
88         t( "Comma Support", "a.blog , div", ["mark","simon","main","foo"] );
89         t( "Comma Support", "a.blog ,div", ["mark","simon","main","foo"] );
90         t( "Comma Support", "a.blog,div", ["mark","simon","main","foo"] );
91 });
92
93 test("child and adjacent", function() {
94         expect(19);
95         t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
96         t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
97         t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
98         t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
99         t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
100         t( "All Children", "code > *", ["anchor1","anchor2"] );
101         t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
102         t( "Adjacent", "a + a", ["groups"] );
103         t( "Adjacent", "a +a", ["groups"] );
104         t( "Adjacent", "a+ a", ["groups"] );
105         t( "Adjacent", "a+a", ["groups"] );
106         t( "Adjacent", "p + p", ["ap","en","sap"] );
107         t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] );
108         
109         t( "First Child", "p:first-child", ["firstp","sndp"] );
110         t( "Nth Child", "p:nth-child(1)", ["firstp","sndp"] );
111         
112         t( "Last Child", "p:last-child", ["sap"] );
113         t( "Last Child", "a:last-child", ["simon1","anchor1","mark","yahoo","anchor2","simon"] );
114         
115         t( "Nth-child", "#main form > *:nth-child(2)", ["text2","idTest"] );
116         t( "Nth-child", "#main form > :nth-child(2)", ["text2","idTest"] );
117 });
118
119 test("attributes", function() {
120         expect(20);
121         t( "Attribute Exists", "a[@title]", ["google"] );
122         t( "Attribute Exists", "*[@title]", ["google"] );
123         t( "Attribute Exists", "[@title]", ["google"] );
124         
125         t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
126         t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
127         t( "Attribute Equals", "a[@rel=bookmark]", ["simon1"] );
128         t( "Multiple Attribute Equals", "input[@type='hidden'],input[@type='radio']", ["hidden1","radio1","radio2"] );
129         t( "Multiple Attribute Equals", "input[@type=\"hidden\"],input[@type='radio']", ["hidden1","radio1","radio2"] );
130         t( "Multiple Attribute Equals", "input[@type=hidden],input[@type=radio]", ["hidden1","radio1","radio2"] );
131         
132         t( "Attribute selector using UTF8", "span[@lang=中文]", ["台北"] );
133         
134         t( "Attribute Begins With", "a[@href ^= 'http://www']", ["google","yahoo"] );
135         t( "Attribute Ends With", "a[@href $= 'org/']", ["mark"] );
136         t( "Attribute Contains", "a[@href *= 'google']", ["google","groups"] );
137         
138         t("Select options via [@selected]", "#select1 option[@selected]", ["option1a"] );
139         t("Select options via [@selected]", "#select2 option[@selected]", ["option2d"] );
140         t("Select options via [@selected]", "#select3 option[@selected]", ["option3b", "option3c"] );
141         
142         t( "Grouped Form Elements", "input[@name='foo[bar]']", ["hidden2"] );
143         
144         t( ":not() Existing attribute", "select:not([@multiple])", ["select1", "select2"]);
145         t( ":not() Equals attribute", "select:not([@name=select1])", ["select2", "select3"]);
146         t( ":not() Equals quoted attribute", "select:not([@name='select1'])", ["select2", "select3"]);
147 });
148
149 test("pseudo (:) selectors", function() {
150         expect(30);
151         t( "First Child", "p:first-child", ["firstp","sndp"] );
152         t( "Last Child", "p:last-child", ["sap"] );
153         t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
154         t( "Empty", "ul:empty", ["firstUL"] );
155         t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name","length","idTest"] );
156         t( "Disabled UI Element", "input:disabled", ["text2"] );
157         t( "Checked UI Element", "input:checked", ["radio2","check1"] );
158         t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
159         t( "Text Contains", "a:contains('Google')", ["google","groups"] );
160         t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
161         t( "Element Preceded By", "p ~ div", ["foo"] );
162         t( "Not", "a.blog:not(.link)", ["mark"] );
163         
164         t( "nth Element", "p:nth(1)", ["ap"] );
165         t( "First Element", "p:first", ["firstp"] );
166         t( "Last Element", "p:last", ["first"] );
167         t( "Even Elements", "p:even", ["firstp","sndp","sap"] );
168         t( "Odd Elements", "p:odd", ["ap","en","first"] );
169         t( "Position Equals", "p:eq(1)", ["ap"] );
170         t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
171         t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
172         t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
173         t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2","name","length","idTest"] );
174         t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] );
175         
176         t( "Form element :input", ":input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "button", "area1", "select1", "select2", "select3", "length", "idTest"] );
177         t( "Form element :radio", ":radio", ["radio1", "radio2"] );
178         t( "Form element :checkbox", ":checkbox", ["check1", "check2"] );
179         t( "Form element :text", ":text", ["text1", "text2", "hidden2", "name", "length", "idTest"] );
180         t( "Form element :radio:checked", ":radio:checked", ["radio2"] );
181         t( "Form element :checkbox:checked", ":checkbox:checked", ["check1"] );
182         t( "Form element :checkbox:checked, :radio:checked", ":checkbox:checked, :radio:checked", ["check1", "radio2"] );
183 });
184
185 test("basic xpath", function() {
186         expect(15);
187         ok( jQuery.find("//*").length >= 30, "All Elements (//*)" );
188         t( "All Div Elements", "//div", ["main","foo"] );
189         t( "Absolute Path", "/html/body", ["body"] );
190         t( "Absolute Path w/ *", "/* /body", ["body"] );
191         t( "Long Absolute Path", "/html/body/dl/div/div/p", ["sndp","en","sap"] );
192         t( "Absolute and Relative Paths", "/html//div", ["main","foo"] );
193         t( "All Children, Explicit", "//code/*", ["anchor1","anchor2"] );
194         t( "All Children, Implicit", "//code/", ["anchor1","anchor2"] );
195         t( "Attribute Exists", "//a[@title]", ["google"] );
196         t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
197         t( "Parent Axis", "//p/..", ["main","foo"] );
198         t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","iframe","lengthtest","table","sndp","en","sap"] );
199         t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","iframe","lengthtest","table","sndp","en","sap"] );
200         t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
201         
202         $("#foo").each(function() {
203                 isSet( $("/p", this).get(), q("sndp", "en", "sap"), "Check XPath context" );
204         });
205 });