Skip to content

Commit 30bd774

Browse files
MayaElfkseni542
authored andcommitted
4988-refactoringSelectDeleteDuplicates
1 parent 7a978e3 commit 30bd774

File tree

6 files changed

+388
-455
lines changed

6 files changed

+388
-455
lines changed

jdi-light-angular-tests/src/test/java/io/github/epam/angular/tests/elements/complex/select/BasicMatSelectTests.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.Arrays;
77
import java.util.Collections;
88

9-
import static com.epam.jdi.light.settings.JDISettings.ELEMENT;
109
import static com.jdiai.tools.Timer.waitCondition;
1110
import static io.github.com.StaticSite.selectPage;
1211
import static io.github.com.pages.SelectPage.basicMatSelect;
@@ -20,42 +19,30 @@ public void before() {
2019
selectPage.checkOpened();
2120
}
2221

23-
@Test
22+
@Test(description = "Test checks label value")
2423
public void checkLabelValue() {
2524
basicMatSelect.label().has().value("Favorite food");
2625
}
2726

28-
@Test
27+
@Test(description = "Test checks expand-collapse functionality")
2928
public void checkSelectorExpanded() {
3029
basicMatSelect.expand();
3130
basicMatSelect.is().expanded();
3231
basicMatSelect.collapse();
3332
basicMatSelect.is().collapsed();
3433
}
3534

36-
@Test
37-
public void checkSelectorCollapsed() {
38-
basicMatSelect.collapse();
39-
basicMatSelect.is().collapsed();
40-
}
41-
42-
@Test
43-
public void checkOptionCanBeSelectedByIndex() {
44-
basicMatSelect.select(ELEMENT.startIndex + 1);
45-
basicMatSelect.is().selected(PIZZA);
46-
}
47-
48-
@Test
35+
@Test(description = "Test checks that element does not contain disabled options")
4936
public void checkListDisabledOptions() {
5037
basicMatSelect.has().listDisabled(Collections.EMPTY_LIST);
5138
}
5239

53-
@Test
40+
@Test(description = "Test checks that element contains certain enabled options")
5441
public void checkListEnabledOptions() {
5542
basicMatSelect.has().listEnabled(Arrays.asList(STEAK, PIZZA, TACOS));
5643
}
5744

58-
@Test
45+
@Test(description = "Test checks that element contains certain options")
5946
public void checkAvailableOptions() {
6047
basicMatSelect.assertThat().values(hasItems(TACOS, STEAK, PIZZA));
6148
}

jdi-light-angular/src/main/java/com/epam/jdi/light/angular/asserts/MaterialSelectorAssert.java

Lines changed: 0 additions & 128 deletions
This file was deleted.
Lines changed: 121 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,128 @@
11
package com.epam.jdi.light.angular.asserts;
22

3-
import com.epam.jdi.light.angular.elements.complex.Select;
3+
import com.epam.jdi.light.angular.elements.complex.MaterialSelector;
44
import com.epam.jdi.light.asserts.generic.UIAssert;
5+
import com.epam.jdi.light.common.JDIAction;
6+
import org.hamcrest.Matcher;
7+
import org.hamcrest.Matchers;
58

