xref: /AOO41X/test/testgui/source/fvt/gui/sc/cell/Cells.java (revision 424494b095bc90dc2fe31bd4233af124f1760355)
1*424494b0SLi Feng Wang /**************************************************************
2*424494b0SLi Feng Wang  *
3*424494b0SLi Feng Wang  * Licensed to the Apache Software Foundation (ASF) under one
4*424494b0SLi Feng Wang  * or more contributor license agreements.  See the NOTICE file
5*424494b0SLi Feng Wang  * distributed with this work for additional information
6*424494b0SLi Feng Wang  * regarding copyright ownership.  The ASF licenses this file
7*424494b0SLi Feng Wang  * to you under the Apache License, Version 2.0 (the
8*424494b0SLi Feng Wang  * "License"); you may not use this file except in compliance
9*424494b0SLi Feng Wang  * with the License.  You may obtain a copy of the License at
10*424494b0SLi Feng Wang  *
11*424494b0SLi Feng Wang  *   http://www.apache.org/licenses/LICENSE-2.0
12*424494b0SLi Feng Wang  *
13*424494b0SLi Feng Wang  * Unless required by applicable law or agreed to in writing,
14*424494b0SLi Feng Wang  * software distributed under the License is distributed on an
15*424494b0SLi Feng Wang  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*424494b0SLi Feng Wang  * KIND, either express or implied.  See the License for the
17*424494b0SLi Feng Wang  * specific language governing permissions and limitations
18*424494b0SLi Feng Wang  * under the License.
19*424494b0SLi Feng Wang  *
20*424494b0SLi Feng Wang  *************************************************************/
21*424494b0SLi Feng Wang 
22*424494b0SLi Feng Wang package fvt.gui.sc.cell;
23*424494b0SLi Feng Wang 
24*424494b0SLi Feng Wang import static org.junit.Assert.*;
25*424494b0SLi Feng Wang import static testlib.gui.AppTool.*;
26*424494b0SLi Feng Wang import static testlib.gui.UIMap.*;
27*424494b0SLi Feng Wang 
28*424494b0SLi Feng Wang import org.junit.After;
29*424494b0SLi Feng Wang import org.junit.Before;
30*424494b0SLi Feng Wang import org.junit.Test;
31*424494b0SLi Feng Wang 
32*424494b0SLi Feng Wang import testlib.gui.AppTool;
33*424494b0SLi Feng Wang import testlib.gui.SCTool;
34*424494b0SLi Feng Wang 
35*424494b0SLi Feng Wang 
36*424494b0SLi Feng Wang 
37*424494b0SLi Feng Wang public class Cells {
38*424494b0SLi Feng Wang 
39*424494b0SLi Feng Wang 
40*424494b0SLi Feng Wang 	@Before
41*424494b0SLi Feng Wang 	public void setUp() throws Exception {
42*424494b0SLi Feng Wang 		app.start();
43*424494b0SLi Feng Wang 		AppTool.newSpreadsheet();
44*424494b0SLi Feng Wang 	}
45*424494b0SLi Feng Wang 
46*424494b0SLi Feng Wang 	@After
47*424494b0SLi Feng Wang 	public void tearDown() throws Exception {
48*424494b0SLi Feng Wang 		app.stop();
49*424494b0SLi Feng Wang 	}
50*424494b0SLi Feng Wang 
51*424494b0SLi Feng Wang 	/**
52*424494b0SLi Feng Wang 	 * Shift row and column, insert entire row and column
53*424494b0SLi Feng Wang 	 *
54*424494b0SLi Feng Wang 	 * @throws Exception
55*424494b0SLi Feng Wang 	 */
56*424494b0SLi Feng Wang 
57*424494b0SLi Feng Wang 	@Test
58*424494b0SLi Feng Wang 	public void testShiftRowandColumn() {
59*424494b0SLi Feng Wang 
60*424494b0SLi Feng Wang 		// Input data to cell range A1:B2
61*424494b0SLi Feng Wang 		SCTool.selectRange("A1");
62*424494b0SLi Feng Wang 		typeKeys("1<right>2<down><left>3<right>4");
63*424494b0SLi Feng Wang 		// Set expected result after executing shift cell down
64*424494b0SLi Feng Wang 		String[][] expectedShiftCellDownResult = new String[][] { { "", "2" },
65*424494b0SLi Feng Wang 				{ "1", "4" }, { "3", "" }, };
66*424494b0SLi Feng Wang 		// Select Cell A1
67*424494b0SLi Feng Wang 		SCTool.selectRange("Sheet1.A1");
68*424494b0SLi Feng Wang 		// Launch insert cells dialog via menu
69*424494b0SLi Feng Wang 		calc.menuItem("Insert->Cells...").select();
70*424494b0SLi Feng Wang 		// Select the first option "shift cells down" from dialog
71*424494b0SLi Feng Wang 		typeKeys("<enter>");
72*424494b0SLi Feng Wang 		// 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"));
75*424494b0SLi Feng Wang 		// Set expected result after executing shift cell right
76*424494b0SLi Feng Wang 		String[][] expectedShiftCellRightResult = new String[][] {
77*424494b0SLi Feng Wang 				{ "", "1", "2" }, { "3", "4", "" }, };
78*424494b0SLi Feng Wang 		// Undo
79*424494b0SLi Feng Wang 		calc.menuItem("Edit->Undo: Insert").select();
80*424494b0SLi Feng Wang 
81*424494b0SLi Feng Wang 		// Select cell B2
82*424494b0SLi Feng Wang 		SCTool.selectRange("Sheet1.A1");
83*424494b0SLi Feng Wang 		// Launch insert cells dialog via menu
84*424494b0SLi Feng Wang 		calc.menuItem("Insert->Cells...").select();
85*424494b0SLi Feng Wang 		// Select the second option "shift cells right" from dialog
86*424494b0SLi Feng Wang 		typeKeys("<down>");
87*424494b0SLi Feng Wang 		typeKeys("<enter>");
88*424494b0SLi Feng Wang 		// 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"));
91*424494b0SLi Feng Wang 		// Set expected result after executing insert entire row
92*424494b0SLi Feng Wang 		String[][] expectedEntireRowResult = new String[][] { { "", "" },
93*424494b0SLi Feng Wang 				{ "1", "2" }, { "3", "4" }, };
94*424494b0SLi Feng Wang 
95*424494b0SLi Feng Wang 		// Undo
96*424494b0SLi Feng Wang 		calc.menuItem("Edit->Undo: Insert").select();
97*424494b0SLi Feng Wang 		// Select Cell B2
98*424494b0SLi Feng Wang 		SCTool.selectRange("Sheet1.A1");
99*424494b0SLi Feng Wang 		// Launch insert cells dialog via menu
100*424494b0SLi Feng Wang 		calc.menuItem("Insert->Cells...").select();
101*424494b0SLi Feng Wang 
102*424494b0SLi Feng Wang 		// Select the third option "Entire row" from dialog
103*424494b0SLi Feng Wang 		typeKeys("<down>");
104*424494b0SLi Feng Wang 		typeKeys("<enter>");
105*424494b0SLi Feng Wang 
106*424494b0SLi Feng Wang 		// 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"));
109*424494b0SLi Feng Wang 
110*424494b0SLi Feng Wang 		// Set expected result after executing insert entire column
111*424494b0SLi Feng Wang 		String[][] expectedEntireColumnResult = new String[][] {
112*424494b0SLi Feng Wang 		{ "", "1", "2" }, { "", "3", "4" }, };
113*424494b0SLi Feng Wang 		// Undo
114*424494b0SLi Feng Wang 		calc.menuItem("Edit->Undo: Insert").select();
115*424494b0SLi Feng Wang 
116*424494b0SLi Feng Wang 		// Select Cell A1
117*424494b0SLi Feng Wang 		SCTool.selectRange("Sheet1.A1");
118*424494b0SLi Feng Wang 
119*424494b0SLi Feng Wang 		// Launch insert cells dialog via menu
120*424494b0SLi Feng Wang 		calc.menuItem("Insert->Cells...").select();
121*424494b0SLi Feng Wang 
122*424494b0SLi Feng Wang 		// Select the fourth option "Entire column" from dialog
123*424494b0SLi Feng Wang 		typeKeys("<down>");
124*424494b0SLi Feng Wang 		typeKeys("<enter>");
125*424494b0SLi Feng Wang 
126*424494b0SLi Feng Wang 		// 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"));
129*424494b0SLi Feng Wang 
130*424494b0SLi Feng Wang 	}
131*424494b0SLi Feng Wang 
132*424494b0SLi Feng Wang }
133