| 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 libreoffice.uno.propertyvalue import mkPropertyValues |
| 12 |
from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file |
| 13 |
|
| 14 |
class tdf40427(UITestCase): |
| 15 |
|
| 16 |
def get_item(self, xTree, name): |
| 17 |
for i in xTree.getChildren(): |
| 18 |
xItem = xTree.getChild(i) |
| 19 |
if name == get_state_as_dict(xItem)['Text']: |
| 20 |
return xItem |
| 21 |
|
| 22 |
def expand_all(self, xTreeItem): |
| 23 |
count = len(xTreeItem.getChildren()) |
| 24 |
for i in xTreeItem.getChildren(): |
| 25 |
xTreeItem.getChild(i).executeAction("EXPAND", ()) |
| 26 |
count += self.expand_all(xTreeItem.getChild(i)) |
| 27 |
return count |
| 28 |
|
| 29 |
def get_names(self, xTreeItem): |
| 30 |
names = [] |
| 31 |
for i in xTreeItem.getChildren(): |
| 32 |
names.append(get_state_as_dict(xTreeItem.getChild(str(i)))['Text']) |
| 33 |
names += self.get_names(xTreeItem.getChild(i)) |
| 34 |
return names |
| 35 |
|
| 36 |
def test_tdf40427(self): |
| 37 |
with self.ui_test.load_file(get_url_for_data_file("tdf40427_SectionPositions.odt")) as document: |
| 38 |
xMainWindow = self.xUITest.getTopFocusWindow() |
| 39 |
xWriterEdit = xMainWindow.getChild("writer_edit") |
| 40 |
|
| 41 |
self.assertEqual(2, document.CurrentController.PageCount) |
| 42 |
|
| 43 |
# Make sure that the view is 2 pages side-by-side - look at dialog View-Zoom-Zoom |
| 44 |
with self.ui_test.execute_dialog_through_command(".uno:Zoom") as xDialog: |
| 45 |
|
| 46 |
columnssb = xDialog.getChild("columnssb") |
| 47 |
columns = xDialog.getChild("columns") |
| 48 |
bookmode = xDialog.getChild("bookmode") |
| 49 |
self.assertEqual("true", get_state_as_dict(columns)["Checked"]) |
| 50 |
self.assertEqual("2", get_state_as_dict(columnssb)["Text"]) |
| 51 |
self.assertEqual("false", get_state_as_dict(bookmode)["Selected"]) |
| 52 |
|
| 53 |
|
| 54 |
# In this view, the sections "SectionB" and "SectionC" on second page are positioned on screen |
| 55 |
# higher than "SectionY" and "SectionA" respectively; there are nested and anchored sections. |
| 56 |
# Make sure that order in Navigator follows their relative position in document, not vertical |
| 57 |
# position on screen, nor sorted alphabetically. Sections in flying frames are sorted by their |
| 58 |
# anchor position in the document. |
| 59 |
|
| 60 |
self.xUITest.executeCommand(".uno:Sidebar") |
| 61 |
xWriterEdit.executeAction("SIDEBAR", mkPropertyValues({"PANEL": "SwNavigatorPanel"})) |
| 62 |
|
| 63 |
# wait until the navigator panel is available |
| 64 |
xNavigatorPanel = self.ui_test.wait_until_child_is_available('NavigatorPanel') |
| 65 |
|
| 66 |
xContentTree = xNavigatorPanel.getChild("contenttree") |
| 67 |
xSections = self.get_item(xContentTree, 'Sections') |
| 68 |
self.assertEqual('Sections', get_state_as_dict(xSections)['Text']) |
| 69 |
xSections.executeAction("EXPAND", ()) |
| 70 |
totalSectionsCount = self.expand_all(xSections) |
| 71 |
|
| 72 |
refSectionNames = [ |
| 73 |
'SectionZ', |
| 74 |
'SectionY', # SectionB should not get before this, despite its Y position on screen is higher |
| 75 |
'SectionT3', # Sections in tables go in rows, then across rows |
| 76 |
'SectionT1', |
| 77 |
'SectionT2', |
| 78 |
'SectionT0', |
| 79 |
'SectionF2', # Goes before SectionF1, because their fly anchors go in that order |
| 80 |
'SectionF3', # Same as SectionF1, but anchor section is in fly itself |
| 81 |
'SectionFinF3', # Check order of nested sections inside fly |
| 82 |
'SectionA', |
| 83 |
'SectionF1', # Section in fly anchored in a section goes immediately after its anchor section |
| 84 |
'SectionB', # High on screen, but late in list because it's on second page |
| 85 |
'SectionC', |
| 86 |
] |
| 87 |
self.assertEqual(len(refSectionNames), totalSectionsCount) |
| 88 |
|
| 89 |
actSectionNames = self.get_names(xSections) |
| 90 |
|
| 91 |
# Without the fix in place, this would fail with |
| 92 |
# AssertionError: Lists differ: ['SectionZ', 'SectionY', 'SectionT3', 'SectionT1', 'SectionT2'[100 chars]onC'] != ['SectionZ', 'SectionB', 'SectionF3', 'SectionFinF3', 'Section[100 chars]onA'] |
| 93 |
self.assertEqual(refSectionNames, actSectionNames) |
| 94 |
|
| 95 |
self.xUITest.executeCommand(".uno:Sidebar") |
| 96 |
|
| 97 |
# vim: set shiftwidth=4 softtabstop=4 expandtab: |