Merge lp:~aacid/unity8/action_preview_widget into lp:unity8

Proposed by Albert Astals Cid
Status: Superseded
Proposed branch: lp:~aacid/unity8/action_preview_widget
Merge into: lp:unity8
Prerequisite: lp:~aacid/unity8/image_gallery_preview_widget
Diff against target: 360 lines (+319/-0)
6 files modified
qml/Dash/Previews/PreviewActionButton.qml (+30/-0)
qml/Dash/Previews/PreviewActionCombo.qml (+66/-0)
qml/Dash/Previews/PreviewActions.qml (+64/-0)
qml/Dash/Previews/PreviewWidget.qml (+10/-0)
tests/qmltests/CMakeLists.txt (+1/-0)
tests/qmltests/Dash/Previews/tst_PreviewActions.qml (+148/-0)
To merge this branch: bzr merge lp:~aacid/unity8/action_preview_widget
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michał Sawicz Needs Fixing
Review via email: mp+204998@code.launchpad.net

This proposal has been superseded by a proposal from 2014-02-06.

Commit message

Actions Preview Widget

Description of the change

 * Are there any related MPs required for this MP to build/function as expected?
It's listed in the prerequisite field

 * Did you perform an exploratory manual test run of your code change and any related functionality?
Yes, the tests work, it's not hooked into the rest of the app yet

 * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
N/A

 * If you changed the UI, has there been a design review?
No, it's not hooked into the rest of the app yet, will get a whole review when we do that.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:680
http://jenkins.qa.ubuntu.com/job/unity8-ci/2245/
Executed test runs:
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/2950
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty-touch/2686
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/1116
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-ci/767
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/769
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/769/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-ci/767
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/2589
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/2952
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/2952/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/2687
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/2687/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/5111
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/3682

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/unity8-ci/2245/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

27 + property var data: null

33 + onClicked: triggeredAction(data)

164 + root.triggered(root.widgetId, data.id, data);

306 + compare(spy.signalArguments[0][2], target.widgetData["actions"][buttonNumber]);

Those actions should not submit any data. Only actions triggered by data-generating widgets (rating-input, progress) will actually send any data.

Can we override the clicked() signal to send just the action id?

=====

62 + width: childrenRect.width
63 + height: childrenRect.height

I've a feeling this should be implicitWidth, but the buttons should be divided in two if the widget is wider.

Remember a single button should be right-aligned, too.

=====

81 + id: c

More name, please.

=====

