Skip to content

Commit bc26b65

Browse files
committed
#4926: Tests refactoring: Paginator element fix 1
1 parent 1a7c77c commit bc26b65

File tree

4 files changed

+165
-96
lines changed

4 files changed

+165
-96
lines changed

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

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -57,63 +57,65 @@ public void basicPaginatorTest() {
5757

5858
//Go through each page sequentially:
5959
for (int pageIndex = 0; pageIndex < PAGE_SIZE - 1; pageIndex++) {
60-
paginatorConfigurable.has().pageIndex(pageIndex)
61-
.and().has().length(LENGTH)
62-
.and().has().rangeLabel(format(RANGE_PATTERN, pageIndex * STEP + 1, Math.min(pageIndex * STEP + STEP, LENGTH), LENGTH));
60+
final String rangeLabel = format(RANGE_PATTERN, pageIndex * STEP + 1, Math.min(pageIndex * STEP + STEP, LENGTH), LENGTH);
61+
62+
paginatorConfigurable.has().pageIndexCurrent(pageIndex)
63+
.and().has().totalNumberOfItems(LENGTH)
64+
.and().has().rangeLabel(rangeLabel);
6365
paginatorConfigurable.nextPage();
6466
}
6567

6668
//Go through each page backwards
6769
for (int pageIndex = PAGE_SIZE - 1; pageIndex > 0; pageIndex--) {
68-
paginatorConfigurable.has().pageIndex(pageIndex)
69-
.and().has().length(LENGTH)
70-
.and().has().rangeLabel(format(RANGE_PATTERN, pageIndex * STEP + 1, Math.min(pageIndex * STEP + STEP, LENGTH), LENGTH));
70+
final String rangeLabel = format(RANGE_PATTERN, pageIndex * STEP + 1, Math.min(pageIndex * STEP + STEP, LENGTH), LENGTH);
71+
72+
paginatorConfigurable.has().pageIndexCurrent(pageIndex)
73+
.and().has().totalNumberOfItems(LENGTH)
74+
.and().has().rangeLabel(rangeLabel);
7175
paginatorConfigurable.previousPage();
7276
}
73-
paginatorConfigurable.has().pageIndex(0)
74-
.and().has().length(LENGTH)
77+
paginatorConfigurable.has().pageIndexCurrent(0)
78+
.and().has().totalNumberOfItems(LENGTH)
7579
.and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(STEP, LENGTH), LENGTH));
7680

7781
}
7882

7983
@Test(description = "The test checks first page and last page buttons labels for paginator")
8084
public void firstAndLastPageButtonPaginatorTest() {
81-
paginatorFirstLastButtons.has().showFirstLastButtons(true);
82-
paginatorFirstLastButtons.has().firstPageLabel("test firstPageLabel");
83-
paginatorFirstLastButtons.has().lastPageLabel("test lastPageLabel");
84-
85-
paginatorFirstLastButtons.firstPageButton().is().disabled();
86-
paginatorFirstLastButtons.lastPageButton().is().enabled();
85+
paginatorFirstLastButtons.has().firstLastButtonsShown(true)
86+
.and().has().firstPageLabel("test firstPageLabel")
87+
.and().has().lastPageLabel("test lastPageLabel")
88+
.and().has().firstPageDisplayed(true)
89+
.and().has().lastPageDisplayed(true);
8790

88-
paginatorFirstLastButtons.lastPageButton().click();
89-
paginatorFirstLastButtons.firstPageButton().is().enabled();
90-
paginatorFirstLastButtons.lastPageButton().is().disabled();
91-
92-
paginatorConfigurable.has().showFirstLastButtons(false);
91+
paginatorConfigurable.has().firstLastButtonsShown(false);
9392
}
9493

