summaryrefslogtreecommitdiffstats
path: root/sfx2/qa/python/check_sidebar.py
blob: 59cc955b8016c7100b50b8553bd032a8f1c448d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

import unittest
import unohelper
import os
from org.libreoffice.unotest import UnoInProcess

from com.sun.star.ui import XSidebarProvider
from com.sun.star.ui import XDecks
from com.sun.star.ui import XDeck
from com.sun.star.ui import XPanels
from com.sun.star.ui import XPanel

class CheckSidebar(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls._uno = UnoInProcess()
        cls._uno.setUp()

    @classmethod
    def tearDownClass(cls):
        cls._uno.tearDown() 

    def test_check_sidebar(self):

        xDoc = self.__class__._uno.openEmptyDoc( url = "private:factory/scalc", bHidden = False, bReadOnly = False)
        xController = xDoc.getCurrentController()

        xSidebar = xController.getSidebar()
        assert(xSidebar)

        xSidebar.setVisible(True)
        isVisible = xSidebar.isVisible()
        self.assertTrue ( xSidebar.isVisible() )

        # TODO: does not work in unit test context 
#        xSidebar.setVisible(False)
#        isVisible = xSidebar.isVisible()
#        assert( not isVisible )
#        xSidebar.setVisible(True)

        xSidebar.showDecks(False)
        xSidebar.showDecks(True)

        xDecks = xSidebar.getDecks()

        first_deck_name = "PropertyDeck";

        deck_element_names = xDecks.getElementNames()
        assert ( first_deck_name in deck_element_names )
        assert ( xDecks.hasByName(first_deck_name) )

        decks_count = len(xDecks)
        self.assertEqual ( 5, decks_count )

        xDeck = xDecks[first_deck_name]
        assert ( xDeck )
        assert ( xDeck.getId() == first_deck_name )

        new_deck_title = "New title"
        xDeck.setTitle(new_deck_title)
        assert ( xDeck.getTitle() == new_deck_title )

        xDeck.moveFirst()
        initial_index = xDeck.getOrderIndex()
        self.assertEqual(100, initial_index)

        xDeck.moveLast()
        assert ( xDeck.getOrderIndex() > initial_index )

        initial_index = xDeck.getOrderIndex()
        xDeck.moveFirst()
        assert ( xDeck.getOrderIndex() < initial_index )

        initial_index = xDeck.getOrderIndex()
        xDeck.moveDown()
        assert ( xDeck.getOrderIndex() > initial_index )

        initial_index = xDeck.getOrderIndex()
        xDeck.moveUp()
        assert ( xDeck.getOrderIndex() < initial_index )

        xPanels = xDeck.getPanels()

        panels_count = len(xPanels)
        self.assertEqual ( panels_count, 5 )

        first_panel_name = self.getFirstPanel(xPanels)

        panel_element_names = xPanels.getElementNames()
        assert ( first_panel_name in panel_element_names )
        assert ( xPanels.hasByName(first_panel_name) )

        xPanel = xPanels[first_panel_name]
        assert ( xPanel )
        assert ( xPanel.getId() == first_panel_name )

        new_title = "New title"
        xPanel.setTitle(new_title)
        assert ( xPanel.getTitle() == new_title )

        initial_index = xPanel.getOrderIndex()
        xPanel.moveLast()
        assert ( xPanel.getOrderIndex() > initial_index )

        initial_index = xPanel.getOrderIndex()
        xPanel.moveFirst()
        assert ( xPanel.getOrderIndex() < initial_index )

        initial_index = xPanel.getOrderIndex()
        xPanel.moveDown()
        assert ( xPanel.getOrderIndex() > initial_index )

        initial_index = xPanel.getOrderIndex()
        xPanel.moveUp()
        assert ( xPanel.getOrderIndex() < initial_index )

        xPanel.collapse()
        assert( not xPanel.isExpanded() )

        last_panel_name = self.getLastPanel(xPanels)

        other_panel = xPanels[last_panel_name]
        other_panel.expand(False)
        assert( other_panel.isExpanded() )

        xPanel.expand(True)
        assert( xPanel.isExpanded() )
        assert( not other_panel.isExpanded() )

    # close the document
        xDoc.dispose()

    def getFirstPanel(self, xPanels):

        panel_name = ""
        cur_index = 10000

        for panel in xPanels:
            if panel.getOrderIndex() < cur_index:
                panel_name = panel.getId()
                cur_index = panel.getOrderIndex()

        return panel_name

    def getLastPanel(self, xPanels):

        panel_name = ""
        cur_index = 0

        for panel in xPanels:
            if panel.getOrderIndex() > cur_index:
                panel_name = panel.getId()
                cur_index = panel.getOrderIndex()

        return panel_name

if __name__ == "__main__":
    unittest.main()

# vim: set shiftwidth=4 softtabstop=4 expandtab: