Merge lp:~unity-team/unity8/previewcommentinput into lp:unity8

Proposed by Andrea Cimitan on 2015-06-25
Status: Merged
Approved by: Albert Astals Cid on 2015-07-06
Approved revision: 1803
Merged at revision: 1865
Proposed branch: lp:~unity-team/unity8/previewcommentinput
Merge into: lp:unity8
Diff against target: 196 lines (+154/-0)
5 files modified
qml/Dash/Previews/PreviewCommentInput.qml (+66/-0)
qml/Dash/Previews/PreviewWidgetFactory.qml (+1/-0)
tests/qmltests/CMakeLists.txt (+1/-0)
tests/qmltests/Dash/Previews/tst_PreviewCommentInput.qml (+85/-0)
tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml (+1/-0)
To merge this branch: bzr merge lp:~unity-team/unity8/previewcommentinput
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration 2015-06-25 Needs Fixing on 2015-07-15
Albert Astals Cid (community) Approve on 2015-07-06
Andrea Cimitan Pending
Review via email: mp+262959@code.launchpad.net

This proposal supersedes a proposal from 2015-06-01.

Commit Message

Implements a comment input widget

Description of the Change

 * Are there any related MPs required for this MP to build/function as expected? Please list.

no

 * Did you perform an exploratory manual test run of your code change and any related functionality?

yes

 * Did you make sure that your branch does not contain spurious tags?

yes

 * 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?

added a new component as per visual spec.

 * Did you have a look at the warnings when running tests? Can they be reduced?

yes. only the old Theme.palette thing.

To post a comment you must log in.
Andrea Cimitan (cimi) : Posted in a previous version of this proposal
review: Needs Fixing
Michael Zanetti (mzanetti) wrote : Posted in a previous version of this proposal

Addressed all comments. Thanks.

Lukáš Tinkl (lukas-kde) wrote : Posted in a previous version of this proposal

Minor optimizations/coding style issues, see inline comments

Michael Zanetti (mzanetti) wrote : Posted in a previous version of this proposal

> Minor optimizations/coding style issues, see inline comments

fixed.

Andrea Cimitan (cimi) wrote : Posted in a previous version of this proposal

Add this file to the test in previewwidgetfactory

review: Needs Fixing
Michael Zanetti (mzanetti) wrote : Posted in a previous version of this proposal

> Add this file to the test in previewwidgetfactory

done

Albert Astals Cid (aacid) wrote : Posted in a previous version of this proposal

Text conflict in tests/qmltests/CMakeLists.txt
1 conflicts encountered.

Michael Zanetti (mzanetti) wrote : Posted in a previous version of this proposal

> Text conflict in tests/qmltests/CMakeLists.txt
> 1 conflicts encountered.

merged

Andrea Cimitan (cimi) wrote :

Moved from TextField to TextArea

Albert Astals Cid (aacid) wrote :

AFAICS we don't need the emitted field in the test_submit_data dictionary?

review: Needs Fixing
Albert Astals Cid (aacid) wrote :

We don't seem to need
    property real validInputRating: 1
    property real invalidInputRating: -1
either

review: Needs Fixing
Albert Astals Cid (aacid) wrote :

Can you please make test_submit actually check that the successeful submit emits triggered(widgetId, "commented", data), with data being {"comment": comment}?

review: Needs Fixing
Albert Astals Cid (aacid) wrote :

property alias commentText: commentTextArea.text
do we actually need/use this alias for anything? Maybe we can remove it?

review: Needs Information
Albert Astals Cid (aacid) wrote :

   implicitHeight: commentSubmitContainer.implicitHeight + anchors.topMargin
looks a bit weird given we don't specify any topMargin at all so i guess we should either remove anchors.topMargin from the equation or add anchors.bottomMargin ?

review: Needs Fixing
Albert Astals Cid (aacid) wrote :