9594
@Test(description = "The test checks color theme of the paginators")
9695
public void colorPaginatorTest() {
97-
paginatorColorPrimary.has().color(PRIMARY);
98-
paginatorColorPrimary.has().colorOfBoarder(PRIMARY);
99-
paginatorColorPrimary.has().colorOfSelectedOption(PRIMARY);
96+
paginatorColorPrimary.has().colorTheme(PRIMARY)
97+
.and().has().borderColor(PRIMARY)
98+
.and().has().selectedOptionColor(PRIMARY);
99+
100+
paginatorColorPrimary.has().colorTheme("primary")
101+
.and().has().borderColor("rgb(103, 58, 183)")
102+
.and().has().selectedOptionColor("rgba(103, 58, 183, 1)");
100103

101-
paginatorColorWarn.has().color(WARN);
102-
paginatorColorWarn.has().colorOfBoarder(WARN);
103-
paginatorColorWarn.has().colorOfSelectedOption(WARN);
104+
paginatorColorWarn.has().colorTheme(WARN)
105+
.and().has().borderColor(WARN)
106+
.and().has().selectedOptionColor(WARN);
104107

105-
paginatorColorAccent.has().color(ACCENT);
106-
paginatorColorAccent.has().colorOfBoarder(ACCENT);
107-
paginatorColorAccent.has().colorOfSelectedOption(ACCENT);
108+
paginatorColorAccent.has().colorTheme(ACCENT)
109+
.and().has().borderColor(ACCENT)
110+
.and().has().selectedOptionColor(ACCENT);
108111
}
109112

110113
@Test(description = "The test checks disabled paginator and disabled elements of the paginators")
111114
public void navigationDisabledPaginatorTest() {
112-
paginatorDisabledOption.is().disabled();
113-
114-
paginatorDisabledOption.previousButton().is().disabled();
115-
paginatorDisabledOption.nextButton().is().disabled();
116-
paginatorDisabledOption.itemPerPageSelector().is().disabled();
115+
paginatorDisabledOption.is().disabled()
116+
.and().has().previousDisabled()
117+
.and().has().nextDisabled()
118+
.and().has().itemPerPageSelectorDisabled();
117119

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

139141
for (Integer option : PAGE_SIZE_OPTIONS) {
140142
paginatorConfigurable.select(option);
143+
final String rangeLabel = format(RANGE_PATTERN, 1, Math.min(option, LENGTH), LENGTH);
141144
paginatorConfigurable.has().itemsPerPageSelected(option)
142-
.and().has().rangeLabel(format(RANGE_PATTERN, 1, Math.min(option, LENGTH), LENGTH));
145+
.and().has().rangeLabel(rangeLabel);
143146
}
144147
}
145148
}

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

Lines changed: 86 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,77 +9,94 @@
99
import java.util.List;
1010

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

