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

Fix for #269 : onChange event not fired #279

Merged
merged 9 commits into from
Oct 16, 2015
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
33 changes: 29 additions & 4 deletions integration-test/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>gwtchosen-project</artifactId>
<groupId>com.arcbees</groupId>
Expand Down Expand Up @@ -35,6 +36,23 @@
</dependency>
</dependencies>

<build>
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${target.jdk}</source>
<target>${target.jdk}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>integration-test</id>
Expand All @@ -48,6 +66,8 @@
<systemPropertyVariables>
<testPort>${allocated-port}</testPort>
</systemPropertyVariables>
<parallel>all</parallel>
<threadCount>1</threadCount>
</configuration>
<executions>
<execution>
Expand All @@ -63,11 +83,16 @@
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwt.version}</version>
<configuration>
<copyWebapp>true</copyWebapp>
<hostedWebapp>${webappDirectory}</hostedWebapp>

<module>com.arcbees.chosen.integrationtest.ChosenIntegrationTests</module>

<runTarget>index.html</runTarget>
</configuration>
<executions>
<execution>
<configuration>
<module>com.arcbees.chosen.integrationtest.ChosenIntegrationTests</module>
</configuration>
<goals>
<goal>compile</goal>
</goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@

import com.arcbees.chosen.integrationtest.client.testcases.AllowSingleDeselect;
import com.arcbees.chosen.integrationtest.client.testcases.ChooseOption;
import com.arcbees.chosen.integrationtest.client.testcases.ChosenListBoxMultipleSelectAddItems;
import com.arcbees.chosen.integrationtest.client.testcases.DisableSearchThreshold;
import com.arcbees.chosen.integrationtest.client.testcases.EnabledDisabled;
import com.arcbees.chosen.integrationtest.client.testcases.HideEmptyValues;
import com.arcbees.chosen.integrationtest.client.testcases.MaxSelectedOptions;
import com.arcbees.chosen.integrationtest.client.testcases.SearchContains;
import com.arcbees.chosen.integrationtest.client.testcases.ShowNonEmptyValues;
import com.arcbees.chosen.integrationtest.client.testcases.SimpleMultiValueListBox;
import com.arcbees.chosen.integrationtest.client.testcases.SimpleMultiValueListBoxOnChange;
import com.arcbees.chosen.integrationtest.client.testcases.SimpleValueListBox;
import com.arcbees.chosen.integrationtest.client.testcases.SimpleValueListBoxOnChange;
import com.arcbees.chosen.integrationtest.client.testcases.SingleBackstrokeDelete;
import com.arcbees.chosen.integrationtest.client.testcases.TabNavigation;
import com.arcbees.chosen.integrationtest.client.testcases.dropdownposition.Above;
Expand Down Expand Up @@ -66,6 +69,9 @@ public ChosenSampleIntegrationTests() {
registerTestCase(new SearchContains());
registerTestCase(new MaxSelectedOptions());
registerTestCase(new SingleBackstrokeDelete());
registerTestCase(new SimpleValueListBoxOnChange());
registerTestCase(new SimpleMultiValueListBoxOnChange());
registerTestCase(new ChosenListBoxMultipleSelectAddItems());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2015 ArcBees Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.arcbees.chosen.integrationtest.client.testcases;

import com.arcbees.chosen.client.gwt.ChosenListBox;
import com.arcbees.chosen.integrationtest.client.TestCase;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;

public class ChosenListBoxMultipleSelectAddItems extends TestCase {
public static final String BUTTON_ID = "ChosenListBoxMultipleSelectAddItems-button";
public static final String SELECTED_VALUE = "Six";

@Override
public void run() {
final ChosenListBox listBox = new ChosenListBox(true);
listBox.setWidth("200px");
listBox.addItem("One");
listBox.addItem("Two");
listBox.addItem("Three");

Button button = new Button("Add items and select Six");
button.getElement().setId(BUTTON_ID);
button.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
listBox.clear();
listBox.addItem("Four");
listBox.addItem("Five");
listBox.addItem("Six");
listBox.update();
listBox.setSelectedValue(SELECTED_VALUE);
}
});

RootPanel.get().add(listBox);
RootPanel.get().add(button);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2015 ArcBees Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.arcbees.chosen.integrationtest.client.testcases;

import java.util.List;

import com.arcbees.chosen.client.ChosenOptions;
import com.arcbees.chosen.integrationtest.client.domain.CarBrand;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

