Skip to content

Commit

Permalink
Added corrections according to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Bulavin committed Nov 20, 2023
1 parent 9a846af commit aad3991
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.epam.jdi.light.angular.elements.enums.AngularColors;
import io.github.com.pages.ChipsPage;
import io.github.epam.TestsInit;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.Arrays;
Expand All @@ -17,10 +17,10 @@
import static io.github.com.pages.ChipsPage.basicChips;
import static io.github.com.pages.ChipsPage.disabledChips;
import static io.github.com.pages.ChipsPage.errorChips;
import static io.github.com.pages.ChipsPage.highlightedChips;
import static io.github.com.pages.ChipsPage.inputChips;
import static io.github.com.pages.ChipsPage.multipleChips;
import static io.github.com.pages.ChipsPage.stackedChips;
import static io.github.com.pages.ChipsPage.stackedSelectedValue;

public class ChipsTests extends TestsInit {

Expand All @@ -39,7 +39,7 @@ public class ChipsTests extends TestsInit {
private static final String LEMON = "Lemon";
private static final String LIME = "Lime";

@BeforeMethod
@BeforeClass
public void before() {
chipsPage.open();
waitCondition(() -> chipsPage.isOpened());
Expand All @@ -49,34 +49,47 @@ public void before() {
@Test(description = "Test verifies that chip group is selectable")
public void basicChipsTest() {
basicChips.show();
basicChips.is().displayed();
basicChips.is().displayed().and().enabled();
basicChips.selectByText(TWOFISH);
basicChips.selectByText(PRIMARYFISH);
basicChips.getElement(TWOFISH).is().selected();
basicChips.selectByText(WARNFISH);
basicChips.getElement(WARNFISH).is().selected();

ChipsPage.basicSelectedValue.has().text(format("You clicked: %s", WARNFISH));
}

@Test(description = "Test verifies that chip group is vertical")
public void stackedChipsTest() {
stackedChips.show();
stackedChips.is().displayed();
stackedChips.is().vertical();
stackedChips.selectByText(NONE);
stackedChips.selectByText(PRIMARY);
stackedChips.selectByText(ACCENT);
stackedChips.selectByText(WARN);
stackedChips.is().displayed().and().vertical();
}

stackedSelectedValue.has().text(format("You clicked: %s", WARN));
@Test(description = "Test verifies that chip group is not vertical")
public void horizontalChipsTest() {
basicChips.show();
basicChips.is().displayed().and().notVertical();
}

@Test(description = "Test check chips colors")
public void chipsColorTest() {
stackedChips.show();
stackedChips.is().displayed();
stackedChips.getElement(PRIMARY).is().color(AngularColors.MAT_PRIMARY);
stackedChips.getElement(ACCENT).is().color(AngularColors.MAT_ACCENT);
stackedChips.getElement(WARN).is().color(AngularColors.MAT_WARN);
highlightedChips.show();
highlightedChips.is().displayed();
highlightedChips.getElement("Highlighted color Primary").is().color(AngularColors.PRIMARY)
.and().highlighted();
highlightedChips.getElement("Highlighted color Accent").is().color(AngularColors.ACCENT)
.and().highlighted();
;
highlightedChips.getElement("Highlighted color Warn").is().color(AngularColors.WARN)
.and().highlighted();
;
}

@Test(description = "Test verifies that chips isn't highlighted")
public void chipsNotHighlightedTest() {
basicChips.show();
basicChips.is().displayed().and().enabled();
basicChips.getElement(TWOFISH).is().notHighlighted();
basicChips.getElement(WARNFISH).is().notHighlighted();
}

@Test(description = "Test checks the operation of the autocomplete in chips group")
Expand Down Expand Up @@ -119,6 +132,13 @@ public void chipsRemovableTest() {
inputChips.getElement("Lemon").close();
}

@Test(description = "Test checks that chips can't be removed")
public void chipsNotRemovableTest() {
basicChips.show();
basicChips.is().displayed();
basicChips.getElement(WARNFISH).is().notRemovable();
}

@Test(description = "Test checks that chips can be focused")
public void chipFocusedTest() {
inputChips.show();
Expand All @@ -127,6 +147,7 @@ public void chipFocusedTest() {
inputChips.getElement("Apple").is().focused();
inputChips.getElement("Lime").click();
inputChips.getElement("Lime").is().focused();
inputChips.getElement("Apple").is().notFocused();
}

@Test(description = "Test checks that chips has avatar image")
Expand All @@ -139,8 +160,7 @@ public void chipAvatarTest() {
@Test(description = "Test checks that chips can be disabled")
public void chipDisabledTest() {
disabledChips.show();
disabledChips.is().displayed();
disabledChips.is().disabled();
disabledChips.is().displayed().and().disabled();
}

@Test(description = "Test checks chips multiply selection")
Expand All @@ -154,11 +174,23 @@ public void chipsMultipleSelectionTest() {
multipleChips.getElement("multiple color Primary").is().selected();
}

@Test(description = "Test checks chips isn't multiply selection")
public void chipsNotMultipleSelectionTest() {
basicChips.show();
basicChips.is().displayed();
basicChips.is().notMultiselectable();
basicChips.selectByText(TWOFISH);
basicChips.selectByText(WARNFISH);
basicChips.getElement(TWOFISH).is().deselected();
basicChips.getElement(WARNFISH).is().selected();

}

@Test(description = "Test checks that chips has error state")
public void chipsErrorState() {
errorChips.show();
errorChips.is().displayed();
errorChips.input("Kiwi" + "\n");
errorChips.has().errorState();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,50 @@ public ChipAssert selected() {
return this;
}

@JDIAction("Assert that '{name}' is enabled")
public ChipAssert deselected() {
jdiAssert(element().selected(), Matchers.is(false));
return this;
}

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

@JDIAction("Assert that '{name}' is removable ")
public ChipAssert notRemovable() {
jdiAssert(element().removable(), Matchers.is(false));
return this;
}

@JDIAction("Assert that '{name}' has '{0}' color")
public ChipAssert color(AngularColors color) {
return cssClass(color.getColor());
return cssClass(color.getStyle());
}

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

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

@JDIAction("Assert that '{name}' isn't highlighted ")
public ChipAssert notHighlighted() {
jdiAssert(element().highlighted(), Matchers.is(false));
return this;
}

@JDIAction("Assert that '{name}' isn't focused ")
public ChipAssert notFocused() {
jdiAssert(element().focused(), Matchers.is(false));
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public ChipGroupAssert vertical() {
return this;
}

@JDIAction("Assert that '{name}' aria-orientation is not vertical")
public ChipGroupAssert notVertical() {
jdiAssert(element().isVertical(), Matchers.is(false));
return this;
}

@JDIAction("Assert that '{name}' has placeholder '{0}'")
public ChipGroupAssert placeholder(String expected) {
jdiAssert(element().getPlaceholderForChips(), Matchers.is(expected));
Expand All @@ -49,6 +55,12 @@ public ChipGroupAssert multiselectable() {
return this;
}

@JDIAction("Assert that '{name}' has multiple select options")
public ChipGroupAssert notMultiselectable() {
jdiAssert(element().multiselectable(), Matchers.is("false"));
return this;
}

@JDIAction("Assert that '{name}' has '{0}' element")
public ChipGroupAssert hasElement(String expected) {
jdiAssert(element().hasElement(expected), Matchers.is(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public class Chip extends UIBaseElement<ChipAssert> implements HasClick, HasColor, HasIcon, HasImage {

public static final String MAT_CHIP_REMOVE = "[matChipRemove]";

@JDIAction("Get if '{name} is selected'")
public boolean selected() {
Expand All @@ -19,35 +20,35 @@ public boolean selected() {

@JDIAction("Close '{name}'")
public void close() {
find("[matChipRemove]").click();
find(MAT_CHIP_REMOVE).click();
}

@JDIAction("Get if '{name}' is removable")
public boolean removable() {
return find("[matChipRemove]").isDisplayed();
return find(MAT_CHIP_REMOVE).isDisplayed();
}

@JDIAction("Get if '{name}' background-color")
public String getBackgroundColor() {
return css("background-color");
}

@JDIAction("Get if '{name} is focused'")
@JDIAction("Get if '{name}' is focused")
public boolean focused() {
return hasClass("cdk-focused");
}

@JDIAction("Get if '{name} checkmark is visible'")
public boolean showCheckMark() {
@JDIAction("Get if '{name}' checkmark is visible")
public boolean hasCheckMark() {
return find("mdc-evolution-chip__checkmark").isVisible();
}

@JDIAction("Get '{name} label text")
@JDIAction("Get if '{name}' is highlighted")
public boolean highlighted() {
return hasClass("mat-mdc-chip-highlighted");
}

@JDIAction("Get '{name}' label text")
public String getText() {
return find(".mdc-evolution-chip__text-label").getText();
}

@JDIAction("Get '{name} avatar image")
@JDIAction("Get '{name}' avatar image")
public Image leadingIcon() {
return new Image().setCore(Image.class, find("[matchipavatar]"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

public class ChipGroup extends UIBaseElement<ChipGroupAssert> implements IsGroupElement<Chip>, HasOrientation {

public static final String CHIP_LOCATOR = ".mat-mdc-chip";
private final String matOptions = "mat-option";
public String backdropField = "#chips-autocomplete-field";

@Override
@JDIAction("Get list of '{name}' items")
public List<Chip> groupElements() {
core().timer().wait(() -> core().finds(".mat-mdc-chip").isDisplayed());
return core().finds(".mat-mdc-chip").stream()
core().timer().wait(() -> core().finds(CHIP_LOCATOR).isDisplayed());
return core().finds(CHIP_LOCATOR).stream()
.map(listItem -> new Chip().setCore(Chip.class, listItem))
.collect(Collectors.toList());
}
Expand Down Expand Up @@ -62,7 +62,18 @@ public boolean isEnabled() {

@JDIAction("Select chip element in '{name}' by '{0}'")
public void selectByText(String text) {
getElement(text).click();
Chip chip = getElement(text);
if (!chip.selected()){
chip.click();
}
}

@JDIAction("Deselect chip element in '{name}' by '{0}'")
public void deselectByText(String text) {
Chip chip = getElement(text);
if (chip.selected()){
chip.click();
}
}

@JDIAction("Get '{name}' input field")
Expand Down Expand Up @@ -97,8 +108,7 @@ public String getPlaceholderForChips() {

@JDIAction("Collapse '{name}' chips autocomplete field")
public void collapseField() {
getBackdropField().core()
.click(getPointOutsideField().getX(), getPointOutsideField().getY());
core().click(getPointOutsideField().getX(), getPointOutsideField().getY());
}

@JDIAction("Get options for '{name}' autocomplete field")
Expand All @@ -113,12 +123,12 @@ public boolean isVertical() {
return core().attr("class").contains("mat-chip-list-stacked");
}

@JDIAction("Get if '{namr}' has multiple selection")
@JDIAction("Get if '{name}' has multiple selection")
public String multiselectable() {
return attr("aria-multiselectable");
}

@JDIAction("Get if '{namr}' has error state")
@JDIAction("Get if '{name}' has error state")
public boolean errorState() {
return core().hasClass("mat-form-field-invalid");
}
Expand All @@ -128,14 +138,9 @@ public ChipGroupAssert is() {
return new ChipGroupAssert().set(this);
}

protected UIElement getBackdropField() {
return new UIElement(By.cssSelector(backdropField));
}

protected Point getPointOutsideField() {
UIElement uiElement = getBackdropField();
return new Point(uiElement.core().getRect().
getWidth() + 3, uiElement.core().getRect().getHeight() + 3);
return new Point(core().getRect().
getWidth() + 3, core().getRect().getHeight() + 3);
}

private WebList getOptions(String css) {
Expand Down

0 comments on commit aad3991

Please sign in to comment.