| 1 |
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- |
| 2 |
# |
| 3 |
# This file is part of the LibreOffice project. |
| 4 |
# |
| 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/. |
| 8 |
# |
| 9 |
from uitest.framework import UITestCase |
| 10 |
from uitest.uihelper.common import get_url_for_data_file, get_state_as_dict |
| 11 |
|
| 12 |
from libreoffice.calc.document import get_cell_by_position |
| 13 |
from libreoffice.uno.propertyvalue import mkPropertyValues |
| 14 |
|
| 15 |
|
| 16 |
class goalSeek(UITestCase): |
| 17 |
def test_goalSeek(self): |
| 18 |
with self.ui_test.load_file(get_url_for_data_file("goalSeek.ods")) as calc_doc: |
| 19 |
xCalcDoc = self.xUITest.getTopFocusWindow() |
| 20 |
gridwin = xCalcDoc.getChild("grid_window") |
| 21 |
gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "B4"})) |
| 22 |
with self.ui_test.execute_modeless_dialog_through_command(".uno:GoalSeekDialog", close_button="") as xDialog: |
| 23 |
xFormulaEdit = xDialog.getChild("formulaedit") |
| 24 |
self.assertEqual("$B$4", get_state_as_dict(xFormulaEdit)["Text"]) |
| 25 |
|
| 26 |
xtarget = xDialog.getChild("target") |
| 27 |
xvaredit = xDialog.getChild("varedit") |
| 28 |
xtarget.executeAction("TYPE", mkPropertyValues({"TEXT":"15000"})) |
| 29 |
xvaredit.executeAction("TYPE", mkPropertyValues({"TEXT":"B1"})) |
| 30 |
xOKBtn = xDialog.getChild("ok") |
| 31 |
|
| 32 |
with self.ui_test.execute_blocking_action(xOKBtn.executeAction, args=('CLICK', ()), close_button="yes"): |
| 33 |
pass |
| 34 |
|
| 35 |
# tdf#118226: Without the fix in place, this test would have failed with |
| 36 |
# AssertionError: 100000.0 != 200000 |
| 37 |
self.assertEqual(200000, get_cell_by_position(calc_doc, 0, 1, 0).getValue()) |
| 38 |
self.assertEqual(15000, get_cell_by_position(calc_doc, 0, 1, 3).getValue()) |
| 39 |
|
| 40 |
self.xUITest.executeCommand(".uno:Undo") |
| 41 |
|
| 42 |
self.assertEqual(100000, get_cell_by_position(calc_doc, 0, 1, 0).getValue()) |
| 43 |
self.assertEqual(7500, get_cell_by_position(calc_doc, 0, 1, 3).getValue()) |
| 44 |
|
| 45 |
# tdf#161462 check settings are remembered |
| 46 |
with self.ui_test.execute_modeless_dialog_through_command(".uno:GoalSeekDialog", close_button="") as xDialog: |
| 47 |
xFormulaEdit = xDialog.getChild("formulaedit") |
| 48 |
xTarget = xDialog.getChild("target") |
| 49 |
xVarEdit = xDialog.getChild("varedit") |
| 50 |
|
| 51 |
self.assertEqual("$B$4", get_state_as_dict(xFormulaEdit)["Text"]) |
| 52 |
self.assertEqual("15000", get_state_as_dict(xTarget)["Text"]) |
| 53 |
self.assertEqual("$B$1", get_state_as_dict(xVarEdit)["Text"]) |
| 54 |
xOKBtn = xDialog.getChild("ok") |
| 55 |
|
| 56 |
with self.ui_test.execute_blocking_action(xOKBtn.executeAction, args=('CLICK', ()), close_button="no"): |
| 57 |
pass |
| 58 |
|
| 59 |
# Clicking on 'no' doesn't update the data |
| 60 |
self.assertEqual(100000, get_cell_by_position(calc_doc, 0, 1, 0).getValue()) |
| 61 |
self.assertEqual(7500, get_cell_by_position(calc_doc, 0, 1, 3).getValue()) |
| 62 |
|
| 63 |
# vim: set shiftwidth=4 softtabstop=4 expandtab: |