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/.
9 from uitest
.framework
import UITestCase
10 from uitest
.uihelper
.common
import get_state_as_dict
11 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
12 #uitest sc - move/copy sheet dialog
14 class moveCopySheet(UITestCase
):
15 def test_copy_move_sheet(self
):
16 with self
.ui_test
.create_doc_in_start_center("calc") as document
:
17 #default - 1 sheet; select the sheet (is selected), dialog move/copy sheet
18 with self
.ui_test
.execute_dialog_through_command(".uno:Move") as xDialog
:
20 newName
= xDialog
.getChild("newName")
21 newName
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
22 newName
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
23 newName
.executeAction("TYPE", mkPropertyValues({"TEXT":"newName"}))
24 #verify, the file has 2 sheets; first one "newName" is selected
25 self
.assertEqual(document
.Sheets
.getCount(), 2)
26 # dialog move/copy sheet ; Copy is selected; Select move and -move to end position - ; New Name = moveName
27 with self
.ui_test
.execute_dialog_through_command(".uno:Move") as xDialog
:
28 xMoveButton
= xDialog
.getChild("move")
29 xMoveButton
.executeAction("CLICK", tuple())
30 insertBefore
= xDialog
.getChild("insertBefore")
32 xTreeEntry
= insertBefore
.getChild('2')
33 xTreeEntry
.executeAction("SELECT", tuple())
35 newName
= xDialog
.getChild("newName")
36 self
.assertEqual(get_state_as_dict(newName
)["Text"], "newName")
37 newName
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
38 newName
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
39 newName
.executeAction("TYPE", mkPropertyValues({"TEXT":"moveName"}))
40 # Verify, the file has 2 sheets; first one is "Sheet1" ; second one is "moveName"
41 self
.assertEqual(document
.Sheets
.getCount(), 2)
43 self
.assertEqual(document
.Sheets
[0].Name
, "Sheet1")
44 self
.assertEqual(document
.Sheets
[1].Name
, "moveName")
46 # Verify that the cancel button does not do anything
47 with self
.ui_test
.execute_dialog_through_command(".uno:Move", close_button
="cancel"):
50 self
.assertEqual(document
.Sheets
.getCount(), 2)
51 self
.assertEqual(document
.Sheets
[0].Name
, "Sheet1")
52 self
.assertEqual(document
.Sheets
[1].Name
, "moveName")
55 with self
.ui_test
.execute_dialog_through_command(".uno:Move") as xDialog
:
56 xCopy
= xDialog
.getChild("copy")
57 xCopy
.executeAction("CLICK", tuple())
58 sheetName
= "moveName_2"
59 newName
= xDialog
.getChild("newName")
60 self
.assertEqual(get_state_as_dict(newName
)["Text"], sheetName
)
63 self
.assertEqual(document
.Sheets
.getCount(), 3)
64 self
.assertEqual(document
.Sheets
[0].Name
, sheetName
)
65 self
.assertEqual(document
.Sheets
[1].Name
, "Sheet1")
66 self
.assertEqual(document
.Sheets
[2].Name
, "moveName")
68 # tdf#56973 - copy/paste (single) sheet is checked but not enabled
69 def test_tdf56973_copy_paste_inactive(self
):
70 with self
.ui_test
.create_doc_in_start_center("calc"):
71 with self
.ui_test
.execute_dialog_through_command(".uno:Move") as xDialog
:
72 # A single sheet can only be copied
73 xCopyButton
= xDialog
.getChild("copy")
74 self
.assertEqual(get_state_as_dict(xCopyButton
)["Checked"], "true")
75 self
.assertEqual(get_state_as_dict(xCopyButton
)["Enabled"], "true")
76 # A single sheet can not be moved
77 xMoveButton
= xDialog
.getChild("move")
78 self
.assertEqual(get_state_as_dict(xMoveButton
)["Checked"], "false")
79 self
.assertEqual(get_state_as_dict(xMoveButton
)["Enabled"], "false")
81 # tdf#96854 - remember last used option for copy/move sheet
82 def test_tdf96854_remember_copy_move_option(self
):
83 with self
.ui_test
.create_doc_in_start_center("calc"):
84 # Add a second sheet to the calc document
85 with self
.ui_test
.execute_dialog_through_command(".uno:Move") as xDialog
:
88 # Check if the copy option was remembered
89 with self
.ui_test
.execute_dialog_through_command(".uno:Move") as xDialog
:
90 xCopyButton
= xDialog
.getChild("copy")
91 self
.assertEqual(get_state_as_dict(xCopyButton
)["Checked"], "true")
92 xMoveButton
= xDialog
.getChild("move")
93 self
.assertEqual(get_state_as_dict(xMoveButton
)["Checked"], "false")
94 # Move selected sheet and check if option was remembered
95 xMoveButton
.executeAction("CLICK", tuple())
97 # Check if move option was remembered
98 with self
.ui_test
.execute_dialog_through_command(".uno:Move") as xDialog
:
99 xCopyButton
= xDialog
.getChild("copy")
100 self
.assertEqual(get_state_as_dict(xCopyButton
)["Checked"], "false")
101 xMoveButton
= xDialog
.getChild("move")
102 self
.assertEqual(get_state_as_dict(xMoveButton
)["Checked"], "true")
104 #tdf#139464 Set OK button label to selected action: Move or Copy
105 def test_tdf139464_move_sheet(self
):
106 with self
.ui_test
.create_doc_in_start_center("calc"):
107 with self
.ui_test
.execute_dialog_through_command(".uno:Move") as xDialog
:
108 xOkButton
= xDialog
.getChild("ok")
109 xCopyButton
= xDialog
.getChild("copy")
110 self
.assertEqual(get_state_as_dict(xCopyButton
)['Text'], get_state_as_dict(xOkButton
)['Text'])
111 with self
.ui_test
.execute_dialog_through_command(".uno:Move") as xDialog
:
112 xOkButton
= xDialog
.getChild("ok")
113 xCopyButton
= xDialog
.getChild("copy")
114 xMoveButton
= xDialog
.getChild("move")
115 self
.assertEqual(get_state_as_dict(xCopyButton
)['Text'], get_state_as_dict(xOkButton
)['Text'])
116 xMoveButton
.executeAction("CLICK", tuple())
117 self
.assertEqual(get_state_as_dict(xMoveButton
)['Text'], get_state_as_dict(xOkButton
)['Text'])
118 xCopyButton
.executeAction("CLICK", tuple())
119 self
.assertEqual(get_state_as_dict(xCopyButton
)['Text'], get_state_as_dict(xOkButton
)['Text'])
121 # vim: set shiftwidth=4 softtabstop=4 expandtab: