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

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Nick Dedekind
  • Date: 2016-08-26 13:06:11 UTC
  • mfrom: (2080.1.4 staging)
  • Revision ID: tarmac-20160826130611-pvqtzn2c16c8hgrp
API for MenuBar, Menus, MenuItem & MenuSeparator.

Approved by ubuntu-sdk-build-bot, Zsombor Egri.

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
 
 
17
import QtQuick 2.0
 
18
import QtTest 1.0
 
19
import Ubuntu.Components 1.3
 
20
import Ubuntu.Components.Labs 1.0
 
21
 
 
22
TestCase {
 
23
    name: "MenuAPI"
 
24
 
 
25
    TestUtil {
 
26
        id: util
 
27
    }
 
28
 
 
29
    function test_menubar() {
 
30
        compare(menuBar.menus.length, 2, "Incorrect number of menus in menubar")
 
31
        compare(menuBar.menus[0], submenu1, "Incorrect element found at menu bar index")
 
32
        compare(menuBar.menus[1], submenu2, "Incorrect element found at menu bar index")
 
33
    }
 
34
 
 
35
    function test_menu() {
 
36
        compare(floatingMenu.data.length, 5, "Incorrect number of menu items in menu");
 
37
        compare(floatingMenu.data[0], actionList, "Incorrect element found at menu index");
 
38
        compare(floatingMenu.data[1], menuGroup, "Incorrect element found at menu index");
 
39
        compare(floatingMenu.data[2], action1, "Incorrect element found at menu index");
 
40
        compare(floatingMenu.data[3], action2, "Incorrect element found at menu index");
 
41
        compare(floatingMenu.data[4], menu1, "Incorrect element found at menu index");
 
42
    }
 
43
 
 
44
    function test_menugroup() {
 
45
        compare(group.data.length, 4, "Incorrect number of menu items in MenuGroup");
 
46
        compare(group.data[0], groupAction, "Action not found at correct index in MenuGroup");
 
47
        compare(group.data[1], groupList, "ActionList not found at correct index in MenuGroup");
 
48
        compare(group.data[2], groupMenu, "Menu not found at correct index in MenuGroup");
 
49
        compare(group.data[3], groupGroup, "MenuGroup not found at correct index in MenuGroup");
 
50
    }
 
51
 
 
52
    function test_dynamic_append() {
 
53
        dynamicMenu.appendObject(floatingAction);
 
54
        compare(dynamicMenu.data.length, 1, "Action not added to menu");
 
55
 
 
56
        dynamicMenu.removeObject(floatingAction);
 
57
        compare(dynamicMenu.data.length, 0, "Action not removed from menu");
 
58
    }
 
59
 
 
60
    function test_dynamic_action_list_append() {
 
61
        dynamicMenu.appendObject(floatingList);
 
62
        compare(dynamicMenu.data.length, 1, "ActionList not added to menu");
 
63
 
 
64
        dynamicMenu.removeObject(floatingList);
 
65
        compare(dynamicMenu.data.length, 0, "ActionList not removed from menu");
 
66
    }
 
67
 
 
68
    function test_dynamic_insert() {
 
69
        dynamicMenu.insertObject(0, floatingAction);
 
70
        dynamicMenu.insertObject(0, floatingList);
 
71
        compare(dynamicMenu.data.length, 2, "ActionList not removed from menu");
 
72
 
 
73
        compare(dynamicMenu.data[0], floatingList, "Object was not inserted at correct index");
 
74
        compare(dynamicMenu.data[1], floatingAction, "Object was not inserted at correct index");
 
75
 
 
76
        dynamicMenu.removeObject(floatingAction);
 
77
        dynamicMenu.removeObject(floatingList);
 
78
        compare(dynamicMenu.data.length, 0, "Menu should be empty");
 
79
    }
 
80
 
 
81
    MenuBar {
 
82
        id: menuBar
 
83
        Menu {
 
84
            id: submenu1
 
85
        }
 
86
        Menu {
 
87
            id: submenu2
 
88
        }
 
89
    }
 
90
 
 
91
    Menu {
 
92
        id: floatingMenu
 
93
        ActionList {
 
94
            id: actionList
 
95
        }
 
96
        MenuGroup {
 
97
            id: menuGroup
 
98
        }
 
99
        Action {
 
100
            id: action1
 
101
        }
 
102
        Action {
 
103
            id: action2
 
104
        }
 
105
        Menu {
 
106
            id: menu1
 
107
        }
 
108
    }
 
109
 
 
110
    MenuGroup {
 
111
        id: group
 
112
        Action {
 
113
            id: groupAction
 
114
        }
 
115
        ActionList {
 
116
            id: groupList
 
117
        }
 
118
        Menu {
 
119
            id: groupMenu
 
120
        }
 
121
        MenuGroup {
 
122
            id: groupGroup
 
123
        }
 
124
    }
 
125
 
 
126
    Menu {
 
127
        id: dynamicMenu
 
128
    }
 
129
 
 
130
    Action {
 
131
        id: floatingAction
 
132
    }
 
133
 
 
134
    ActionList {
 
135
        id: floatingList
 
136
    }
 
137
}