summaryrefslogtreecommitdiffstats
path: root/sw/qa/uitest/writer_tests2/tdf146375.py
blob: e22e6c4d3dc2f5b0be9aabfa9e6fc70c0457177b (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
# -*- 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/.
#

from uitest.framework import UITestCase
from uitest.uihelper.common import get_state_as_dict, select_by_text
from libreoffice.uno.propertyvalue import mkPropertyValues
import random
import string

class Tdf146375(UITestCase):

   def test_tdf146375(self):
        with self.ui_test.create_doc_in_start_center("writer") as document:

            count = 0
            # Use a random name
            categoryName = ''.join(random.choice(string.ascii_lowercase) for i in range(15))
            renamedCategory = categoryName + "-renamed"

            with self.ui_test.execute_dialog_through_command(".uno:NewDoc", close_button="close") as xDialog:
                xFilterFolder = xDialog.getChild("filter_folder")
                self.assertEqual("All Categories", get_state_as_dict(xFilterFolder)["SelectEntryText"])
                count = int(get_state_as_dict(xFilterFolder)["EntryCount"])

                xActionMenu = xDialog.getChild("action_menu")

                # Create a new category
                with self.ui_test.execute_blocking_action(
                        xActionMenu.executeAction, args=('OPENFROMLIST', mkPropertyValues({"POS": "0"}))) as xNameDialog:
                    xEntry = xNameDialog.getChild("entry")
                    xEntry.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
                    xEntry.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
                    xEntry.executeAction("TYPE", mkPropertyValues({"TEXT": categoryName}))

                self.assertEqual(count + 1, int(get_state_as_dict(xFilterFolder)["EntryCount"]))

                select_by_text(xFilterFolder, categoryName)
                self.assertEqual(categoryName, get_state_as_dict(xFilterFolder)["SelectEntryText"])

                # Rename the category
                with self.ui_test.execute_blocking_action(
                        xActionMenu.executeAction, args=('OPENFROMLIST', mkPropertyValues({"POS": "1"}))) as xNameDialog:
                    xEntry = xNameDialog.getChild("entry")
                    xEntry.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
                    xEntry.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
                    xEntry.executeAction("TYPE", mkPropertyValues({"TEXT": renamedCategory}))

                self.assertEqual(count + 1, int(get_state_as_dict(xFilterFolder)["EntryCount"]))
                self.assertEqual(renamedCategory, get_state_as_dict(xFilterFolder)["SelectEntryText"])

            with self.ui_test.execute_dialog_through_command(".uno:NewDoc", close_button="close") as xDialog:
                xFilterFolder = xDialog.getChild("filter_folder")
                self.assertEqual(count + 1, int(get_state_as_dict(xFilterFolder)["EntryCount"]))

                select_by_text(xFilterFolder, renamedCategory)

                # Without the fix in place, this test would have failed with
                # AssertionError: 'zwpyzgwuwleanap-renamed' != 'All Categories'
                self.assertEqual(renamedCategory, get_state_as_dict(xFilterFolder)["SelectEntryText"])

                xActionMenu = xDialog.getChild("action_menu")

                # Delete the category
                with self.ui_test.execute_blocking_action(
                        xActionMenu.executeAction, args=('OPENFROMLIST', mkPropertyValues({"POS": "2"})), close_button="yes") as xNameDialog:
                    pass

                self.assertEqual(count, int(get_state_as_dict(xFilterFolder)["EntryCount"]))

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