on xenial help sign in
Add QML test to check panel resize has indicator item reposition correctly
20f4269Gerry Boland
tests/qmltests/Panel/tst_IndicatorsBar.qml+26−1
@@ -46,7 +46,7 @@ IndicatorTest {
46 IndicatorsBar {
46 IndicatorsBar {
47 id: indicatorsBar
47 id: indicatorsBar
48 height: expanded ? units.gu(7) : units.gu(3)
48 height: expanded ? units.gu(7) : units.gu(3)
49− width: units.gu(30)
49+ width: units.gu(widthSlider.value)
50 anchors.centerIn: parent
50 anchors.centerIn: parent
51 indicatorsModel: root.indicatorsModel
51 indicatorsModel: root.indicatorsModel
52 interactive: expanded && height === units.gu(7)
52 interactive: expanded && height === units.gu(7)
@@ -79,6 +79,14 @@ IndicatorTest {
79 onClicked: indicatorsBar.expanded = !indicatorsBar.expanded
79 onClicked: indicatorsBar.expanded = !indicatorsBar.expanded
80 }
80 }
81
81
82+ Slider {
83+ id: widthSlider
84+ Layout.fillWidth: true
85+ minimumValue: 10
86+ maximumValue: 60
87+ value: 30
88+ }
89+
82 Rectangle {
90 Rectangle {
83 Layout.preferredHeight: units.dp(1);
91 Layout.preferredHeight: units.dp(1);
84 Layout.fillWidth: true;
92 Layout.fillWidth: true;
@@ -114,6 +122,7 @@ IndicatorTest {
114 when: windowShown
122 when: windowShown
115
123
116 function init() {
124 function init() {
125+ widthSlider.value = 30;
117 indicatorsBar.expanded = false;
126 indicatorsBar.expanded = false;
118 wait_for_expansion_to_settle();
127 wait_for_expansion_to_settle();
119 }
128 }
@@ -220,5 +229,21 @@ IndicatorTest {
220 tryCompareFunction(function() { return dataItem.width > 0.0; }, true);
229 tryCompareFunction(function() { return dataItem.width > 0.0; }, true);
221 }
230 }
222 }
231 }
232+
233+ // Rough test that resizing the IndicatorsBar has the items reposition correctly
234+ function test_widthChangeRepositionsItems() {
235+ var lastItemIndex = root.originalModelData.length-1;
236+ var dataItem = findChild(indicatorsBar, root.originalModelData[lastItemIndex]["identifier"] + "-panelItem");
237+ verify(dataItem !== null);
238+
239+ var mappedPosition = indicatorsBar.mapFromItem(dataItem, dataItem.width/2, dataItem.height/2);
240+ var oldDistanceFromRightEdge = indicatorsBar.width - mappedPosition.x;
241+
242+ widthSlider.value = 50;
243+ mappedPosition = indicatorsBar.mapFromItem(dataItem, dataItem.width/2, dataItem.height/2);
244+ var newDistanceFromRightEdge = indicatorsBar.width - mappedPosition.x;
245+
246+ compare(newDistanceFromRightEdge, oldDistanceFromRightEdge);
247+ }
223 }
248 }
224}
249}