~ci-train-bot/ubuntu-settings-components/ubuntu-settings-components-ubuntu-zesty-2022

« back to all changes in this revision

Viewing changes to tests/qmltests/Components/tst_ActionTextField.qml

  • Committer: Bileto Bot
  • Date: 2016-10-24 11:32:00 UTC
  • mfrom: (146.3.110 slots-layout)
  • Revision ID: ci-train-bot@canonical.com-20161024113200-85dvkl9m1o0msi5i
* Menus: rewrite components using ListItemLayout's and SlotsLayout's
* Bump revision to 0.10, as per Components removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2016 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by Marco Trevisan <marco.trevisan@canonical.com>
 
17
 */
 
18
 
 
19
import QtQuick 2.4
 
20
import QtTest 1.0
 
21
import Ubuntu.Test 0.1
 
22
import Ubuntu.Settings.Components 0.1
 
23
 
 
24
Item {
 
25
    width: units.gu(42)
 
26
    height: units.gu(75)
 
27
 
 
28
    Flickable {
 
29
        anchors.fill: parent
 
30
 
 
31
        ActionTextField {
 
32
            id: actionField
 
33
            text: "Message"
 
34
            buttonText: "Send!"
 
35
        }
 
36
    }
 
37
 
 
38
    SignalSpy {
 
39
        id: activatedSignalSpy
 
40
        target: actionField
 
41
        signalName: "activated"
 
42
    }
 
43
 
 
44
    UbuntuTestCase {
 
45
        name: "ActionTextField"
 
46
        when: windowShown
 
47
 
 
48
        property QtObject replyText
 
49
        property QtObject sendButton
 
50
 
 
51
        function init() {
 
52
            replyText = findChild(actionField, "replyText");
 
53
            verify(replyText !== undefined)
 
54
 
 
55
            sendButton = findChild(actionField, "sendButton");
 
56
            verify(sendButton !== undefined)
 
57
        }
 
58
 
 
59
        function cleanup() {
 
60
            activatedSignalSpy.clear()
 
61
        }
 
62
 
 
63
        function test_replyText() {
 
64
            actionField.text = "FoooBar"
 
65
            compare(replyText.text, "FoooBar")
 
66
        }
 
67
 
 
68
        function test_replyTextLosesFocusOnDisabled() {
 
69
            mouseClick(replyText, replyText.width/2, replyText.height/2)
 
70
            compare(replyText.focus, true)
 
71
 
 
72
            replyText.enabled = false
 
73
            compare(replyText.focus, false)
 
74
        }
 
75
 
 
76
        function test_buttonText() {
 
77
            actionField.buttonText = "BarBar"
 
78
            compare(sendButton.text, "BarBar")
 
79
        }
 
80
 
 
81
        function test_buttonState() {
 
82
            actionField.activateEnabled = false
 
83
            actionField.text = "Send me"
 
84
            compare(sendButton.enabled, false)
 
85
 
 
86
            actionField.activateEnabled = true
 
87
            compare(sendButton.enabled, true)
 
88
 
 
89
            actionField.text = ""
 
90
            compare(sendButton.enabled, false)
 
91
 
 
92
            actionField.text = "Enable again"
 
93
            compare(sendButton.enabled, true)
 
94
        }
 
95
 
 
96
        function test_buttonClickActivatesTextArea() {
 
97
            actionField.activateEnabled = true
 
98
            mouseClick(sendButton, sendButton.width/2, sendButton.height/2)
 
99
            compare(activatedSignalSpy.count, 1)
 
100
            compare(activatedSignalSpy.signalArguments[0][0], replyText.text)
 
101
        }
 
102
    }
 
103
}