public class SimpleMultiValueListBoxOnChange extends SimpleMultiValueListBox {
public static final String PLACEHOLDER = "Some placeholder";
public static final String LABEL_ID = "SimpleMultiValueListBoxOnChange-label";

public SimpleMultiValueListBoxOnChange() {
super(createChosenOption());
}

@Override
public void run() {
super.run();

final Label label = new Label();
label.getElement().setId(LABEL_ID);

getListBox().addValueChangeHandler(new ValueChangeHandler<List<CarBrand>>() {
@Override
public void onValueChange(ValueChangeEvent<List<CarBrand>> event) {
label.setText(joinValues(event.getValue()));
}
});

RootPanel.get().add(label);
}

private String joinValues(List<CarBrand> value) {
if (value.isEmpty()) {
return "";
} else if (value.size() == 1) {
return value.get(0).name();
} else {
String result = value.get(0).name();
for (int i = 1; i < value.size(); i++) {
result += ", " + value.get(i).name();
}

return result;
}
}

private static ChosenOptions createChosenOption() {
ChosenOptions chosenOptions = new ChosenOptions();
chosenOptions.setPlaceholderText(PLACEHOLDER);
chosenOptions.setAllowSingleDeselect(true);

return chosenOptions;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2015 ArcBees Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.arcbees.chosen.integrationtest.client.testcases;

import com.arcbees.chosen.client.ChosenOptions;
import com.arcbees.chosen.integrationtest.client.domain.CarBrand;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

public class SimpleValueListBoxOnChange extends SimpleValueListBox {
public static final String PLACEHOLDER = "Some placeholder";
public static final String LABEL_ID = "SimpleValueListBoxOnChange-label";

public SimpleValueListBoxOnChange() {
super(createChosenOption(), true);
}

@Override
public void run() {
super.run();

final Label label = new Label();
label.getElement().setId(LABEL_ID);

getListBox().addValueChangeHandler(new ValueChangeHandler<CarBrand>() {
@Override
public void onValueChange(ValueChangeEvent<CarBrand> event) {
CarBrand value = event.getValue();
label.setText(value == null ? "" : value.name());
}
});

RootPanel.get().add(label);
}

private static ChosenOptions createChosenOption() {
ChosenOptions chosenOptions = new ChosenOptions();
chosenOptions.setPlaceholderText(PLACEHOLDER);
chosenOptions.setAllowSingleDeselect(true);

return chosenOptions;
}
}
50 changes: 49 additions & 1 deletion integration-test/src/test/java/ChosenIT.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright 2015 ArcBees Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
Expand All @@ -16,8 +16,10 @@

import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.TimeoutException;
Expand All @@ -35,7 +37,9 @@
import com.arcbees.chosen.integrationtest.client.testcases.SearchContains;
import com.arcbees.chosen.integrationtest.client.testcases.ShowNonEmptyValues;
import com.arcbees.chosen.integrationtest.client.testcases.SimpleMultiValueListBox;
import com.arcbees.chosen.integrationtest.client.testcases.SimpleMultiValueListBoxOnChange;
import com.arcbees.chosen.integrationtest.client.testcases.SimpleValueListBox;
import com.arcbees.chosen.integrationtest.client.testcases.SimpleValueListBoxOnChange;
import com.arcbees.test.ByDebugId;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
Expand All @@ -47,6 +51,7 @@
import static org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable;
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfAllElementsLocatedBy;
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;
import static org.openqa.selenium.support.ui.ExpectedConditions.textToBePresentInElement;

import static com.arcbees.chosen.integrationtest.client.domain.CarBrand.AUDI;
import static com.arcbees.chosen.integrationtest.client.domain.CarBrand.FORD;
Expand All @@ -63,6 +68,11 @@ public void after() {
webDriver.quit();
}

@Before
public void before() {
webDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}

@Test
public void chooseOption() throws Throwable {
// Given
Expand Down Expand Up @@ -214,6 +224,40 @@ public void search_single_reduceOptions() {
assertThat(options).contains(audi);
}

/**
* Tests that the ValueChangeEvent is working with the ChosenValueListBox.
* See https://github.com/ArcBees/gwtchosen/issues/269
*/
@Test
public void select_singleValueListBox_changeEvent() throws InterruptedException {
// Given
loadTestCase(new SimpleValueListBoxOnChange());
String fordRender = RENDERER.render(FORD);

// When
clickOptionWithDisplayString(fordRender);

// Then
WebElement label = getElementById(SimpleValueListBoxOnChange.LABEL_ID);
webDriverWait().until(textToBePresentInElement(label, fordRender));
assertThat(label.getText()).isEqualTo(fordRender);
}

@Test
public void select_multiValueListBox_changeEvent() throws InterruptedException {
// Given
loadTestCase(new SimpleMultiValueListBoxOnChange());
String fordRender = RENDERER.render(FORD);

// When
clickOptionWithDisplayString(fordRender);

// Then
WebElement label = getElementById(SimpleMultiValueListBoxOnChange.LABEL_ID);
webDriverWait().until(textToBePresentInElement(label, fordRender));
assertThat(label.getText()).isEqualTo(fordRender);
}

/**
* This test makes sure that when null values are rendered as a non-empty string,
* then that exact non-empty string will be displayed in the dropdown options.
Expand Down Expand Up @@ -320,6 +364,10 @@ protected void singleDeselect() {
abbr.click();
}

protected WebElement getElementById(String id) {
return webDriverWait().until(presenceOfElementLocated(By.id(id)));
}

protected WebDriverWait webDriverWait() {
return new WebDriverWait(webDriver, TIME_OUT_IN_SECONDS);
}
Expand Down
Loading