@@ -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)
29− property var actionDataOneAction: {
29+ readonly property var actionDataOneAction: {
30 "actions": [{"label": "Some Label", "id": "someid"}]
30 "actions": [{"label": "Some Label", "id": "someid"}]
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"}
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 {
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"}
48 SignalSpy {
57 SignalSpy {
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)
102+ id: changeModelActions
107+ id: updateModelActions
93 UT.UnityTestCase {
112 UT.UnityTestCase {
94 name: "PreviewActionTest"
113 name: "PreviewActionTest"
95 when: windowShown
114 when: windowShown
102 function checkButtonPressSignal(target, id)
116 function checkButtonPressSignal(target, id)
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);
113 function test_checkButtons_data() {
128 function test_checkButtons_data() {
@@ -120,7 +135,7 @@ Rectangle {
122 function test_checkButtons(data) {
137 function test_checkButtons(data) {
123− checkButtonPressSignal(data.target, data.id, data.buttonNumber)
138+ checkButtonPressSignal(data.target, data.id)
126 function test_comboButton_data() {
141 function test_comboButton_data() {
@@ -132,17 +147,85 @@ Rectangle {
135− function test_comboButton(data) {
150+ function pressMoreButton(buttonGroup)
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);
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);
168+ function test_modelChange() {
169+ changeModelActions.widgetData = actionDataOneAction;
170+ waitForRendering(changeModelActions);
171+ checkButtonPressSignal(changeModelActions, "someid");
173+ changeModelActions.widgetData = actionDataTwoActions;
174+ waitForRendering(changeModelActions);
175+ checkButtonPressSignal(changeModelActions, "someid1");
176+ checkButtonPressSignal(changeModelActions, "someid2");
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");
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");
197+ updateModelActions["actions"].pop();
198+ updateModelActions.actionsChanged();
200+ // Check that some12 is gone
201+ verify(!findChild(updateModelActions, "buttonsomeid12"));
203+ updateModelActions["actions"][3].id = "someidmoo";
204+ updateModelActions.actionsChanged();
205+ checkButtonPressSignal(updateModelActions, "someidmoo");
207+ verify(findChild(updateModelActions, "moreLessButton"));
209+ updateModelActions["actions"].pop();
210+ updateModelActions["actions"].pop();
211+ updateModelActions.actionsChanged();
213+ // Check there is no more/less button anymore
214+ verify(!findChild(updateModelActions, "moreLessButton"));
216+ updateModelActions["actions"][1].id = "someidbar";
217+ updateModelActions.actionsChanged();
218+ checkButtonPressSignal(updateModelActions, "someidbar");
220+ updateModelActions["actions"].pop();
221+ updateModelActions.actionsChanged();
223+ // Check the loader for the second button/combo is gone
224+ compare(findChild(updateModelActions, "loader").source, "");
226+ updateModelActions["actions"][0].id = "someidlolar";
227+ updateModelActions.actionsChanged();
228+ checkButtonPressSignal(updateModelActions, "someidlolar");