Skip to content

Commit

Permalink
#4926: Tests refactoring: Paginator element fix 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Kate-Semenova committed Mar 5, 2024
1 parent ab7732d commit b3370dd
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,63 +57,65 @@ public void basicPaginatorTest() {

//Go through each page sequentially:
for (int pageIndex = 0; pageIndex < PAGE_SIZE - 1; pageIndex++) {
paginatorConfigurable.has().pageIndex(pageIndex)
.and().has().length(LENGTH)
.and().has().rangeLabel(format(RANGE_PATTERN, pageIndex * STEP + 1, Math.min(pageIndex * STEP + STEP, LENGTH), LENGTH));
final String rangeLabel = format(RANGE_PATTERN, pageIndex * STEP + 1, Math.min(pageIndex * STEP + STEP, LENGTH), LENGTH);

paginatorConfigurable.has().pageIndexCurrent(pageIndex)
.and().has().totalNumberOfItems(LENGTH)
.and().has().rangeLabel(rangeLabel);
paginatorConfigurable.nextPage();
}

//Go through each page backwards
for (int pageIndex = PAGE_SIZE - 1; pageIndex > 0; pageIndex--) {
paginatorConfigurable.has().pageIndex(pageIndex)
.and().has().length(LENGTH)
.and().has().rangeLabel(format(RANGE_PATTERN, pageIndex * STEP + 1, Math.min(pageIndex * STEP + STEP, LENGTH), LENGTH));
final String rangeLabel = format(RANGE_PATTERN, pageIndex * STEP + 1, Math.min(pageIndex * STEP + STEP, LENGTH), LENGTH);

paginatorConfigurable.has().pageIndexCurrent(pageIndex)
.and().has().totalNumberOfItems(LENGTH)
.and().has().rangeLabel(rangeLabel);
paginatorConfigurable.previousPage();
}
paginatorConfigurable.has().pageIndex(0)
.and().has().length(LENGTH)
paginatorConfigurable.has().pageIndexCurrent(0)
.and().has().totalNumberOfItems(LENGTH)
.and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(STEP, LENGTH), LENGTH));

}

@Test(description = "The test checks first page and last page buttons labels for paginator")
public void firstAndLastPageButtonPaginatorTest() {
paginatorFirstLastButtons.has().showFirstLastButtons(true);
paginatorFirstLastButtons.has().firstPageLabel("test firstPageLabel");
paginatorFirstLastButtons.has().lastPageLabel("test lastPageLabel");

paginatorFirstLastButtons.firstPageButton().is().disabled();
paginatorFirstLastButtons.lastPageButton().is().enabled();
paginatorFirstLastButtons.has().firstLastButtonsShown(true)
.and().has().firstPageLabel("test firstPageLabel")
.and().has().lastPageLabel("test lastPageLabel")
.and().has().firstPageDisplayed(true)
.and().has().lastPageDisplayed(true);

paginatorFirstLastButtons.lastPageButton().click();
paginatorFirstLastButtons.firstPageButton().is().enabled();
paginatorFirstLastButtons.lastPageButton().is().disabled();

paginatorConfigurable.has().showFirstLastButtons(false);
paginatorConfigurable.has().firstLastButtonsShown(false);
}

@Test(description = "The test checks color theme of the paginators")
public void colorPaginatorTest() {
paginatorColorPrimary.has().color(PRIMARY);
paginatorColorPrimary.has().colorOfBoarder(PRIMARY);
paginatorColorPrimary.has().colorOfSelectedOption(PRIMARY);
paginatorColorPrimary.has().colorTheme(PRIMARY)
.and().has().borderColor(PRIMARY)
.and().has().selectedOptionColor(PRIMARY);

paginatorColorPrimary.has().colorTheme("primary")
.and().has().borderColor("rgb(103, 58, 183)")
.and().has().selectedOptionColor("rgba(103, 58, 183, 1)");

paginatorColorWarn.has().color(WARN);
paginatorColorWarn.has().colorOfBoarder(WARN);
paginatorColorWarn.has().colorOfSelectedOption(WARN);
paginatorColorWarn.has().colorTheme(WARN)
.and().has().borderColor(WARN)
.and().has().selectedOptionColor(WARN);

paginatorColorAccent.has().color(ACCENT);
paginatorColorAccent.has().colorOfBoarder(ACCENT);
paginatorColorAccent.has().colorOfSelectedOption(ACCENT);
paginatorColorAccent.has().colorTheme(ACCENT)
.and().has().borderColor(ACCENT)
.and().has().selectedOptionColor(ACCENT);
}

