Debian Codegraph @

sw/qa/uitest/writer_tests7/tdf135938.py

raw symbols SCIP
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
10 from uitest.framework import UITestCase
11 from uitest.uihelper.common import get_state_as_dict
12 from libreoffice.uno.propertyvalue import mkPropertyValues
13
14 class tdf135938(UITestCase):
15
16 def test_tdf135938_cross_reference_update(self):
17 with self.ui_test.create_doc_in_start_center("writer"):
18 with self.ui_test.execute_modeless_dialog_through_command(".uno:InsertReferenceField", close_button="cancel") as xDialog:
19 # Select set reference type
20 xTreelistType = xDialog.getChild("type-ref")
21 xTreeEntry = xTreelistType.getChild('0')
22 self.assertEqual(get_state_as_dict(xTreeEntry)["Text"], "Set Reference")
23 xTreeEntry.executeAction("SELECT", tuple())
24
25 # Insert cross references
26 xName = xDialog.getChild("name-ref")
27 xName.executeAction("TYPE", mkPropertyValues({"TEXT": "ABC"}))
28 xInsert = xDialog.getChild("ok")
29 xInsert.executeAction("CLICK", tuple())
30
31 # See the `m_aUpdateTimer.SetTimeout(200)` (to "avoid flickering of buttons")
32 # in the SwChildWinWrapper ctor in sw/source/uibase/fldui/fldwrap.cxx, where that
33 # m_aUpdateTimer is started by SwChildWinWrapper::ReInitDlg triggered from the
34 # xInsert click above.
35 xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
36 xToolkit.waitUntilAllIdlesDispatched()
37
38 xSelect = xDialog.getChild("select-ref")
39 self.assertEqual("1", get_state_as_dict(xSelect)["Children"])
40 self.assertEqual("ABC", get_state_as_dict(xSelect.getChild(0))["Text"])
41
42 xName.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
43 xName.executeAction("TYPE", mkPropertyValues({"TEXT": "DEF"}))
44 xInsert.executeAction("CLICK", tuple())
45
46 self.assertEqual("2", get_state_as_dict(xSelect)["Children"])
47 self.assertEqual("ABC", get_state_as_dict(xSelect.getChild(0))["Text"])
48 self.assertEqual("DEF", get_state_as_dict(xSelect.getChild(1))["Text"])
49
50 # Search for insert reference type
51 xFilter = None
52 for childIx in range(len(xTreelistType.getChildren())):
53 xTreeEntry = xTreelistType.getChild(childIx)
54 if get_state_as_dict(xTreeEntry)["Text"] == "Insert Reference":
55 xTreeEntry.executeAction("SELECT", tuple())
56 # Filter the cross references
57 xFilter = xDialog.getChild("filter")
58 xFilter.executeAction("TYPE", mkPropertyValues({"TEXT": "A"}))
59 # Without the fix in place, this test would have failed with
60 # AssertionError: 'ABC' != 'DEF', i.e., the text of the name field did not change
61 self.assertEqual(get_state_as_dict(xName)["Text"], "ABC")
62
63 self.assertEqual("1", get_state_as_dict(xSelect)["Children"])
64 break
65
66 # Check if insert reference entry was found
67 self.assertFalse(xFilter is None)
68
69 # vim: set shiftwidth=4 softtabstop=4 expandtab: