1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 from uitest
.framework
import UITestCase
11 from uitest
.uihelper
.common
import get_url_for_data_file
13 from libreoffice
.calc
.document
import get_cell_by_position
14 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
17 # Testcases Sorting TCS_Sorting Stable sorting
18 class CalcStableSorting(UITestCase
):
20 def test_Must_keep_sort_order_previous_sorting_toolbar_button_Ascending(self
):
21 with self
.ui_test
.load_file(get_url_for_data_file("stableSorting.ods")) as calc_doc
:
22 xCalcDoc
= self
.xUITest
.getTopFocusWindow()
23 gridwin
= xCalcDoc
.getChild("grid_window")
24 #Select cell E1 ("Sales") and press toolbar button for ascending sorting.
25 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "E1"}))
26 self
.xUITest
.executeCommand(".uno:SortAscending")
27 #Select cell D1 ("Product") and press toolbar button for ascending sorting.
28 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "D1"}))
29 self
.xUITest
.executeCommand(".uno:SortAscending")
30 #Select cell C1 ("Salesman") and press toolbar button for ascending sorting.
31 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
32 self
.xUITest
.executeCommand(".uno:SortAscending")
33 # Select cell B1 ("Region") and press toolbar button for ascending sorting.
34 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "B1"}))
35 self
.xUITest
.executeCommand(".uno:SortAscending")
36 #Verify that the numbers in column "CheckOrder" are ascending
37 for i
in range(1, 501):
38 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 5, i
).getValue(), i
)
40 def test_Must_keep_sort_order_previous_sorting_toolbar_button_Descending(self
):
41 with self
.ui_test
.load_file(get_url_for_data_file("stableSorting.ods")) as calc_doc
:
42 xCalcDoc
= self
.xUITest
.getTopFocusWindow()
43 gridwin
= xCalcDoc
.getChild("grid_window")
44 #Select cell E1 ("Sales") and press toolbar button for descending sorting.
45 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "E1"}))
46 self
.xUITest
.executeCommand(".uno:SortDescending")
47 #Select cell D1 ("Product") and press toolbar button for descending sorting.
48 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "D1"}))
49 self
.xUITest
.executeCommand(".uno:SortDescending")
50 #Select cell C1 ("Salesman") and press toolbar button for descending sorting.
51 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
52 self
.xUITest
.executeCommand(".uno:SortDescending")
53 # Select cell B1 ("Region") and press toolbar button for descending sorting.
54 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "B1"}))
55 self
.xUITest
.executeCommand(".uno:SortDescending")
56 #Verify that the numbers in column "CheckOrder" are ascending
57 for i
in range(1, 501):
59 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 5, i
).getValue(), j
)
61 # def test_Must_keep_sort_order_previous_sorting_using_sort_dialog(self):
62 # cannot test for now - criteria names are identical - Markus https://gerrit.libreoffice.org/#/c/52534/
63 # calc_doc = self.ui_test.load_file(get_url_for_data_file("stableSorting.ods"))
64 # xCalcDoc = self.xUITest.getTopFocusWindow()
65 # gridwin = xCalcDoc.getChild("grid_window")
66 # document = self.ui_test.get_component()
67 # Select cell A1 and open sort dialog by DATA - SORT
68 # gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
69 # Open sort dialog by DATA - SORT /Switch to tabpage Options
70 # self.ui_test.execute_dialog_through_command(".uno:DataSort")
71 # xDialog = self.xUITest.getTopFocusWindow()
72 # xTabs = xDialog.getChild("tabcontrol")
73 # select_pos(xTabs, "1")
74 # Check option "Range contains column labels"
75 # xHeader = xDialog.getChild("header")
76 # self.assertEqual(get_state_as_dict(xHeader)["Selected"], "true")
77 # Switch to tabpage "Sort Criteria"
78 # select_pos(xTabs, "0")
79 # Choose "Salesman(ascending)" as first criteria
80 # xSortKey1 = xDialog.getChild("sortlb")
81 # xAsc = xDialog.getChild("up")
82 # props = {"TEXT": "Salesman"}
83 # actionProps = mkPropertyValues(props)
84 # xSortKey1.executeAction("SELECT", actionProps)
85 # self.assertEqual(get_state_as_dict(xAsc)["Checked"], "true")
86 #Choose "Product (ascending)" as second criteria
87 # xSortKey2 = xDialog.getChild("sortuserlb")
88 # xAsc = xDialog.getChild("up")
89 # props = {"TEXT": "Salesman"}
90 # actionProps = mkPropertyValues(props)
91 # xSortKey1.executeAction("SELECT", actionProps)
92 # self.assertEqual(get_state_as_dict(xAsc)["Checked"], "true")
93 # self.ui_test.close_doc()
95 # vim: set shiftwidth=4 softtabstop=4 expandtab: