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
.calc
import enter_text_to_cell
12 from uitest
.uihelper
.common
import select_by_text
, select_pos
13 from uitest
.uihelper
.common
import get_url_for_data_file
15 from libreoffice
.calc
.document
import get_cell_by_position
16 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
19 class Subtotals(UITestCase
):
21 def test_tdf114720(self
):
22 with self
.ui_test
.create_doc_in_start_center("calc") as document
:
23 XcalcDoc
= self
.xUITest
.getTopFocusWindow()
24 gridwin
= XcalcDoc
.getChild("grid_window")
26 enter_text_to_cell(gridwin
, "A1", "1")
27 enter_text_to_cell(gridwin
, "A2", "1")
28 enter_text_to_cell(gridwin
, "A3", "1")
29 enter_text_to_cell(gridwin
, "A4", "1")
30 enter_text_to_cell(gridwin
, "A5", "1")
31 enter_text_to_cell(gridwin
, "A6", "1")
32 enter_text_to_cell(gridwin
, "A7", "1")
33 enter_text_to_cell(gridwin
, "A8", "1")
34 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "A9"}))
36 with self
.ui_test
.execute_dialog_through_command(".uno:DataSubTotals"):
39 self
.assertEqual(get_cell_by_position(document
, 0, 0, 7).getValue(), 1)
40 self
.assertEqual(get_cell_by_position(document
, 0, 0, 8).getString(), "")
43 with self
.ui_test
.execute_dialog_through_command(".uno:DataSubTotals", close_button
="cancel"):
47 def test_tdf88792(self
):
48 with self
.ui_test
.load_file(get_url_for_data_file("tdf88792.ods")) as calc_doc
:
49 XcalcDoc
= self
.xUITest
.getTopFocusWindow()
50 gridwin
= XcalcDoc
.getChild("grid_window")
53 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
54 # Select from the menu bar Data
55 # Select option subtotal
56 # Subtotal dialog displays
57 with self
.ui_test
.execute_dialog_through_command(".uno:DataSubTotals") as xDialog
:
58 # Select group by: Category
59 xGroupBy
= xDialog
.getChild("group_by1")
60 select_by_text(xGroupBy
, "Category")
61 # Select calculate subtotals for the months - selected by default
63 xTabs
= xDialog
.getChild("tabcontrol")
64 select_pos(xTabs
, "3")
65 # select option include formats
66 xformats
= xDialog
.getChild("formats")
67 xformats
.executeAction("CLICK", tuple())
70 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 3, 5).getValue(), 28000)
72 def test_tdf88735(self
):
73 with self
.ui_test
.load_file(get_url_for_data_file("tdf88735.ods")) as calc_doc
:
75 self
.xUITest
.executeCommand(".uno:SelectAll")#use uno command Menu Edit->Select All
76 # 2 invoke sub-total menu and select none
77 with self
.ui_test
.execute_dialog_through_command(".uno:DataSubTotals") as xDialog
:
78 xGroupBy
= xDialog
.getChild("group_by1")
79 select_by_text(xGroupBy
, "- none -")
80 # 2 invoke sort menu and... crash
81 with self
.ui_test
.execute_dialog_through_command(".uno:DataSort", close_button
="cancel"):
84 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 0, 8).getString(), "z")
85 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 1, 8).getValue(), 8)
87 def test_tdf56958(self
):
88 with self
.ui_test
.load_file(get_url_for_data_file("tdf56958.ods")) as calc_doc
:
89 # 1. Open the test file
91 with self
.ui_test
.execute_dialog_through_command(".uno:DataSubTotals") as xDialog
:
92 # 3. Group by->Trans date
93 xGroupBy
= xDialog
.getChild("group_by1")
94 select_by_text(xGroupBy
, "Trans Date")
95 # 4. Tick 'Calculate subtotals for' -> Amount (grid1)
96 xCheckListMenu
= xDialog
.getChild("grid1")
97 xTreeList
= xCheckListMenu
.getChild("columns1")
98 xFirstEntry
= xTreeList
.getChild("2")
99 xFirstEntry
.executeAction("CLICK", tuple())
102 with self
.ui_test
.execute_dialog_through_command(".uno:DataSubTotals") as xDialog
:
103 # 7. Group by->-none-
104 xGroupBy
= xDialog
.getChild("group_by1")
105 select_by_text(xGroupBy
, "- none -")
106 # 8. Untick 'Calculate subtotals for' -> Amount
107 xCheckListMenu
= xDialog
.getChild("grid1")
108 xTreeList
= xCheckListMenu
.getChild("columns1")
109 xFirstEntry
= xTreeList
.getChild("2")
110 xFirstEntry
.executeAction("CLICK", tuple())
113 with self
.ui_test
.execute_dialog_through_command(".uno:DataSort") as xDialog
:
114 # 11. Sort key 1->Post Date.
115 sortkey1
= xDialog
.getChild("sortlb")
116 select_by_text(sortkey1
, "Post Date")
117 # 12. Sort key 2->-undefined-
118 sortkey2
= xDialog
.getChild("sortuserlb")
119 select_by_text(sortkey2
, "- undefined -")
121 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 2, 1).getValue(), -0.25)
123 def test_tdf55734(self
):
124 with self
.ui_test
.load_file(get_url_for_data_file("tdf55734.ods")) as calc_doc
:
125 XcalcDoc
= self
.xUITest
.getTopFocusWindow()
126 gridwin
= XcalcDoc
.getChild("grid_window")
127 # 1. Open attached document
128 # 2. Place cursor in cell outside of subtotals range (e.g. B7)
129 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "B7"}))
130 # 3. Data → Subtotals
131 with self
.ui_test
.execute_dialog_through_command(".uno:DataSubTotals") as xDialog
:
132 # 4. Group by: "- none -"
133 xGroupBy
= xDialog
.getChild("group_by1")
134 select_by_text(xGroupBy
, "- none -")
135 # 5. Press "OK" and watch LibreOffice crash.
137 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 0, 1).getValue(), 1)
138 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 1, 1).getValue(), 2)
140 # vim: set shiftwidth=4 softtabstop=4 expandtab: