~ubuntu-sdk-team/ubuntu-ui-toolkit/quickWindowRootItem

« back to all changes in this revision

Viewing changes to tests/unit/components/tst_action.qml

  • Committer: Zoltán Balogh
  • Date: 2016-08-23 10:39:12 UTC
  • mfrom: (1000.105.31 uitk.actionlist)
  • Revision ID: zoltan@bakter.hu-20160823103912-m4g13qqajjzir8cf
Introduced Action states & ExclusiveGroup action list / https://code.launchpad.net/~nick-dedekind/ubuntu-ui-toolkit/exclusiveGroup/+merge/297921

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import QtQuick 2.0
18
18
import QtTest 1.0
19
 
import Ubuntu.Components 1.1
 
19
import Ubuntu.Components 1.3
20
20
 
21
21
TestCase {
22
22
     name: "ActionAPI"
39
39
         triggeredSignalSpy.clear();
40
40
         context1.active = false;
41
41
         context2.active = false;
 
42
 
 
43
         checkableAction.checkable = true;
 
44
         checkableAction.checked = false;
 
45
         action1.checked = true;
 
46
         currentActionSpy.clear();
 
47
         checkableSpy.clear();
42
48
     }
43
49
 
44
50
     function initTestCase() {
166
172
         compare(data.action.invoked, data.invoked);
167
173
     }
168
174
 
 
175
     function test_checkable() {
 
176
         checkableAction.checkable = true;
 
177
         checkableAction.checked = true;
 
178
         checkableSpy.wait();
 
179
         compare(checkableAction.checked, true, "Checkable action should be checked");
 
180
     }
 
181
 
 
182
     function test_not_checkable() {
 
183
         checkableAction.checkable = false;
 
184
         checkableAction.checked = true;
 
185
         compare(checkableAction.checked, false, "Non-checkable action should never be checked");
 
186
     }
 
187
 
 
188
     function test_actionlist() {
 
189
         verify(actionList.actions.length, 2, "Default actions not added to actionList");
 
190
     }
 
191
 
 
192
     function test_actionlist_dynamic_actions() {
 
193
         actionList.addAction(dynamicListAction);
 
194
         verify(actionList.actions.length, 3, "Dynamic action not added to actionList");
 
195
         actionList.removeAction(dynamicListAction);
 
196
         verify(actionList.actions.length, 2, "Dynamic action not remove from actionList");
 
197
     }
 
198
 
 
199
     function test_exclusive_group() {
 
200
         compare(exclusiveGroup.actions.length, 3, "Incorrect number of actions");
 
201
     }
 
202
 
 
203
     function test_exclusive_group_activation_data() {
 
204
         return [
 
205
             {tag: "Activate action2", active: [action2], inactive: [action1, action3], current: action2},
 
206
             {tag: "Activate action3", active: [action3], inactive: [action1, action2], current: action3},
 
207
             {tag: "Activate action2, action3", active: [action2, action3], inactive: [action1, action2], current: action3},
 
208
         ];
 
209
     }
 
210
     function test_exclusive_group_activation(data) {
 
211
         for (var i = 0; i < data.active.length; i++) {
 
212
             data.active[i].trigger();
 
213
             compare(data.active[i].checked, true, "Active action checked property should be 'true'");
 
214
         }
 
215
         for (var i = 0; i < data.inactive.length; i++) {
 
216
            compare(data.inactive[i].checked, false, "Inactive action checked property should be 'false'");
 
217
         }
 
218
         currentActionSpy.wait();
 
219
         compare(exclusiveGroup.current, data.current, "Current action in exclusiveGroup does not match");
 
220
     }
 
221
 
 
222
     function test_always_one_action_selected() {
 
223
         action1.trigger();
 
224
         compare(action1.checked, true, "Triggering an exclusive group action should check the action");
 
225
         action1.trigger();
 
226
         compare(action1.checked, true, "Triggering an exclusive group action again will not uncheck the action.");
 
227
     }
 
228
 
169
229
     Action {
170
230
         id: action
171
231
     }
197
257
         target: action
198
258
         signalName: "textChanged"
199
259
     }
 
260
     SignalSpy {
 
261
         id: checkableSpy
 
262
         target: checkableAction
 
263
         signalName: "toggled"
 
264
     }
 
265
     SignalSpy {
 
266
         id: currentActionSpy
 
267
         target: exclusiveGroup
 
268
         signalName: "currentChanged"
 
269
     }
200
270
 
201
271
     ActionManager {
202
272
         id: manager
236
306
         id: testItem
237
307
     }
238
308
 
 
309
     Action {
 
310
         id: checkableAction
 
311
         checkable: true
 
312
     }
 
313
 
 
314
     ActionList {
 
315
         id: actionList
 
316
         Action {
 
317
         }
 
318
         Action {
 
319
         }
 
320
     }
 
321
 
 
322
     Action {
 
323
         id: dynamicListAction
 
324
     }
 
325
 
 
326
     ExclusiveGroup {
 
327
         id: exclusiveGroup
 
328
         Action {
 
329
             id: action1
 
330
             checkable: true
 
331
             checked: true
 
332
         }
 
333
         Action {
 
334
             id: action2
 
335
             checkable: true
 
336
             checked: false
 
337
         }
 
338
         Action {
 
339
             id: action3
 
340
             checkable: true
 
341
             checked: false
 
342
         }
 
343
     }
 
344
 
239
345
}