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
17 class tdf139858(UITestCase
):
18 def test_tdf139858_paste_comment(self
):
19 with self
.ui_test
.create_doc_in_start_center("calc") as document
:
20 xGridWin
= self
.xUITest
.getTopFocusWindow().getChild("grid_window")
22 # Write text to cell A1 and B1
23 enter_text_to_cell(xGridWin
, "A1", "A1 sample text")
24 enter_text_to_cell(xGridWin
, "B1", "B1 sample text")
26 # Insert a comment in cell B1
27 xArgs
= mkPropertyValues({"Text": "Comment 1"})
28 self
.xUITest
.executeCommandWithParameters(".uno:InsertAnnotation", xArgs
)
30 # Insert a comment in cell A2
31 xGridWin
.executeAction("SELECT", mkPropertyValues({"CELL":"A2"}))
32 xArgs
= mkPropertyValues({"Text": "Comment 2"})
33 self
.xUITest
.executeCommandWithParameters(".uno:InsertAnnotation", xArgs
)
35 # Copy cell A2 to clipboard
36 xGridWin
.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
37 self
.xUITest
.executeCommand(".uno:Copy")
39 # Set cursor to cells and paste data using special options (check only comments)
40 targetCells
= ["A1", "B1"]
41 for index
, targetCell
in enumerate(targetCells
):
42 xGridWin
.executeAction("SELECT", mkPropertyValues({"CELL": targetCell
}))
43 with self
.ui_test
.execute_dialog_through_command(".uno:PasteSpecial") as xPasteSpecialDlg
:
44 reset_default_values(self
, xPasteSpecialDlg
)
45 xDateTimeChkBox
= xPasteSpecialDlg
.getChild("datetime")
46 xDateTimeChkBox
.executeAction("CLICK", tuple())
47 xTextChkBox
= xPasteSpecialDlg
.getChild("text")
48 xTextChkBox
.executeAction("CLICK", tuple())
49 xNumbersChkBox
= xPasteSpecialDlg
.getChild("numbers")
50 xNumbersChkBox
.executeAction("CLICK", tuple())
51 xCommentsChkBox
= xPasteSpecialDlg
.getChild("comments")
52 xCommentsChkBox
.executeAction("CLICK", tuple())
54 # Without the fix in place, this test would have failed with
55 # AssertionError: 'A1 sample text' != ''
56 # i.e., the cell content was overwritten
57 self
.assertEqual(targetCell
+ " sample text", get_cell_by_position(document
, 0, index
, 0).getString())
58 self
.assertEqual("Comment 2", get_cell_by_position(document
, 0, index
, 0).Annotation
.String
)
60 # vim: set shiftwidth=4 softtabstop=4 expandtab: