@@ -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}