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
, get_url_for_data_file
11 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
14 class dateFormFieldDialog(UITestCase
):
16 def test_setting_date_format(self
):
17 # open a file with a date form field
18 with self
.ui_test
.load_file(get_url_for_data_file("date_form_field.odt")):
20 # open the dialog (cursor is at the field)
21 with self
.ui_test
.execute_dialog_through_command(".uno:ControlProperties") as xDialog
:
23 itemsList
= xDialog
.getChild("date_formats_treeview")
25 # check whether we have the right format selected
26 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "20")
27 self
.assertEqual(get_state_as_dict(itemsList
)["SelectEntryText"], "12/01/99")
30 itemsList
.getChild("11").executeAction("SELECT", tuple())
31 self
.assertEqual(get_state_as_dict(itemsList
)["SelectEntryText"], "12-01")
34 # open the dialog again
35 with self
.ui_test
.execute_dialog_through_command(".uno:ControlProperties") as xDialog
:
36 itemsList
= xDialog
.getChild("date_formats_treeview")
37 self
.assertEqual(get_state_as_dict(itemsList
)["SelectEntryText"], "12-01")
40 def test_date_field_with_custom_format(self
):
41 # open a file with a date form field
42 with self
.ui_test
.load_file(get_url_for_data_file("date_form_field_custom_format.odt")):
44 # open the dialog (cursor is at the field)
45 with self
.ui_test
.execute_dialog_through_command(".uno:ControlProperties") as xDialog
:
47 itemsList
= xDialog
.getChild("date_formats_treeview")
49 # check whether we have the right format selected
50 # This is awkward though because checking for a fixed number of
51 # entries if the selected default format happens to equal a
52 # standard system format the entry gets duplicated with
53 # "[System]" appended. So this may be either 20 or 21 ... and
54 # in that case it is the selected format and the
55 # SelectEntryText doesn't match the sample string, so all this
56 # is rather fragile depending on actual locale data.
57 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "21")
58 self
.assertEqual(get_state_as_dict(itemsList
)["SelectEntryText"], "1999. december 1., szerda[System]")
61 def test_date_reformat(self
):
62 # open a file with a date form field
63 with self
.ui_test
.load_file(get_url_for_data_file("date_form_field.odt")) as writer_doc
:
64 self
.assertEqual(writer_doc
.getText().getString(), "07/17/19")
66 # open the dialog (cursor is at the field)
67 with self
.ui_test
.execute_dialog_through_command(".uno:ControlProperties") as xDialog
:
69 itemsList
= xDialog
.getChild("date_formats_treeview")
71 # check whether we have the right format selected
72 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "20")
73 self
.assertEqual(get_state_as_dict(itemsList
)["SelectEntryText"], "12/01/99")
76 itemsList
.getChild("11").executeAction("SELECT", tuple())
77 self
.assertEqual(get_state_as_dict(itemsList
)["SelectEntryText"], "12-01")
80 # after applying the new format, the field content should be updated
81 self
.assertEqual(writer_doc
.getText().getString(), "07-17")
83 def test_date_field_with_placeholder(self
):
84 # open a file with a date form field
85 with self
.ui_test
.load_file(get_url_for_data_file("date_form_field_with_placeholder.odt")) as writer_doc
:
86 self
.assertEqual(writer_doc
.getText().getString(), "[select date]")
88 # open the dialog (cursor is at the field)
89 with self
.ui_test
.execute_dialog_through_command(".uno:ControlProperties") as xDialog
:
91 itemsList
= xDialog
.getChild("date_formats_treeview")
93 # check whether we have the right format selected
94 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "20")
95 self
.assertEqual(get_state_as_dict(itemsList
)["SelectEntryText"], "Wed 01/Dec 99")
98 itemsList
.getChild("11").executeAction("SELECT", tuple())
99 self
.assertEqual(get_state_as_dict(itemsList
)["SelectEntryText"], "12-01")
102 # a placeholder text is not changed by format change
103 self
.assertEqual(writer_doc
.getText().getString(), "[select date]")
105 def test_date_field_without_current_date(self
):
106 # current date means the current date fieldmark parameter which contains the current date in YYYY-MM-DD format
107 # when this parameter is missing LO tries to parse the content string to find out the set date
109 # open a file with a date form field
110 with self
.ui_test
.load_file(get_url_for_data_file("date_form_field_without_current_date.odt")) as writer_doc
:
111 self
.assertEqual(writer_doc
.getText().getString(), "07/17/19")
113 # open the dialog (cursor is at the field)
114 with self
.ui_test
.execute_dialog_through_command(".uno:ControlProperties") as xDialog
:
116 itemsList
= xDialog
.getChild("date_formats_treeview")
118 # check whether we have the right format selected
119 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "20")
120 self
.assertEqual(get_state_as_dict(itemsList
)["SelectEntryText"], "12/01/99")
122 # select a new format
123 itemsList
.getChild("3").executeAction("SELECT", tuple())
124 self
.assertEqual(get_state_as_dict(itemsList
)["SelectEntryText"], "Dec 1, 1999")
127 # a placeholder text is not changed by format change
128 self
.assertEqual(writer_doc
.getText().getString(), "Jul 17, 2019")
130 def test_date_picker_drop_down(self
):
131 with self
.ui_test
.load_file(get_url_for_data_file("date_picker.docx")) as writer_doc
:
132 xWriterDoc
= self
.xUITest
.getTopFocusWindow()
133 xWriterEdit
= xWriterDoc
.getChild("writer_edit")
135 xWriterEdit
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RIGHT"}))
136 xWriterEdit
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RIGHT"}))
138 # open the dialog (cursor is at the field)
139 xWriterEdit
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "ALT+DOWN"}))
140 xWriterEdit
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "ESC"}))
141 xWriterEdit
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "UP"}))
142 if platform
.system() == "Windows":
143 self
.assertEqual(writer_doc
.getText().getString(), "\r\nClick to choose a date")
145 self
.assertEqual(writer_doc
.getText().getString(), "\nClick to choose a date")
147 # vim: set shiftwidth=4 softtabstop=4 expandtab: