Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / qa / uitest / calc_tests4 / tdf91305.py
blobeae7e8c4555e66abd2437ea35d369c72cf165ae5
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 from uitest.framework import UITestCase
8 from uitest.uihelper.common import get_state_as_dict
9 from uitest.uihelper.common import select_pos
10 from uitest.uihelper.calc import enter_text_to_cell
11 from libreoffice.calc.document import get_sheet_from_doc
12 from libreoffice.calc.conditional_format import get_conditional_format_from_sheet
13 from uitest.debug import sleep
14 from libreoffice.calc.document import get_cell_by_position
15 from libreoffice.uno.propertyvalue import mkPropertyValues
16 #Bug 91305 - Sort button does not sort first cell if it has text format
18 class tdf91305(UITestCase):
20 def test_tdf91305_sort_text_cells_rows(self):
21 calc_doc = self.ui_test.create_doc_in_start_center("calc")
22 xCalcDoc = self.xUITest.getTopFocusWindow()
23 gridwin = xCalcDoc.getChild("grid_window")
24 document = self.ui_test.get_component()
25 #In column A enter texts
26 enter_text_to_cell(gridwin, "A1", "cc")
27 enter_text_to_cell(gridwin, "A2", "ff")
28 enter_text_to_cell(gridwin, "A3", "aa")
30 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:A3"}))
31 #Press toolbarbutton for ascending sorting .uno:SortAsc
32 self.xUITest.executeCommand(".uno:SortAscending")
33 #verify
34 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "aa")
35 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "cc")
36 self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "ff")
37 #Press toolbarbutton for descending sorting .uno:SortDescending
38 self.xUITest.executeCommand(".uno:SortDescending")
39 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "ff")
40 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "cc")
41 self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "aa")
43 def test_tdf91305_sort_text_cells_columns(self):
44 calc_doc = self.ui_test.create_doc_in_start_center("calc")
45 xCalcDoc = self.xUITest.getTopFocusWindow()
46 gridwin = xCalcDoc.getChild("grid_window")
47 document = self.ui_test.get_component()
48 #In column A enter texts
49 enter_text_to_cell(gridwin, "A1", "cc")
50 enter_text_to_cell(gridwin, "B1", "ff")
51 enter_text_to_cell(gridwin, "C1", "aa")
53 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:C1"}))
54 #Open sort dialog by DATA - SORT
55 self.ui_test.execute_dialog_through_command(".uno:DataSort")
56 xDialog = self.xUITest.getTopFocusWindow()
57 xTabs = xDialog.getChild("tabcontrol")
58 xleftright = xDialog.getChild("leftright")
59 select_pos(xTabs, "1")
60 xleftright.executeAction("CLICK", tuple())
61 xOK = xDialog.getChild("ok")
62 self.ui_test.close_dialog_through_button(xOK)
63 #verify
64 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "aa")
65 self.assertEqual(get_cell_by_position(document, 0, 1, 0).getString(), "cc")
66 self.assertEqual(get_cell_by_position(document, 0, 2, 0).getString(), "ff")
67 #Open sort dialog by DATA - SORT
68 self.ui_test.execute_dialog_through_command(".uno:DataSort")
69 xDialog = self.xUITest.getTopFocusWindow()
70 xTabs = xDialog.getChild("tabcontrol")
71 xleftright = xDialog.getChild("leftright")
72 xdown = xDialog.getChild("down")
73 select_pos(xTabs, "1")
74 xleftright.executeAction("CLICK", tuple())
75 select_pos(xTabs, "0")
76 xdown.executeAction("CLICK", tuple())
77 xOK = xDialog.getChild("ok")
78 self.ui_test.close_dialog_through_button(xOK)
79 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "ff")
80 self.assertEqual(get_cell_by_position(document, 0, 1, 0).getString(), "cc")
81 self.assertEqual(get_cell_by_position(document, 0, 2, 0).getString(), "aa")
82 self.ui_test.close_doc()
84 #comment 6 - Additional sub-bugs:
85 def test_tdf91305_sort_text_cells_rows(self):
86 #Selecting some empty cells and pressing SORT causes empty cells to move below.
87 #No matter if you sort from A to Z or from Z to A.
88 calc_doc = self.ui_test.create_doc_in_start_center("calc")
89 xCalcDoc = self.xUITest.getTopFocusWindow()
90 gridwin = xCalcDoc.getChild("grid_window")
91 document = self.ui_test.get_component()
92 #In column A enter text
93 enter_text_to_cell(gridwin, "A5", "ff")
94 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:A4"}))
95 #sorting
96 self.xUITest.executeCommand(".uno:SortAscending")
97 self.xUITest.executeCommand(".uno:SortDescending")
98 #verify
99 self.assertEqual(get_cell_by_position(document, 0, 0, 4).getString(), "ff")
100 # Assert that the correct range has been selected
101 gridWinState = get_state_as_dict(gridwin)
102 self.assertEqual(gridWinState["MarkedArea"], "Sheet1.A1:Sheet1.A4")
104 self.ui_test.close_doc()
106 #2) Placing digit to the header position and running set of sorts will make digit to be on 2nd or last position.
107 def test_tdf91305_sort_text_cells_1st_row_digit(self):
108 calc_doc = self.ui_test.create_doc_in_start_center("calc")
109 xCalcDoc = self.xUITest.getTopFocusWindow()
110 gridwin = xCalcDoc.getChild("grid_window")
111 document = self.ui_test.get_component()
112 #In column A enter texts
113 enter_text_to_cell(gridwin, "A1", "1")
114 enter_text_to_cell(gridwin, "A2", "ff")
115 enter_text_to_cell(gridwin, "A3", "aa")
116 enter_text_to_cell(gridwin, "A4", "cc")
118 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:A4"}))
119 #Press toolbarbutton for ascending sorting .uno:SortAsc
120 self.xUITest.executeCommand(".uno:SortAscending")
121 #verify
122 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "1")
123 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "aa")
124 self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "cc")
125 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "ff")
126 #Press toolbarbutton for descending sorting .uno:SortDescending
127 self.xUITest.executeCommand(".uno:SortDescending")
128 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "ff")
129 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "cc")
130 self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "aa")
131 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "1")
132 #Undo
133 self.xUITest.executeCommand(".uno:Undo")
134 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "1")
135 self.assertEqual(get_cell_by_position(document, 0, 0, 1).getString(), "aa")
136 self.assertEqual(get_cell_by_position(document, 0, 0, 2).getString(), "cc")
137 self.assertEqual(get_cell_by_position(document, 0, 0, 3).getString(), "ff")
139 self.ui_test.close_doc()
140 # vim: set shiftwidth=4 softtabstop=4 expandtab: