-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...i/src/main/java/com/github/grossopa/selenium/component/mui/v4/datadisplay/MuiTooltip.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright © 2024 the original author or authors. | ||
* | ||
* Licensed under the The MIT License (MIT) (the "License"); | ||
* You may obtain a copy of the License at | ||
* | ||
* https://mit-license.org/ | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the “Software”), to deal in the Software without | ||
* restriction, including without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | ||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.github.grossopa.selenium.component.mui.v4.datadisplay; | ||
|
||
import com.github.grossopa.selenium.component.mui.MuiVersion; | ||
import com.github.grossopa.selenium.component.mui.config.MuiConfig; | ||
import com.github.grossopa.selenium.component.mui.v4.AbstractMuiComponent; | ||
import com.github.grossopa.selenium.core.ComponentWebDriver; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import java.util.EnumSet; | ||
import java.util.Set; | ||
|
||
import static com.github.grossopa.selenium.component.mui.MuiVersion.V4; | ||
import static com.github.grossopa.selenium.component.mui.MuiVersion.V5; | ||
|
||
/** | ||
* Tooltips display informative text when users hover over, focus on, or tap an element. | ||
* | ||
* @author Jack Yin | ||
* @since 1.12.0 | ||
*/ | ||
public class MuiTooltip extends AbstractMuiComponent { | ||
|
||
/** | ||
* The component name | ||
*/ | ||
public static final String COMPONENT_NAME = "Tooltip"; | ||
|
||
/** | ||
* Constructs an instance with the delegated element and root driver | ||
* | ||
* @param element the delegated element | ||
* @param driver the root driver | ||
* @param config the Material UI configuration | ||
*/ | ||
public MuiTooltip(WebElement element, ComponentWebDriver driver, MuiConfig config) { | ||
super(element, driver, config); | ||
} | ||
|
||
@Override | ||
public boolean validate() { | ||
return config.validateComponentByCss(this, "Popper") | ||
&& attributeContains("role", "tooltip"); | ||
} | ||
|
||
@Override | ||
public Set<MuiVersion> versions() { | ||
return EnumSet.of(V4, V5); | ||
} | ||
|
||
@Override | ||
public String getComponentName() { | ||
return COMPONENT_NAME; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...c/test/java/com/github/grossopa/selenium/component/mui/v4/datadisplay/MuiTooltipTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright © 2024 the original author or authors. | ||
* | ||
* Licensed under the The MIT License (MIT) (the "License"); | ||
* You may obtain a copy of the License at | ||
* | ||
* https://mit-license.org/ | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the “Software”), to deal in the Software without | ||
* restriction, including without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | ||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
package com.github.grossopa.selenium.component.mui.v4.datadisplay; | ||
|
||
import com.github.grossopa.selenium.component.mui.MuiVersion; | ||
import com.github.grossopa.selenium.component.mui.config.MuiConfig; | ||
import com.github.grossopa.selenium.core.ComponentWebDriver; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import static com.github.grossopa.selenium.component.mui.MuiVersion.V4; | ||
import static com.github.grossopa.selenium.component.mui.MuiVersion.V5; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Tests for {@link MuiTooltip} | ||
* | ||
* @author Jack Yin | ||
* @since 1.12.0 | ||
*/ | ||
class MuiTooltipTest { | ||
MuiTooltip testSubject; | ||
WebElement element = mock(WebElement.class); | ||
ComponentWebDriver driver = mock(ComponentWebDriver.class); | ||
MuiConfig config = mock(MuiConfig.class); | ||
|
||
@BeforeEach | ||
void setUp() { | ||
testSubject = new MuiTooltip(element, driver, config); | ||
} | ||
|
||
@Test | ||
void versions() { | ||
Assertions.assertArrayEquals(new MuiVersion[]{V4, V5}, testSubject.versions().toArray()); | ||
} | ||
|
||
@Test | ||
void getComponentName() { | ||
Assertions.assertEquals("Tooltip", testSubject.getComponentName()); | ||
} | ||
|
||
@Test | ||
void testToString() { | ||
when(element.toString()).thenReturn("element-toString"); | ||
Assertions.assertEquals("MuiTooltip{element=element-toString}", testSubject.toString()); | ||
} | ||
|
||
@Test | ||
void validate() { | ||
when(element.getAttribute("role")).thenReturn("tooltip"); | ||
when(config.validateComponentByCss(testSubject, "Popper")).thenReturn(true); | ||
Assertions.assertTrue(testSubject.validate()); | ||
} | ||
|
||
@Test | ||
void validateNegative() { | ||
when(element.getAttribute("role")).thenReturn("dialog"); | ||
when(config.validateComponentByCss(testSubject, "Popper")).thenReturn(true); | ||
Assertions.assertFalse(testSubject.validate()); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...st/java/com/github/grossopa/selenium/examples/mui/v5/datadisplay/MuiTooltipTestCases.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright © 2021 the original author or authors. | ||
* | ||
* Licensed under the The MIT License (MIT) (the "License"); | ||
* You may obtain a copy of the License at | ||
* | ||
* https://mit-license.org/ | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the “Software”), to deal in the Software without | ||
* restriction, including without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | ||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.github.grossopa.selenium.examples.mui.v5.datadisplay; | ||
|
||
import com.github.grossopa.selenium.component.mui.v4.datadisplay.MuiTooltip; | ||
import com.github.grossopa.selenium.component.mui.v4.inputs.MuiButton; | ||
import com.github.grossopa.selenium.core.locator.By2; | ||
import com.github.grossopa.selenium.examples.helper.AbstractBrowserSupport; | ||
import org.openqa.selenium.By; | ||
|
||
import java.util.List; | ||
|
||
import static com.github.grossopa.selenium.component.mui.MuiComponents.muiV5; | ||
import static com.github.grossopa.selenium.core.driver.WebDriverType.EDGE; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* Test cases for {@link MuiTooltip}. | ||
* | ||
* @author Jack Yin | ||
* @since 1.12.0 | ||
*/ | ||
public class MuiTooltipTestCases extends AbstractBrowserSupport { | ||
|
||
/** | ||
* Tests the basic lists. | ||
* | ||
* @see <a href="https://mui.com/material-ui/react-divider/#basic-list"> | ||
* https://mui.com/material-ui/react-divider/#basic-list</a> | ||
*/ | ||
public void testBasicList() { | ||
List<MuiButton> buttons = driver.findComponent(By.id("BasicTooltip.js")).findComponent(By2.parent()) | ||
.findComponentsAs(By2.attrExact("aria-label", "Delete"), c -> c.as(muiV5()).toButton()); | ||
assertEquals(1, buttons.size()); | ||
|
||
driver.moveTo(buttons.get(0)); | ||
driver.threadSleep(1000L); | ||
|
||
MuiTooltip tooltip = driver.findComponent(By2.attrExact("role", "tooltip")).as(muiV5()).toTooltip(); | ||
|
||
assertTrue(tooltip.validate()); | ||
assertEquals("Delete", tooltip.getText()); | ||
} | ||
|
||
public static void main(String[] args) { | ||
MuiTooltipTestCases test = new MuiTooltipTestCases(); | ||
test.setUpDriver(EDGE); | ||
test.driver.navigate().to("https://mui.com/material-ui/react-tooltip/"); | ||
|
||
test.testBasicList(); | ||
} | ||
} |