on xenial help sign in
Make the previewActions react to the actions model changing

i.e. use a binding instead of a direct assingment Fixes: #1485887 Approved by: Andrea Cimitan

commit80c6df416c3b4d054035c527478ca633263e6a82 authorAlbert Astals Cid <albert.astals@canonical.com> dateWed 4 May 2016, 18:08 (10 years ago) parentf2ffa9323b9ef5
3 files changed+109−25
qml/Dash/Previews/PreviewActionCombo.qml+1−1 qml/Dash/Previews/PreviewActions.qml+8−7 tests/qmltests/Dash/Previews/tst_PreviewActions.qml+100−17
qml/Dash/Previews/PreviewActionCombo.qml+1−1
@@ -59,7 +59,7 @@ Item {
5959
6060 delegate: PreviewActionButton {
6161 data: modelData
62− width: implicitWidth < parent.width ? parent.width : implicitWidth
62+ width: implicitWidth < root.width ? root.width : implicitWidth
6363 onClicked: root.triggeredAction(modelData)
6464 strokeColor: moreButton.strokeColor
6565 }
qml/Dash/Previews/PreviewActions.qml+8−7
@@ -26,25 +26,26 @@ PreviewWidget {
2626 id: root
2727
2828 implicitHeight: row.height + units.gu(1)
29+ readonly property var actions: root.widgetData ? root.widgetData["actions"] : null
2930
3031 Row {
3132 id: row
32− readonly property var actions: root.widgetData ? root.widgetData["actions"] : null
3333 anchors.right: parent.right
3434
3535 spacing: units.gu(1)
3636
3737 Loader {
3838 id: loader
39− readonly property bool button: row.actions && row.actions.length == 2
40− readonly property bool combo: row.actions && row.actions.length > 2
39+ objectName: "loader"
40+ readonly property bool button: root.actions && root.actions.length == 2
41+ readonly property bool combo: root.actions && root.actions.length > 2
4142 source: button ? "PreviewActionButton.qml" : (combo ? "PreviewActionCombo.qml" : "")
4243 width: (root.width - units.gu(1)) / 2
4344 onLoaded: {
4445 if (button) {
45− item.data = row.actions[1];
46+ item.data = Qt.binding(function() { return root.actions[1]; });
4647 } else if (combo) {
47− item.model = row.actions.slice(1);
48+ item.model = Qt.binding(function() { return root.actions.slice(1); });
4849 }
4950 }
5051 Binding {
@@ -61,8 +62,8 @@ PreviewWidget {
6162 }
6263
6364 PreviewActionButton {
64− data: visible ? row.actions[0] : null
65− visible: row.actions && row.actions.length > 0
65+ data: visible ? root.actions[0] : null
66+ visible: root.actions && root.actions.length > 0
6667 onTriggeredAction: root.triggered(root.widgetId, actionData.id, actionData)
6768 width: (root.width - units.gu(1)) / 2
6869 color: root.scopeStyle ? root.scopeStyle.previewButtonColor : UbuntuColors.orange
tests/qmltests/Dash/Previews/tst_PreviewActions.qml+100−17
@@ -26,17 +26,17 @@ Rectangle {
2626 width: units.gu(60)
2727 height: units.gu(80)
2828
29− property var actionDataOneAction: {
29+ readonly property var actionDataOneAction: {
3030 "actions": [{"label": "Some Label", "id": "someid"}]
3131 }
3232
33− property var actionDataTwoActions: {
33+ readonly property var actionDataTwoActions: {
3434 "actions": [{"label": "Some Label A", "id": "someid1"},
3535 {"label": "Some Label B", "id": "someid2"}
3636 ]
3737 }
3838
39− property var actionDataFiveActions: {
39+ readonly property var actionDataFiveActions: {
4040 "actions": [{"label": "Some Label C", "id": "someid3"},
4141 {"label": "Some Label D", "id": "someid4"},
4242 {"label": "Some Label E", "id": "someid5"},
@@ -45,6 +45,15 @@ Rectangle {
4545 ]
4646 }
4747
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+
4857 SignalSpy {
4958 id: spy
5059 signalName: "triggered"
@@ -88,26 +97,32 @@ Rectangle {
8897 onTriggered: console.log("triggered", widgetId, actionId);
8998 width: units.gu(60)
9099 }
100+
101+ PreviewActions {
102+ id: changeModelActions
103+ width: units.gu(60)
104+ }
105+
106+ PreviewActions {
107+ id: updateModelActions
108+ width: units.gu(60)
109+ }
91110 }
92111
93112 UT.UnityTestCase {
94113 name: "PreviewActionTest"
95114 when: windowShown
96115
97− function cleanup()
98− {
99− spy.clear();
100− }
101−
102116 function checkButtonPressSignal(target, id)
103117 {
104− var button = findChild(root, "button" + id);
118+ var button = findChild(target, "button" + id);
105119 verify(button != null);
106120 spy.target = target;
107121 mouseClick(button);
108122 compare(spy.count, 1);
109123 compare(spy.signalArguments[0][0], target.widgetId);
110124 compare(spy.signalArguments[0][1], id);
125+ spy.clear();
111126 }
112127
113128 function test_checkButtons_data() {
@@ -120,7 +135,7 @@ Rectangle {
120135 }
121136
122137 function test_checkButtons(data) {
123− checkButtonPressSignal(data.target, data.id, data.buttonNumber)
138+ checkButtonPressSignal(data.target, data.id)
124139 }
125140
126141 function test_comboButton_data() {
@@ -132,17 +147,85 @@ Rectangle {
132147 ]
133148 }
134149
135− function test_comboButton(data) {
136− var button = findChild(root, "moreLessButton");
137− var buttonColumn = findChild(root, "buttonColumn");
150+ function pressMoreButton(buttonGroup)
151+ {
152+ var button = findChild(buttonGroup, "moreLessButton");
153+ var buttonColumn = findChild(buttonGroup, "buttonColumn");
138154 verify(button != null);
139− var twoActionsY = twoActions.y
140155 mouseClick(button);
141− tryCompareFunction(function () { return twoActions.y <= twoActionsY; }, false);
142156 tryCompare(buttonColumn, "height", buttonColumn.implicitHeight);
143− checkButtonPressSignal(buttonAndCombo, data.id, data.buttonNumber);
144− mouseClick(button);
157+ }
158+
159+ function test_comboButton(data) {
160+ var twoActionsY = twoActions.y
161+ pressMoreButton(buttonAndCombo);
162+ tryCompareFunction(function () { return twoActions.y <= twoActionsY; }, false);
163+ checkButtonPressSignal(buttonAndCombo, data.id);
164+ mouseClick(findChild(buttonAndCombo, "moreLessButton"));
145165 tryCompare(twoActions, "y", twoActionsY);
146166 }
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+ }
147230 }
148231}