6-
public class SelectAssert extends UIAssert<SelectAssert, Select> {
9+
import java.util.List;
10+
import java.util.Map;
711

12+
import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert;
13+
import static com.jdiai.tools.EnumUtils.getEnumValue;
14+
import static com.jdiai.tools.LinqUtils.toStringArray;
15+
import static org.hamcrest.Matchers.hasItem;
16+
import static org.hamcrest.Matchers.hasItems;
817

18+
public class SelectAssert extends UIAssert<SelectAssert, MaterialSelector> {
19+
@JDIAction("Assert that '{name}' expanded")
20+
public SelectAssert expanded() {
21+
jdiAssert(element().isExpanded(), Matchers.is(true));
22+
return this;
23+
}
24+
25+
@JDIAction("Assert that '{name}' collapsed")
26+
public SelectAssert collapsed() {
27+
jdiAssert(element().isCollapsed(), Matchers.is(true));
28+
return this;
29+
}
30+
31+
@JDIAction("Assert that '{0}' option selected for '{name}'")
32+
public SelectAssert selected(final Matcher<String> condition) {
33+
jdiAssert(element().selected(), condition);
34+
return this;
35+
}
36+
37+
@JDIAction("Assert that '{0}' option selected for '{name}'")
38+
public SelectAssert selected(final String option) {
39+
return selected(Matchers.is(option));
40+
}
41+
42+
public <T extends Enum<?>> SelectAssert selected(final T option) {
43+
return selected(getEnumValue(option));
44+
}
45+
46+
public <T extends Enum<?>> SelectAssert value(final T option) {
47+
jdiAssert(element().values(), hasItem(getEnumValue(option)));
48+
return this;
49+
}
50+
51+
@JDIAction("Assert that '{name}' value '{0}'")
52+
public SelectAssert value(final Matcher<String> condition) {
53+
return values(hasItem(condition));
54+
}
55+
56+
@JDIAction("Assert that '{name}' has value '{0}'")
57+
public SelectAssert value(final String value) {
58+
return values(hasItem(value));
59+
}
60+
61+
@JDIAction("Assert that '{name}' values '{0}'")
62+
public SelectAssert values(final Matcher<? super List<String>> condition) {
63+
jdiAssert(element().values(), condition);
64+
return this;
65+
}
66+
67+
public SelectAssert values(final String... values) {
68+
return values(hasItems(values));
69+
}
70+
71+
public SelectAssert values(final List<String> values) {
72+
return values(toStringArray(values));
73+
}
74+
75+
@JDIAction("Assert that '{name}' has groups '{0}'")
76+
public SelectAssert groups(final Matcher<? super List<String>> condition) {
77+
jdiAssert(element().groups(), condition);
78+
return this;
79+
}
80+
81+
public SelectAssert groups(final List<String> groups) {
82+
return groups(toStringArray(groups));
83+
}
84+
85+
public SelectAssert groups(final String... values) {
86+
return groups(hasItems(values));
87+
}
88+
89+
@JDIAction("Assert that '{name}' has groups and options '{0}'")
90+
public SelectAssert groupsAndOptions(final Map<String, List<String>> expectedGroupsAndOptions) {
91+
jdiAssert(element().groupsAndOptions(), Matchers.is(expectedGroupsAndOptions));
92+
return this;
93+
}
94+
95+
@JDIAction("Assert that '{name}' has enabled values '{0}'")
96+
public SelectAssert listEnabled(final Matcher<? super List<String>> condition) {
97+
jdiAssert(element().listEnabled(), condition);
98+
return this;
99+
}
100+
101+
public SelectAssert listEnabled(final List<String> listEnabled) {
102+
return listEnabled(toStringArray(listEnabled));
103+
}
104+
105+
public SelectAssert listEnabled(final String... values) {
106+
return listEnabled(hasItems(values));
107+
}
108+
109+
@JDIAction("Assert that '{name}' has disabled values '{0}'")
110+
public SelectAssert listDisabled(final Matcher<? super List<String>> condition) {
111+
jdiAssert(element().listDisabled(), condition);
112+
return this;
113+
}
114+
115+
public SelectAssert listDisabled(final List<String> listDisabled) {
116+
return listDisabled(toStringArray(listDisabled));
117+
}
118+
119+
public SelectAssert listDisabled(final String... values) {
120+
return listDisabled(hasItems(values));
121+
}
122+
123+
@JDIAction("Assert that rgba({0}, {1}, {2}, {3}) is the specified color")
124+
public SelectAssert color(final int red, final int green, final int blue, final double a) {
125+
jdiAssert(element().color(red, green, blue, a), Matchers.is(true));
126+
return this;
127+
}
9128
}

jdi-light-angular/src/main/java/com/epam/jdi/light/angular/elements/complex/MaterialSelector.java

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.epam.jdi.light.angular.elements.complex;
22

3-
import com.epam.jdi.light.angular.asserts.MaterialSelectorAssert;
3+
import com.epam.jdi.light.angular.asserts.SelectAssert;
44
import com.epam.jdi.light.angular.elements.composite.MaterialSelectorContainer;
55
import com.epam.jdi.light.common.JDIAction;
66
import com.epam.jdi.light.elements.base.UIBaseElement;
@@ -19,8 +19,8 @@
1919
* To see an example of MaterialSelector web element please visit https://material.angular.io/components/select/overview.
2020
*/
2121

22-
public class MaterialSelector extends UIBaseElement<MaterialSelectorAssert> implements HasLabel {
23-
public String toggle = "//*[@id='%s']//div[contains(@class,'mat-select-arrow')][not(contains(@class, 'wrapper'))]";
22+
public class MaterialSelector extends UIBaseElement<SelectAssert> implements HasLabel {
23+
public String toggle = "//*[@id='%s']//div[contains(@class,'mat-mdc-select-arrow')][not(contains(@class, 'wrapper'))]";
2424
public String hintLocator = "//*[@id='%s']/ancestor::mat-form-field//mat-hint";
2525
public String errorLocator = "//*[@id='%s']/ancestor::mat-form-field//mat-error";
2626
public String smart = "smart: ";
@@ -60,7 +60,7 @@ public void collapse() {
6060
@JDIAction(value = "Is '{name}' expanded", level = DEBUG, timeout = 0)
6161
public boolean isExpanded() {
6262
setupLocators();
63-
return this.hasAttribute("aria-owns");
63+
return "true".equalsIgnoreCase(this.core().attr("aria-expanded"));
6464
}
6565

6666
@JDIAction(value = "Is '{name}' collapsed", level = DEBUG, timeout = 0)
@@ -229,13 +229,53 @@ public UIElement error() {
229229
}
230230

231231
@Override
232-
public MaterialSelectorAssert is() {
233-
return new MaterialSelectorAssert().set(this);
232+
public SelectAssert is() {
233+
return new SelectAssert().set(this);
234234
}
235235

236236
protected UIElement toggle() {
237237
return new UIElement(By.xpath(format(toggle,
238238
this.core().locator.printLocator().replace(smartSharp, "")
239239
.replace(cssSharp, "").replace("'", ""))));
240240
}
241+
242+
@JDIAction("Get '{name}' name")
243+
public String name() {
244+
return core().getAttribute("name");
245+
}
246+
247+
@JDIAction("Is '{name}' required")
248+
public boolean required() {
249+
return attrs().has("required");
250+
}
251+
252+
@JDIAction("Is '{name}' disabled")
253+
public boolean disabled() {
254+
return attrs().has("disabled");
255+
}
256+
257+
@JDIAction("Is '{name}' multiple")
258+
public boolean multiple() {
259+
return attrs().has("multiple");
260+
}
261+
262+
@JDIAction("Is '{name}' hide single selection indicator")
263+
public boolean hideSingleSelectionIndicator() {
264+
return attrs().has("hidesingleselectionindicator");
265+
}
266+
267+
@JDIAction("Is '{name}' label disabled")
268+
public boolean labelDisabled() {
269+
return core().getAttribute("aria-disabled").equalsIgnoreCase("true");
270+
}
271+
272+
@JDIAction("Is '{name}' label required")
273+
public boolean labelRequired() {
274+
return core().getAttribute("aria-required").equalsIgnoreCase("true");
275+
}
276+
277+
@JDIAction("Get '{name}' aria-label")
278+
public String ariaLabel() {
279+
return core().getAttribute("aria-label");
280+
}
241281
}

0 commit comments

Comments
 (0)