1413
public class PaginatorAssert extends UIAssert<PaginatorAssert, Paginator> {
1514
@JDIAction(value = "Assert that '{name}' has '{0}' label", isAssert = true)
16-
public PaginatorAssert itemPerPageLabel(String label) {
17-
jdiAssert(element().itemPerPageLabel(), Matchers.is(label));
15+
public PaginatorAssert itemPerPageLabel(final String label) {
16+
jdiAssert(element().itemPerPageLabel(), Matchers.equalTo(label));
1817
return this;
1918
}
2019

2120
@JDIAction(value = "Assert that '{0}' option selected for '{name}'", isAssert = true)
2221
public PaginatorAssert itemsPerPageSelected(final int number) {
23-
jdiAssert(element().selected(), Matchers.is(number));
22+
jdiAssert(element().selected(), Matchers.equalTo(number));
2423
return this;
2524
}
2625

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

3231
}
3332

3433
@JDIAction(value = "Assert that range is '{0}' for '{name}'", isAssert = true)
35-
public PaginatorAssert rangeLabel(String label) {
36-
String expected = format(label);
37-
jdiAssert(element().range(), Matchers.is(expected));
34+
public PaginatorAssert rangeLabel(final String label) {
35+
jdiAssert(element().range(), Matchers.equalTo(label));
3836
return this;
3937
}
4038

4139
@JDIAction(value = "Assert that '{name}' has '{0}' color theme", isAssert = true)
42-
public PaginatorAssert color(AngularColors value) {
43-
jdiAssert(element().color(), Matchers.equalTo(value));
40+
public PaginatorAssert colorTheme(final AngularColors value) {
41+
final AngularColors color = AngularColors.fromName(element().colorTheme());
42+
jdiAssert(color, Matchers.equalTo(value));
43+
return this;
44+
}
45+
46+
@JDIAction(value = "Assert that '{name}' has '{0}' color theme", isAssert = true)
47+
public PaginatorAssert colorTheme(final String value) {
48+
jdiAssert(element().colorTheme(), Matchers.equalToIgnoringCase(value));
4449
return this;
4550
}
4651

4752
@JDIAction(value = "Assert that '{name}' has '{0}' color of the boarder", isAssert = true)
48-
public PaginatorAssert colorOfBoarder(AngularColors value) {
49-
AngularColors actualColor = AngularColors.fromColor(element().colorOfBoarder());
53+
public PaginatorAssert borderColor(final AngularColors value) {
54+
AngularColors actualColor = AngularColors.fromColor(element().boarderColor());
5055
jdiAssert(actualColor, Matchers.equalTo(value));
5156
return this;
5257
}
5358

59+
@JDIAction(value = "Assert that '{name}' has '{0}' color of the boarder", isAssert = true)
60+
public PaginatorAssert borderColor(final String value) {
61+
jdiAssert(element().boarderColor(), Matchers.equalTo(value));
62+
return this;
63+
}
64+
5465
@JDIAction(value = "Assert that '{name}' has '{0}' color of the selected option", isAssert = true)
55-
public PaginatorAssert colorOfSelectedOption(AngularColors value) {
56-
AngularColors actualColorInList = AngularColors.fromColor(element().colorInList());
66+
public PaginatorAssert selectedOptionColor(final AngularColors value) {
67+
AngularColors actualColorInList = AngularColors.fromColor(element().selectedOptionColor());
5768
jdiAssert(actualColorInList, Matchers.equalTo(value));
5869
return this;
5970
}
6071

72+
@JDIAction(value = "Assert that '{name}' has '{0}' color of the selected option", isAssert = true)
73+
public PaginatorAssert selectedOptionColor(final String value) {
74+
jdiAssert(element().selectedOptionColor(), Matchers.equalTo(value));
75+
return this;
76+
}
77+
6178
@JDIAction(value = "Assert that '{name} has firstPageLabel='{0}'", isAssert = true)
62-
public PaginatorAssert firstPageLabel(String label) {
63-
jdiAssert(element().firstPageLabel(), Matchers.is(label));
79+
public PaginatorAssert firstPageLabel(final String label) {
80+
jdiAssert(element().firstPageLabel(), Matchers.equalTo(label));
6481
return this;
6582
}
6683

6784
@JDIAction(value = "Assert that '{name} has lastPageLabel='{0}'", isAssert = true)
68-
public PaginatorAssert lastPageLabel(String label) {
69-
jdiAssert(element().lastPageLabel(), Matchers.is(label));
85+
public PaginatorAssert lastPageLabel(final String label) {
86+
jdiAssert(element().lastPageLabel(), Matchers.equalTo(label));
7087
return this;
7188
}
7289

7390
@JDIAction(value = "Assert that '{name}' has hidden page size", isAssert = true)
74-
public PaginatorAssert hiddenPageSize(final boolean value) {
75-
jdiAssert(element().hidePageSize(), Matchers.is(value),
91+
public PaginatorAssert hiddenPageSize(boolean value) {
92+
jdiAssert(element().isPageSizeHidden(), Matchers.is(value),
7693
value ? "page size should be hidden" : "page size should be visible");
7794
return this;
7895
}
7996

8097
@JDIAction(value = "Assert that '{name}' has shown first and last page buttons", isAssert = true)
81-
public PaginatorAssert showFirstLastButtons(boolean value) {
82-
jdiAssert(element().showFirstLastButtons(), Matchers.is(value),
98+
public PaginatorAssert firstLastButtonsShown(boolean value) {
99+
jdiAssert(element().isFirstLastButtonsShown(), Matchers.is(value),
83100
value ? "first and last buttons should be shown" : "first and last buttons should be hidden"
84101
);
85102
return this;
@@ -88,15 +105,57 @@ public PaginatorAssert showFirstLastButtons(boolean value) {
88105
/**
89106
* @param pageIndex starts from 0
90107
*/
91-
@JDIAction(value = "Assert that '{name}' has page index of {0}", isAssert = true)
92-
public PaginatorAssert pageIndex(int pageIndex) {
93-
jdiAssert(element().pageIndex(), Matchers.is(pageIndex));
108+
@JDIAction(value = "Assert that '{name}' has current page index of {0}", isAssert = true)
109+
public PaginatorAssert pageIndexCurrent(int pageIndex) {
110+
jdiAssert(element().pageIndexCurrent(), Matchers.equalTo(pageIndex));
94111
return this;
95112
}
96113

97114
@JDIAction(value = "Assert that '{name}' has page index of {0}", isAssert = true)
98-
public PaginatorAssert length(int length) {
99-
jdiAssert(element().length(), Matchers.is(length));
115+
public PaginatorAssert totalNumberOfItems(int length) {
116+
jdiAssert(element().totalNumberOfItems(), Matchers.equalTo(length));
117+
return this;
118+
}
119+
120+
@JDIAction(value = "Assert that previous button enabled for '{name}'", isAssert = true)
121+
public PaginatorAssert previousEnabled() {
122+
jdiAssert(element().previousButton().isEnabled() ? "enabled" : "disabled", Matchers.equalTo("enabled"));
123+
return this;
124+
}
125+
126+
@JDIAction(value = "Assert that previous button disabled for '{name}'", isAssert = true)
127+
public PaginatorAssert previousDisabled() {
128+
jdiAssert(element().previousButton().isEnabled() ? "enabled" : "disabled", Matchers.equalTo("disabled"));
129+
return this;
130+
}
131+
132+
@JDIAction(value = "Assert that next button enabled for '{name}'", isAssert = true)
133+
public PaginatorAssert nextEnabled() {
134+
jdiAssert(element().nextButton().isEnabled() ? "enabled" : "disabled", Matchers.equalTo("enabled"));
135+
return this;
136+
}
137+
138+
@JDIAction(value = "Assert that next button disabled for '{name}'", isAssert = true)
139+
public PaginatorAssert nextDisabled() {
140+
jdiAssert(element().nextButton().isEnabled() ? "enabled" : "disabled", Matchers.equalTo("disabled"));
141+
return this;
142+
}
143+
144+
@JDIAction(value = "Assert that item per page selector is disabled for '{name}'", isAssert = true)
145+
public PaginatorAssert itemPerPageSelectorDisabled() {
146+
jdiAssert(element().itemPerPageSelector().isDisabled() ? "disabled" : "enabled", Matchers.equalTo("disabled"));
147+
return this;
148+
}
149+
150+
@JDIAction(value = "Assert that first page button displayed={0} for '{name}'", isAssert = true)
151+
public PaginatorAssert firstPageDisplayed(boolean value) {
152+
jdiAssert(element().firstPageButton().isDisplayed() ? "displayed" : "hidden", Matchers.equalTo(value ? "displayed" : "hidden"));
153+
return this;
154+
}
155+
156+
@JDIAction(value = "Assert that last page button displayed={0} for '{name}'", isAssert = true)
157+
public PaginatorAssert lastPageDisplayed(boolean value) {
158+
jdiAssert(element().lastPageButton().isDisplayed() ? "displayed" : "hidden", Matchers.equalTo(value ? "displayed" : "hidden"));
100159
return this;
101160
}
102161
}

0 commit comments

Comments
 (0)