File: tst_actionitem.11.qml

package info (click to toggle)
lomiri-ui-toolkit 1.3.5110%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 26,436 kB
  • sloc: cpp: 85,830; python: 5,537; sh: 1,344; javascript: 919; ansic: 573; makefile: 204
file content (199 lines) | stat: -rw-r--r-- 7,510 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
 * Copyright 2012 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.0
import QtTest 1.0
import Lomiri.Components 1.1

Item {
    id: main
    width: units.gu(20)
    height: units.gu(20)

    property bool customVisible: true
    property bool customEnabled: true

    ActionItem {
        id: item1
        SignalSpy {
            id: signalSpy
            target: parent
        }
    }

    Component {
        id: dynamicItem
        ActionItem {
            action: action1
        }
    }
    Component {
        id: dynamicItem2
        ActionItem {
            action: action1
            visible: customVisible
            enabled: customEnabled
        }
    }

    Action {
        id: action1
        objectName: "action1"
        text: "actionText"
        iconSource: "imageURL"
    }
    Action {
        id: action2
        objectName: "action2"
    }

    Loader {
        id: loader
        asynchronous: false
    }

    TestCase {
        id: testCase
        when: windowShown
        name: "ActionItemAPI"

        SignalSpy {
            id: triggerSpy
            target: action1
            signalName: "triggered"
        }

        function initTestCase() {
            compare(item1.action, null, "action is null by default")
            compare(item1.text, "", "text is empty string set by default")
            compare(item1.iconSource, "", "iconSource is empty string by default")
            compare(item1.iconName, "", "iconSource is empty string by default")
        }

        function cleanup() {
            loader.sourceComponent = null;
            item1.action = null;
            action1.visible = true;
            action1.enabled = true;
            action2.visible = true;
            action2.enabled = true;
            main.customEnabled = true;
            main.customVisible = true;
            triggerSpy.clear();
        }

        function test_action() {
            compare(item1.action, null,"Action is null by default")
            item1.action = action1
            compare(item1.action, action1, "Action can be set")
            compare(item1.text, action1.text, "text is automatically set to action text")
            compare(item1.iconSource, action1.iconSource, "iconSource is automatically set to action iconSource")
            item1.triggered(null)
            triggerSpy.wait(400);
        }

        // NOTE: This test must be run AFTER test_action(), otherwise setting the action will
        // not update the text
        function test_text() {
            compare(item1.text, "", "text is empty string by default")
            var newText = "new text"
            item1.text = newText
            compare(item1.text, newText, "text can be set")
            item1.text = ""
            compare(item1.text, "", "text can be unset")
        }

        // NOTE: This test must be run AFTER test_action(), otherwise setting the action will
        // will not update the iconSource
        function test_iconSource() {
            compare(item1.iconSource, "", "iconSource is empty string by default")
            var newIconSource = Qt.resolvedUrl("../../../examples/lomiri-ui-toolkit-gallery/small_avatar.png")
            item1.iconSource = newIconSource
            compare(item1.iconSource, newIconSource, "iconSource can be set")
            item1.iconSource = ""
            compare(item1.iconSource, "", "iconSource can be unset")
        }

        // NOTE: This test must be run AFTER test_action(), otherwise setting the action will
        // will not update the iconName
        function test_iconName() {
            compare(item1.iconName, "", "iconName is empty string by default")
            var newIconName = "compose"
            item1.iconName = newIconName
            compare(item1.iconName, newIconName, "iconName can be set")
            item1.iconName = ""
            compare(item1.iconName, "", "iconName can be unset")
        }

        function test_signal_triggered() {
            signalSpy.signalName = "triggered";
            compare(signalSpy.valid,true,"triggered signal exists")
        }

        function test_default_bindings_visible_enabled_data() {
            return [
                        {tag: "visible", property: "visible"},
                        {tag: "enabled", property: "enabled"},
                    ];
        }
        function test_default_bindings_visible_enabled(data) {
            item1.action = action1;
            action1[data.property] = false;
            compare(item1[data.property], action1[data.property], "The item1 and action1 '" + data.property + "' value differs");
        }

        function test_custom_bindings_visible_enabled_bug1495408_data() {
            return [
                {tag: "visible", component: dynamicItem, property: "visible"},
                {tag: "enabled", component: dynamicItem, property: "enabled"},
                {tag: "visible binding", component: dynamicItem2, property: "visible", customProperty: "customVisible"},
                {tag: "enabled binding", component: dynamicItem2, property: "enabled", customProperty: "customEnabled"},
            ];
        }
        function test_custom_bindings_visible_enabled_bug1495408(data) {
            loader.sourceComponent = data.component;
            var item = loader.item;
            compare(item[data.property], action1[data.property], "The item and action1 '" + data.property + "' value differs");
            if (data.customProperty) {
                main[data.customProperty] = false;
            } else {
                item[data.property] = false;
            }
            // change the action so the internal bindings are updated
            item.action = action2;
            expectFail(data.tag, "default binding must be broken");
            compare(item[data.property], item.action[data.property], "The item's and action's '" + data.property + "' value is the same");
        }
        function test_custom_bindings_visible_enabled_reparenting_bug1495408_data() {
            return [
                {tag: "visible binding", component: dynamicItem2, property: "visible"},
                {tag: "enabled binding", component: dynamicItem2, property: "enabled"},
            ];
        }
        function test_custom_bindings_visible_enabled_reparenting_bug1495408(data) {
            loader.sourceComponent = dynamicItem2;
            var item = loader.item;
            compare(item[data.property], item.action[data.property], "The item and item.action '" + data.property + "' value differs");
            // then reparent
            item.parent = item1;
            // change the action property

            item.action[data.property] = false;
            expectFail(data.tag, "default binding must be broken");
            compare(item[data.property], item.action[data.property], "The item and action2 '" + data.property + "' value is the same");
        }
    }
}