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

« back to all changes in this revision

Viewing changes to tests/qmltests/Menus/tst_RadioMenu.qml

  • Committer: Bileto Bot
  • Author(s): Marco Trevisan (Treviño)
  • Date: 2016-11-11 16:53:12 UTC
  • mfrom: (146.6.6 radio-menuitem)
  • Revision ID: ci-train-bot@canonical.com-20161111165312-wereh72v48swb6fz
RadioMenu: add menu item for creating radio items

In this case the component has a quite different look in pointer mode compared to touch mode, since
the bullet has to be placed in the middle of the leading padding space when using pointer.
Instead in touch-mode it behaves like any other icon or action item.

Approved by: Lukáš Tinkl, Unity8 CI Bot

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.Menus 0.1
 
23
 
 
24
Item {
 
25
    width: units.gu(42)
 
26
    height: units.gu(75)
 
27
 
 
28
    Column {
 
29
        anchors.fill: parent
 
30
 
 
31
        RadioMenu {
 
32
            id: radioMenu
 
33
        }
 
34
 
 
35
        RadioMenu {
 
36
            id: checkedRadioMenu
 
37
            checked: true
 
38
        }
 
39
 
 
40
        RadioMenu {
 
41
            id: clickMenu
 
42
        }
 
43
    }
 
44
 
 
45
    SignalSpy {
 
46
        id: signalSpy
 
47
    }
 
48
 
 
49
    UbuntuTestCase {
 
50
        name: "BaseMenu"
 
51
        when: windowShown
 
52
 
 
53
        function getRadio(item) {
 
54
            var radio = findChild(item, "bullet");
 
55
            verify(radio !== undefined)
 
56
            return radio
 
57
        }
 
58
 
 
59
        function cleanup() {
 
60
            clickMenu.checked = false
 
61
            signalSpy.clear()
 
62
        }
 
63
 
 
64
        function test_checked() {
 
65
            compare(getRadio(radioMenu).visible, false, "radio should be hidden by default")
 
66
        }
 
67
 
 
68
        function test_unChecked() {
 
69
            compare(getRadio(checkedRadioMenu).visible, true, "radio should be visible on checked item")
 
70
        }
 
71
 
 
72
        function checkedData() {
 
73
            return [ {tag: "unchecked", checked: false}, {tag: "checked", checked: true}]
 
74
        }
 
75
 
 
76
        function test_radioVisiblity_data() {
 
77
            return checkedData()
 
78
        }
 
79
 
 
80
        function test_radioVisiblity(data) {
 
81
            clickMenu.checked = data.checked
 
82
            compare(getRadio(clickMenu).visible, data.checked, "radio should be %1 by default".arg(data.checked ? "visible" : "hidden"))
 
83
        }
 
84
 
 
85
        function test_clickEvent_data() {
 
86
            return checkedData()
 
87
        }
 
88
 
 
89
        function test_clickEvent(data) {
 
90
            signalSpy.target = clickMenu
 
91
            signalSpy.signalName = "onClicked"
 
92
            clickMenu.checked = data.checked
 
93
            mouseClick(clickMenu, clickMenu.width/2, clickMenu.height/2)
 
94
            compare(signalSpy.count, 1)
 
95
        }
 
96
 
 
97
        function test_triggeredEvent_data() {
 
98
            return checkedData()
 
99
        }
 
100
 
 
101
        function test_triggeredEvent(data) {
 
102
            signalSpy.target = clickMenu
 
103
            signalSpy.signalName = "onTriggered"
 
104
            clickMenu.checked = data.checked
 
105
            mouseClick(clickMenu, clickMenu.width/2, clickMenu.height/2)
 
106
            compare(signalSpy.count, 1)
 
107
            compare(signalSpy.signalArguments[0][0], true)
 
108
        }
 
109
 
 
110
        function test_onCheckedChanged_data() {
 
111
            return checkedData()
 
112
        }
 
113
 
 
114
        function test_onCheckedChanged(data) {
 
115
            clickMenu.checked = data.checked
 
116
            signalSpy.clear()
 
117
            signalSpy.target = clickMenu
 
118
            signalSpy.signalName = "onCheckedChanged"
 
119
            mouseClick(clickMenu, clickMenu.width/2, clickMenu.height/2)
 
120
            compare(signalSpy.count, data.checked ? 0 : 1)
 
121
            compare(clickMenu.checked, true)
 
122
        }
 
123
 
 
124
        function test_ClickOnCheckedDoesntUnchecks() {
 
125
            clickMenu.checked = true
 
126
            signalSpy.clear()
 
127
            signalSpy.target = clickMenu
 
128
            signalSpy.signalName = "onTriggered"
 
129
            compare(clickMenu.checked, true)
 
130
            mouseClick(clickMenu, clickMenu.width/2, clickMenu.height/2)
 
131
            compare(signalSpy.count, 1)
 
132
            compare(clickMenu.checked, true)
 
133
        }
 
134
    }
 
135
}