8000 #97 End-to-end tests for $().filter() - closes #97 · seleniumQuery/seleniumQuery@22f9b56 · GitHub
[go: up one dir, main page]

Skip to content

Commit 22f9b56

Browse files
committed
#97 End-to-end tests for $().filter() - closes #97
1 parent 278eb66 commit 22f9b56

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<!--
3+
~ Copyright (c) 2016 seleniumQuery authors
4+
~
5+
~ 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+
<html>
19+
<head>
20+
<meta charset="utf-8">
21+
<title>seleniumQuery .filter() test page</title>
22+
</head>
23+
<body>
24+
<div>CONTENT</div>
25+
<div id="myDiv">CONTENT</div>
26+
<div id="id-empty"></div>
27+
<div>CONTENT</div>
28+
</body>
29+
</html>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2016 seleniumQuery authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package endtoend.functions.jquery.traversing.filtering;
18+
19+
import com.google.common.base.Predicate;
20+
import io.github.seleniumquery.SeleniumQueryObject;
21+
import org.junit.Before;
22+
import org.junit.ClassRule;
23+
import org.junit.Rule;
24+
import org.junit.Test;
25+
import org.openqa.selenium.WebElement;
26+
import testinfrastructure.junitrule.SetUpAndTearDownDriver;
27+
28+
import static io.github.seleniumquery.SeleniumQuery.$;
29+
import static org.hamcrest.Matchers.is;
30+
import static org.junit.Assert.assertThat;
31+
32+
public class FilterFunctionTest {
33+
34+
private static final String MY_DIV_ID = "#myDiv";
35+
@ClassRule @Rule public static SetUpAndTearDownDriver setUpAndTearDownDriverRule = new SetUpAndTearDownDriver();
36+
37+
private SeleniumQueryObject $myDiv;
38+
private WebElement myDivWebElement;
39+
40+
@Before
41+
public void setUp() {
42+
this.$myDiv = $(MY_DIV_ID);
43+
this.myDivWebElement = $myDiv.get(0);
44+
assertThat($myDiv.size(), is(1));
45+
}
46+
47+
@Test
48+
public void filterSelector_into_emptySet() {
49+
assertThat($myDiv.filter("").size(), is(0));
50+
assertThat($myDiv.filter((String) null).size(), is(0));
51+
assertThat($myDiv.filter(".non-existant-class").size(), is(0));
52+
}
53+
54+
@Test
55+
public void filterPredicate_into_emptySet() {
56+
assertThat($myDiv.filter((Predicate<WebElement>) null).size(), is(0));
57+
assertThat($myDiv.filter(new Predicate<WebElement>() {
58+
@Override
59+
public boolean apply(WebElement input) {
60+
assertThat(input, is(myDivWebElement));
61+
return false;
62+
}
63+
}).size(), is(0));
64+
}
65+
66+
@Test
67+
public void filterSelector_regularUse() {
68+
assertThat($myDiv.filter(MY_DIV_ID).get(0), is(myDivWebElement));
69+
assertThat($("*").filter(MY_DIV_ID).get(0), is(myDivWebElement));
70+
}
71+
72+
@Test
73+
public void filterPredicate_regularUse() {
74+
assertThat($myDiv.filter(new Predicate<WebElement>() {
75+
@Override
76+
public boolean apply(WebElement input) {
77+
return input == myDivWebElement;
78+
}
79+
}).get(0), is(myDivWebElement));
80+
assertThat($("*").filter(new Predicate<WebElement>() {
81+
@Override
82+
public boolean apply(WebElement input) {
83+
return $(input).is(MY_DIV_ID);
84+
}
85+
}).get(0), is(myDivWebElement));
86+
}
87+
88+
@Test
89+
public void filterSelector_with_pseudo() {
90+
assertThat($("div").filter(":empty").attr("id"), is("id-empty"));
91+
}
92+
93+
}

0 commit comments

Comments
 (0)
0