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_cell_by_position
12 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
13 import org
.libreoffice
.unotest
15 #Bug 53482 - UI: Option 'Range contains column headings' ignored
17 def get_url_for_data_file(file_name
):
18 return pathlib
.Path(org
.libreoffice
.unotest
.makeCopyFromTDOC(file_name
)).as_uri()
20 class tdf53482(UITestCase
):
22 def test_tdf53482_Range_contains_column_headings_file(self
):
23 calc_doc
= self
.ui_test
.load_file(get_url_for_data_file("tdf53482.ods"))
24 xCalcDoc
= self
.xUITest
.getTopFocusWindow()
25 gridwin
= xCalcDoc
.getChild("grid_window")
26 document
= self
.ui_test
.get_component()
27 #1. Highlight cells to be sorted A8:J124
28 gridwin
.executeAction("SELECT", mkPropertyValues({"RANGE": "A8:J124"}))
29 #2. Click Data menu, Sort
30 self
.ui_test
.execute_dialog_through_command(".uno:DataSort")
31 xDialog
= self
.xUITest
.getTopFocusWindow()
32 xTabs
= xDialog
.getChild("tabcontrol")
33 select_pos(xTabs
, "1")
34 #3. On Options tab, tick 'Range contains column labels'
35 xHeader
= xDialog
.getChild("header")
36 xHeader
.executeAction("CLICK", tuple())
37 if (get_state_as_dict(xHeader
)["Selected"]) == "false":
38 xHeader
.executeAction("CLICK", tuple())
39 #4. On Sort Criteria tab, set appropriate criteria
40 select_pos(xTabs
, "0")
41 xDown
= xDialog
.getChild("down")
42 xDown
.executeAction("CLICK", tuple())
43 xSortKey1
= xDialog
.getChild("sortlb")
44 props
= {"TEXT": "Occupation"}
45 actionProps
= mkPropertyValues(props
)
46 xSortKey1
.executeAction("SELECT", actionProps
)
48 xOK
= xDialog
.getChild("ok")
49 self
.ui_test
.close_dialog_through_button(xOK
)
50 #6. Expected behavior: Ignore column labels when sorting
51 self
.assertEqual(get_cell_by_position(document
, 0, 6, 7).getString(), "Occupation")
52 self
.assertEqual(get_cell_by_position(document
, 0, 6, 8).getString(), "Travel Industry")
53 self
.assertEqual(get_cell_by_position(document
, 0, 6, 123).getString(), "13")
55 self
.ui_test
.close_doc()
57 def test_tdf53482_Range_contains_column_headings(self
):
58 calc_doc
= self
.ui_test
.create_doc_in_start_center("calc")
59 xCalcDoc
= self
.xUITest
.getTopFocusWindow()
60 gridwin
= xCalcDoc
.getChild("grid_window")
61 document
= self
.ui_test
.get_component()
62 #In column A enter: Misc; s; d; f; g
63 enter_text_to_cell(gridwin
, "A1", "Misc")
64 enter_text_to_cell(gridwin
, "A2", "s")
65 enter_text_to_cell(gridwin
, "A3", "d")
66 enter_text_to_cell(gridwin
, "A4", "f")
67 enter_text_to_cell(gridwin
, "A5", "g")
68 #1. Highlight cells to be sorted
69 gridwin
.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:A5"}))
70 #2. Click Data menu, Sort
71 self
.ui_test
.execute_dialog_through_command(".uno:DataSort")
72 xDialog
= self
.xUITest
.getTopFocusWindow()
73 xTabs
= xDialog
.getChild("tabcontrol")
74 select_pos(xTabs
, "1")
75 #3. On Options tab, tick 'Range contains column labels'
76 xHeader
= xDialog
.getChild("header")
77 xHeader
.executeAction("CLICK", tuple())
78 if (get_state_as_dict(xHeader
)["Selected"]) == "false":
79 xHeader
.executeAction("CLICK", tuple())
80 #4. On Sort Criteria tab, set appropriate criteria
81 select_pos(xTabs
, "0")
82 xDown
= xDialog
.getChild("down")
83 xDown
.executeAction("CLICK", tuple())
85 xOK
= xDialog
.getChild("ok")
86 self
.ui_test
.close_dialog_through_button(xOK
)
87 #6. Expected behavior: Ignore column labels when sorting
88 self
.assertEqual(get_cell_by_position(document
, 0, 0, 0).getString(), "Misc")
89 self
.assertEqual(get_cell_by_position(document
, 0, 0, 1).getString(), "s")
90 self
.assertEqual(get_cell_by_position(document
, 0, 0, 2).getString(), "g")
91 self
.assertEqual(get_cell_by_position(document
, 0, 0, 3).getString(), "f")
92 self
.assertEqual(get_cell_by_position(document
, 0, 0, 4).getString(), "d")
94 self
.ui_test
.close_doc()
96 # vim: set shiftwidth=4 softtabstop=4 expandtab: