| 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 libreoffice.uno.propertyvalue import mkPropertyValues |
| 11 |
from uitest.uihelper.common import get_state_as_dict, type_text |
| 12 |
from uitest.uihelper.common import select_pos |
| 13 |
from uitest.uihelper.common import select_by_text |
| 14 |
|
| 15 |
class Tdf140257(UITestCase): |
| 16 |
|
| 17 |
def change_outline_level(self, sText): |
| 18 |
|
| 19 |
with self.ui_test.execute_dialog_through_command(".uno:ParagraphDialog") as xDialog: |
| 20 |
xTabs = xDialog.getChild("tabcontrol") |
| 21 |
select_pos(xTabs, "4") |
| 22 |
|
| 23 |
xOutline = xDialog.getChild("comboLB_OUTLINE_LEVEL") |
| 24 |
|
| 25 |
select_by_text(xOutline, sText) |
| 26 |
|
| 27 |
|
| 28 |
def test_tdf140257(self): |
| 29 |
with self.ui_test.create_doc_in_start_center("writer") as document: |
| 30 |
xMainWindow = self.xUITest.getTopFocusWindow() |
| 31 |
xWriterEdit = xMainWindow.getChild("writer_edit") |
| 32 |
|
| 33 |
self.change_outline_level("Level 1") |
| 34 |
|
| 35 |
for i in range(4): |
| 36 |
type_text(xWriterEdit, 'P' + str(i + 1)) |
| 37 |
xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"})) |
| 38 |
|
| 39 |
type_text(xWriterEdit, 'P5') |
| 40 |
|
| 41 |
self.xUITest.executeCommand(".uno:Sidebar") |
| 42 |
|
| 43 |
xWriterEdit.executeAction("SIDEBAR", mkPropertyValues({"PANEL": "SwNavigatorPanel"})) |
| 44 |
|
| 45 |
# wait until the navigator panel is available |
| 46 |
xNavigatorPanel = self.ui_test.wait_until_child_is_available('NavigatorPanel') |
| 47 |
|
| 48 |
xContentTree = xNavigatorPanel.getChild("contenttree") |
| 49 |
xHeadings = xContentTree.getChild('0') |
| 50 |
self.assertEqual('Headings', get_state_as_dict(xHeadings)['Text']) |
| 51 |
|
| 52 |
xHeadings.executeAction("EXPAND", tuple()) |
| 53 |
|
| 54 |
self.assertEqual(5, len(xHeadings.getChildren())) |
| 55 |
|
| 56 |
for i in range(5): |
| 57 |
self.assertEqual('P' + str(i + 1), get_state_as_dict(xHeadings.getChild(str(i)))['Text']) |
| 58 |
|
| 59 |
self.xUITest.executeCommand(".uno:Sidebar") |
| 60 |
|
| 61 |
cursor = document.getCurrentController().getViewCursor() |
| 62 |
|
| 63 |
# Use Adding Selection |
| 64 |
selectionProperty = mkPropertyValues({"SelectionMode": 2}) |
| 65 |
self.xUITest.executeCommandWithParameters(".uno:SelectionMode", selectionProperty) |
| 66 |
|
| 67 |
# Go to P2 and select it |
| 68 |
cursor.goUp(3, False) |
| 69 |
cursor.gotoStartOfLine(False) |
| 70 |
cursor.gotoEndOfLine(True) |
| 71 |
|
| 72 |
# Go to P4 and select it |
| 73 |
cursor.goDown(2, False) |
| 74 |
cursor.gotoStartOfLine(False) |
| 75 |
cursor.gotoEndOfLine(True) |
| 76 |
|
| 77 |
self.change_outline_level("Level 2") |
| 78 |
|
| 79 |
self.xUITest.executeCommand(".uno:Sidebar") |
| 80 |
|
| 81 |
xWriterEdit.executeAction("SIDEBAR", mkPropertyValues({"PANEL": "SwNavigatorPanel"})) |
| 82 |
|
| 83 |
# wait until the navigator panel is available |
| 84 |
xNavigatorPanel = self.ui_test.wait_until_child_is_available('NavigatorPanel') |
| 85 |
|
| 86 |
xContentTree = xNavigatorPanel.getChild("contenttree") |
| 87 |
xHeadings = xContentTree.getChild('0') |
| 88 |
self.assertEqual('Headings', get_state_as_dict(xHeadings)['Text']) |
| 89 |
|
| 90 |
xHeadings.executeAction("EXPAND", tuple()) |
| 91 |
|
| 92 |
# Without the fix in place, this test would have failed with |
| 93 |
# AssertionError: 3 != 4 |
| 94 |
self.assertEqual(3, len(xHeadings.getChildren())) |
| 95 |
xChild1 = xHeadings.getChild('0') |
| 96 |
self.assertEqual('P1', get_state_as_dict(xChild1)['Text']) |
| 97 |
xChild1.executeAction("EXPAND", tuple()) |
| 98 |
self.assertEqual(1, len(xChild1.getChildren())) |
| 99 |
self.assertEqual('P2', get_state_as_dict(xChild1.getChild('0'))['Text']) |
| 100 |
|
| 101 |
xChild2 = xHeadings.getChild('1') |
| 102 |
self.assertEqual('P3', get_state_as_dict(xChild2)['Text']) |
| 103 |
xChild2.executeAction("EXPAND", tuple()) |
| 104 |
self.assertEqual(1, len(xChild2.getChildren())) |
| 105 |
self.assertEqual('P4', get_state_as_dict(xChild2.getChild('0'))['Text']) |
| 106 |
|
| 107 |
self.assertEqual('P5', get_state_as_dict(xHeadings.getChild('2'))['Text']) |
| 108 |
|
| 109 |
self.xUITest.executeCommand(".uno:Sidebar") |
| 110 |
|
| 111 |
|
| 112 |
# vim: set shiftwidth=4 softtabstop=4 expandtab: |