@Test(description = "The test checks disabled paginator and disabled elements of the paginators")
public void navigationDisabledPaginatorTest() {
paginatorDisabledOption.is().disabled();

paginatorDisabledOption.previousButton().is().disabled();
paginatorDisabledOption.nextButton().is().disabled();
paginatorDisabledOption.itemPerPageSelector().is().disabled();
paginatorDisabledOption.is().disabled()
.and().has().previousDisabled()
.and().has().nextDisabled()
.and().has().itemPerPageSelectorDisabled();

paginatorHideSizeOption.is().enabled();
paginatorColorWarn.is().enabled();
Expand All @@ -138,8 +140,9 @@ public void itemPerPagePaginatorTest() {

for (Integer option : PAGE_SIZE_OPTIONS) {
paginatorConfigurable.select(option);
final String rangeLabel = format(RANGE_PATTERN, 1, Math.min(option, LENGTH), LENGTH);
paginatorConfigurable.has().itemsPerPageSelected(option)
.and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(option, LENGTH), LENGTH));
.and().has().rangeLabel(rangeLabel);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,77 +9,94 @@
import java.util.List;

import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert;
import static com.jdiai.tools.StringUtils.format;

public class PaginatorAssert extends UIAssert<PaginatorAssert, Paginator> {
@JDIAction(value = "Assert that '{name}' has '{0}' label", isAssert = true)
public PaginatorAssert itemPerPageLabel(String label) {
jdiAssert(element().itemPerPageLabel(), Matchers.is(label));
public PaginatorAssert itemPerPageLabel(final String label) {
jdiAssert(element().itemPerPageLabel(), Matchers.equalTo(label));
return this;
}

@JDIAction(value = "Assert that '{0}' option selected for '{name}'", isAssert = true)
public PaginatorAssert itemsPerPageSelected(final int number) {
jdiAssert(element().selected(), Matchers.is(number));
jdiAssert(element().selected(), Matchers.equalTo(number));
return this;
}

@JDIAction(value = "Assert that '{0}' options for '{name}'", isAssert = true)
public PaginatorAssert itemsPerPageList(final List<Integer> options) {
jdiAssert(element().options(), Matchers.is(options));
jdiAssert(element().options(), Matchers.equalTo(options));
return this;

}

@JDIAction(value = "Assert that range is '{0}' for '{name}'", isAssert = true)
public PaginatorAssert rangeLabel(String label) {
String expected = format(label);
jdiAssert(element().range(), Matchers.is(expected));
public PaginatorAssert rangeLabel(final String label) {
jdiAssert(element().range(), Matchers.equalTo(label));
return this;
}

@JDIAction(value = "Assert that '{name}' has '{0}' color theme", isAssert = true)
public PaginatorAssert color(AngularColors value) {
jdiAssert(element().color(), Matchers.equalTo(value));
public PaginatorAssert colorTheme(final AngularColors value) {
final AngularColors color = AngularColors.fromName(element().colorTheme());
jdiAssert(color, Matchers.equalTo(value));
return this;
}

@JDIAction(value = "Assert that '{name}' has '{0}' color theme", isAssert = true)
public PaginatorAssert colorTheme(final String value) {
jdiAssert(element().colorTheme(), Matchers.equalToIgnoringCase(value));
return this;
}

@JDIAction(value = "Assert that '{name}' has '{0}' color of the boarder", isAssert = true)
public PaginatorAssert colorOfBoarder(AngularColors value) {
AngularColors actualColor = AngularColors.fromColor(element().colorOfBoarder());
public PaginatorAssert borderColor(final AngularColors value) {
AngularColors actualColor = AngularColors.fromColor(element().boarderColor());
jdiAssert(actualColor, Matchers.equalTo(value));
return this;
}

@JDIAction(value = "Assert that '{name}' has '{0}' color of the boarder", isAssert = true)
public PaginatorAssert borderColor(final String value) {
jdiAssert(element().boarderColor(), Matchers.equalTo(value));
return this;
}

@JDIAction(value = "Assert that '{name}' has '{0}' color of the selected option", isAssert = true)
public PaginatorAssert colorOfSelectedOption(AngularColors value) {
AngularColors actualColorInList = AngularColors.fromColor(element().colorInList());
public PaginatorAssert selectedOptionColor(final AngularColors value) {
AngularColors actualColorInList = AngularColors.fromColor(element().selectedOptionColor());
jdiAssert(actualColorInList, Matchers.equalTo(value));
return this;
}

@JDIAction(value = "Assert that '{name}' has '{0}' color of the selected option", isAssert = true)
public PaginatorAssert selectedOptionColor(final String value) {
jdiAssert(element().selectedOptionColor(), Matchers.equalTo(value));
return this;
}

@JDIAction(value = "Assert that '{name} has firstPageLabel='{0}'", isAssert = true)
public PaginatorAssert firstPageLabel(String label) {
jdiAssert(element().firstPageLabel(), Matchers.is(label));
public PaginatorAssert firstPageLabel(final String label) {
jdiAssert(element().firstPageLabel(), Matchers.equalTo(label));
return this;
}

@JDIAction(value = "Assert that '{name} has lastPageLabel='{0}'", isAssert = true)
public PaginatorAssert lastPageLabel(String label) {
jdiAssert(element().lastPageLabel(), Matchers.is(label));
public PaginatorAssert lastPageLabel(final String label) {
jdiAssert(element().lastPageLabel(), Matchers.equalTo(label));
return this;
}

@JDIAction(value = "Assert that '{name}' has hidden page size", isAssert = true)
public PaginatorAssert hiddenPageSize(final boolean value) {
jdiAssert(element().hidePageSize(), Matchers.is(value),
public PaginatorAssert hiddenPageSize(boolean value) {
jdiAssert(element().isPageSizeHidden(), Matchers.is(value),
value ? "page size should be hidden" : "page size should be visible");
return this;
}

@JDIAction(value = "Assert that '{name}' has shown first and last page buttons", isAssert = true)
public PaginatorAssert showFirstLastButtons(boolean value) {
jdiAssert(element().showFirstLastButtons(), Matchers.is(value),
public PaginatorAssert firstLastButtonsShown(boolean value) {
jdiAssert(element().isFirstLastButtonsShown(), Matchers.is(value),
value ? "first and last buttons should be shown" : "first and last buttons should be hidden"
);
return this;
Expand All @@ -88,15 +105,57 @@ public PaginatorAssert showFirstLastButtons(boolean value) {
/**
* @param pageIndex starts from 0
*/
@JDIAction(value = "Assert that '{name}' has page index of {0}", isAssert = true)
public PaginatorAssert pageIndex(int pageIndex) {
jdiAssert(element().pageIndex(), Matchers.is(pageIndex));
@JDIAction(value = "Assert that '{name}' has current page index of {0}", isAssert = true)
public PaginatorAssert pageIndexCurrent(int pageIndex) {
jdiAssert(element().pageIndexCurrent(), Matchers.equalTo(pageIndex));
return this;
}

@JDIAction(value = "Assert that '{name}' has page index of {0}", isAssert = true)
public PaginatorAssert length(int length) {
jdiAssert(element().length(), Matchers.is(length));
public PaginatorAssert totalNumberOfItems(int length) {
jdiAssert(element().totalNumberOfItems(), Matchers.equalTo(length));
return this;
}

@JDIAction(value = "Assert that previous button enabled for '{name}'", isAssert = true)
public PaginatorAssert previousEnabled() {
jdiAssert(element().previousButton().isEnabled() ? "enabled" : "disabled", Matchers.equalTo("enabled"));
return this;
}

@JDIAction(value = "Assert that previous button disabled for '{name}'", isAssert = true)
public PaginatorAssert previousDisabled() {
jdiAssert(element().previousButton().isEnabled() ? "enabled" : "disabled", Matchers.equalTo("disabled"));
return this;
}

@JDIAction(value = "Assert that next button enabled for '{name}'", isAssert = true)
public PaginatorAssert nextEnabled() {
jdiAssert(element().nextButton().isEnabled() ? "enabled" : "disabled", Matchers.equalTo("enabled"));
return this;
}

@JDIAction(value = "Assert that next button disabled for '{name}'", isAssert = true)
public PaginatorAssert nextDisabled() {
jdiAssert(element().nextButton().isEnabled() ? "enabled" : "disabled", Matchers.equalTo("disabled"));
return this;
}

@JDIAction(value = "Assert that item per page selector is disabled for '{name}'", isAssert = true)
public PaginatorAssert itemPerPageSelectorDisabled() {
jdiAssert(element().itemPerPageSelector().isDisabled() ? "disabled" : "enabled", Matchers.equalTo("disabled"));
return this;
}

@JDIAction(value = "Assert that first page button displayed={0} for '{name}'", isAssert = true)
public PaginatorAssert firstPageDisplayed(boolean value) {
jdiAssert(element().firstPageButton().isDisplayed() ? "displayed" : "hidden", Matchers.equalTo(value ? "displayed" : "hidden"));
return this;
}

@JDIAction(value = "Assert that last page button displayed={0} for '{name}'", isAssert = true)
public PaginatorAssert lastPageDisplayed(boolean value) {
jdiAssert(element().lastPageButton().isDisplayed() ? "displayed" : "hidden", Matchers.equalTo(value ? "displayed" : "hidden"));
return this;
}
}
Expand Down
Loading

0 comments on commit b3370dd

Please sign in to comment.