Skip to content

Commit

Permalink
Merge pull request #5461 from jdi-testing/5331
Browse files Browse the repository at this point in the history
#5331 fix ItemGroup
  • Loading branch information
pnatashap authored Apr 13, 2024
2 parents 00b06bf + 7695efa commit 3c3bdb1
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package io.github.com.custom.itemGroups;

import com.epam.jdi.light.common.JDIAction;
import com.epam.jdi.light.elements.complex.WebList;
import com.epam.jdi.light.vuetify.elements.complex.ItemGroup;

public class PrimaryItemGroup extends ItemGroup {

@Override
@JDIAction("Is item '{0}' selected in {name}")
public boolean selected(int index) {
return get(index).hasClass("primary");
return items().get(index).hasClass("primary");
}

@Override
@JDIAction("Is item '{0}' selected in {name}")
public WebList selected() {
return core().finds(".primary");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public class SelectionItemGroup extends ItemGroup {

@JDIAction("Get icon of item {0} in {name}")
public Icon itemIcon(int index) {
return new Icon().setCore(Icon.class, get(index).find(".v-icon"));
return new Icon().setCore(Icon.class, items().get(index).find(".v-icon"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@

public class ItemGroupsPage extends VuetifyPage {

/**
* @todo #5298 v-card is locator for the Card class, so wrong logic is used
*/

@UI("#ActiveClassItemGroup .v-card")
@UI("#ActiveClassItemGroup")
public static PrimaryItemGroup activeClassItemGroup;

@UI("#MandatoryItemGroup .v-card")
@UI("#MandatoryItemGroup")
public static ItemGroup mandatoryItemGroup;

@UI("#MultipleItemGroup .v-card")
@UI("#MultipleItemGroup")
public static ItemGroup multipleItemGroup;

@UI("#ChipsItemGroup .v-text-field")
Expand All @@ -29,12 +25,12 @@ public class ItemGroupsPage extends VuetifyPage {
@UI("#ChipsItemGroup .v-textarea")
public static TextArea textArea;

@UI("#ChipsItemGroup .v-chip")
@UI("#ChipsItemGroup .v-item-group")
public static ItemGroup chipsItemGroup;

@UI("#ChipsItemGroup button")
public static VuetifyButton button;

@UI("#SelectionItemGroup .v-image")
@UI("#SelectionItemGroup")
public static SelectionItemGroup selectionItemGroup;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@ public void setup() {
@Test(description="Test checks items default feature: 'single', we have only one item--active at a time, "
+ "but all items may be not active")
public void singleItemGroupTest() {
// Check that at the start we do not have default selected items (no v-item--active present)
activeClassItemGroup.has().notSelected(1)
.and().has().notSelected(2)
.and().has().notSelected(3);


// Check that when 1st item selected, other items are not selected
activeClassItemGroup.select(1);
activeClassItemGroup.is().selected(1);
activeClassItemGroup.has().notSelected(2)
.and().has().notSelected(3);
.and().notSelected(3);

// Check that when 2nd item selected, 1st becomes not selected, other items remain not selected
activeClassItemGroup.select(2);
Expand All @@ -50,21 +44,16 @@ public void singleItemGroupTest() {
// other items remain not selected
activeClassItemGroup.select(2);
activeClassItemGroup.has().notSelected(2)
.and().has().notSelected(1)
.and().has().notSelected(3);
.and().notSelected(1)
.and().notSelected(3);
}
@Test(description="Test checks item group feature: active-class")
@Test(description="Test checks item group selecting")
public void activeClassTests() {
//Vuetify: The active-class property allows you to set custom CSS class on active items.
//In our test-side code: <v-item-group active-class="primary">
//As a result we should not see 'v-item--active' in class

activeClassItemGroup.select(1);

//Check that the element does not contain 'v-item--active'
activeClassItemGroup.get(1).has().text("Active");
activeClassItemGroup.select(1);
activeClassItemGroup.get(1).has().text(Matchers.emptyString());
activeClassItemGroup.items().get(1).has().text("Active");
activeClassItemGroup.select(2);
activeClassItemGroup.has().selected(2).and().notSelected(1);
}
@Test(description="Test checks items feature: 'mandatory', i.e. only one item is always chosen")
public void mandatoryItemGroupTest() {
Expand All @@ -75,12 +64,12 @@ public void mandatoryItemGroupTest() {

//Check that if we select next item it becomes 'selected' and all other items become 'not selected'
mandatoryItemGroup.select(2);
mandatoryItemGroup.has().selected(2);
mandatoryItemGroup.has().notSelected(1)
.and().notSelected(3);
mandatoryItemGroup.has().selected(2)
.and().notSelected(1)
.and().notSelected(3);

//Check theme of the group
mandatoryItemGroup.is().darkTheme();
mandatoryItemGroup.is().lightTheme();
}

@Test(description="Test checks items feature: 'multiple', i.e. several items can be chosen")
Expand All @@ -105,7 +94,7 @@ public void multipleItemGroupTest() {
.and().notSelected(3);

//Check theme of the group
multipleItemGroup.is().darkTheme();
multipleItemGroup.is().lightTheme();
}

@Test(description="Test checks items feature: 'icon' and its type, and two types of selection")
Expand All @@ -115,7 +104,7 @@ public void selectionItemGroupTest() {

//1st option - we can click on item and make it item--active. And it will change the icon type.
selectionItemGroup.itemIcon(1).has().type("mdi-heart-outline");
selectionItemGroup.list().check(1);
selectionItemGroup.itemIcon(1).click();
selectionItemGroup.itemIcon(1).has().type("mdi-heart");

//2nd option - we can click on icon, and it will change icon type. And it will make item--active
Expand All @@ -134,10 +123,9 @@ public void selectionItemGroupTest() {
@Test(description="Test checks item group feature: 'max'(Sets a maximum number of selections that can be made)")
public void maxChipsItemGroupTest() {
//On our test-site max=3
chipsItemGroup.has().subheader(Matchers.is("Tags"));
chipsItemGroup.is().displayed();
chipsItemGroup.list().forEach(HasClick::click);
chipsItemGroup.selected();
long selectedItems = chipsItemGroup.list().stream().filter(el -> el.hasClass("v-item--active")).count();
Assert.assertEquals(selectedItems, 3, "");
chipsItemGroup.items().forEach(HasClick::click);
chipsItemGroup.selected().has().size(3);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,33 @@

import static com.epam.jdi.light.asserts.core.SoftAssert.jdiAssert;

import com.epam.jdi.light.asserts.generic.UISelectAssert;
import com.epam.jdi.light.asserts.generic.UIAssert;
import com.epam.jdi.light.common.JDIAction;
import com.epam.jdi.light.vuetify.elements.complex.ItemGroup;
import com.epam.jdi.light.vuetify.interfaces.asserts.ThemeAssert;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;

public class ItemGroupAssert extends UISelectAssert<ItemGroupAssert, ItemGroup>
public class ItemGroupAssert extends UIAssert<ItemGroupAssert, ItemGroup>
implements ThemeAssert<ItemGroupAssert, ItemGroup> {

@Override
@JDIAction(value = "Assert that {name} has subheader", isAssert = true)
public ItemGroupAssert subheader(Matcher<String> matcher) {
jdiAssert(element().subheader().text(), matcher);
return this;
}

@JDIAction(value = "Assert that {0} item is selected in {name}", isAssert = true)
public ItemGroupAssert selected(int index) {
jdiAssert(element().selected(index), Matchers.is(true), String.format("Item with index %d is not selected", index));
jdiAssert(element().selected(index), Matchers.is(true),
String.format("Item with index %d is not selected", index));
return this;
}

@JDIAction(value = "Assert that {0} item is not selected in {name}", isAssert = true)
public ItemGroupAssert notSelected(int index) {
jdiAssert(element().notSelected(index), Matchers.is(true), String.format("Item with index %d is selected", index));
jdiAssert(element().selected(index), Matchers.is(false),
String.format("Item with index %d is selected", index));
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
package com.epam.jdi.light.vuetify.elements.complex;

import com.epam.jdi.light.common.JDIAction;
import com.epam.jdi.light.elements.base.UIListBase;
import com.epam.jdi.light.elements.base.UIBaseElement;
import com.epam.jdi.light.elements.common.UIElement;
import com.epam.jdi.light.elements.complex.WebList;
import com.epam.jdi.light.vuetify.asserts.ItemGroupAssert;
import com.epam.jdi.light.vuetify.elements.common.Icon;
import com.epam.jdi.light.vuetify.interfaces.HasTheme;
import com.epam.jdi.light.vuetify.interfaces.IsMultiple;

public class ItemGroup extends UIListBase<ItemGroupAssert> implements HasTheme {
public class ItemGroup extends UIBaseElement<ItemGroupAssert> implements HasTheme, IsMultiple {

// @todo #5298 Implement get selected items function Interface IsMultiple is not applicable here, as there is no "--is-multi"
public UIElement subheader() {
return core().find(".v-subheader");
}

public WebList items() {
WebList row = core().finds(".row");
if (row.isEmpty()) {
return core().finds("./child::*[not(contains(@class, 'v-subheader'))]");
} else {
// skipping columns
return row.finds("./*[contains(@class, 'col-')]/child::*");
}
}

@Override
public boolean isMultiple() {
return core().attr("file").equals("v-item-group/prop-multiple");
}

@JDIAction("Click in {0} element in the list")
public void select(int index) {
items().get(index).click();
}

@JDIAction("Is item '{0}' selected in {name}")
public boolean selected(int index) {
return get(index).hasClass("v-item--active");
return this.items().get(index).hasClass("v-item--active");
}

@JDIAction("Is item '{0}' not selected in {name}")
public boolean notSelected(int index) {
return !selected(index);
}

@JDIAction("Get icon of item {0} in {name}")
public Icon itemIcon(int index) {
return new Icon().setCore(Icon.class, get(index).find(".v-icon"));
public WebList selected() {
return core().finds(".v-item--active");
}

@Override
Expand Down

0 comments on commit 3c3bdb1

Please sign in to comment.