summaryrefslogtreecommitdiffstats
path: root/sw/qa/uitest/writer_tests/comments.py
blob: 3e9d3a6301d83dfcdafb9033c24385df682ddb8b (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
# -*- 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
from libreoffice.uno.propertyvalue import mkPropertyValues
#test comments

class Comments(UITestCase):

    def test_comments_features(self):

        with self.ui_test.create_doc_in_start_center("writer"):

            xMainWindow = self.xUITest.getTopFocusWindow()

            xwriter_edit = xMainWindow.getChild("writer_edit")
            xwriter_edit.executeAction("TYPE", mkPropertyValues({"TEXT": "Before "}))

            # adding new Comment
            self.xUITest.executeCommand(".uno:InsertAnnotation")

            # wait until the comment is available
            xComment1 = self.ui_test.wait_until_child_is_available('Comment1')

            xEditView1 = xComment1.getChild("editview")
            xEditView1.executeAction("TYPE", mkPropertyValues({"TEXT": "This is the First Comment"}))
            self.assertEqual(get_state_as_dict(xComment1)["Text"], "This is the First Comment" )
            self.assertEqual(get_state_as_dict(xComment1)["Resolved"], "false" )
            self.assertEqual(get_state_as_dict(xComment1)["Author"], "Unknown Author" )
            self.assertEqual(get_state_as_dict(xComment1)["ReadOnly"], "false" )

            xComment1.executeAction("LEAVE", mkPropertyValues({}))

            xwriter_edit.executeAction("TYPE", mkPropertyValues({"TEXT": "After"}))
            xwriter_edit.executeAction("SELECT", mkPropertyValues({"END_POS": "0", "START_POS": "13"}))
            self.assertEqual(get_state_as_dict(xwriter_edit)["SelectedText"], "Before After" )

            # test Resolve Comment
            xComment1.executeAction("RESOLVE", mkPropertyValues({}))
            self.assertEqual(get_state_as_dict(xComment1)["Resolved"], "true" )

            # test Select text from Comment
            xComment1.executeAction("SELECT", mkPropertyValues({"FROM": "0", "TO": "4"}))
            self.assertEqual(get_state_as_dict(xComment1)["SelectedText"], "This" )

            # test Hide then Show Comment
            xComment1.executeAction("HIDE", mkPropertyValues({}))
            self.assertEqual(get_state_as_dict(xComment1)["Visible"], "false" )
            xComment1.executeAction("SHOW", mkPropertyValues({}))
            self.assertEqual(get_state_as_dict(xComment1)["Visible"], "true" )

            # test delete Comment
            xComment1.executeAction("DELETE", mkPropertyValues({}))
            self.assertTrue("Comment1" not in xMainWindow.getChildren())


    def test_multi_comments(self):

        with self.ui_test.create_doc_in_start_center("writer"):

            xMainWindow = self.xUITest.getTopFocusWindow()

            xwriter_edit = xMainWindow.getChild("writer_edit")

            # adding 3 new Comment
            xwriter_edit.executeAction("TYPE", mkPropertyValues({"TEXT": "Line 1"}))
            self.xUITest.executeCommand(".uno:InsertAnnotation")
            # wait until the comment is available
            xComment1 = self.ui_test.wait_until_child_is_available('Comment1')
            xEditView1 = xComment1.getChild("editview")
            xEditView1.executeAction("TYPE", mkPropertyValues({"TEXT": "First Comment"}))
            xComment1.executeAction("LEAVE", mkPropertyValues({}))
            xwriter_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))

            xwriter_edit.executeAction("TYPE", mkPropertyValues({"TEXT": "Line 2"}))
            self.xUITest.executeCommand(".uno:InsertAnnotation")
            # wait until the comment is available
            xComment2 = self.ui_test.wait_until_child_is_available('Comment2')
            xEditView2 = xComment2.getChild("editview")
            xEditView2.executeAction("TYPE", mkPropertyValues({"TEXT": "Second Comment"}))
            xComment2.executeAction("LEAVE", mkPropertyValues({}))
            xwriter_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))

            xwriter_edit.executeAction("TYPE", mkPropertyValues({"TEXT": "Line 3"}))
            self.xUITest.executeCommand(".uno:InsertAnnotation")
            # wait until the comment is available
            xComment3 = self.ui_test.wait_until_child_is_available('Comment3')
            xEditView3 = xComment3.getChild("editview")
            xEditView3.executeAction("TYPE", mkPropertyValues({"TEXT": "Third Comment"}))
            xComment3.executeAction("LEAVE", mkPropertyValues({}))
            xwriter_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))

            # Check text
            self.assertEqual(get_state_as_dict(xComment1)["Text"], "First Comment" )
            self.assertEqual(get_state_as_dict(xComment2)["Text"], "Second Comment" )
            self.assertEqual(get_state_as_dict(xComment3)["Text"], "Third Comment" )

            xComment2.executeAction("RESOLVE", mkPropertyValues({}))
            xComment3.executeAction("RESOLVE", mkPropertyValues({}))

            # Check Resolved
            self.assertEqual(get_state_as_dict(xComment1)["Resolved"], "false" )
            self.assertEqual(get_state_as_dict(xComment2)["Resolved"], "true" )
            self.assertEqual(get_state_as_dict(xComment3)["Resolved"], "true" )

            # Check ReadOnly
            self.assertEqual(get_state_as_dict(xComment1)["ReadOnly"], "false" )
            self.assertEqual(get_state_as_dict(xComment2)["ReadOnly"], "false" )
            self.assertEqual(get_state_as_dict(xComment3)["ReadOnly"], "false" )

            # Check Select
            xComment1.executeAction("SELECT", mkPropertyValues({"FROM": "0", "TO": "5"}))
            self.assertEqual(get_state_as_dict(xComment1)["SelectedText"], "First" )

            xComment2.executeAction("SELECT", mkPropertyValues({"FROM": "0", "TO": "6"}))
            self.assertEqual(get_state_as_dict(xComment2)["SelectedText"], "Second" )

            xComment3.executeAction("SELECT", mkPropertyValues({"FROM": "0", "TO": "5"}))
            self.assertEqual(get_state_as_dict(xComment3)["SelectedText"], "Third" )

            # Check that they all are Visible
            self.assertEqual(get_state_as_dict(xComment1)["Visible"], "true" )
            self.assertEqual(get_state_as_dict(xComment2)["Visible"], "true" )
            self.assertEqual(get_state_as_dict(xComment3)["Visible"], "true" )

            # Hide all
            xComment1.executeAction("HIDE", mkPropertyValues({}))
            self.assertEqual(get_state_as_dict(xComment1)["Visible"], "false" )
            xComment2.executeAction("HIDE", mkPropertyValues({}))
            self.assertEqual(get_state_as_dict(xComment2)["Visible"], "false" )
            xComment3.executeAction("HIDE", mkPropertyValues({}))
            self.assertEqual(get_state_as_dict(xComment3)["Visible"], "false" )

            # Show comment 2 only
            xComment2.executeAction("SHOW", mkPropertyValues({}))
            self.assertEqual(get_state_as_dict(xComment2)["Visible"], "true" )

            # Then remove the 3 comments
            xComment1.executeAction("DELETE", mkPropertyValues({}))
            xComment2.executeAction("DELETE", mkPropertyValues({}))
            xComment3.executeAction("DELETE", mkPropertyValues({}))
            self.assertTrue("Comment1" not in xMainWindow.getChildren())
            self.assertTrue("Comment2" not in xMainWindow.getChildren())
            self.assertTrue("Comment3" not in xMainWindow.getChildren())

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