summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Collovati <mcollovati@gmail.com>2015-09-19 22:54:48 +0200
committerVaadin Code Review <review@vaadin.com>2015-10-19 04:52:44 +0000
commit2333da589320f216cf77b0e1562403c1e72c4222 (patch)
treed5a3b80ed7ae3b0f6a686d9915d77acadd7e391a
parent24921e5f77629b4553bd1460f4e78b2296af5c94 (diff)
downloadvaadin-framework-2333da589320f216cf77b0e1562403c1e72c4222.tar.gz
vaadin-framework-2333da589320f216cf77b0e1562403c1e72c4222.zip
Implemented HasEnabled on VLink (#18530)
Method setWidgetEnabled in AbstractComponentConnector, called from updateEnabledState, sets enable state only for widgets implementing HasEnabled interface. Change-Id: Idc700d0c28efd13b9a9470333b19a1509cca4a51
-rw-r--r--client/src/com/vaadin/client/ui/VLink.java13
-rw-r--r--uitest/src/com/vaadin/tests/components/link/LinkInsideDisabledContainer.java61
-rw-r--r--uitest/src/com/vaadin/tests/components/link/LinkInsideDisabledContainerTest.java141
3 files changed, 214 insertions, 1 deletions
diff --git a/client/src/com/vaadin/client/ui/VLink.java b/client/src/com/vaadin/client/ui/VLink.java
index baad9bd955..de99a8617f 100644
--- a/client/src/com/vaadin/client/ui/VLink.java
+++ b/client/src/com/vaadin/client/ui/VLink.java
@@ -23,10 +23,11 @@ import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.HasEnabled;
import com.vaadin.client.Util;
import com.vaadin.shared.ui.BorderStyle;
-public class VLink extends HTML implements ClickHandler {
+public class VLink extends HTML implements ClickHandler, HasEnabled {
public static final String CLASSNAME = "v-link";
@@ -134,4 +135,14 @@ public class VLink extends HTML implements ClickHandler {
}
+ @Override
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ @Override
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
}
diff --git a/uitest/src/com/vaadin/tests/components/link/LinkInsideDisabledContainer.java b/uitest/src/com/vaadin/tests/components/link/LinkInsideDisabledContainer.java
new file mode 100644
index 0000000000..2a040b413f
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/link/LinkInsideDisabledContainer.java
@@ -0,0 +1,61 @@
+package com.vaadin.tests.components.link;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.vaadin.server.ExternalResource;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.JavaScriptFunction;
+import com.vaadin.ui.Link;
+import com.vaadin.ui.VerticalLayout;
+
+import elemental.json.JsonArray;
+
+public class LinkInsideDisabledContainer extends AbstractTestUIWithLog {
+
+ private final AtomicInteger clickCounter = new AtomicInteger(0);
+ public static final String CLICK_COUNT_TEXT = "Click count: ";
+
+ @Override
+ protected void setup(VaadinRequest request) {
+
+ VerticalLayout layout = new VerticalLayout();
+
+ final Link link = new Link(CLICK_COUNT_TEXT + 0,
+ new ExternalResource("javascript:__linkClicked()"));
+
+ getPage().getJavaScript().addFunction("__linkClicked",
+ new JavaScriptFunction() {
+
+ @Override
+ public void call(JsonArray arguments) {
+ log(CLICK_COUNT_TEXT + clickCounter.incrementAndGet());
+ }
+ });
+
+ final VerticalLayout vlayout = new VerticalLayout();
+ vlayout.addComponent(link);
+ vlayout.setId("testContainer");
+ layout.addComponent(vlayout);
+
+ Button toggleLinkButton = new Button("enable/disable link");
+ toggleLinkButton.addClickListener(new Button.ClickListener() {
+ @Override
+ public void buttonClick(Button.ClickEvent clickEvent) {
+ link.setEnabled(!link.isEnabled());
+ }
+ });
+ layout.addComponent(toggleLinkButton);
+
+ Button toggleContainerButton = new Button("enable/disable container");
+ toggleContainerButton.addClickListener(new Button.ClickListener() {
+ @Override
+ public void buttonClick(Button.ClickEvent clickEvent) {
+ vlayout.setEnabled(!vlayout.isEnabled());
+ }
+ });
+ layout.addComponent(toggleContainerButton);
+ addComponent(layout);
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/link/LinkInsideDisabledContainerTest.java b/uitest/src/com/vaadin/tests/components/link/LinkInsideDisabledContainerTest.java
new file mode 100644
index 0000000000..8d65101be3
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/link/LinkInsideDisabledContainerTest.java
@@ -0,0 +1,141 @@
+package com.vaadin.tests.components.link;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openqa.selenium.By;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.LinkElement;
+import com.vaadin.testbench.elements.VerticalLayoutElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class LinkInsideDisabledContainerTest extends MultiBrowserTest {
+
+ private static final Pattern CLICK_MATCHER = Pattern
+ .compile(LinkInsideDisabledContainer.CLICK_COUNT_TEXT + "(\\d+)");
+
+ @Before
+ public void init() {
+ openTestURL();
+ }
+
+ @Test
+ public void clickOnEnabledLinkInEnabledContainerShouldPerformAction()
+ throws InterruptedException {
+
+ clickLink();
+ assertTrue(isLinkEnabled());
+ assertThat(clicksOnLink(), is(1));
+
+ clickLink();
+ assertThat(clicksOnLink(), is(2));
+
+ }
+
+ @Test
+ public void clickOnEnabledLinkInDisabledContainerShouldNotPerformAction()
+ throws InterruptedException {
+
+ disableContainer();
+
+ clickLink();
+
+ assertFalse(isLinkEnabled());
+ assertThat(clicksOnLink(), is(0));
+ }
+
+ @Test
+ public void linkShouldMaintainDisabledStatusWhenTogglingContainerEnabledStatus()
+ throws InterruptedException {
+
+ toggleLinkEnabledStatus();
+ clickLink();
+ assertFalse(isLinkEnabled());
+ assertThat(clicksOnLink(), is(0));
+
+ disableContainer();
+ clickLink();
+ assertFalse(isLinkEnabled());
+ assertThat(clicksOnLink(), is(0));
+
+ enableContainer();
+ clickLink();
+ assertFalse(isLinkEnabled());
+ assertThat(clicksOnLink(), is(0));
+
+ }
+
+ @Test
+ public void linkShouldMaintainEnabledStatusWhenTogglingContainerEnabledStatus()
+ throws InterruptedException {
+
+ clickLink();
+ assertTrue(isLinkEnabled());
+ assertThat(clicksOnLink(), is(1));
+
+ disableContainer();
+ clickLink();
+ assertFalse(isLinkEnabled());
+ assertThat(clicksOnLink(), is(1));
+
+ enableContainer();
+ clickLink();
+ assertTrue(isLinkEnabled());
+ assertThat(clicksOnLink(), is(2));
+
+ }
+
+ private void disableContainer() {
+ VerticalLayoutElement container = $(VerticalLayoutElement.class)
+ .id("testContainer");
+ if (container.isEnabled()) {
+ toggleContainerEnabledStatus();
+ }
+ }
+
+ private void enableContainer() {
+ VerticalLayoutElement container = $(VerticalLayoutElement.class)
+ .id("testContainer");
+ if (!container.isEnabled()) {
+ toggleContainerEnabledStatus();
+ }
+ }
+
+ private void toggleContainerEnabledStatus() {
+ ButtonElement button = $(ButtonElement.class).get(1);
+ button.click();
+ }
+
+ private void toggleLinkEnabledStatus() {
+ ButtonElement button = $(ButtonElement.class).get(0);
+ button.click();
+ }
+
+ protected void clickLink() throws InterruptedException {
+ findElement(By.tagName("A")).click();
+ sleep(250);
+ }
+
+ private boolean isLinkEnabled() {
+ return $(LinkElement.class).first().isEnabled();
+ }
+
+ private Integer clicksOnLink() {
+
+ if (!getLogs().isEmpty()) {
+ Matcher m = CLICK_MATCHER.matcher(getLogRow(0));
+ if (m.find()) {
+ return Integer.valueOf(m.group(1));
+ }
+ }
+ return 0;
+ }
+}