Not asking you to change it but having "commentContainer" as a sole child of "root" makes me feel as if we could just kill it and move things up. Same for "commentSubmitContainer". This way we'd save a few binding evaluations and the code would be probably more flat/easy to understand. Any particular reason the code is like that?

review: Needs Information
1802. By Andrea Cimitan on 2015-07-06

Fixes as review

1803. By Andrea Cimitan on 2015-07-06

As albert suggests

Albert Astals Cid (aacid) wrote :

 * Did you perform an exploratory manual test run of the code change and any related functionality?
Yes

 * Did CI run pass?
Unrelated reasons

 * Did you make sure that the branch does not contain spurious tags?
Aye

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'qml/Dash/Previews/PreviewCommentInput.qml'
2--- qml/Dash/Previews/PreviewCommentInput.qml 1970-01-01 00:00:00 +0000
3+++ qml/Dash/Previews/PreviewCommentInput.qml 2015-07-06 13:14:55 +0000
4@@ -0,0 +1,66 @@
5+/*
6+ * Copyright (C) 2015 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 1.1
23+import "../../Components"
24+
25+/*! \brief Preview widget for commenting.
26+
27+ The widget can show a field to enter a comment.
28+ It is possible to customise the submit button's label by setting widgetData["submit-label"]
29+ The successeful submit emits triggered(widgetId, "commented", data),
30+ with data being {"comment": comment}.
31+*/
32+
33+PreviewWidget {
34+ id: root
35+ implicitHeight: Math.max(commentTextArea.implicitHeight, submitButton.implicitHeight)
36+
37+ function submit() {
38+ var data = { "comment": commentTextArea.text };
39+ triggered(root.widgetId, "commented", data);
40+ }
41+
42+ TextArea {
43+ id: commentTextArea
44+ objectName: "commentTextArea"
45+ anchors {
46+ top: parent.top
47+ left: parent.left
48+ right: submitButton.left
49+ rightMargin: units.gu(1)
50+ }
51+ autoSize: true
52+ }
53+
54+ Button {
55+ id: submitButton
56+ objectName: "submitButton"
57+
58+ readonly property bool readyToSubmit: commentTextArea.text.trim().length > 0
59+
60+ anchors {
61+ top: parent.top
62+ right: parent.right
63+ }
64+ color: readyToSubmit ? Theme.palette.selected.base : Theme.palette.normal.base
65+ text: widgetData["submit-label"] || i18n.tr("Send")
66+ onClicked: {
67+ if (readyToSubmit) root.submit()
68+ }
69+ }
70+}
71
72=== modified file 'qml/Dash/Previews/PreviewWidgetFactory.qml'
73--- qml/Dash/Previews/PreviewWidgetFactory.qml 2015-05-08 13:12:02 +0000
74+++ qml/Dash/Previews/PreviewWidgetFactory.qml 2015-07-06 13:14:55 +0000
75@@ -62,6 +62,7 @@
76 case "table": return "PreviewTable.qml";
77 case "text": return "PreviewTextSummary.qml";
78 case "video": return "PreviewVideoPlayback.qml";
79+ case "comment-input": return "PreviewCommentInput.qml";
80 default: return "";
81 }
82 }
83
84=== modified file 'tests/qmltests/CMakeLists.txt'
85--- tests/qmltests/CMakeLists.txt 2015-06-18 19:23:08 +0000
86+++ tests/qmltests/CMakeLists.txt 2015-07-06 13:14:55 +0000
87@@ -27,6 +27,7 @@
88 add_unity8_qmltest(Dash/Previews Preview)
89 add_unity8_qmltest(Dash/Previews PreviewActions)
90 add_unity8_qmltest(Dash/Previews PreviewAudioPlayback)
91+add_unity8_qmltest(Dash/Previews PreviewCommentInput)
92 add_unity8_qmltest(Dash/Previews PreviewExpandable)
93 add_unity8_qmltest(Dash/Previews PreviewHeader)
94 add_unity8_qmltest(Dash/Previews PreviewImageGallery)
95
96=== added file 'tests/qmltests/Dash/Previews/tst_PreviewCommentInput.qml'
97--- tests/qmltests/Dash/Previews/tst_PreviewCommentInput.qml 1970-01-01 00:00:00 +0000
98+++ tests/qmltests/Dash/Previews/tst_PreviewCommentInput.qml 2015-07-06 13:14:55 +0000
99@@ -0,0 +1,85 @@
100+/*
101+ * Copyright 2015 Canonical Ltd.
102+ *
103+ * This program is free software; you can redistribute it and/or modify
104+ * it under the terms of the GNU General Public License as published by
105+ * the Free Software Foundation; version 3.
106+ *
107+ * This program is distributed in the hope that it will be useful,
108+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
109+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
110+ * GNU General Public License for more details.
111+ *
112+ * You should have received a copy of the GNU General Public License
113+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
114+ */
115+
116+import QtQuick 2.0
117+import QtTest 1.0
118+import Ubuntu.Components 1.1
119+import "../../../../qml/Dash/Previews"
120+import Unity.Test 0.1 as UT
121+
122+Rectangle {
123+ id: root
124+ width: units.gu(40)
125+ height: units.gu(80)
126+ color: Theme.palette.selected.background
127+
128+ property string validInputText: "Great!"
129+ property string invalidInputText: ""
130+
131+ property var widgetDataNewLabels: { "submit-label": "TestSubmitLabel" }
132+
133+ PreviewCommentInput {
134+ id: previewCommentInput
135+ anchors.left: parent.left
136+ anchors.right: parent.right
137+ widgetData: widgetDataNewLabels
138+ widgetId: "previewCommentInput"
139+ }
140+
141+ SignalSpy {
142+ id: spy
143+ signalName: "triggered"
144+ }
145+
146+ UT.UnityTestCase {
147+ name: "PreviewCommentInputTest"
148+ when: windowShown
149+
150+ property var commentTextArea: findChild(previewCommentInput, "commentTextArea")
151+ property var submitButton: findChild(previewCommentInput, "submitButton")
152+
153+ function init() {
154+ commentTextArea.text = "";
155+ }
156+
157+ function test_labels() {
158+ previewCommentInput.widgetData = widgetDataNewLabels;
159+ compare(submitButton.text, widgetDataNewLabels["submit-label"]);
160+ }
161+
162+ function test_submit_data() {
163+ return [
164+ {tag: "empty review", inputText: invalidInputText, emitted: false},
165+ {tag: "filled review", inputText: validInputText, emitted: true},
166+ ];
167+ }
168+
169+ function test_submit(data) {
170+ spy.clear();
171+ spy.target = previewCommentInput;
172+
173+ commentTextArea.text = data.inputText;
174+ mouseClick(submitButton);
175+ if (!data.emitted) {
176+ compare(spy.count, 0);
177+ } else {
178+ compare(spy.count, 1);
179+ var args = spy.signalArguments[0];
180+ compare(args[2]["comment"], data.inputText);
181+ }
182+ }
183+ }
184+}
185
186=== modified file 'tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml'
187--- tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml 2014-08-26 19:21:31 +0000
188+++ tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml 2015-07-06 13:14:55 +0000
189@@ -77,6 +77,7 @@
190 return [
191 { tag: "Actions", type: "actions", source: "PreviewActions.qml" },
192 { tag: "Audio", type: "audio", source: "PreviewAudioPlayback.qml" },
193+ { tag: "Comment Input", type: "comment-input", source: "PreviewCommentInput.qml" },
194 { tag: "Expandable", type: "expandable", source: "PreviewExpandable.qml" },
195 { tag: "Gallery", type: "gallery", source: "PreviewImageGallery.qml" },
196 { tag: "Header", type: "header", source: "PreviewHeader.qml" },

Subscribers

People subscribed via source and target branches