92 + delegate: Button {

Why not PreviewActionButton?

=====

77 + width: c.maxWidth

82 + property real maxWidth: -1

98 + width: implicitWidth < parent.width ? parent.width : implicitWidth

100 + Component.onCompleted: {
101 + c.maxWidth = Math.max(c.maxWidth, implicitWidth);
102 + }

I don't think that's necessary, see above about widths.

=====

83 + anchors.top: moreButton.bottom
84 + anchors.topMargin: spacing

Compress into { } please.

=====

84 + anchors.topMargin: spacing

86 + spacing: height > 0 ? units.gu(1) : 0

Shouldn't the topMargin have that condition instead?

=====

97 + height: moreButton.expanded ? implicitHeight : 0

99 + visible: height > 0

Shouldn't that be on the Column instead?

=====

Animate the Column height please.

=====

142 + width: childrenRect.width

Should be parent-driven.

=====

144 + readonly property var actions: root.widgetData ? root.widgetData["actions"] : null

Move lower in the hierarchy, please, so it's not exposed.

=====

158 + item.model = actions.slice(1)

Smart! ++; please.

=====

174 +

--\n, please.

=====

185 + //! The id of the widget

ETOOMANYTHES, "The widget identifier"?

=====

301 + spy.clear();

→ cleanup()?

=====

303 + compare(spy.count, 1);

spy.wait();

review: Needs Fixing
681. By Albert Astals Cid

Buttons just pass their id up, not the whole data

Revision history for this message
Albert Astals Cid (aacid) wrote :

> 27 + property var data: null
>
> 33 + onClicked: triggeredAction(data)
>
> 164 + root.triggered(root.widgetId, data.id, data);
>
> 306 + compare(spy.signalArguments[0][2],
> target.widgetData["actions"][buttonNumber]);
>
> Those actions should not submit any data. Only actions triggered by data-
> generating widgets (rating-input, progress) will actually send any data.

Done

> Can we override the clicked() signal to send just the action id?

No, it complains about duplicate signals

682. By Albert Astals Cid

longer name

Revision history for this message
Albert Astals Cid (aacid) wrote :

> =====
>
> 81 + id: c
>
> More name, please.

done

683. By Albert Astals Cid

Use PreviewActionButton in PreviewActionCombo

And other minor stuff

Revision history for this message
Albert Astals Cid (aacid) wrote :

> 92 + delegate: Button {
>
> Why not PreviewActionButton?

Done.

684. By Albert Astals Cid

Missing ;

Revision history for this message
Albert Astals Cid (aacid) wrote :

> 158 + item.model = actions.slice(1)
>
> Smart! ++; please.

Done

Revision history for this message
Albert Astals Cid (aacid) wrote :

>
>
> 174 +
>
> --\n, please.

Really? Done

685. By Albert Astals Cid

One line less!

686. By Albert Astals Cid

better docu-comment

Revision history for this message
Albert Astals Cid (aacid) wrote :

> =====
>
> 185 + //! The id of the widget
>
> ETOOMANYTHES, "The widget identifier"?

Done.

Revision history for this message
Albert Astals Cid (aacid) wrote :

> 301 + spy.clear();
>
> → cleanup()?

Object SignalSpy_QMLTYPE_3(0x15abe60) has no method 'cleanup'

So no :D

Revision history for this message
Albert Astals Cid (aacid) wrote :

> 303 + compare(spy.count, 1);
>
> spy.wait();

Why? It should trigger immediately and only once, spy.wait() seems a worse check than spy.count == 1

687. By Albert Astals Cid

Hide "actions" from the outside users

Revision history for this message
Albert Astals Cid (aacid) wrote :

> 144 + readonly property var actions: root.widgetData ?
> root.widgetData["actions"] : null
>
> Move lower in the hierarchy, please, so it's not exposed.

Done

Revision history for this message
Albert Astals Cid (aacid) wrote :

> 62 + width: childrenRect.width
> 63 + height: childrenRect.height
>
> I've a feeling this should be implicitWidth, but the buttons should be divided
> in two if the widget is wider.
>
> Remember a single button should be right-aligned, too.

I made it implicitWidth and right-aligned the buttons.

I did not understand the "buttons should be divided in two if the widget is wider" part.

Revision history for this message
Albert Astals Cid (aacid) wrote :

> 77 + width: c.maxWidth
>
> 82 + property real maxWidth: -1
>
> 98 + width: implicitWidth < parent.width ? parent.width : implicitWidth
>
> 100 + Component.onCompleted: {
> 101 + c.maxWidth = Math.max(c.maxWidth, implicitWidth);
> 102 + }
>
> I don't think that's necessary, see above about widths.

Well, this makes sure all the buttons in the "combo button column" have the same width, otherwise the thing looked ultra ugly to me. Why do you think it's not necessary?

688. By Albert Astals Cid

Right align and make the width implcitWidth

689. By Albert Astals Cid

The condition makes more sense in topMargin than in spacing

Revision history for this message
Albert Astals Cid (aacid) wrote :

>
> 84 + anchors.topMargin: spacing
>
> 86 + spacing: height > 0 ? units.gu(1) : 0
>
> Shouldn't the topMargin have that condition instead?

Makes sense, done.

690. By Albert Astals Cid

Saviq doesn't want to see two anchors. one after the other

Revision history for this message
Albert Astals Cid (aacid) wrote :

> 83 + anchors.top: moreButton.bottom
> 84 + anchors.topMargin: spacing
>
> Compress into { } please.

Done

Revision history for this message
Albert Astals Cid (aacid) wrote :

> =====
>
> 97 + height: moreButton.expanded ? implicitHeight : 0
>
> 99 + visible: height > 0
>
> Shouldn't that be on the Column instead?
>
> =====
>
> Animate the Column height please.
>

Done both, it was part of a failed animation experiment from yesterday after another one failed and another one failed (yeah it was late on the day :D)

691. By Albert Astals Cid

Animate height of the combo

692. By Albert Astals Cid

Wait for the height animation to finish

otherwise we click on something that is still not there and the test fails

693. By Albert Astals Cid

move clear into cleanup

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:686
http://jenkins.qa.ubuntu.com/job/unity8-ci/2249/
Executed test runs:
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/2959
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty-touch/2693
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/1120
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-ci/771
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/773
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/773/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-ci/771
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/2598
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/2961
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/2961/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/2694
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/2694/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/5118
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/3692

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/unity8-ci/2249/rebuild

review: Needs Fixing (continuous-integration)
694. By Albert Astals Cid

The button sizing comes from the parent

Revision history for this message
Michał Sawicz (saviq) wrote :

74 + gradient: UbuntuColors.orangeGradient

No gradient, please - use color: Theme.palette.selected.foreground

=====

76 + width: parent.width

86 + width: parent.width

I'd use anchors, but your call.

=====

129 +/*! This preview widget shows a either one button, two buttons or one button

"shows either"

=====

137 + implicitHeight: row.height
138 + implicitWidth: row.width

Please make it height:, and drop the implicitWidth I think?

=====

158 + item.width = Qt.binding(function() { return (root.width - units.gu(1)) / 2; });

Just make Loader.width ↑, the loaded item will be sized to that.

review: Needs Fixing
695. By Albert Astals Cid

color instead of gradient

696. By Albert Astals Cid

typo--

697. By Albert Astals Cid

better width setting

698. By Albert Astals Cid

more tweaking suggested by saviq

Revision history for this message
Albert Astals Cid (aacid) wrote :

Done everything expect the "width: parent.width" -> anchors thing. If you want that it'll have to wait until tomorrow, i have to run now :D

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:693
http://jenkins.qa.ubuntu.com/job/unity8-ci/2251/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/2966
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty-touch/2700
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/1122
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-ci/773
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/775
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/775/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-ci/773
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/2605
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/2968
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/2968/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/2701
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/2701/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/5124
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/3700

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/unity8-ci/2251/rebuild

review: Approve (continuous-integration)

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'qml/Dash/Previews/PreviewActionButton.qml'
2--- qml/Dash/Previews/PreviewActionButton.qml 1970-01-01 00:00:00 +0000
3+++ qml/Dash/Previews/PreviewActionButton.qml 2014-02-06 17:48:25 +0000
4@@ -0,0 +1,30 @@
5+/*
6+ * Copyright (C) 2014 Canonical, Ltd.
7+ *
8+ * This program is free software; you can redistribute it and/or modify
9+ * it under the terms of the GNU General Public License as published by
10+ * the Free Software Foundation; version 3.
11+ *
12+ * This program is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ * GNU General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU General Public License
18+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19+ */
20+
21+import QtQuick 2.0
22+import Ubuntu.Components 0.1
23+
24+Button {
25+ signal triggeredAction(string id)
26+
27+ property var data: null
28+ objectName: "button" + (data && data.id || "")
29+ color: Theme.palette.selected.foreground
30+ text: data && data.label || ""
31+ iconSource: data && data.icon || ""
32+ iconPosition: "left"
33+ onClicked: triggeredAction(data.id)
34+}
35
36=== added file 'qml/Dash/Previews/PreviewActionCombo.qml'
37--- qml/Dash/Previews/PreviewActionCombo.qml 1970-01-01 00:00:00 +0000
38+++ qml/Dash/Previews/PreviewActionCombo.qml 2014-02-06 17:48:25 +0000
39@@ -0,0 +1,66 @@
40+/*
41+ * Copyright (C) 2014 Canonical, Ltd.
42+ *
43+ * This program is free software; you can redistribute it and/or modify
44+ * it under the terms of the GNU General Public License as published by
45+ * the Free Software Foundation; version 3.
46+ *
47+ * This program is distributed in the hope that it will be useful,
48+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
49+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50+ * GNU General Public License for more details.
51+ *
52+ * You should have received a copy of the GNU General Public License
53+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
54+ */
55+
56+import QtQuick 2.0
57+import Ubuntu.Components 0.1
58+
59+Item {
60+ id: root
61+
62+ implicitHeight: childrenRect.height
63+
64+ signal triggeredAction(string id)
65+
66+ property alias model: actionRepeater.model
67+
68+ Button {
69+ id: moreButton
70+ property bool expanded: false
71+
72+ objectName: "moreLessButton"
73+ text: !expanded ? i18n.tr("More...") : i18n.tr("Less...")
74+ color: Theme.palette.selected.foreground
75+ onClicked: expanded = !expanded
76+ width: parent.width
77+ }
78+
79+ Column {
80+ anchors {
81+ top: moreButton.bottom
82+ topMargin: height > 0 ? spacing : 0
83+ }
84+ objectName: "buttonColumn"
85+ spacing: units.gu(1)
86+ width: parent.width
87+ height: moreButton.expanded ? implicitHeight : 0
88+ clip: true
89+ Behavior on height {
90+ UbuntuNumberAnimation {
91+ duration: UbuntuAnimation.SnapDuration
92+ }
93+ }
94+
95+ Repeater {
96+ id: actionRepeater
97+
98+ delegate: PreviewActionButton {
99+ data: modelData
100+ width: implicitWidth < parent.width ? parent.width : implicitWidth
101+ onClicked: root.triggeredAction(modelData.id)
102+ }
103+ }
104+ }
105+}
106
107=== added file 'qml/Dash/Previews/PreviewActions.qml'
108--- qml/Dash/Previews/PreviewActions.qml 1970-01-01 00:00:00 +0000
109+++ qml/Dash/Previews/PreviewActions.qml 2014-02-06 17:48:25 +0000
110@@ -0,0 +1,64 @@
111+/*
112+ * Copyright (C) 2014 Canonical, Ltd.
113+ *
114+ * This program is free software; you can redistribute it and/or modify
115+ * it under the terms of the GNU General Public License as published by
116+ * the Free Software Foundation; version 3.
117+ *
118+ * This program is distributed in the hope that it will be useful,
119+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
120+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
121+ * GNU General Public License for more details.
122+ *
123+ * You should have received a copy of the GNU General Public License
124+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
125+ */
126+
127+import QtQuick 2.1
128+
129+/*! This preview widget shows either one button, two buttons or one button
130+ * and a combo button depending on the number of items in widgetData["actions"].
131+ * For each of the items we recognize the fields "label", "icon" and "id".
132+ */
133+
134+PreviewWidget {
135+ id: root
136+
137+ height: row.height
138+
139+ Row {
140+ id: row
141+ readonly property var actions: root.widgetData ? root.widgetData["actions"] : null
142+ anchors.right: parent.right
143+
144+ spacing: units.gu(1)
145+
146+ Loader {
147+ id: loader
148+ readonly property bool button: row.actions && row.actions.length == 2
149+ readonly property bool combo: row.actions && row.actions.length > 2
150+ source: button ? "PreviewActionButton.qml" : (combo ? "PreviewActionCombo.qml" : "")
151+ width: (root.width - units.gu(1)) / 2
152+ onLoaded: {
153+ if (button) {
154+ item.data = row.actions[1];
155+ } else if (combo) {
156+ item.model = row.actions.slice(1);
157+ }
158+ }
159+ Connections {
160+ target: loader.item
161+ onTriggeredAction: {
162+ root.triggered(root.widgetId, id, null);
163+ }
164+ }
165+ }
166+
167+ PreviewActionButton {
168+ data: visible ? row.actions[0] : null
169+ visible: row.actions && row.actions.length > 0
170+ onTriggeredAction: root.triggered(root.widgetId, id, null)
171+ width: (root.width - units.gu(1)) / 2
172+ }
173+ }
174+}
175
176=== modified file 'qml/Dash/Previews/PreviewWidget.qml'
177--- qml/Dash/Previews/PreviewWidget.qml 2014-02-06 17:48:24 +0000
178+++ qml/Dash/Previews/PreviewWidget.qml 2014-02-06 17:48:25 +0000
179@@ -22,6 +22,16 @@
180 /// type:bool Specifies the preview widget being currently used or not
181 property bool isCurrentPreview: true
182
183+ //! The widget identifier
184+ property string widgetId
185+
186 /// Variable used to contain widget's data
187 property var widgetData
188+
189+ /*! \brief This signal should be emitted when a preview action was triggered.
190+ *
191+ * \param widgetId,actionId Respective identifiers from widgetData.
192+ * \param data Optional widget-specific data sent to the scope.
193+ */
194+ signal triggered(string widgetId, string actionId, var data)
195 }
196
197=== modified file 'tests/qmltests/CMakeLists.txt'
198--- tests/qmltests/CMakeLists.txt 2014-02-06 17:48:24 +0000
199+++ tests/qmltests/CMakeLists.txt 2014-02-06 17:48:25 +0000
200@@ -55,6 +55,7 @@
201 add_qml_test(Dash/Apps AppPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
202 add_qml_test(Dash/Movie MoviePreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
203 add_qml_test(Dash/Music MusicPreview IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
204+add_qml_test(Dash/Previews PreviewActions IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
205 add_qml_test(Dash/Previews PreviewAudioPlayback IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
206 add_qml_test(Dash/Previews PreviewImageGallery IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
207 add_qml_test(Dash/Previews PreviewTextSummary IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
208
209=== added file 'tests/qmltests/Dash/Previews/tst_PreviewActions.qml'
210--- tests/qmltests/Dash/Previews/tst_PreviewActions.qml 1970-01-01 00:00:00 +0000
211+++ tests/qmltests/Dash/Previews/tst_PreviewActions.qml 2014-02-06 17:48:25 +0000
212@@ -0,0 +1,148 @@
213+/*
214+ * Copyright 2014 Canonical Ltd.
215+ *
216+ * This program is free software; you can redistribute it and/or modify
217+ * it under the terms of the GNU General Public License as published by
218+ * the Free Software Foundation; version 3.
219+ *
220+ * This program is distributed in the hope that it will be useful,
221+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
222+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
223+ * GNU General Public License for more details.
224+ *
225+ * You should have received a copy of the GNU General Public License
226+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
227+ */
228+
229+import QtQuick 2.0
230+import QtTest 1.0
231+import "../../../../qml/Dash/Previews"
232+import Unity.Test 0.1 as UT
233+import Ubuntu.Components 0.1
234+
235+
236+Rectangle {
237+ id: root
238+ width: units.gu(60)
239+ height: units.gu(80)
240+
241+ property var actionDataOneAction: {
242+ "actions": [{"label": "Some Label", "icon": "../graphics/play_button.png", "id": "someid"}]
243+ }
244+
245+ property var actionDataTwoActions: {
246+ "actions": [{"label": "Some Label A", "icon": "../graphics/icon_clear.png", "id": "someid1"},
247+ {"label": "Some Label B", "icon": "../graphics/play_button.png", "id": "someid2"}
248+ ]
249+ }
250+
251+ property var actionDataFiveActions: {
252+ "actions": [{"label": "Some Label C", "icon": "../graphics/play_button.png", "id": "someid3"},
253+ {"label": "Some Label D", "icon": "../graphics/icon_clear.png", "id": "someid4"},
254+ {"label": "Some Label E", "icon": "../graphics/play_button.png", "id": "someid5"},
255+ {"label": "Some Label F", "icon": "../graphics/icon_clear.png", "id": "someid6"},
256+ {"label": "Some Label G", "icon": "../graphics/play_button.png", "id": "someid7"}
257+ ]
258+ }
259+
260+ SignalSpy {
261+ id: spy
262+ signalName: "triggered"
263+ }
264+
265+ Column {
266+ spacing: units.gu(1)
267+
268+ PreviewActions {
269+ id: oneAction
270+ widgetId: "button"
271+ widgetData: actionDataOneAction
272+ onTriggered: console.log("triggered", widgetId, actionId);
273+ width: units.gu(50)
274+
275+ Rectangle {
276+ anchors.fill: parent
277+ color: "red"
278+ opacity: 0.1
279+ }
280+ }
281+
282+ PreviewActions {
283+ id: buttonAndCombo
284+ widgetId: "buttonAndCombo"
285+ widgetData: actionDataFiveActions
286+ onTriggered: console.log("triggered", widgetId, actionId);
287+ width: units.gu(40)
288+
289+ Rectangle {
290+ anchors.fill: parent
291+ color: "red"
292+ opacity: 0.1
293+ }
294+ }
295+
296+ PreviewActions {
297+ id: twoActions
298+ widgetId: "2buttons"
299+ widgetData: actionDataTwoActions
300+ onTriggered: console.log("triggered", widgetId, actionId);
301+ width: units.gu(60)
302+ }
303+ }
304+
305+ UT.UnityTestCase {
306+ name: "PreviewActionTest"
307+ when: windowShown
308+
309+ function cleanup()
310+ {
311+ spy.clear();
312+ }
313+
314+ function checkButtonPressSignal(target, id)
315+ {
316+ var button = findChild(root, "button" + id);
317+ verify(button != null);
318+ spy.target = target;
319+ mouseClick(button, button.width / 2, button.height / 2);
320+ compare(spy.count, 1);
321+ compare(spy.signalArguments[0][0], target.widgetId);
322+ compare(spy.signalArguments[0][1], id);
323+ }
324+
325+ function test_checkButtons_data() {
326+ return [
327+ {tag: "oneActionButton", target: oneAction, id: "someid" },
328+ {tag: "twobuttonsButton0", target: twoActions, id: "someid1" },
329+ {tag: "twobuttonsButton1", target: twoActions, id: "someid2" },
330+ {tag: "buttonAndComboButton0", target: buttonAndCombo, id: "someid3" }
331+ ]
332+ }
333+
334+ function test_checkButtons(data) {
335+ checkButtonPressSignal(data.target, data.id, data.buttonNumber)
336+ }
337+
338+ function test_comboButton_data() {
339+ return [
340+ {tag: "button1", id: "someid4" },
341+ {tag: "button2", id: "someid5" },
342+ {tag: "button3", id: "someid6" },
343+ {tag: "button4", id: "someid7" }
344+ ]
345+ }
346+
347+ function test_comboButton(data) {
348+ var button = findChild(root, "moreLessButton");
349+ var buttonColumn = findChild(root, "buttonColumn");
350+ verify(button != null);
351+ var twoActionsY = twoActions.y
352+ mouseClick(button, button.width / 2, button.height / 2);
353+ tryCompareFunction(function () { return twoActions.y <= twoActionsY; }, false);
354+ tryCompare(buttonColumn, "height", buttonColumn.implicitHeight);
355+ checkButtonPressSignal(buttonAndCombo, data.id, data.buttonNumber);
356+ mouseClick(button, button.width / 2, button.height / 2);
357+ tryCompare(twoActions, "y", twoActionsY);
358+ }
359+ }
360+}

Subscribers

People subscribed via source and target branches