diff options
author | Mikael Grankvist <mgrankvi@vaadin.com> | 2015-03-12 14:19:14 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-04-10 12:12:24 +0000 |
commit | 37be37449713b3e07fc2e284695d94ea116e43e7 (patch) | |
tree | 8ea64d01c55dd1a6d6d5c5e15b5f95378b969545 /uitest/src | |
parent | d175f53e44bb835139fd10097fed4cb8eee58870 (diff) | |
download | vaadin-framework-37be37449713b3e07fc2e284695d94ea116e43e7.tar.gz vaadin-framework-37be37449713b3e07fc2e284695d94ea116e43e7.zip |
Grid layout slots should be slot size not slot content size (#17039)
Change-Id: I73a26b0d2f07bb624df6037e4e77f7137fd21791
Diffstat (limited to 'uitest/src')
-rw-r--r-- | uitest/src/com/vaadin/tests/components/gridlayout/GridLayoutCellSizesUI.java | 53 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/gridlayout/GridLayoutCellSizesUITest.java | 111 |
2 files changed, 164 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/gridlayout/GridLayoutCellSizesUI.java b/uitest/src/com/vaadin/tests/components/gridlayout/GridLayoutCellSizesUI.java new file mode 100644 index 0000000000..d2ca7700ad --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/gridlayout/GridLayoutCellSizesUI.java @@ -0,0 +1,53 @@ +package com.vaadin.tests.components.gridlayout; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.datefield.Resolution; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.InlineDateField; +import com.vaadin.ui.Label; + +@SuppressWarnings("serial") +public class GridLayoutCellSizesUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + + // Create a 4 by 4 grid layout + final GridLayout grid = new GridLayout(4, 4); + + // Fill out the first row using the cursor + grid.addComponent(new Button("R/C 1")); + for (int i = 0; i < 3; i++) { + grid.addComponent(new Button("Col " + (grid.getCursorX() + 1))); + } + + // Fill out the first column using coordinates + for (int i = 1; i < 4; i++) { + grid.addComponent(new Button("Row " + i), 0, i); + } + + // Add some components of various shapes. + grid.addComponent(new Button("3x1 button"), 1, 1, 3, 1); + grid.addComponent(new Label("1x2 cell"), 1, 2, 1, 3); + final InlineDateField date = new InlineDateField("A 2x2 date field"); + date.setResolution(Resolution.DAY); + grid.addComponent(date, 2, 2, 3, 3); + + grid.setMargin(true); + grid.setSizeUndefined(); + + addComponent(grid); + } + + @Override + protected Integer getTicketNumber() { + return 17039; + } + + @Override + protected String getTestDescription() { + return "Grid cells should be full size when adding borders around the cells"; + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/gridlayout/GridLayoutCellSizesUITest.java b/uitest/src/com/vaadin/tests/components/gridlayout/GridLayoutCellSizesUITest.java new file mode 100644 index 0000000000..8c753b1f5c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/gridlayout/GridLayoutCellSizesUITest.java @@ -0,0 +1,111 @@ +/* + * Copyright 2000-2014 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.gridlayout; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.GridLayoutElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridLayoutCellSizesUITest extends MultiBrowserTest { + + private List<WebElement> slots4x4; + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + slots4x4 = getSlots(); + } + + @Test + public void equalsHeightSlotsShouldHaveTheSameHeight() { + // items in positions 0,1,2,3,4,5 should have the same height + int firstSlotHeight = getSlotHeight(0); + for (int i = 1; i < 6; i++) { + Assert.assertEquals("Cell height didn't match for cell: " + i, + firstSlotHeight, getSlotHeight(i)); + } + } + + @Test + public void expandedAndLargeSizeSlotsShouldNotEqualFirstSlot() { + int firstSlotHeight = getSlotHeight(0); + + assertNotMatchesSmallHeight(firstSlotHeight, 6, "Row 2"); + assertNotMatchesSmallHeight(firstSlotHeight, 7, "1x2 cell"); + assertNotMatchesSmallHeight(firstSlotHeight, 8, "A 2x2 date field"); + assertNotMatchesSmallHeight(firstSlotHeight, 9, "Row 3"); + } + + @Test + public void expandedRowsShouldHaveCorrectHeight() { + // Slots expanding over 2 rows should have the same height. + Assert.assertEquals("1x2 and 2x2 cell heights didn't match", + getSlotHeight(7), getSlotHeight(8)); + + // Slots on same row as the 1x2 label should have the same combined + // height. + Assert.assertEquals( + "1x2 and combined row two and row three cell heights didn't match", + getSlotHeight(7), getSlotHeight(6) + getSlotHeight(9)); + } + + @Test + public void expandedRowsShouldHaveCorrectWidth() { + // Col 2 slot should be the dame width as 1x2 cell slot + Assert.assertEquals( + "Col 2 slot was not the same width as slot for 1x2 cell", + getSlotWidth(1), getSlotWidth(7)); + + // Row one col 3 & 4 should be as wide as the 2x2 date field + Assert.assertEquals( + "2x2 date field width didn't match col 3 & col 4 combined width", + getSlotWidth(8), getSlotWidth(2) + getSlotWidth(3)); + + // 3x1 button should be as wide as 1x2cell + 2x2 data field + Assert.assertEquals( + "3x1 slot width wasn't the same as the combined slot widths of 1x2 cell and 2x2 date field", + getSlotWidth(5), getSlotWidth(7) + getSlotWidth(8)); + + } + + private void assertNotMatchesSmallHeight(int firstSlotHeight, int i, + String id) { + Assert.assertNotEquals("Big slot '" + id + + "' matched small slots in height", firstSlotHeight, + getSlotHeight(i)); + } + + private int getSlotHeight(int slot) { + return slots4x4.get(slot).getSize().height; + } + + private int getSlotWidth(int slot) { + return slots4x4.get(slot).getSize().width; + } + + private List<WebElement> getSlots() { + GridLayoutElement layout = $(GridLayoutElement.class).first(); + + return layout.findElements(By.className("v-gridlayout-slot")); + } +} |