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
11 from uitest
.uihelper
.common
import get_state_as_dict
12 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
15 class FindBar(UITestCase
):
17 def test_find_bar(self
):
19 with self
.ui_test
.create_doc_in_start_center("writer"):
20 xWriterDoc
= self
.xUITest
.getTopFocusWindow()
21 xWriterEdit
= xWriterDoc
.getChild("writer_edit")
23 # Type some lines to search for words on them
24 xWriterEdit
.executeAction("TYPE", mkPropertyValues({"TEXT": "LibreOffice"}))
25 xWriterEdit
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
26 xWriterEdit
.executeAction("TYPE", mkPropertyValues({"TEXT": "LibreOffice Writer"}))
27 xWriterEdit
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
28 xWriterEdit
.executeAction("TYPE", mkPropertyValues({"TEXT": "LibreOffice Calc"}))
29 xWriterEdit
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
30 xWriterEdit
.executeAction("TYPE", mkPropertyValues({"TEXT": "The Document Foundation"}))
33 xWriterEdit
.executeAction("TYPE", mkPropertyValues({"KEYCODE": "CTRL+f"}))
35 # Type the Word that we want to search for it
36 xfind
= xWriterDoc
.getChild("find")
37 xfind
.executeAction("TYPE", mkPropertyValues({"TEXT": "Libre"}))
40 xfind_bar
= xWriterDoc
.getChild("FindBar")
41 self
.assertEqual(get_state_as_dict(xfind_bar
)["ItemCount"], "14")
43 # Press on FindAll in the Find Bar
44 xfind_bar
.executeAction("CLICK", mkPropertyValues({"POS": "4"}))
45 self
.assertEqual(get_state_as_dict(xfind_bar
)["CurrSelectedItemID"], "5") # 5 is FindAll id for Pos 4
46 self
.assertEqual(get_state_as_dict(xfind_bar
)["CurrSelectedItemText"], "Find All")
47 self
.assertEqual(get_state_as_dict(xfind_bar
)["CurrSelectedItemCommand"], ".uno:FindAll")
48 self
.assertEqual(get_state_as_dict(xWriterEdit
)["SelectedText"], "LibreLibreLibre")
50 # Press on Find Next in the Find Bar
51 xfind_bar
.executeAction("CLICK", mkPropertyValues({"POS": "3"})) # 3 is Find Next pos
52 self
.assertEqual(get_state_as_dict(xfind_bar
)["CurrSelectedItemID"], "4")
53 self
.assertEqual(get_state_as_dict(xfind_bar
)["CurrSelectedItemText"], "Find Next")
54 self
.assertEqual(get_state_as_dict(xfind_bar
)["CurrSelectedItemCommand"], ".uno:DownSearch")
55 self
.assertEqual(get_state_as_dict(xWriterEdit
)["SelectedText"], "Libre")
57 # Press on Find Previous in the Find Bar
58 xfind_bar
.executeAction("CLICK", mkPropertyValues({"POS": "2"})) # 2 is Find Previous pos
59 self
.assertEqual(get_state_as_dict(xfind_bar
)["CurrSelectedItemID"], "3")
60 self
.assertEqual(get_state_as_dict(xfind_bar
)["CurrSelectedItemText"], "Find Previous")
61 self
.assertEqual(get_state_as_dict(xfind_bar
)["CurrSelectedItemCommand"], ".uno:UpSearch")
62 self
.assertEqual(get_state_as_dict(xWriterEdit
)["SelectedText"], "Libre")
65 xfind_bar
.executeAction("CLICK", mkPropertyValues({"POS": "0"})) # 0 is pos for close
68 # vim: set shiftwidth=4 softtabstop=4 expandtab: