Skip to content

Commit

Permalink
4988-refactoringSelectDeleteDuplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
MayaElf committed Oct 20, 2023
1 parent 5535a81 commit d50930e
Show file tree
Hide file tree
Showing 6 changed files with 388 additions and 455 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Arrays;
import java.util.Collections;

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

@Test
@Test(description = "Test checks label value")
public void checkLabelValue() {
basicMatSelect.label().has().value("Favorite food");
}

@Test
@Test(description = "Test checks expand-collapse functionality")
public void checkSelectorExpanded() {
basicMatSelect.expand();
basicMatSelect.is().expanded();
basicMatSelect.collapse();
basicMatSelect.is().collapsed();
}

@Test
public void checkSelectorCollapsed() {
basicMatSelect.collapse();
basicMatSelect.is().collapsed();
}

@Test
public void checkOptionCanBeSelectedByIndex() {
basicMatSelect.select(ELEMENT.startIndex + 1);
basicMatSelect.is().selected(PIZZA);
}

@Test
@Test(description = "Test checks that element does not contain disabled options")
public void checkListDisabledOptions() {
basicMatSelect.has().listDisabled(Collections.EMPTY_LIST);
}

@Test
@Test(description = "Test checks that element contains certain enabled options")
public void checkListEnabledOptions() {
basicMatSelect.has().listEnabled(Arrays.asList(STEAK, PIZZA, TACOS));
}

@Test
@Test(description = "Test checks that element contains certain options")
public void checkAvailableOptions() {
basicMatSelect.assertThat().values(hasItems(TACOS, STEAK, PIZZA));
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,128 @@
package com.epam.jdi.light.angular.asserts;

import com.epam.jdi.light.angular.elements.complex.Select;
import com.epam.jdi.light.angular.elements.complex.MaterialSelector;
import com.epam.jdi.light.asserts.generic.UIAssert;
import com.epam.jdi.light.common.JDIAction;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;

public class SelectAssert extends UIAssert<SelectAssert, Select> {
import java.util.List;
import java.util.Map;

import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert;
import static com.jdiai.tools.EnumUtils.getEnumValue;
import static com.jdiai.tools.LinqUtils.toStringArray;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasItems;

public class SelectAssert extends UIAssert<SelectAssert, MaterialSelector> {
@JDIAction("Assert that '{name}' expanded")
public SelectAssert expanded() {
jdiAssert(element().isExpanded(), Matchers.is(true));
return this;
}

@JDIAction("Assert that '{name}' collapsed")
public SelectAssert collapsed() {
jdiAssert(element().isCollapsed(), Matchers.is(true));
return this;
}

@JDIAction("Assert that '{0}' option selected for '{name}'")
public SelectAssert selected(final Matcher<String> condition) {
jdiAssert(element().selected(), condition);
return this;
}

@JDIAction("Assert that '{0}' option selected for '{name}'")
public SelectAssert selected(final String option) {
return selected(Matchers.is(option));
}

public <T extends Enum<?>> SelectAssert selected(final T option) {
return selected(getEnumValue(option));
}

public <T extends Enum<?>> SelectAssert value(final T option) {
jdiAssert(element().values(), hasItem(getEnumValue(option)));
return this;
}

@JDIAction("Assert that '{name}' value '{0}'")
public SelectAssert value(final Matcher<String> condition) {
return values(hasItem(condition));
}

@JDIAction("Assert that '{name}' has value '{0}'")
public SelectAssert value(final String value) {
return values(hasItem(value));
}

@JDIAction("Assert that '{name}' values '{0}'")
public SelectAssert values(final Matcher<? super List<String>> condition) {
jdiAssert(element().values(), condition);
return this;
}

public SelectAssert values(final String... values) {
return values(hasItems(values));
}

public SelectAssert values(final List<String> values) {
return values(toStringArray(values));
}

@JDIAction("Assert that '{name}' has groups '{0}'")
public SelectAssert groups(final Matcher<? super List<String>> condition) {
jdiAssert(element().groups(), condition);
return this;
}

public SelectAssert groups(final List<String> groups) {
return groups(toStringArray(groups));
}

public SelectAssert groups(final String... values) {
return groups(hasItems(values));
}

@JDIAction("Assert that '{name}' has groups and options '{0}'")
public SelectAssert groupsAndOptions(final Map<String, List<String>> expectedGroupsAndOptions) {
jdiAssert(element().groupsAndOptions(), Matchers.is(expectedGroupsAndOptions));
return this;
}

@JDIAction("Assert that '{name}' has enabled values '{0}'")
public SelectAssert listEnabled(final Matcher<? super List<String>> condition) {
jdiAssert(element().listEnabled(), condition);
return this;
}

public SelectAssert listEnabled(final List<String> listEnabled) {
return listEnabled(toStringArray(listEnabled));
}

public SelectAssert listEnabled(final String... values) {
return listEnabled(hasItems(values));
}

@JDIAction("Assert that '{name}' has disabled values '{0}'")
public SelectAssert listDisabled(final Matcher<? super List<String>> condition) {
jdiAssert(element().listDisabled(), condition);
return this;
}

public SelectAssert listDisabled(final List<String> listDisabled) {
return listDisabled(toStringArray(listDisabled));
}

public SelectAssert listDisabled(final String... values) {
return listDisabled(hasItems(values));
}

@JDIAction("Assert that rgba({0}, {1}, {2}, {3}) is the specified color")
public SelectAssert color(final int red, final int green, final int blue, final double a) {
jdiAssert(element().color(red, green, blue, a), Matchers.is(true));
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.epam.jdi.light.angular.elements.complex;

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

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

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

@Override
public MaterialSelectorAssert is() {
return new MaterialSelectorAssert().set(this);
public SelectAssert is() {
return new SelectAssert().set(this);
}

protected UIElement toggle() {
return new UIElement(By.xpath(format(toggle,
this.core().locator.printLocator().replace(smartSharp, "")
.replace(cssSharp, "").replace("'", ""))));
}

@JDIAction("Get '{name}' name")
public String name() {
return core().getAttribute("name");
}

@JDIAction("Is '{name}' required")
public boolean required() {
return attrs().has("required");
}

@JDIAction("Is '{name}' disabled")
public boolean disabled() {
return attrs().has("disabled");
}

@JDIAction("Is '{name}' multiple")
public boolean multiple() {
return attrs().has("multiple");
}

@JDIAction("Is '{name}' hide single selection indicator")
public boolean hideSingleSelectionIndicator() {
return attrs().has("hidesingleselectionindicator");
}

@JDIAction("Is '{name}' label disabled")
public boolean labelDisabled() {
return core().getAttribute("aria-disabled").equalsIgnoreCase("true");
}

@JDIAction("Is '{name}' label required")
public boolean labelRequired() {
return core().getAttribute("aria-required").equalsIgnoreCase("true");
}

@JDIAction("Get '{name}' aria-label")
public String ariaLabel() {
return core().getAttribute("aria-label");
}
}
Loading

0 comments on commit d50930e

Please sign in to comment.