Skip to content

Commit

Permalink
#5470 fix MuiList
Browse files Browse the repository at this point in the history
  • Loading branch information
pnatashap committed May 2, 2024
1 parent 52d802c commit 8187662
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.epam.jdi.light.material.elements.displaydata.Avatar;
import com.epam.jdi.light.material.elements.displaydata.Icon;
import com.epam.jdi.light.material.elements.inputs.Checkbox;
import com.epam.jdi.light.material.elements.inputs.Switch;
import com.epam.jdi.light.material.interfaces.CanBeDisabled;
import com.epam.jdi.light.material.interfaces.CanBeSelected;
import com.epam.jdi.light.ui.html.elements.common.Button;
Expand Down Expand Up @@ -85,6 +86,11 @@ public Checkbox checkbox() {
return new Checkbox().setCore(Checkbox.class, core().find(CHECKBOX));
}

@JDIAction(value = "Get '{name}' checkbox element")
public Switch switcher() {
return new Switch().setCore(Switch.class, this.secondaryAction().find(".MuiSwitch-root"));
}

@Override
public CustomSiteListItemAssert is() {
return new CustomSiteListItemAssert().set(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.epam.jdi.light.elements.composite.WebPage;
import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI;
import com.epam.jdi.light.material.annotations.JMUIList;
import com.epam.jdi.light.material.elements.displaydata.list.MUIList;
import com.epam.jdi.light.material.elements.displaydata.list.SimpleList;
import com.epam.jdi.light.material.elements.inputs.Checkbox;
Expand Down Expand Up @@ -45,6 +46,7 @@ public class MUIListPage extends WebPage {
public static MUIList<CustomSiteListItem> checkboxList;

@UI("#listWithSwitch")
@JMUIList(items = ".MuiListItem-container")
public static MUIList<CustomSiteListItem> listWithSwitch;

@UI("#pinnedSubheaderList")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.github.epam.material.tests.displaydata;

import com.epam.jdi.light.material.elements.displaydata.Icon;
import com.epam.jdi.light.material.elements.inputs.Checkbox;
import com.epam.jdi.light.material.elements.inputs.Switch;
import com.epam.jdi.light.ui.html.elements.common.Text;
import io.github.com.custom.elements.CustomSiteListItem;
import io.github.epam.TestsInit;
Expand Down Expand Up @@ -121,12 +119,10 @@ public void checkboxListTests() {
public void listWithSwitchTests() {
listWithSwitch.show();
listWithSwitch.has().headers();
CustomSiteListItem item = listWithSwitch.item(0).with(CustomSiteListItem.class);
Switch el = new Switch().setCore(Switch.class, item.secondaryAction().find(".MuiSwitch-root").base());
el.is().enabled();
el.is().checked();
el.uncheck();
el.is().unchecked();
CustomSiteListItem item = listWithSwitch.items(CustomSiteListItem.class).get(0);
item.switcher().is().enabled().and().checked();
item.switcher().uncheck();
item.switcher().is().unchecked();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
@Target(ElementType.FIELD)
public @interface JMUIList {
@MarkupLocator String header() default ".MuiListSubheader-root";
@MarkupLocator String items() default ".MuiListItem-container";
@MarkupLocator String items() default ".MuiListItem-root";
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package com.epam.jdi.light.material.elements.displaydata.list;

import com.epam.jdi.light.elements.base.UIBaseElement;
import com.epam.jdi.light.elements.complex.ISetup;
import com.epam.jdi.light.elements.complex.WebList;
import com.epam.jdi.light.elements.interfaces.base.ICoreElement;
import com.epam.jdi.light.material.annotations.JMUIList;
import com.epam.jdi.light.material.asserts.displaydata.ContainerListAssert;
import com.epam.jdi.light.material.interfaces.displaydata.IMUIList;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.stream.Collectors;

import static com.epam.jdi.light.common.Exceptions.runtimeException;
import static com.epam.jdi.light.elements.pageobjects.annotations.objects.FillFromAnnotationRules.fieldHasAnnotation;


Expand All @@ -26,11 +24,13 @@
* @see <a href="https://jdi-testing.github.io/jdi-light/material/simple_list">MUI test page</a>
*/

public class MUIList<T extends ICoreElement> extends UIBaseElement<ContainerListAssert> implements IMUIList<ICoreElement> {
public class MUIList<T extends ICoreElement> extends UIBaseElement<ContainerListAssert>
implements IMUIList<ICoreElement>, ISetup {

protected String itemLocator = ".MuiListItem-root";
protected String headerLocator = ".MuiListSubheader-root";

@Override
public void setup(Field field) {
if (fieldHasAnnotation(field, JMUIList.class, MUIList.class)) {
JMUIList listLocators = field.getAnnotation(JMUIList.class);
Expand All @@ -55,26 +55,6 @@ public List<ICoreElement> items() {
public WebList weblist() {
return core().finds(itemLocator);
}
/**
* Get list of items
*
* @return list of items as {@code List<MUIButton>}
*/
public <T extends ICoreElement> List<T> items(Class<T> cl) {
try {
Constructor<T> constr = cl.getConstructor();
return core().finds(itemLocator).stream().map(o -> {
try {
return constr.newInstance().setCore(cl, o);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw runtimeException("Can not create a new object " + cl, e);
}
})
.collect(Collectors.toList());
} catch (Exception ex) {
throw runtimeException("Can not create a list " + cl, ex);
}
}

@Override
public ContainerListAssert is() {
Expand Down

0 comments on commit 8187662

Please sign in to comment.