Skip to content

Commit

Permalink
4934_toggleSlideRefacFinal
Browse files Browse the repository at this point in the history
  • Loading branch information
MayaElf committed Dec 15, 2023
1 parent 2a41667 commit cec3791
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.epam.jdi.light.angular.elements.common.Checkbox;
import com.epam.jdi.light.angular.elements.common.SlideToggle;
import com.epam.jdi.light.angular.elements.complex.radiobuttons.RadioButton;
import com.epam.jdi.light.elements.pageobjects.annotations.locators.Css;
import com.epam.jdi.light.elements.pageobjects.annotations.locators.UI;
import com.epam.jdi.light.ui.html.elements.common.Button;
Expand All @@ -24,6 +25,9 @@ public class SlideTogglePage extends NewAngularPage {
@Css("#slide-toggles-colors_radio_buttons")
public static RadioButtons colorRadioButtons;

@UI("#slide-toggles-set_before_position_radio")
public static RadioButton beforeLabelPositionRadioButton;

@UI("#slide-toggles-set_primary_color_radio")
public static Button primaryRadioButton;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ public void basicToggleCheckedTest() {
basicSlideToggle.check();
basicSlideToggle.is().selected();
basicSlideToggle.uncheck();
basicSlideToggle.is().deselected();
basicSlideToggle.is().notSelected();
}

@Test(description="Test verifies color of button toggle")
public void resultToggleColorTest() {
disableCheckbox.uncheck();
resultSlideToggle.check();
primaryRadioButton.click();
resultSlideToggle.has().cssClass("mat-primary");
Expand All @@ -45,7 +44,7 @@ public void resultToggleCheckedTest() {
checkedCheckbox.check();
resultSlideToggle.is().selected();
checkedCheckbox.uncheck();
resultSlideToggle.is().deselected();
resultSlideToggle.is().notSelected();
}

@Test(description="Test verifies feature enabled/disabled for button toggle")
Expand All @@ -55,4 +54,12 @@ public void resultToggleDisableTest() {
disableCheckbox.uncheck();
resultSlideToggle.is().enabled();
}

@Test(description = "Test verifies that button toggle label in in before/after position")
public void labelButtonTogglePositionTest() {
beforeLabelPositionRadioButton.click();
resultSlideToggle.has().labelBeforePosition();
basicSlideToggle.has().labelAfterPosition();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,40 @@ public class SlideToggleAssert extends UIAssert<SlideToggleAssert, SlideToggle>
@Override
@JDIAction("Assert that '{name}' is disabled")
public SlideToggleAssert disabled() {
jdiAssert(element().isDisabled(), Matchers.is(true), "Element is enabled");
jdiAssert(element().isDisabled(), Matchers.is(true), "Button toggle is enabled");
return this;
}

@Override
@JDIAction("Assert that '{name}' is disabled")
public SlideToggleAssert enabled() {
jdiAssert(element().isDisabled(), Matchers.is(false), "Element is disabled");
jdiAssert(element().isDisabled(), Matchers.is(false), "Button toggle is disabled");
return this;
}

@JDIAction("'{name}' element label is in before position")
public SlideToggleAssert labelBeforePosition() {
jdiAssert(element().hasLabelBeforePosition(), Matchers.is(true),
"Button toggle label is not in before position");
return this;
}

@JDIAction("'{name}' element label is in after position")
public SlideToggleAssert labelAfterPosition() {
jdiAssert(element().hasLabelBeforePosition(), Matchers.is(false),
"Button toggle label is not in after position");
return this;
}

@JDIAction("'{name}' is selected")
public SlideToggleAssert selected() {
jdiAssert(element().isSelected(), Matchers.is(true), "Button toggle is not selected");
return this;
}

@JDIAction("'{name}' is not selected")
public SlideToggleAssert notSelected() {
jdiAssert(element().isSelected(), Matchers.is(false), "Button toggle is selected");
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package com.epam.jdi.light.angular.elements.common;

import com.epam.jdi.light.angular.asserts.SlideToggleAssert;
import com.epam.jdi.light.common.JDIAction;
import com.epam.jdi.light.elements.base.UIBaseElement;
import com.epam.jdi.light.elements.common.UIElement;
import com.epam.jdi.light.ui.html.elements.common.Checkbox;

/**
* To see an example of SlideToggle web element please visit https://material.angular.io/components/slide-toggle/overview.
*/

public class SlideToggle extends Checkbox {
public class SlideToggle extends UIBaseElement<SlideToggleAssert> {

private static final String FORM_FIELD_LOCATOR = ".mdc-form-field";

@Override
public boolean isSelected() {
return super.isSelected() || hasClass("mat-checked") || hasClass("mat-mdc-slide-toggle-checked");
return hasClass("mat-checked") || hasClass("mat-mdc-slide-toggle-checked");
}

@Override
Expand All @@ -25,16 +28,23 @@ public boolean isDisabled() {
return e.hasAttribute("disabled");
}

@Override
@JDIAction("'{name}' element label is in before position")
public boolean hasLabelBeforePosition() {
return core().find(FORM_FIELD_LOCATOR).hasClass("mdc-form-field--align-end");
}

public void check() {
if (!isSelected())
click();
core().find(FORM_FIELD_LOCATOR).click();
}

@Override
public void uncheck() {
if (isSelected())
click();
core().find(FORM_FIELD_LOCATOR).click();
}

@Override
public SlideToggleAssert is() {
return new SlideToggleAssert().set(this);
}
}

0 comments on commit cec3791

Please sign in to comment.