1# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
2#
3# This Source Code Form is subject to the terms of the Mozilla Public
4# License, v. 2.0. If a copy of the MPL was not distributed with this
5# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6#
7from uitest.framework import UITestCase
8from uitest.uihelper.calc import enter_text_to_cell
9from uitest.uihelper.common import select_by_text, get_state_as_dict
10from libreoffice.uno.propertyvalue import mkPropertyValues
11from libreoffice.calc.document import get_row
12
13#Bug 46184 - [Calc] [AutoFilter] Option "Copy results to ..." remains activated in AutoFilter
14
15class tdf46184(UITestCase):
16    def test_tdf46184_copy_results_to(self):
17        self.ui_test.create_doc_in_start_center("calc")
18        calcDoc = self.xUITest.getTopFocusWindow()
19        gridwin = calcDoc.getChild("grid_window")
20
21        enter_text_to_cell(gridwin, "A1", "A")
22        enter_text_to_cell(gridwin, "A2", "1")
23        enter_text_to_cell(gridwin, "A3", "2")
24        enter_text_to_cell(gridwin, "A4", "3")
25
26        gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:A4"}))
27
28        self.xUITest.executeCommand(".uno:DataFilterAutoFilter")
29
30        gridwin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": "0", "ROW": "0"}))
31        xFloatWindow = self.xUITest.getFloatWindow()
32        #Choose Standard Filter... button
33        xMenu = xFloatWindow.getChild("menu")
34        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
35        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
36        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
37        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
38        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
39        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
40        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DOWN"}))
41        self.assertEqual("Standard Filter...", get_state_as_dict(xMenu)['SelectEntryText'])
42        xMenu.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RETURN"}))
43
44        xDialog = self.xUITest.getTopFocusWindow()
45        xfield1 = xDialog.getChild("field1")
46        xcond1 = xDialog.getChild("cond1")
47        xval1 = xDialog.getChild("val1")
48        xcopyresult = xDialog.getChild("copyresult")
49        xedcopyarea = xDialog.getChild("edcopyarea")
50        xdestpers = xDialog.getChild("destpers")
51
52        select_by_text(xfield1, "A")
53        select_by_text(xcond1, ">")
54        xval1.executeAction("TYPE", mkPropertyValues({"TEXT":"1"}))
55        xcopyresult.executeAction("CLICK", tuple())
56        xedcopyarea.executeAction("TYPE", mkPropertyValues({"TEXT":"A6"}))
57        if get_state_as_dict(xdestpers)['Selected'] == 'false':
58            xdestpers.executeAction("CLICK", tuple())
59        self.assertEqual('true', get_state_as_dict(xcopyresult)['Selected'])
60        xOKBtn = xDialog.getChild("ok")
61        self.ui_test.close_dialog_through_button(xOKBtn)
62
63        document = self.ui_test.get_component()
64        row1 = get_row(document, 1)
65        row2 = get_row(document, 2)
66        row3 = get_row(document, 3)
67        self.assertTrue(row1.getPropertyValue("IsVisible"))
68        self.assertTrue(row2.getPropertyValue("IsVisible"))
69        self.assertTrue(row3.getPropertyValue("IsVisible"))
70
71        gridwin.executeAction("LAUNCH", mkPropertyValues({"AUTOFILTER": "", "COL": "0", "ROW": "0"}))
72        xFloatWindow = self.xUITest.getFloatWindow()
73        xCheckListMenu = xFloatWindow.getChild("check_list_menu")
74        xTreeList = xCheckListMenu.getChild("check_list_box")
75        xEntry = xTreeList.getChild("1")
76        xEntry.executeAction("CLICK", tuple())
77        xOkBtn = xFloatWindow.getChild("ok")
78        xOkBtn.executeAction("CLICK", tuple())
79
80        self.assertTrue(row1.getPropertyValue("IsVisible"))
81        self.assertFalse(row2.getPropertyValue("IsVisible"))
82        self.assertTrue(row3.getPropertyValue("IsVisible"))
83
84        self.ui_test.close_doc()
85
86# vim: set shiftwidth=4 softtabstop=4 expandtab:
87