1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
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/.
10 from uitest
.framework
import UITestCase
12 from libreoffice
.calc
.document
import get_cell_by_position
13 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
14 from uitest
.uihelper
.calc
import enter_text_to_cell
15 from libreoffice
.calc
.paste_special
import reset_default_values
16 from uitest
.uihelper
.common
import get_state_as_dict
18 class tdf160765(UITestCase
):
19 def test_tdf160765_paste_special_comments_checked(self
):
20 with self
.ui_test
.create_doc_in_start_center("calc"):
21 xGridWin
= self
.xUITest
.getTopFocusWindow().getChild("grid_window")
23 # Insert a comment in cell A1
24 xGridWin
.executeAction("SELECT", mkPropertyValues({"CELL":"A1"}))
25 xArgs
= mkPropertyValues({"Text": "Comment 1"})
26 self
.xUITest
.executeCommandWithParameters(".uno:InsertAnnotation", xArgs
)
28 # Copy cell A1 to clipboard
29 xGridWin
.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
30 self
.xUITest
.executeCommand(".uno:Copy")
32 # Paste data using special options (check only comments)
33 xGridWin
.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
34 with self
.ui_test
.execute_dialog_through_command(".uno:PasteSpecial") as xPasteSpecialDlg
:
35 reset_default_values(self
, xPasteSpecialDlg
)
36 xDateTimeChkBox
= xPasteSpecialDlg
.getChild("datetime")
37 xDateTimeChkBox
.executeAction("CLICK", tuple())
38 xTextChkBox
= xPasteSpecialDlg
.getChild("text")
39 xTextChkBox
.executeAction("CLICK", tuple())
40 xNumbersChkBox
= xPasteSpecialDlg
.getChild("numbers")
41 xNumbersChkBox
.executeAction("CLICK", tuple())
42 xCommentsChkBox
= xPasteSpecialDlg
.getChild("comments")
43 xCommentsChkBox
.executeAction("CLICK", tuple())
45 with self
.ui_test
.execute_dialog_through_command(".uno:PasteSpecial") as xPasteSpecialDlg
:
46 xCommentsChkBox
= xPasteSpecialDlg
.getChild("comments")
47 # Without the fix in place, this test would have failed with
48 # AssertionError: 'true' != 'false'
49 # i.e., the comments checkbox was not remembered
50 self
.assertEqual(get_state_as_dict(xCommentsChkBox
)["Selected"], "true")
52 def test_tdf160765_undo_paste_comment(self
):
53 with self
.ui_test
.create_doc_in_start_center("calc") as document
:
54 xGridWin
= self
.xUITest
.getTopFocusWindow().getChild("grid_window")
56 # Write text to cell A1 and B1
57 enter_text_to_cell(xGridWin
, "A1", "A1 sample text")
58 enter_text_to_cell(xGridWin
, "B1", "B1 sample text")
60 # Insert a comment in cell B1
61 xArgs
= mkPropertyValues({"Text": "Comment 1"})
62 self
.xUITest
.executeCommandWithParameters(".uno:InsertAnnotation", xArgs
)
64 # Insert a comment in cell A2
65 xGridWin
.executeAction("SELECT", mkPropertyValues({"CELL":"A2"}))
66 xArgs
= mkPropertyValues({"Text": "Comment 2"})
67 self
.xUITest
.executeCommandWithParameters(".uno:InsertAnnotation", xArgs
)
69 # Copy cell A2 to clipboard
70 xGridWin
.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
71 self
.xUITest
.executeCommand(".uno:Copy")
73 # Set cursor to cells and paste data using special options (check only comments)
74 targetCells
= ["A1", "B1"]
75 for index
, targetCell
in enumerate(targetCells
):
76 xGridWin
.executeAction("SELECT", mkPropertyValues({"CELL": targetCell
}))
77 with self
.ui_test
.execute_dialog_through_command(".uno:PasteSpecial") as xPasteSpecialDlg
:
78 reset_default_values(self
, xPasteSpecialDlg
)
79 xDateTimeChkBox
= xPasteSpecialDlg
.getChild("datetime")
80 xDateTimeChkBox
.executeAction("CLICK", tuple())
81 xTextChkBox
= xPasteSpecialDlg
.getChild("text")
82 xTextChkBox
.executeAction("CLICK", tuple())
83 xNumbersChkBox
= xPasteSpecialDlg
.getChild("numbers")
84 xNumbersChkBox
.executeAction("CLICK", tuple())
85 xCommentsChkBox
= xPasteSpecialDlg
.getChild("comments")
86 xCommentsChkBox
.executeAction("CLICK", tuple())
88 # Undo both inserted comments
89 self
.xUITest
.executeCommand(".uno:Undo")
90 # Without the fix in place, this test would have failed with
91 # AssertionError: 'Comment 1' != ''
92 # i.e., the cell does not contain any comment
93 self
.assertEqual("Comment 1", get_cell_by_position(document
, 0, 1, 0).Annotation
.String
)
94 self
.xUITest
.executeCommand(".uno:Undo")
95 self
.assertEqual("", get_cell_by_position(document
, 0, 0, 0).Annotation
.String
)
97 # Redo both inserted comments
98 self
.xUITest
.executeCommand(".uno:Redo")
99 # Without the fix in place, this test would have failed with
100 # AssertionError: 'Comment 2' != ''
101 # i.e., the cell does not contain the restored comment
102 self
.assertEqual("Comment 2", get_cell_by_position(document
, 0, 0, 0).Annotation
.String
)
103 self
.xUITest
.executeCommand(".uno:Redo")
104 # Without the fix in place, this test would have failed with
105 # AssertionError: 'Comment 2' != ''
106 # i.e., the cell does not contain the restored comment
107 self
.assertEqual("Comment 2", get_cell_by_position(document
, 0, 0, 0).Annotation
.String
)
109 # vim: set shiftwidth=4 softtabstop=4 expandtab: