107d7dbdcSHerbert Dürr /************************************************************** 207d7dbdcSHerbert Dürr * 307d7dbdcSHerbert Dürr * Licensed to the Apache Software Foundation (ASF) under one 407d7dbdcSHerbert Dürr * or more contributor license agreements. See the NOTICE file 507d7dbdcSHerbert Dürr * distributed with this work for additional information 607d7dbdcSHerbert Dürr * regarding copyright ownership. The ASF licenses this file 707d7dbdcSHerbert Dürr * to you under the Apache License, Version 2.0 (the 807d7dbdcSHerbert Dürr * "License"); you may not use this file except in compliance 907d7dbdcSHerbert Dürr * with the License. You may obtain a copy of the License at 1007d7dbdcSHerbert Dürr * 1107d7dbdcSHerbert Dürr * http://www.apache.org/licenses/LICENSE-2.0 1207d7dbdcSHerbert Dürr * 1307d7dbdcSHerbert Dürr * Unless required by applicable law or agreed to in writing, 1407d7dbdcSHerbert Dürr * software distributed under the License is distributed on an 1507d7dbdcSHerbert Dürr * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1607d7dbdcSHerbert Dürr * KIND, either express or implied. See the License for the 1707d7dbdcSHerbert Dürr * specific language governing permissions and limitations 1807d7dbdcSHerbert Dürr * under the License. 1907d7dbdcSHerbert Dürr * 2007d7dbdcSHerbert Dürr *************************************************************/ 2107d7dbdcSHerbert Dürr 2280a6f5c5SLiu Zhe package fvt.gui.sc.cell; 23cb6ac572SLiu Zhe 24cb6ac572SLiu Zhe import static org.junit.Assert.*; 25b4d2d410SLiu Zhe import static testlib.gui.AppTool.*; 26cb6ac572SLiu Zhe import static testlib.gui.UIMap.*; 27cb6ac572SLiu Zhe 28cb6ac572SLiu Zhe import org.junit.After; 29cb6ac572SLiu Zhe import org.junit.Before; 30cb6ac572SLiu Zhe import org.junit.Test; 31cb6ac572SLiu Zhe 32*424494b0SLi Feng Wang import testlib.gui.AppTool; 33b4d2d410SLiu Zhe import testlib.gui.SCTool; 34cb6ac572SLiu Zhe 35cb6ac572SLiu Zhe 36cb6ac572SLiu Zhe 37*424494b0SLi Feng Wang public class Cells { 38*424494b0SLi Feng Wang 39cb6ac572SLiu Zhe 40cb6ac572SLiu Zhe @Before 41cb6ac572SLiu Zhe public void setUp() throws Exception { 42cb6ac572SLiu Zhe app.start(); 43*424494b0SLi Feng Wang AppTool.newSpreadsheet(); 44cb6ac572SLiu Zhe } 45cb6ac572SLiu Zhe 46cb6ac572SLiu Zhe @After 47cb6ac572SLiu Zhe public void tearDown() throws Exception { 48*424494b0SLi Feng Wang app.stop(); 49cb6ac572SLiu Zhe } 5022a14f28SLiu Zhe 51cb6ac572SLiu Zhe /** 52cb6ac572SLiu Zhe * Shift row and column, insert entire row and column 5322a14f28SLiu Zhe * 54cb6ac572SLiu Zhe * @throws Exception 55cb6ac572SLiu Zhe */ 5622a14f28SLiu Zhe 57cb6ac572SLiu Zhe @Test 5822a14f28SLiu Zhe public void testShiftRowandColumn() { 5922a14f28SLiu Zhe 6022a14f28SLiu Zhe // Input data to cell range A1:B2 61b4d2d410SLiu Zhe SCTool.selectRange("A1"); 62cb6ac572SLiu Zhe typeKeys("1<right>2<down><left>3<right>4"); 6322a14f28SLiu Zhe // Set expected result after executing shift cell down 64*424494b0SLi Feng Wang String[][] expectedShiftCellDownResult = new String[][] { { "", "2" }, 65*424494b0SLi Feng Wang { "1", "4" }, { "3", "" }, }; 6622a14f28SLiu Zhe // Select Cell A1 67b4d2d410SLiu Zhe SCTool.selectRange("Sheet1.A1"); 6822a14f28SLiu Zhe // Launch insert cells dialog via menu 69cb6ac572SLiu Zhe calc.menuItem("Insert->Cells...").select(); 7022a14f28SLiu Zhe // Select the first option "shift cells down" from dialog 71cb6ac572SLiu Zhe typeKeys("<enter>"); 7222a14f28SLiu Zhe // Verify results after shift one cell down 73*424494b0SLi Feng Wang assertArrayEquals("Verify results after shift one cell down", 74*424494b0SLi Feng Wang expectedShiftCellDownResult, SCTool.getCellTexts("A1:B3")); 7522a14f28SLiu Zhe // Set expected result after executing shift cell right 76*424494b0SLi Feng Wang String[][] expectedShiftCellRightResult = new String[][] { 77*424494b0SLi Feng Wang { "", "1", "2" }, { "3", "4", "" }, }; 78cb6ac572SLiu Zhe // Undo 79cb6ac572SLiu Zhe calc.menuItem("Edit->Undo: Insert").select(); 80*424494b0SLi Feng Wang 8122a14f28SLiu Zhe // Select cell B2 82b4d2d410SLiu Zhe SCTool.selectRange("Sheet1.A1"); 8322a14f28SLiu Zhe // Launch insert cells dialog via menu 8422a14f28SLiu Zhe calc.menuItem("Insert->Cells...").select(); 8522a14f28SLiu Zhe // Select the second option "shift cells right" from dialog 86cb6ac572SLiu Zhe typeKeys("<down>"); 87cb6ac572SLiu Zhe typeKeys("<enter>"); 8822a14f28SLiu Zhe // Verify results after shift one cell right 89*424494b0SLi Feng Wang assertArrayEquals("Verify results after shift one cell right", 90*424494b0SLi Feng Wang expectedShiftCellRightResult, SCTool.getCellTexts("A1:C2")); 9122a14f28SLiu Zhe // Set expected result after executing insert entire row 92*424494b0SLi Feng Wang String[][] expectedEntireRowResult = new String[][] { { "", "" }, 93*424494b0SLi Feng Wang { "1", "2" }, { "3", "4" }, }; 9422a14f28SLiu Zhe 95cb6ac572SLiu Zhe // Undo 96cb6ac572SLiu Zhe calc.menuItem("Edit->Undo: Insert").select(); 9722a14f28SLiu Zhe // Select Cell B2 98b4d2d410SLiu Zhe SCTool.selectRange("Sheet1.A1"); 9922a14f28SLiu Zhe // Launch insert cells dialog via menu 10022a14f28SLiu Zhe calc.menuItem("Insert->Cells...").select(); 10122a14f28SLiu Zhe 10222a14f28SLiu Zhe // Select the third option "Entire row" from dialog 103cb6ac572SLiu Zhe typeKeys("<down>"); 104cb6ac572SLiu Zhe typeKeys("<enter>"); 10522a14f28SLiu Zhe 10622a14f28SLiu Zhe // Verify results after insert entire row 107*424494b0SLi Feng Wang assertArrayEquals("Verify results after insert entire row", 108*424494b0SLi Feng Wang expectedEntireRowResult, SCTool.getCellTexts("A1:B3")); 10922a14f28SLiu Zhe 11022a14f28SLiu Zhe // Set expected result after executing insert entire column 111cb6ac572SLiu Zhe String[][] expectedEntireColumnResult = new String[][] { 11222a14f28SLiu Zhe { "", "1", "2" }, { "", "3", "4" }, }; 113cb6ac572SLiu Zhe // Undo 114cb6ac572SLiu Zhe calc.menuItem("Edit->Undo: Insert").select(); 11522a14f28SLiu Zhe 11622a14f28SLiu Zhe // Select Cell A1 117b4d2d410SLiu Zhe SCTool.selectRange("Sheet1.A1"); 11822a14f28SLiu Zhe 11922a14f28SLiu Zhe // Launch insert cells dialog via menu 12022a14f28SLiu Zhe calc.menuItem("Insert->Cells...").select(); 12122a14f28SLiu Zhe 12222a14f28SLiu Zhe // Select the fourth option "Entire column" from dialog 123cb6ac572SLiu Zhe typeKeys("<down>"); 124cb6ac572SLiu Zhe typeKeys("<enter>"); 12522a14f28SLiu Zhe 12622a14f28SLiu Zhe // Verify the results after inserting entire column 127*424494b0SLi Feng Wang assertArrayEquals("Verify the results after inserting entire column", 128*424494b0SLi Feng Wang expectedEntireColumnResult, SCTool.getCellTexts("A1:C2")); 12922a14f28SLiu Zhe 130cb6ac572SLiu Zhe } 131cb6ac572SLiu Zhe 132cb6ac572SLiu Zhe } 133