diff options
author | Henri Sara <hesara@vaadin.com> | 2017-09-20 10:59:02 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-09-26 18:24:43 +0300 |
commit | 59c79733319c21e2e3402fb5ef9a8db4d0e356fe (patch) | |
tree | 06e5b7f12be3c14fc5868fffaa24a0d32c60d583 | |
parent | c9d537b26bdec8dde8660e8ead63aeee3bd5fc1c (diff) | |
download | vaadin-framework-8.1.5.tar.gz vaadin-framework-8.1.5.zip |
Fix ColorPickerGrid indexing8.1.5
Fixes #9018
3 files changed, 80 insertions, 3 deletions
diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGrid.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGrid.java index 6ab1ac1ccb..e51d03c5e0 100644 --- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGrid.java +++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerGrid.java @@ -38,7 +38,7 @@ public class ColorPickerGrid extends AbstractField<Color> { @Override public void select(int x, int y) { - Color oldValue = colorGrid[x][y]; + Color oldValue = colorGrid[y][x]; ColorPickerGrid.this.x = x; ColorPickerGrid.this.y = y; fireEvent(new ValueChangeEvent<>(ColorPickerGrid.this, oldValue, @@ -195,12 +195,12 @@ public class ColorPickerGrid extends AbstractField<Color> { @Override public Color getValue() { - return colorGrid[x][y]; + return colorGrid[y][x]; } @Override protected void doSetValue(Color color) { - colorGrid[x][y] = color; + colorGrid[y][x] = color; changedColors.put(new Point(x, y), color); sendChangedColors(); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/colorpicker/ColorPickerGridUI.java b/uitest/src/main/java/com/vaadin/tests/components/colorpicker/ColorPickerGridUI.java new file mode 100644 index 0000000000..efffada19a --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/colorpicker/ColorPickerGridUI.java @@ -0,0 +1,34 @@ +package com.vaadin.tests.components.colorpicker; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.colorpicker.Color; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.ui.components.colorpicker.ColorPickerGrid; + +/** + * Tests index handling in ColorPickerGrid. + */ +@Widgetset("com.vaadin.DefaultWidgetSet") +public class ColorPickerGridUI extends AbstractReindeerTestUI { + + @Override + protected void setup(VaadinRequest request) { + ColorPickerGrid colorPickerGrid = new ColorPickerGrid( + new Color[][] { { Color.RED, Color.GREEN, Color.BLUE } }); + colorPickerGrid.setWidth("300px"); + colorPickerGrid.setHeight("100px"); + addComponent(colorPickerGrid); + } + + @Override + protected String getTestDescription() { + return "Click on the second color and check that no exceptions are thrown."; + } + + @Override + protected Integer getTicketNumber() { + return 9018; + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/colorpicker/ColorPickerGridUITest.java b/uitest/src/test/java/com/vaadin/tests/components/colorpicker/ColorPickerGridUITest.java new file mode 100644 index 0000000000..f1a44a1779 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/colorpicker/ColorPickerGridUITest.java @@ -0,0 +1,43 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * 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.vaadin.tests.components.colorpicker; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class ColorPickerGridUITest extends SingleBrowserTest { + + @Test + public void testNoError() throws Exception { + openTestURL(); + + // find the color picker grid and click on the second color + WebElement grid = getDriver() + .findElement(By.className("v-colorpicker-grid")); + // click on the second color + grid.findElements(By.tagName("td")).get(1).click(); + + // check that the color picker does not have component error set + if (hasCssClass(grid, "v-colorpicker-grid-error")) { + Assert.fail( + "ColorPickerGrid should not have an active component error"); + } + } +} |