on xenial help sign in
Make the previewActions react to the actions model changing
23b9ef5Albert Astals Cid
qml/Dash/Previews/PreviewActionCombo.qml+1−1
@@ -59,7 +59,7 @@ Item {
59
59
60 delegate: PreviewActionButton {
60 delegate: PreviewActionButton {
61 data: modelData
61 data: modelData
62− width: implicitWidth < parent.width ? parent.width : implicitWidth
62+ width: implicitWidth < root.width ? root.width : implicitWidth
63 onClicked: root.triggeredAction(modelData)
63 onClicked: root.triggeredAction(modelData)
64 strokeColor: moreButton.strokeColor
64 strokeColor: moreButton.strokeColor
65 }
65 }
qml/Dash/Previews/PreviewActions.qml+8−7
@@ -26,25 +26,26 @@ PreviewWidget {
26 id: root
26 id: root
27
27
28 implicitHeight: row.height + units.gu(1)
28 implicitHeight: row.height + units.gu(1)
29+ readonly property var actions: root.widgetData ? root.widgetData["actions"] : null
29
30
30 Row {
31 Row {
31 id: row
32 id: row
32− readonly property var actions: root.widgetData ? root.widgetData["actions"] : null
33 anchors.right: parent.right
33 anchors.right: parent.right
34
34
35 spacing: units.gu(1)
35 spacing: units.gu(1)
36
36
37 Loader {
37 Loader {
38 id: loader
38 id: loader
39+ objectName: "loader"
39− readonly property bool button: row.actions && row.actions.length == 2
40+ readonly property bool button: root.actions && root.actions.length == 2
40− readonly property bool combo: row.actions && row.actions.length > 2
41+ readonly property bool combo: root.actions && root.actions.length > 2
41 source: button ? "PreviewActionButton.qml" : (combo ? "PreviewActionCombo.qml" : "")
42 source: button ? "PreviewActionButton.qml" : (combo ? "PreviewActionCombo.qml" : "")
42 width: (root.width - units.gu(1)) / 2
43 width: (root.width - units.gu(1)) / 2
43 onLoaded: {
44 onLoaded: {
44 if (button) {
45 if (button) {
45− item.data = row.actions[1];
46+ item.data = Qt.binding(function() { return root.actions[1]; });
46 } else if (combo) {
47 } else if (combo) {
47− item.model = row.actions.slice(1);
48+ item.model = Qt.binding(function() { return root.actions.slice(1); });
48 }
49 }
49 }
50 }
50 Binding {
51 Binding {
@@ -61,8 +62,8 @@ PreviewWidget {
61 }
62 }
62
63
63 PreviewActionButton {
64 PreviewActionButton {
64− data: visible ? row.actions[0] : null
65+ data: visible ? root.actions[0] : null
65− visible: row.actions && row.actions.length > 0
66+ visible: root.actions && root.actions.length > 0
66 onTriggeredAction: root.triggered(root.widgetId, actionData.id, actionData)
67 onTriggeredAction: root.triggered(root.widgetId, actionData.id, actionData)
67 width: (root.width - units.gu(1)) / 2
68 width: (root.width - units.gu(1)) / 2
68 color: root.scopeStyle ? root.scopeStyle.previewButtonColor : UbuntuColors.orange
69 color: root.scopeStyle ? root.scopeStyle.previewButtonColor : UbuntuColors.orange
tests/qmltests/Dash/Previews/tst_PreviewActions.qml+100−17
@@ -26,17 +26,17 @@ Rectangle {
26 width: units.gu(60)
26 width: units.gu(60)
27 height: units.gu(80)
27 height: units.gu(80)
28
28
29− property var actionDataOneAction: {
29+ readonly property var actionDataOneAction: {
30 "actions": [{"label": "Some Label", "id": "someid"}]
30 "actions": [{"label": "Some Label", "id": "someid"}]
31 }
31 }
32
32
33− property var actionDataTwoActions: {
33+ readonly property var actionDataTwoActions: {
34 "actions": [{"label": "Some Label A", "id": "someid1"},
34 "actions": [{"label": "Some Label A", "id": "someid1"},
35 {"label": "Some Label B", "id": "someid2"}
35 {"label": "Some Label B", "id": "someid2"}
36 ]
36 ]
37 }
37 }
38
38
39− property var actionDataFiveActions: {
39+ readonly property var actionDataFiveActions: {
40 "actions": [{"label": "Some Label C", "id": "someid3"},
40 "actions": [{"label": "Some Label C", "id": "someid3"},
41 {"label": "Some Label D", "id": "someid4"},
41 {"label": "Some Label D", "id": "someid4"},
42 {"label": "Some Label E", "id": "someid5"},
42 {"label": "Some Label E", "id": "someid5"},
@@ -45,6 +45,15 @@ Rectangle {
45 ]
45 ]
46 }
46 }
47
47
48+ property var actionModelActions: {
49+ "actions": [{"label": "Some Label H", "id": "someid8"},
50+ {"label": "Some Label I", "id": "someid9"},
51+ {"label": "Some Label J", "id": "someid10"},
52+ {"label": "Some Label K", "id": "someid11"},
53+ {"label": "Some Label L", "id": "someid12"}
54+ ]
55+ }
56+
48 SignalSpy {
57 SignalSpy {
49 id: spy
58 id: spy
50 signalName: "triggered"
59 signalName: "triggered"
@@ -88,26 +97,32 @@ Rectangle {
88 onTriggered: console.log("triggered", widgetId, actionId);
97 onTriggered: console.log("triggered", widgetId, actionId);
89 width: units.gu(60)
98 width: units.gu(60)
90 }
99 }
100+
101+ PreviewActions {
102+ id: changeModelActions
103+ width: units.gu(60)
104+ }
105+
106+ PreviewActions {
107+ id: updateModelActions
108+ width: units.gu(60)
109+ }
91 }
110 }
92
111
93 UT.UnityTestCase {
112 UT.UnityTestCase {
94 name: "PreviewActionTest"
113 name: "PreviewActionTest"
95 when: windowShown
114 when: windowShown
96
115
97− function cleanup()
98− {
99− spy.clear();
100− }
101−
102 function checkButtonPressSignal(target, id)
116 function checkButtonPressSignal(target, id)
103 {
117 {
104− var button = findChild(root, "button" + id);
118+ var button = findChild(target, "button" + id);
105 verify(button != null);
119 verify(button != null);
106 spy.target = target;
120 spy.target = target;
107 mouseClick(button);
121 mouseClick(button);
108 compare(spy.count, 1);
122 compare(spy.count, 1);
109 compare(spy.signalArguments[0][0], target.widgetId);
123 compare(spy.signalArguments[0][0], target.widgetId);
110 compare(spy.signalArguments[0][1], id);
124 compare(spy.signalArguments[0][1], id);
125+ spy.clear();
111 }
126 }
112
127
113 function test_checkButtons_data() {
128 function test_checkButtons_data() {
@@ -120,7 +135,7 @@ Rectangle {
120 }
135 }
121
136
122 function test_checkButtons(data) {
137 function test_checkButtons(data) {
123− checkButtonPressSignal(data.target, data.id, data.buttonNumber)
138+ checkButtonPressSignal(data.target, data.id)
124 }
139 }
125
140
126 function test_comboButton_data() {
141 function test_comboButton_data() {
@@ -132,17 +147,85 @@ Rectangle {
132 ]
147 ]
133 }
148 }
134
149
135− function test_comboButton(data) {
150+ function pressMoreButton(buttonGroup)
151+ {
136− var button = findChild(root, "moreLessButton");
152+ var button = findChild(buttonGroup, "moreLessButton");
137− var buttonColumn = findChild(root, "buttonColumn");
153+ var buttonColumn = findChild(buttonGroup, "buttonColumn");
138 verify(button != null);
154 verify(button != null);
139− var twoActionsY = twoActions.y
140 mouseClick(button);
155 mouseClick(button);
141− tryCompareFunction(function () { return twoActions.y <= twoActionsY; }, false);
142 tryCompare(buttonColumn, "height", buttonColumn.implicitHeight);
156 tryCompare(buttonColumn, "height", buttonColumn.implicitHeight);
157+ }
158+
159+ function test_comboButton(data) {
160+ var twoActionsY = twoActions.y
161+ pressMoreButton(buttonAndCombo);
162+ tryCompareFunction(function () { return twoActions.y <= twoActionsY; }, false);
143− checkButtonPressSignal(buttonAndCombo, data.id, data.buttonNumber);
163+ checkButtonPressSignal(buttonAndCombo, data.id);
144− mouseClick(button);
164+ mouseClick(findChild(buttonAndCombo, "moreLessButton"));
145 tryCompare(twoActions, "y", twoActionsY);
165 tryCompare(twoActions, "y", twoActionsY);
146 }
166 }
167+
168+ function test_modelChange() {
169+ changeModelActions.widgetData = actionDataOneAction;
170+ waitForRendering(changeModelActions);
171+ checkButtonPressSignal(changeModelActions, "someid");
172+
173+ changeModelActions.widgetData = actionDataTwoActions;
174+ waitForRendering(changeModelActions);
175+ checkButtonPressSignal(changeModelActions, "someid1");
176+ checkButtonPressSignal(changeModelActions, "someid2");
177+
178+ changeModelActions.widgetData = actionDataFiveActions;
179+ waitForRendering(changeModelActions);
180+ pressMoreButton(changeModelActions);
181+ checkButtonPressSignal(changeModelActions, "someid3");
182+ checkButtonPressSignal(changeModelActions, "someid4");
183+ checkButtonPressSignal(changeModelActions, "someid5");
184+ checkButtonPressSignal(changeModelActions, "someid6");
185+ }
186+
187+ function test_modelUpdate() {
188+ updateModelActions.widgetData = actionModelActions;
189+ waitForRendering(updateModelActions);
190+ pressMoreButton(updateModelActions);
191+ checkButtonPressSignal(updateModelActions, "someid8");
192+ checkButtonPressSignal(updateModelActions, "someid9");
193+ checkButtonPressSignal(updateModelActions, "someid10");
194+ checkButtonPressSignal(updateModelActions, "someid11");
195+ checkButtonPressSignal(updateModelActions, "someid12");
196+
197+ updateModelActions["actions"].pop();
198+ updateModelActions.actionsChanged();
199+
200+ // Check that some12 is gone
201+ verify(!findChild(updateModelActions, "buttonsomeid12"));
202+
203+ updateModelActions["actions"][3].id = "someidmoo";
204+ updateModelActions.actionsChanged();
205+ checkButtonPressSignal(updateModelActions, "someidmoo");
206+
207+ verify(findChild(updateModelActions, "moreLessButton"));
208+
209+ updateModelActions["actions"].pop();
210+ updateModelActions["actions"].pop();
211+ updateModelActions.actionsChanged();
212+
213+ // Check there is no more/less button anymore
214+ verify(!findChild(updateModelActions, "moreLessButton"));
215+
216+ updateModelActions["actions"][1].id = "someidbar";
217+ updateModelActions.actionsChanged();
218+ checkButtonPressSignal(updateModelActions, "someidbar");
219+
220+ updateModelActions["actions"].pop();
221+ updateModelActions.actionsChanged();
222+
223+ // Check the loader for the second button/combo is gone
224+ compare(findChild(updateModelActions, "loader").source, "");
225+
226+ updateModelActions["actions"][0].id = "someidlolar";
227+ updateModelActions.actionsChanged();
228+ checkButtonPressSignal(updateModelActions, "someidlolar");
229+ }
147 }
230 }
148}
231}