Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XWIKI-21597: Make the rights UI use icon themes #2957

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import org.openqa.selenium.support.FindBy;
import org.xwiki.test.ui.po.EditRightsPane;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Represents the actions possible on the Global Rights Administration Page.
*
Expand Down Expand Up @@ -68,18 +71,23 @@ public void unforceAuthenticatedView()

private void setAuthenticatedView(boolean enabled)
{
String desiredAltValue = enabled ? "yes" : "no";

if (!this.forceAuthenticatedViewLink.getAttribute("alt").equals(desiredAltValue)) {
String desiredCheckedValue = enabled ? "checked" : null;
String initialCheckedValue = this.forceAuthenticatedViewLink.getAttribute("checked");
if (initialCheckedValue == null || !initialCheckedValue.equals(desiredCheckedValue)) {
this.forceAuthenticatedViewLink.click();

// Wait for the setting to apply. Wait longer than usual in this case in an attempt to avoid some false
// positives in the tests.
int defaultTimeout = getDriver().getTimeout();
try {
getDriver().setTimeout(defaultTimeout * 2);
getDriver().waitUntilElementHasAttributeValue(
By.id(this.forceAuthenticatedViewLink.getAttribute("id")), "alt", desiredAltValue);
if (enabled) {
getDriver().waitUntilElementHasAttributeValue(
By.id(this.forceAuthenticatedViewLink.getAttribute("id")), "checked", "true");
} else {
getDriver().waitUntilCondition(driver ->
this.forceAuthenticatedViewLink.getAttribute("checked") == null);
}
} finally {
// Restore the utils timeout for other tests.
getDriver().setTimeout(defaultTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,28 @@ public String toString()
/** The possible states of an access right box. */
public enum State
{
NONE("/xwiki/resources/js/xwiki/usersandgroups/img/none.png"),
ALLOW("/xwiki/resources/js/xwiki/usersandgroups/img/allow.png"),
DENY("/xwiki/resources/js/xwiki/usersandgroups/img/deny1.png");
NONE("none"),
ALLOW("yes"),
DENY("no");

String imageURL;
String buttonClass;

State(String imageURL)
State(String buttonClass)
{
this.imageURL = imageURL;
this.buttonClass = buttonClass;
}

State getNextState()
{
return values()[(ordinal() + 1) % values().length];
}

static State getButtonImageState(WebElement button)
static State getButtonState(WebElement button)
{
for (State s : values()) {
// The URL may contain query string parameters (e.g. starting with 11.1RC1 the resource URLs can now
// contain a query parameter to avoid cache issue) and we don't care about that to identify the state.
if ((button.getAttribute("src").contains(s.imageURL))) {
if ((button.getAttribute("class").contains(s.buttonClass))) {
return s;
}
}
Expand Down Expand Up @@ -119,9 +119,9 @@ public State getGuestRight(Right right)
*/
public State getGuestRight(String rightName)
{
final By iconLocator = By.xpath(String.format("//tr[@id='unregistered']/td[@data-title='%s']/button/img", rightName));
final WebElement icon = getDriver().findElement(iconLocator);
return State.getButtonImageState(icon);
final By buttonLocator = By.xpath(String.format("//tr[@id='unregistered']/td[@data-title='%s']/button", rightName));
final WebElement button = getDriver().findElement(buttonLocator);
return State.getButtonState(button);
}

public State getRight(String entityName, Right right)
Expand All @@ -139,13 +139,13 @@ public State getRight(String entityName, Right right)
*/
public State getRight(String entityName, String rightName)
{
final By iconLocator =
final By buttonLocator =
By.xpath(String.format(
"//*[@id='usersandgroupstable-display']//tr[./td[@class='username']//a[contains(@href, '%s')]]"
+ "/td[@data-title='%s']/button/img",
+ "/td[@data-title='%s']/button",
entityName, rightName));
final WebElement icon = getDriver().findElement(iconLocator);
return State.getButtonImageState(icon);
final WebElement button = getDriver().findElement(buttonLocator);
return State.getButtonState(button);
}

public boolean hasEntity(String entityName)
Expand All @@ -172,15 +172,15 @@ public void clickGuestRight(String rightName)
getDriver().executeJavascript(
"window.__oldConfirm = window.confirm; window.confirm = function() { return true; };");
final By buttonLocator = By.xpath(
String.format("*//tr[@id='unregistered']/td[@data-title='%s']/button/img", rightName));
String.format("*//tr[@id='unregistered']/td[@data-title='%s']/button", rightName));
final WebElement button = getDriver().findElement(buttonLocator);
State currentState = State.getButtonImageState(button);
State currentState = State.getButtonState(button);
button.click();
// Note: Selenium 2.0a4 returns a relative URL when calling getAttribute("src") but since we moved to
// Selenium 2.0a7 it returns a *full* URL even though the DOM has a relative URL as in:
// <img src="/xwiki/resources/js/xwiki/usersandgroups/img/allow.png">
getDriver().waitUntilElementContainsAttributeValue(buttonLocator, "src",
currentState.getNextState().imageURL);
getDriver().waitUntilElementContainsAttributeValue(buttonLocator, "class",
currentState.getNextState().buttonClass);
} finally {
getDriver().executeJavascript("window.confirm = window.__oldConfirm;");
}
Expand Down Expand Up @@ -212,14 +212,14 @@ public void clickRight(String entityName, String rightName)
final By buttonLocator =
By.xpath(
String.format("//*[@id='usersandgroupstable-display']//tr[./td[@class='username']"
+ "//a[contains(@href, '%s')]]/td[@data-title='%s']/button/img", entityName, rightName));
+ "//a[contains(@href, '%s')]]/td[@data-title='%s']/button", entityName, rightName));
final WebElement button = getDriver().findElement(buttonLocator);
State currentState = State.getButtonImageState(button).getNextState();
State currentState = State.getButtonState(button).getNextState();
button.click();
// Note: Selenium 2.0a4 returns a relative URL when calling getAttribute("src") but since we moved to
// Selenium 2.0a7 it returns a *full* URL even though the DOM has a relative URL as in:
// <img src="/xwiki/resources/js/xwiki/usersandgroups/img/allow.png">
getDriver().waitUntilElementContainsAttributeValue(buttonLocator, "src", currentState.imageURL);
getDriver().waitUntilElementContainsAttributeValue(buttonLocator, "class", currentState.buttonClass);
} finally {
getDriver().executeJavascript("window.confirm = window.__oldConfirm;");
}
Expand Down
Loading