xref: /AOO41X/test/testgui/source/fvt/gui/sc/sort/SortDialogSetting.java (revision fd3484265709667881cfaec27d41da15d46b6832)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 /**
23  *
24  */
25 package fvt.gui.sc.sort;
26 
27 import static org.junit.Assert.*;
28 import static org.openoffice.test.common.Testspace.*;
29 import static org.openoffice.test.vcl.Tester.*;
30 import static testlib.gui.AppTool.*;
31 import static testlib.gui.UIMap.*;
32 
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.Ignore;
36 import org.junit.Rule;
37 import org.junit.Test;
38 import org.openoffice.test.common.FileUtil;
39 import org.openoffice.test.common.Logger;
40 
41 import testlib.gui.AppTool;
42 import testlib.gui.SCTool;
43 
44 /**
45  * Test Data->Sort dialog setting
46  */
47 public class SortDialogSetting {
48 
49     @Rule
50     public Logger log = Logger.getLogger(this);
51 
52     @Before
setUp()53     public void setUp() throws Exception {
54         app.start(true);
55         AppTool.newSpreadsheet();
56     }
57 
58     @After
tearDown()59     public void tearDown() throws Exception {
60         app.stop();
61     }
62 
63     /**
64      * Test sort with options setting: case sensitive
65      *
66      * @throws Exception
67      */
68     @Test
testSortOptionsCaseSensitive()69     public void testSortOptionsCaseSensitive() throws Exception {
70 
71         // Input some data: A1~A6: 1ColumnName,D,C,B,A,a
72         String[][] data = new String[][] { { "D" }, { "C" }, { "B" }, { "A" }, { "a" }, };
73         String[][] expectedSortedResult = new String[][] { { "a" }, { "A" }, { "B" }, { "C" }, { "D" }, };
74         SCTool.selectRange("A1");
75         typeKeys("1ColumnName<down>D<down>C<down>B<down>A<down>a<down>");
76         SCTool.selectRange("A6");
77         app.dispatch(".uno:ChangeCaseToLower");
78         // In case SC capitalize first letter automatically
79         // "Data->Sort...", choose "Ascending", check "Case sensitive"
80         app.dispatch(".uno:DataSort");
81         sortOptionsPage.select();
82         sortOptionsPageCaseSensitive.check();
83         sortOptionsPage.ok();
84 
85         // Verify sorted result
86         assertArrayEquals("Wrong Sorted result", expectedSortedResult, SCTool.getCellTexts("A2:A6"));
87 
88         // Uodo/redo
89         app.dispatch(".uno:Undo");
90         assertArrayEquals("Wrong Undo sorted result", data, SCTool.getCellTexts("A2:A6"));
91         app.dispatch(".uno:Redo");
92         assertArrayEquals("Wrong Redo sorted result", expectedSortedResult, SCTool.getCellTexts("A2:A6"));
93 
94         // Save and close document
95         String saveTo = getPath("temp/" + "RowsSortWithOptionsCaseSensitive.ods");
96         FileUtil.deleteFile(saveTo);
97         saveAndReopen(saveTo);
98         calc.waitForExistence(10, 2);
99         assertArrayEquals("Saved sorted result", expectedSortedResult, SCTool.getCellTexts("A2:A6"));
100     }
101 
102     /**
103      * Test sort with options setting: copy sort result to
104      *
105      * @throws Exception
106      */
107     @Ignore("Bug #119035 - Redo is not work when sort result to other postion")
testSortOptionsCopyResultTo()108     public void testSortOptionsCopyResultTo() throws Exception {
109 
110         String[][] expectedSortedResult = new String[][] { { "1", "AB" }, { "2", "BC" }, { "3", "D" }, { "4", "E" }, { "5", "FLK" }, { "6", "GE" }, };
111         SCTool.selectRange("A1");
112         typeKeys("3<down>5<down>4<down>2<down>6<down>1");
113         SCTool.selectRange("B1");
114         typeKeys("D<down>FLK<down>E<down>BC<down>GE<down>AB");
115 
116         // Data->Sort..., choose "Ascending", check "Copy sort results to:"
117         app.dispatch(".uno:DataSort");
118         sortOptionsPage.select();
119         sortOptionsPageCopyResultTo.check();
120         sortOptionsPageCopyResultToEdit.setText("$Sheet3.$A4");
121         sortOptionsPage.ok();
122 
123         // Verify sorted result
124         assertArrayEquals("Copy sorted result to", expectedSortedResult, SCTool.getCellTexts("$Sheet3.$A4:$B9"));
125 
126         // Uodo/redo
127         app.dispatch(".uno:Undo");
128         assertEquals("Undo sorted result", "", SCTool.getCellText("$Sheet3.$A4"));
129         app.dispatch(".uno:Redo");
130         assertArrayEquals("Redo sorted result", expectedSortedResult, SCTool.getCellTexts("$Sheet3.$A4:$B9"));
131 
132         // Move focus to sheet2 then select a cell range,
133         // Insert->Names->Define...
134         SCTool.selectRange("$Sheet2.$A1:$B3");
135         app.dispatch(".uno:DefineName");
136         defineNamesDlgNameEdit.setText("cellRange");
137         defineNamesDlg.ok();
138 
139         // Set focus to the original data, Data->Sort...
140         SCTool.selectRange("$Sheet1.$B1");
141         app.dispatch(".uno:DataSort");
142         sortOptionsPage.select();
143         sortOptionsPageCopyResultTo.check();
144         sortOptionsPageCopyResultToCellRange.select("cellRange");
145         sortOptionsPage.ok();
146 
147         // Verify sorted result
148         assertArrayEquals("Copy sorted result to cell range", expectedSortedResult, SCTool.getCellTexts("$Sheet2.$A1:$B6"));
149 
150         // Uodo/redo
151         app.dispatch(".uno:Undo");
152         assertEquals("Undo sorted result", "", SCTool.getCellText("$Sheet2.$A1"));
153         app.dispatch(".uno:Redo");
154         assertArrayEquals("Redo sorted result", expectedSortedResult, SCTool.getCellTexts("$Sheet2.$A1:$B6"));
155 
156         // Save and close document
157         String saveTo = getPath("temp/" + "RowsSortWithOptionsCopyResultTo.ods");
158         FileUtil.deleteFile(saveTo);
159         saveAndReopen(saveTo);
160 
161         calc.waitForExistence(10, 2);
162         assertArrayEquals("Saved sorted result", expectedSortedResult, SCTool.getCellTexts("$Sheet3.$A4:$B9"));
163         assertArrayEquals("Saved sorted result to cell range", expectedSortedResult, SCTool.getCellTexts("$Sheet2.$A1:$B6"));
164     }
165 
166     /**
167      * Test sort criteria: sort first by
168      *
169      * @throws Exception
170      */
171     @Test
testSortCriteriaSortFirstBy()172     public void testSortCriteriaSortFirstBy() throws Exception {
173 
174         // Input some data
175         String[][] data = new String[][] { { "3", "D" }, { "5", "FLK" }, { "4", "E" }, { "2", "BC" }, { "6", "GE" }, { "1", "AB" }, };
176         String[][] expectedResultSortByColumnBAscending = new String[][] { { "1", "AB" }, { "2", "BC" }, { "3", "D" }, { "4", "E" }, { "5", "FLK" }, { "6", "GE" }, };
177         String[][] expectedResultSortByColumnADescending = new String[][] { { "6", "GE" }, { "5", "FLK" }, { "4", "E" }, { "3", "D" }, { "2", "BC" }, { "1", "AB" }, };
178         SCTool.selectRange("A1");
179         typeKeys("3<down>5<down>4<down>2<down>6<down>1");
180         SCTool.selectRange("B1");
181         typeKeys("D<down>FLK<down>E<down>BC<down>GE<down>AB");
182 
183         // "Data->Sort...", choose "Ascending", sort first by Column B
184         app.dispatch(".uno:DataSort");
185         sortPageAscending1.check();
186         sortPageBy1.select(2); // "Column B"
187         sortPage.ok();
188 
189         // Verify sorted result
190         assertArrayEquals("Sorted result", expectedResultSortByColumnBAscending, SCTool.getCellTexts("A1:B6"));
191 
192         // Uodo/redo
193         app.dispatch(".uno:Undo");
194         assertArrayEquals("Undo sorted result", data, SCTool.getCellTexts("A1:B6"));
195         app.dispatch(".uno:Redo");
196         assertArrayEquals("Redo sorted result", expectedResultSortByColumnBAscending, SCTool.getCellTexts("A1:B6"));
197         app.dispatch(".uno:Undo");
198 
199         // Save and close document
200         String saveTo = getPath("temp/" + "SortCriteriaSortFirstBy.ods");
201         FileUtil.deleteFile(saveTo);
202         saveAndReopen(saveTo);
203 
204         calc.waitForExistence(10, 2);
205         // "Data->Sort...", choose "Descending", sort first by Column A
206         app.dispatch(".uno:DataSort");
207         sortPageDescending1.check();
208         sortPageBy1.select(1); // "Column A"
209         sortPage.ok();
210 
211         // Verify sorted result
212         assertArrayEquals("Saved sorted result", expectedResultSortByColumnADescending, SCTool.getCellTexts("A1:B6"));
213     }
214 
215     /**
216      * Test sort criteria: sort second by
217      *
218      * @throws Exception
219      */
220     @Test
testSortCriteriaSortSecondBy()221     public void testSortCriteriaSortSecondBy() throws Exception {
222 
223         // Input some data
224         String[][] data = new String[][] { { "3", "D" }, { "5", "FLK" }, { "4", "E" }, { "1", "AB" }, { "6", "GE" }, { "2", "AB" }, };
225         String[][] expectedResultSortFirstByB = new String[][] { { "1", "AB" }, { "2", "AB" }, { "3", "D" }, { "4", "E" }, { "5", "FLK" }, { "6", "GE" }, };
226         String[][] expectedResultSortSecondByA = new String[][] { { "2", "AB" }, { "1", "AB" }, { "3", "D" }, { "4", "E" }, { "5", "FLK" }, { "6", "GE" }, };
227         SCTool.selectRange("A1");
228         typeKeys("3<down>5<down>4<down>1<down>6<down>2");
229         SCTool.selectRange("B1");
230         typeKeys("D<down>FLK<down>E<down>AB<down>GE<down>AB");
231 
232         // "Data->Sort...", choose "Ascending", sort first by Column B
233         app.dispatch(".uno:DataSort");
234         sortPageAscending1.check();
235         sortPageBy1.select(2); // "Column B"
236         sortPage.ok();
237 
238         // Verify sorted result
239         assertArrayEquals("Sorted result", expectedResultSortFirstByB, SCTool.getCellTexts("A1:B6"));
240 
241         // Uodo/redo
242         app.dispatch(".uno:Undo");
243         assertArrayEquals("Undo sorted result", data, SCTool.getCellTexts("A1:B6"));
244         app.dispatch(".uno:Redo");
245         assertArrayEquals("Redo sorted result", expectedResultSortFirstByB, SCTool.getCellTexts("A1:B6"));
246         app.dispatch(".uno:Undo");
247 
248         // Save and close document
249         String saveTo = getPath("temp/" + "SortCriteriaSortSecondBy.ods");
250         FileUtil.deleteFile(saveTo);
251         saveAndReopen(saveTo);
252 
253 //      // "Data->Sort...", sort first by Column B "Ascending", sort
254 //      // second by Column A "Descending"
255         calc.waitForExistence(10, 2);
256         app.dispatch(".uno:DataSort");
257         sortPageBy1.select(2); // "Column B"
258         sortPageAscending1.check();
259         sortPageBy2.select(1); // "Column A"
260         sortPageDescending2.check();
261         sortPage.ok();
262 
263         // Verify sorted result
264         assertArrayEquals("Saved sorted result", expectedResultSortSecondByA, SCTool.getCellTexts("A1:B6"));
265     }
266 
267     /**
268      * Test sort criteria: sort third by
269      *
270      * @throws Exception
271      */
272     @Test
testSortCriteriaSortThirdBy()273     public void testSortCriteriaSortThirdBy() throws Exception {
274 
275         // Input some data
276         String[][] data = new String[][] { { "3", "AB", "2" }, { "8", "FLK", "5" }, { "6", "E", "4" }, { "1", "AB", "1" }, { "9", "GE", "6" }, { "2", "AB", "2" },
277                 { "7", "EFYU", "7" }, { "5", "DS", "8" }, { "4", "AB", "1" }, };
278         String[][] expectedResultSortFirstByB = new String[][] { { "3", "AB", "2" }, { "1", "AB", "1" }, { "2", "AB", "2" }, { "4", "AB", "1" }, { "5", "DS", "8" },
279                 { "6", "E", "4" }, { "7", "EFYU", "7" }, { "8", "FLK", "5" }, { "9", "GE", "6" }, };
280         String[][] expectedResultSortSecondByC = new String[][] { { "3", "AB", "2" }, { "2", "AB", "2" }, { "1", "AB", "1" }, { "4", "AB", "1" }, { "5", "DS", "8" },
281                 { "6", "E", "4" }, { "7", "EFYU", "7" }, { "8", "FLK", "5" }, { "9", "GE", "6" }, };
282         String[][] expectedResultSortThirdByA = new String[][] { { "3", "AB", "2" }, { "2", "AB", "2" }, { "4", "AB", "1" }, { "1", "AB", "1" }, { "5", "DS", "8" },
283                 { "6", "E", "4" }, { "7", "EFYU", "7" }, { "8", "FLK", "5" }, { "9", "GE", "6" }, };
284         SCTool.selectRange("A1");
285         typeKeys("3<down>8<down>6<down>1<down>9<down>2<down>7<down>5<down>4");
286         SCTool.selectRange("B1");
287         typeKeys("AB<down>FLK<down>E<down>AB<down>GE<down>AB<down>EFYU<down>DS<down>AB");
288         SCTool.selectRange("C1");
289         typeKeys("2<down>5<down>4<down>1<down>6<down>2<down>7<down>8<down>1");
290 
291         // "Data->Sort...", choose "Ascending", sort first by Column B
292         app.dispatch(".uno:DataSort");
293         sortPageBy1.select(2); // "Column B"
294         sortPageAscending1.check();
295         sortPage.ok();
296 
297         // Verify sorted result
298         assertArrayEquals("Sorted result", expectedResultSortFirstByB, SCTool.getCellTexts("A1:C9"));
299 
300         // Uodo/redo
301         app.dispatch(".uno:Undo");
302         assertArrayEquals("Undo sorted result", data, SCTool.getCellTexts("A1:C9"));
303         app.dispatch(".uno:Redo");
304         assertArrayEquals("Redo sorted result", expectedResultSortFirstByB, SCTool.getCellTexts("A1:C9"));
305         app.dispatch(".uno:Undo");
306 
307         // Save and close document
308         String saveTo = getPath("temp/" + "SortCriteriaSortThirdBy.ods");
309         FileUtil.deleteFile(saveTo);
310         saveAndReopen(saveTo);
311 
312         // Reopen, "Data->Sort...", sort first by Column B "Ascending", sort
313         // second by Column C "Descending"
314         calc.waitForExistence(10, 2);
315         app.dispatch(".uno:DataSort");
316         sortPageBy1.select(2); // "Column B"
317         sortPageAscending1.check();
318         sortPageBy2.select(3); // "Column C"
319         sortPageDescending2.check();
320         sortPage.ok();
321 
322         // Verify sorted result
323         assertArrayEquals("Sorted result", expectedResultSortSecondByC, SCTool.getCellTexts("A1:C9"));
324 
325         // "Data->Sort...", sort first by Column B "Ascending", sort second by
326         // Column C "Descending", sort third by Column A "Descending"
327         app.dispatch(".uno:DataSort");
328         sortPageBy1.select(2); // "Column B"
329         sortPageAscending1.check();
330         sortPageBy2.select(3); // "Column C"
331         sortPageDescending2.check();
332         sortPageBy3.select(1); // "Column A"
333         sortPageDescending3.check();
334         sortPage.ok();
335 
336         // Verify sorted result
337         assertArrayEquals("Sorted result", expectedResultSortThirdByA, SCTool.getCellTexts("A1:C9"));
338 
339         // Uodo/redo
340         app.dispatch(".uno:Undo");
341         assertArrayEquals("Undo sorted result", expectedResultSortSecondByC, SCTool.getCellTexts("A1:C9"));
342         app.dispatch(".uno:Redo");
343         assertArrayEquals("Redo sorted result", expectedResultSortThirdByA, SCTool.getCellTexts("A1:C9"));
344 
345         // Save and close document
346         saveTo = getPath("temp/" + "SortCriteriaSortThirdBy1.ods");
347         FileUtil.deleteFile(saveTo);
348         saveAndReopen(saveTo);
349 
350         calc.waitForExistence(10, 2);
351         assertArrayEquals("Saved sorted result", expectedResultSortThirdByA, SCTool.getCellTexts("A1:C9"));
352     }
353 
354     /**
355      * Test sort options: custom sort order, predefined in preferences from copy
356      * list
357      *
358      * @throws Exception
359      */
360     @Test
testSortOptionsCustomSortOrderPredefineFromCopyList()361     public void testSortOptionsCustomSortOrderPredefineFromCopyList() throws Exception {
362 
363         // Dependencies start
364         SCTool.selectRange("A1");
365         typeKeys("red<down>yellow<down>blue<down>green<down>white<down>black");
366         SCTool.selectRange("A1:A6");
367         app.dispatch(".uno:ChangeCaseToLower"); // In case SC capitalize first
368                                                 // letter automatically
369 
370         // Select the cell range,
371         // "Tools->Options...->OpenOffice.org Spreadsheets->Sort Lists"
372         SCTool.selectRange("A1:A6");
373         app.dispatch(".uno:OptionsTreeDialog");
374         optionsDlgList.collapseAll();
375         // // Select "Sort Lists": start. Shrink the tree list and select
376         // OptionsDlgList.select(0);
377         // typeKeys("<left>");
378         // for (int i=0; i<6; i++) {
379         // typeKeys("<down><left>");
380         // }
381         optionsDlgList.expand(3);
382         // typeKeys("<right>");
383         optionsDlgList.select(7);
384         // // Select "Sort Lists": end
385 
386         // Click "Copy" button, "OK", close the document
387         optionsDlgSortListsTabCopy.click();
388         optionsDlg.ok();
389         app.dispatch(".uno:CloseDoc");
390         msgBox_AdditionalRowsNotSaved.no();
391         // Dependencies end
392 
393         // Create a new spreadsheet document
394         app.dispatch("private:factory/scalc");
395 
396         // Input some data
397         String[][] data = new String[][] { { "Color" }, { "black" }, { "yellow" }, { "blue" }, { "black" }, { "white" }, { "red" }, };
398         String[][] expectedResultNoCustomSortOrder = new String[][] { { "Color" }, { "black" }, { "black" }, { "blue" }, { "red" }, { "white" }, { "yellow" }, };
399         String[][] expectedResultCustomSortOrder = new String[][] { { "Color" }, { "red" }, { "yellow" }, { "blue" }, { "white" }, { "black" }, { "black" }, };
400         SCTool.selectRange("A1");
401         typeKeys("Color<down>black<down>yellow<down>blue<down>black<down>white<down>red");
402         SCTool.selectRange("A2:A7");
403         app.dispatch(".uno:ChangeCaseToLower"); // In case SC capitalize first
404                                                 // letter automatically
405 
406         // "Data->Sort...", "Options" tab, check "Range contains column labels",
407         // no custom sort order, "Ascending", sort first by Color
408         SCTool.selectRange("A1:A7");
409         app.dispatch(".uno:DataSort");
410         sortOptionsPage.select();
411         sortOptionsPageRangeContainsColumnLabels.check();
412         sortOptionsPageCustomSortOrder.uncheck();
413         sortPage.select();
414         sortPageBy1.select(1); // "Color"
415         sortPageAscending1.check();
416         sortPage.ok();
417 
418         // Verify sorted result
419         assertArrayEquals("Sorted result without custom sort order", expectedResultNoCustomSortOrder, SCTool.getCellTexts("A1:A7"));
420 
421         // Uodo/redo
422         app.dispatch(".uno:Undo");
423         assertArrayEquals("Undo sorted result", data, SCTool.getCellTexts("A1:A7"));
424         app.dispatch(".uno:Redo");
425         assertArrayEquals("Redo sorted result", expectedResultNoCustomSortOrder, SCTool.getCellTexts("A1:A7"));
426         app.dispatch(".uno:Undo");
427 
428         // Copy original data to sheet2
429         SCTool.selectRange("A1:A7");
430         app.dispatch(".uno:Copy");
431         app.dispatch(".uno:SelectTables");
432         scSheetsList.select(1);
433         scSelectSheetsDlg.ok();
434         app.dispatch(".uno:Paste");
435 
436         // "Data->Sort...", "Options" tab, check "Range contains column labels",
437         // choose custom sort order, "Ascending", sort first by Color
438         app.dispatch(".uno:DataSort");
439         sortOptionsPage.select();
440         sortOptionsPageRangeContainsColumnLabels.check();
441         sortOptionsPageCustomSortOrder.check();
442         sortOptionsPageCustomSortOrderList.select("red,yellow,blue,green,white,black");
443         sortPage.select();
444         sortPageBy1.select(1); // "Color"
445         sortPageAscending1.check();
446         sortPage.ok();
447 
448         // Verify sorted result
449         assertArrayEquals("Sorted result with custom sort order", expectedResultCustomSortOrder, SCTool.getCellTexts("A1:A7"));
450 
451         // Uodo/redo
452         app.dispatch(".uno:Undo");
453         assertArrayEquals("Undo sorted result", data, SCTool.getCellTexts("A1:A7"));
454         app.dispatch(".uno:Redo");
455         assertArrayEquals("Redo sorted result", expectedResultCustomSortOrder, SCTool.getCellTexts("A1:A7"));
456 
457         // Save and close document
458         String saveTo = getPath("temp/" + "SortOptionsCustomSortOrderPredefineFromCopyList.ods");
459         FileUtil.deleteFile(saveTo);
460         saveAndReopen(saveTo);
461 
462         calc.waitForExistence(10, 2);
463         app.dispatch(".uno:SelectTables");
464         scSheetsList.select(0); // Sheet 1
465         scSelectSheetsDlg.ok();
466         assertArrayEquals("Original data", data, SCTool.getCellTexts("$A1:$A7"));
467         app.dispatch(".uno:SelectTables");
468         scSheetsList.select(1); // Sheet 2
469         scSelectSheetsDlg.ok();
470         assertArrayEquals("Saved sorted result", expectedResultCustomSortOrder, SCTool.getCellTexts("$A1:$A7"));
471     }
472 
473     /**
474      * Test sort options: custom sort order, predefined in preferences from new
475      * list
476      *
477      * @throws Exception
478      */
479     @Test
testSortOptionsCustomSortOrderPredefineFromNewList()480     public void testSortOptionsCustomSortOrderPredefineFromNewList() throws Exception {
481 
482         // Dependencies start
483         // "Tools->Options...->OpenOffice.org Spreadsheets->Sort Lists"
484         app.dispatch(".uno:OptionsTreeDialog");
485         // Select "Sort Lists": start. Shrink the tree list and select
486         optionsDlgList.select(0);
487         typeKeys("<left>");
488         for (int i = 0; i < 6; i++) {
489             typeKeys("<down><left>");
490         }
491         optionsDlgList.select(3);
492         typeKeys("<right>");
493         optionsDlgList.select(7);
494         // Select "Sort Lists": end
495 
496         // Click "New" button, input "white,red,yellow,blue,green,black", press
497         // "Add" and "OK", close the document
498         optionsDlgSortListsTabNew.click();
499         typeKeys("white,red,yellow,blue,green,black");
500         optionsDlgSortListsTabAdd.click();
501         optionsDlg.ok();
502         app.dispatch(".uno:CloseDoc");
503         // Dependencies end
504 
505         AppTool.newSpreadsheet();
506 
507         // Input some data
508         String[][] data = new String[][] { { "Color" }, { "black" }, { "yellow" }, { "blue" }, { "black" }, { "white" }, { "red" }, };
509         String[][] expectedResultNoCustomSortOrder = new String[][] { { "Color" }, { "black" }, { "black" }, { "blue" }, { "red" }, { "white" }, { "yellow" }, };
510         String[][] expectedResultCustomSortOrder = new String[][] { { "Color" }, { "white" }, { "red" }, { "yellow" }, { "blue" }, { "black" }, { "black" }, };
511         SCTool.selectRange("A1");
512         typeKeys("Color<down>black<down>yellow<down>blue<down>black<down>white<down>red");
513         SCTool.selectRange("A2:A7");
514         app.dispatch(".uno:ChangeCaseToLower"); // In case SC capitalize first
515                                                 // letter automatically
516 
517         // "Data->Sort...", "Options" tab, check "Range contains column labels",
518         // no custom sort order, "Ascending", sort first by Color
519         SCTool.selectRange("A1:A7");
520         app.dispatch(".uno:DataSort");
521         sortOptionsPage.select();
522         sortOptionsPageRangeContainsColumnLabels.check();
523         sortOptionsPageCustomSortOrder.uncheck();
524         sortPage.select();
525         sortPageBy1.select(1); // "Color"
526         sortPageAscending1.check();
527         sortPage.ok();
528 
529         // Verify sorted result
530         assertArrayEquals("Sorted result without custom sort order", expectedResultNoCustomSortOrder, SCTool.getCellTexts("A1:A7"));
531 
532         // Uodo/redo
533         app.dispatch(".uno:Undo");
534         assertArrayEquals("Undo sorted result", data, SCTool.getCellTexts("A1:A7"));
535         app.dispatch(".uno:Redo");
536         assertArrayEquals("Redo sorted result", expectedResultNoCustomSortOrder, SCTool.getCellTexts("A1:A7"));
537         app.dispatch(".uno:Undo");
538 
539         // Copy original data to sheet2
540         SCTool.selectRange("A1:A7");
541         app.dispatch(".uno:Copy");
542         app.dispatch(".uno:SelectTables");
543         scSheetsList.select(1); // Sheet 2
544         scSelectSheetsDlg.ok();
545         app.dispatch(".uno:Paste");
546 
547         // "Data->Sort...", "Options" tab, check "Range contains column labels",
548         // choose custom sort order, "Ascending", sort first by Color
549         app.dispatch(".uno:DataSort");
550         sortOptionsPage.select();
551         sortOptionsPageRangeContainsColumnLabels.check();
552         sortOptionsPageCustomSortOrder.check();
553         sortOptionsPageCustomSortOrderList.select("white,red,yellow,blue,green,black");
554         sortPage.select();
555         sortPageBy1.select(1); // "Color"
556         sortPageAscending1.check();
557         sortPage.ok();
558 
559         // Verify sorted result
560         assertArrayEquals("Sorted result with custom sort order", expectedResultCustomSortOrder, SCTool.getCellTexts("A1:A7"));
561 
562         // Uodo/redo
563         app.dispatch(".uno:Undo");
564         assertArrayEquals("Undo sorted result", data, SCTool.getCellTexts("A1:A7"));
565         app.dispatch(".uno:Redo");
566         assertArrayEquals("Redo sorted result", expectedResultCustomSortOrder, SCTool.getCellTexts("A1:A7"));
567 
568         // Save and close document
569         String saveTo = getPath("temp/" + "SortOptionsCustomSortOrderPredefineFromNewList.ods");
570         FileUtil.deleteFile(saveTo);
571         saveAndReopen(saveTo);
572 
573         calc.waitForExistence(10, 2);
574         app.dispatch(".uno:SelectTables");
575         scSheetsList.select(0); // Sheet 1
576         scSelectSheetsDlg.ok();
577         assertArrayEquals("Original data", data, SCTool.getCellTexts("$A1:$A7"));
578         app.dispatch(".uno:SelectTables");
579         scSheetsList.select(1); // Sheet 2
580         scSelectSheetsDlg.ok();
581         assertArrayEquals("Saved sorted result", expectedResultCustomSortOrder, SCTool.getCellTexts("$A1:$A7"));
582     }
583 
584     /**
585      * Test sort options: sort columns, direction "Left to right"
586      *
587      * @throws Exception
588      */
589     @Test
testSortOptionsDirectionSortColumns()590     public void testSortOptionsDirectionSortColumns() throws Exception {
591 
592         // Input some data
593         String[][] data = new String[][] { { "Units", "7", "27", "4", "12", "3", "6" }, };
594         String[][] expectedSortedResult = new String[][] { { "Units", "3", "4", "6", "7", "12", "27" }, };
595         SCTool.selectRange("A1");
596         typeKeys("Units<right>7<right>27<right>4<right>12<right>3<right>6");
597         sleep(1); // If no sleep, some strings lost
598 
599         // "Data->Sort...", check "Range contains column labels",
600         // "Left to right", sort first by"Units", "Ascending"
601         app.dispatch(".uno:DataSort");
602         sortOptionsPage.select();
603         sortOptionsPageRangeContainsColumnLabels.check();
604         sortOptionsPageLeftToRight.check();
605         sortPage.select();
606         sortPageBy1.select(1); // Choose "Units"
607         sortPageAscending1.check();
608         sortPage.ok();
609 
610         // Verify sorted result
611         assertArrayEquals("Sorted result", expectedSortedResult, SCTool.getCellTexts("A1:G1"));
612 
613         // Uodo/redo
614         app.dispatch(".uno:Undo");
615         assertArrayEquals("Undo sorted result", data, SCTool.getCellTexts("A1:G1"));
616         app.dispatch(".uno:Redo");
617         assertArrayEquals("Redo sorted result", expectedSortedResult, SCTool.getCellTexts("A1:G1"));
618 
619         // Save and close document
620         String saveTo = getPath("temp/" + "SortOptionsDirectionSortColumns.ods");
621         FileUtil.deleteFile(saveTo);
622         saveAndReopen(saveTo);
623 
624         calc.waitForExistence(10, 2);
625         assertArrayEquals("Saved sorted result", expectedSortedResult, SCTool.getCellTexts("A1:G1"));
626     }
627 
628     /**
629      * Test sort options: "Include formats"
630      *
631      * @throws Exception
632      */
633     @Test
testSortOptionsIncludeFormats()634     public void testSortOptionsIncludeFormats() throws Exception {
635 
636         String[][] dataWithCurrencyFormats = new String[][] { { "Units" }, { "$32.00" }, { "57.00 \u20ac" }, { "\u20a4 74" }, { "R$ 50.00" }, { "\u062c.\u0645. 27" },
637                 { "7.00 \u0440\u0443\u0431" }, };
638         String[][] expectedSortedResultIncludeFormat = new String[][] { { "Units" }, { "7.00 \u0440\u0443\u0431" }, { "\u062c.\u0645. 27" }, { "$32.00" }, { "R$ 50.00" },
639                 { "57.00 \u20ac" }, { "\u20a4 74" }, };
640         String[][] expectedSortedResultExcludeFormat = new String[][] { { "Units" }, { "$7.00" }, { "27.00 \u20ac" }, { "\u20a4 32" }, { "R$ 50.00" }, { "\u062c.\u0645. 57" },
641                 { "74.00 \u0440\u0443\u0431" }, };
642 
643         // Open sample file to get source data
644         String file = prepareData("sc/SortOptionsIncludeFormats.ods");
645         app.dispatch(".uno:Open", 3);
646         submitOpenDlg(file);
647         calc.waitForExistence(10, 2);
648 
649         assertArrayEquals("source", dataWithCurrencyFormats, SCTool.getCellTexts("A1:A7"));
650 
651         // "Data->Sort...", check "Range contains column labels", check
652         // "Include formats", sort first by "Units", "Ascending"
653         app.dispatch(".uno:DataSort");
654         sortOptionsPage.select();
655         sortOptionsPageRangeContainsColumnLabels.check();
656         sortOptionsPageIncludeFormats.check();
657         sortPage.select();
658         sortPageBy1.select(1); // "Units"
659         sortPageAscending1.check();
660         sortPage.ok();
661 
662         // Verify sorted result
663         assertArrayEquals("Sorted result include formats", expectedSortedResultIncludeFormat, SCTool.getCellTexts("A1:A7"));
664 
665         // Uodo/redo
666         app.dispatch(".uno:Undo");
667         assertArrayEquals("Undo sorted result", dataWithCurrencyFormats, SCTool.getCellTexts("A1:A7"));
668         app.dispatch(".uno:Redo");
669         assertArrayEquals("Redo sorted result", expectedSortedResultIncludeFormat, SCTool.getCellTexts("A1:A7"));
670         app.dispatch(".uno:Undo");
671 
672         // Copy the original data to sheet2
673         SCTool.selectRange("A1:A7");
674         app.dispatch(".uno:Copy");
675         SCTool.selectRange("Sheet2.A1");
676         app.dispatch(".uno:Paste");
677 
678         // "Data->Sort...", check "Range contains column labels", uncheck
679         // "Include formats", sort first by "Units", "Ascending"
680         app.dispatch(".uno:DataSort");
681         sortOptionsPage.select();
682         sortOptionsPageRangeContainsColumnLabels.check();
683         sortOptionsPageIncludeFormats.uncheck();
684         sortPage.select();
685         sortPageBy1.select(1); // "Units"
686         sortPageAscending1.check();
687         sortPage.ok();
688 
689         // Verify sorted result
690         assertArrayEquals("Sorted result exclude formats", expectedSortedResultExcludeFormat, SCTool.getCellTexts("A1:A7"));
691 
692         // Uodo/redo
693         app.dispatch(".uno:Undo");
694         assertArrayEquals("Undo sorted result", dataWithCurrencyFormats, SCTool.getCellTexts("A1:A7"));
695         app.dispatch(".uno:Redo");
696         assertArrayEquals("Redo sorted result", expectedSortedResultExcludeFormat, SCTool.getCellTexts("A1:A7"));
697 
698         // Save and close document
699         String saveTo = getPath("temp/" + "SortOptionsIncludeFormats.ods");
700         FileUtil.deleteFile(saveTo);
701         saveAndReopen(saveTo);
702 
703         calc.waitForExistence(10, 2);
704         assertArrayEquals("Original data", dataWithCurrencyFormats, SCTool.getCellTexts("$Sheet1.$A1:$A7"));
705         assertArrayEquals("Saved sorted result exclude format", expectedSortedResultExcludeFormat, SCTool.getCellTexts("$Sheet2.$A1:$A7"));
706     }
707 
708     /**
709      * Test sort options: multiple sort, data overlap
710      *
711      * @throws Exception
712      */
713     @Test
testSortOptionsMultipleSortDataOverlap()714     public void testSortOptionsMultipleSortDataOverlap() throws Exception {
715 
716         // Input some data
717         String[][] data1 = new String[][] { { "D" }, { "C" }, { "B" }, { "A" }, { "E" }, };
718         String[][] expectedSortedResult1 = new String[][] { { "A" }, { "B" }, { "C" }, { "D" }, { "E" }, };
719         String[][] data2 = new String[][] { { "4" }, { "2" }, { "5" }, { "1" }, { "3" }, };
720         String[][] expectedSortedResultDataOverlap = new String[][] { { "A" }, { "B" }, { "C" }, { "1" }, { "2" }, { "3" }, { "4" }, { "5" }, };
721         SCTool.selectRange("A1");
722         typeKeys("D<down>C<down>B<down>A<down>E");
723         sleep(1); // If no sleep, some strings lost
724 
725         // "Data->Sort...", uncheck "Range contains column labels", sort first
726         // by "Column A", "Ascending"
727         app.dispatch(".uno:DataSort");
728         sortOptionsPage.select();
729         sortOptionsPageRangeContainsColumnLabels.uncheck();
730         sortPage.select();
731         sortPageBy1.select(1); // "Column A"
732         sortPageAscending1.check();
733         sortPage.ok();
734 
735         // Verify sorted result
736         assertArrayEquals("Sorted result", expectedSortedResult1, SCTool.getCellTexts("A1:A5"));
737 
738         // Uodo/redo
739         app.dispatch(".uno:Undo");
740         assertArrayEquals("Undo sorted result", data1, SCTool.getCellTexts("A1:A5"));
741         app.dispatch(".uno:Redo");
742         assertArrayEquals("Redo sorted result", expectedSortedResult1, SCTool.getCellTexts("A1:A5"));
743 
744         // Input data2 into same sheet, data1 and data2 are not overlapped
745         SCTool.selectRange("G10");
746         typeKeys("4<down>2<down>5<down>1<down>3");
747 
748         // Focus on data2, "Data->Sort...", "Copy result to" partially overlap
749         // with data1, sort first by "Column G", "Ascending"
750         SCTool.selectRange("G10");
751         app.dispatch(".uno:DataSort");
752         sortOptionsPage.select();
753         sortOptionsPageRangeContainsColumnLabels.uncheck();
754         sortOptionsPageCopyResultTo.check();
755         sortOptionsPageCopyResultToEdit.setText("A4");
756         sortPage.select();
757         sortPageBy1.select(1); // "Column G"
758         sortPageAscending1.check();
759         sortPage.ok();
760 
761         // Verify sorted result
762         assertArrayEquals("Sorted result data overlap", expectedSortedResultDataOverlap, SCTool.getCellTexts("A1:A8"));
763 
764         // Save and close document
765         String saveTo = getPath("temp/" + "SortOptionsMultipleSortDataOverlap.ods");
766         FileUtil.deleteFile(saveTo);
767         saveAndReopen(saveTo);
768 
769         calc.waitForExistence(10, 2);
770         assertArrayEquals("Saved sorted result", expectedSortedResultDataOverlap, SCTool.getCellTexts("A1:A8"));
771         assertArrayEquals("Original data2", data2, SCTool.getCellTexts("G10:G14"));
772     }
773 
774     /**
775      * Test sort options: multiple sort, no data overlap, sort parameter saved
776      * correctly
777      *
778      * @throws Exception
779      */
780     @Test
testSortOptionsMultipleSortSortParameterSaved()781     public void testSortOptionsMultipleSortSortParameterSaved() throws Exception {
782 
783         // Input some data
784         String[][] data1 = new String[][] { { "D" }, { "C" }, { "B" }, { "A" }, { "E" }, };
785         String[][] expectedSortedResult1 = new String[][] { { "A" }, { "B" }, { "C" }, { "D" }, { "E" }, };
786         String[][] data2 = new String[][] { { "Numbers" }, { "4" }, { "2" }, { "5" }, { "1" }, { "3" }, };
787         String[][] expectedSortedResult2 = new String[][] { { "Numbers" }, { "1" }, { "2" }, { "3" }, { "4" }, { "5" }, };
788         SCTool.selectRange("A1");
789         typeKeys("D<down>C<down>B<down>A<down>E");
790         sleep(1); // If no sleep, some strings lost
791 
792         // "Data->Sort...", uncheck "Range contains column labels", check
793         // "Case sensitive" and "Include formats", sort first by "Column A",
794         // "Ascending"
795         app.dispatch(".uno:DataSort");
796         sortOptionsPage.select();
797         sortOptionsPageRangeContainsColumnLabels.uncheck();
798         sortOptionsPageCaseSensitive.check();
799         sortOptionsPageIncludeFormats.check();
800         sortPage.select();
801         sortPageBy1.select(1); // "Column A"
802         sortPageAscending1.check();
803         sortPage.ok();
804 
805         // Verify sorted result
806         assertArrayEquals("Sorted result1", expectedSortedResult1, SCTool.getCellTexts("A1:A5"));
807 
808         // Uodo/redo
809         app.dispatch(".uno:Undo");
810         assertArrayEquals("Undo sorted result", data1, SCTool.getCellTexts("A1:A5"));
811         app.dispatch(".uno:Redo");
812         assertArrayEquals("Redo sorted result", expectedSortedResult1, SCTool.getCellTexts("A1:A5"));
813 
814         // Input data2 into same sheet, data1 and data2 are not overlapped
815         SCTool.selectRange("G10");
816         typeKeys("Numbers<down>4<down>2<down>5<down>1<down>3");
817 
818         // Focus on data2, "Data->Sort...", check
819         // "Range contains column labels", uncheck "Case sensitive" and
820         // "Include formats", sort first by "Numbers", "Ascending"
821         SCTool.selectRange("G10");
822         app.dispatch(".uno:DataSort");
823         sortOptionsPage.select();
824         sortOptionsPageRangeContainsColumnLabels.check();
825         sortOptionsPageCaseSensitive.uncheck();
826         sortOptionsPageIncludeFormats.uncheck();
827         sortPage.select();
828         sortPageBy1.select(1); // "Numbers"
829         sortPageAscending1.check();
830         sortPage.ok();
831 
832         // Verify sorted result
833         assertArrayEquals("Sorted result2", expectedSortedResult2, SCTool.getCellTexts("G10:G15"));
834 
835         // Uodo/redo
836         app.dispatch(".uno:Undo");
837         assertArrayEquals("Undo sorted result", data2, SCTool.getCellTexts("G10:G15"));
838         app.dispatch(".uno:Redo");
839         assertArrayEquals("Redo sorted result", expectedSortedResult2, SCTool.getCellTexts("G10:G15"));
840 
841         // Open sort dialog, check its setting
842         app.dispatch(".uno:DataSort");
843         sortOptionsPage.select();
844         assertTrue("Range contains column labels should be checked", sortOptionsPageRangeContainsColumnLabels.isChecked());
845         assertFalse("Case sensitive should not be checked", sortOptionsPageCaseSensitive.isChecked());
846         assertFalse("Include formats should not be checked", sortOptionsPageIncludeFormats.isChecked());
847         sortOptionsPage.ok();
848 
849         // Save and close document
850         String saveTo = getPath("temp/" + "SortOptionsMultipleSortParameterSaved.ods");
851         FileUtil.deleteFile(saveTo);
852         saveAndReopen(saveTo);
853 
854         calc.waitForExistence(10, 2);
855         assertArrayEquals("Saved sorted result1", expectedSortedResult1, SCTool.getCellTexts("A1:A5"));
856         assertArrayEquals("Saved sorted result2", expectedSortedResult2, SCTool.getCellTexts("G10:G15"));
857         app.dispatch(".uno:DataSort");
858         sortOptionsPage.select();
859         assertTrue("Range contains column labels should be checked", sortOptionsPageRangeContainsColumnLabels.isChecked());
860         assertFalse("Case sensitive should not be checked", sortOptionsPageCaseSensitive.isChecked());
861         assertFalse("Include formats should not be checked", sortOptionsPageIncludeFormats.isChecked());
862         sortOptionsPage.ok();
863     }
864 
865 
866 }
867