Merge lp:~alecu/unity-scope-click/preview-fixes into lp:unity-scope-click/devel

Proposed by Alejandro J. Cura
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 354
Merged at revision: 354
Proposed branch: lp:~alecu/unity-scope-click/preview-fixes
Merge into: lp:unity-scope-click/devel
Diff against target: 264 lines (+158/-11)
4 files modified
libclickscope/click/preview.cpp (+20/-11)
libclickscope/click/preview.h (+6/-0)
libclickscope/tests/CMakeLists.txt (+1/-0)
libclickscope/tests/test_preview.cpp (+131/-0)
To merge this branch: bzr merge lp:~alecu/unity-scope-click/preview-fixes
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Paweł Stołowski (community) Approve
dobey (community) Approve
Review via email: mp+227730@code.launchpad.net

Commit message

Change the order of screenshot and header widgets; initial tests for previews

To post a comment you must log in.
353. By Alejandro J. Cura

A comment about PreviewReply being hard to use in tests

Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Paweł Stołowski (stolowski) wrote :

233 +class FakePreviewReply : public scopes::PreviewReply
234 +{
235 +public:
236 + // TODO: make PreviewReply more easily mockable in scopes-api

Scopes API has MockPreviewReply in the testing namespace, is there any issue with it? (if so, please open a bug against scopes api). I think it does exactly what you need and implement with with this FakePreviewReplyClass.

review: Needs Fixing
354. By Alejandro J. Cura

Use MockPreviewReply instead

Revision history for this message
Paweł Stołowski (stolowski) wrote :

Looks good and works fine. +1

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libclickscope/click/preview.cpp'
2--- libclickscope/click/preview.cpp 2014-07-16 21:49:11 +0000
3+++ libclickscope/click/preview.cpp 2014-07-22 16:06:10 +0000
4@@ -177,6 +177,16 @@
5 {
6 }
7
8+void PreviewStrategy::pushPackagePreviewWidgets(const unity::scopes::PreviewReplyProxy &reply,
9+ const PackageDetails &details,
10+ const scopes::PreviewWidgetList& button_area_widgets)
11+{
12+ reply->push(headerWidgets(details));
13+ reply->push(button_area_widgets);
14+ reply->push(screenshotsWidgets(details));
15+ reply->push(descriptionWidgets(details));
16+}
17+
18 PreviewStrategy::~PreviewStrategy()
19 {
20 }
21@@ -235,10 +245,9 @@
22 }
23 }
24
25-scopes::PreviewWidgetList PreviewStrategy::headerWidgets(const click::PackageDetails& details)
26+scopes::PreviewWidgetList PreviewStrategy::screenshotsWidgets(const click::PackageDetails& details)
27 {
28 scopes::PreviewWidgetList widgets;
29-
30 bool has_screenshots = !details.main_screenshot_url.empty() || !details.more_screenshots_urls.empty();
31
32 if (has_screenshots)
33@@ -259,6 +268,12 @@
34 gallery.add_attribute_value("sources", scopes::Variant(arr));
35 widgets.push_back(gallery);
36 }
37+ return widgets;
38+}
39+
40+scopes::PreviewWidgetList PreviewStrategy::headerWidgets(const click::PackageDetails& details)
41+{
42+ scopes::PreviewWidgetList widgets;
43
44 scopes::PreviewWidget header("hdr", "header");
45 header.add_attribute_value("title", scopes::Variant(details.package.title));
46@@ -423,9 +438,7 @@
47 qDebug() << "Successfully created UDM Download.";
48 populateDetails([this, reply, object_path](const PackageDetails &details) {
49 store_department(details);
50- reply->push(headerWidgets(details));
51- reply->push(progressBarWidget(object_path));
52- reply->push(descriptionWidgets(details));
53+ pushPackagePreviewWidgets(reply, details, progressBarWidget(object_path));
54 startLauncherAnimation(details);
55 },
56 [this, reply](const ReviewList& reviewlist,
57@@ -526,9 +539,7 @@
58 getApplicationUri(manifest, [this, reply, manifest, app_name, &review](const std::string& uri) {
59 populateDetails([this, reply, uri, manifest, app_name, &review](const PackageDetails &details){
60 store_department(details);
61- reply->push(headerWidgets(details));
62- reply->push(createButtons(uri, manifest));
63- reply->push(descriptionWidgets(details));
64+ pushPackagePreviewWidgets(reply, details, createButtons(uri, manifest));
65
66 if (review.rating == 0 && manifest.removable) {
67 scopes::PreviewWidgetList review_input;
68@@ -743,9 +754,7 @@
69
70 populateDetails([this, reply](const PackageDetails &details){
71 store_department(details);
72- reply->push(headerWidgets(details));
73- reply->push(uninstalledActionButtonWidgets(details));
74- reply->push(descriptionWidgets(details));
75+ pushPackagePreviewWidgets(reply, details, uninstalledActionButtonWidgets(details));
76 },
77 [this, reply](const ReviewList& reviewlist,
78 click::Reviews::Error error) {
79
80=== modified file 'libclickscope/click/preview.h'
81--- libclickscope/click/preview.h 2014-07-14 15:35:10 +0000
82+++ libclickscope/click/preview.h 2014-07-22 16:06:10 +0000
83@@ -54,6 +54,7 @@
84 class DepartmentUpdater
85 {
86 protected:
87+ DepartmentUpdater() = default;
88 DepartmentUpdater(const std::shared_ptr<click::DepartmentsDb>& depts);
89 virtual ~DepartmentUpdater() = default;
90 void store_department(const PackageDetails& pkg);
91@@ -120,6 +121,7 @@
92 std::function<void(const click::ReviewList&,
93 click::Reviews::Error)> reviews_callback);
94 virtual scopes::PreviewWidgetList headerWidgets(const PackageDetails &details);
95+ virtual scopes::PreviewWidgetList screenshotsWidgets(const PackageDetails &details);
96 virtual scopes::PreviewWidgetList descriptionWidgets(const PackageDetails &details);
97 virtual scopes::PreviewWidgetList reviewsWidgets(const click::ReviewList &reviewlist);
98 virtual scopes::PreviewWidgetList downloadErrorWidgets();
99@@ -129,6 +131,9 @@
100 const scopes::Variant& action_id,
101 const scopes::Variant& action_label,
102 const scopes::Variant& action_uri = scopes::Variant::null());
103+ virtual void pushPackagePreviewWidgets(const unity::scopes::PreviewReplyProxy &reply,
104+ const PackageDetails& details,
105+ const scopes::PreviewWidgetList& button_area_widgets);
106 scopes::Result result;
107 QSharedPointer<click::web::Client> client;
108 QSharedPointer<click::Index> index;
109@@ -151,6 +156,7 @@
110 class InstallingPreview : public PreviewStrategy, public DepartmentUpdater
111 {
112 public:
113+ InstallingPreview(const unity::scopes::Result& result) : PreviewStrategy(result) {}
114 InstallingPreview(std::string const& download_url,
115 const unity::scopes::Result& result,
116 const QSharedPointer<click::web::Client>& client,
117
118=== modified file 'libclickscope/tests/CMakeLists.txt'
119--- libclickscope/tests/CMakeLists.txt 2014-07-14 08:49:19 +0000
120+++ libclickscope/tests/CMakeLists.txt 2014-07-22 16:06:10 +0000
121@@ -30,6 +30,7 @@
122 test_index.cpp
123 test_interface.cpp
124 test_package.cpp
125+ test_preview.cpp
126 test_reviews.cpp
127 test_smartconnect.cpp
128 test_webclient.cpp
129
130=== added file 'libclickscope/tests/test_preview.cpp'
131--- libclickscope/tests/test_preview.cpp 1970-01-01 00:00:00 +0000
132+++ libclickscope/tests/test_preview.cpp 2014-07-22 16:06:10 +0000
133@@ -0,0 +1,131 @@
134+/*
135+ * Copyright (C) 2014 Canonical Ltd.
136+ *
137+ * This program is free software: you can redistribute it and/or modify it
138+ * under the terms of the GNU General Public License version 3, as published
139+ * by the Free Software Foundation.
140+ *
141+ * This program is distributed in the hope that it will be useful, but
142+ * WITHOUT ANY WARRANTY; without even the implied warranties of
143+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
144+ * PURPOSE. See the GNU General Public License for more details.
145+ *
146+ * You should have received a copy of the GNU General Public License along
147+ * with this program. If not, see <http://www.gnu.org/licenses/>.
148+ *
149+ * In addition, as a special exception, the copyright holders give
150+ * permission to link the code of portions of this program with the
151+ * OpenSSL library under certain conditions as described in each
152+ * individual source file, and distribute linked combinations
153+ * including the two.
154+ * You must obey the GNU General Public License in all respects
155+ * for all of the code used other than OpenSSL. If you modify
156+ * file(s) with this exception, you may extend this exception to your
157+ * version of the file(s), but you are not obligated to do so. If you
158+ * do not wish to do so, delete this exception statement from your
159+ * version. If you delete this exception statement from all source
160+ * files in the program, then also delete it here.
161+ */
162+
163+#include <unity/scopes/testing/MockPreviewReply.h>
164+
165+#include <gtest/gtest.h>
166+#include <click/preview.h>
167+
168+using namespace ::testing;
169+using namespace unity::scopes;
170+
171+class FakeResult : public Result
172+{
173+public:
174+ FakeResult(VariantMap& vm) : Result(vm)
175+ {
176+ }
177+
178+};
179+
180+class FakePreview : public click::PreviewStrategy
181+{
182+public:
183+ FakePreview(Result& result) : click::PreviewStrategy::PreviewStrategy(result)
184+ {
185+
186+ }
187+
188+ void run(const PreviewReplyProxy &/*reply*/)
189+ {
190+
191+ }
192+ using click::PreviewStrategy::screenshotsWidgets;
193+};
194+
195+class PreviewsBaseTest : public Test
196+{
197+public:
198+ VariantMap vm;
199+ VariantMap internal;
200+ VariantMap attrs;
201+
202+ PreviewsBaseTest()
203+ {
204+ attrs["uri"] = "fake://result";
205+ vm["internal"] = internal;
206+ vm["attrs"] = attrs;
207+ }
208+};
209+
210+class PreviewStrategyTest : public PreviewsBaseTest
211+{
212+
213+};
214+
215+TEST_F(PreviewStrategyTest, testScreenshotsWidget)
216+{
217+ FakeResult result{vm};
218+ FakePreview preview{result};
219+ click::PackageDetails details;
220+ details.main_screenshot_url = "sshot1";
221+ details.more_screenshots_urls = {"sshot2", "sshot3"};
222+
223+ auto widgets = preview.screenshotsWidgets(details);
224+ ASSERT_EQ(widgets.size(), 1);
225+ auto first_widget = widgets.front();
226+ auto attributes = first_widget.attribute_values();
227+ auto sources = attributes["sources"].get_array();
228+ ASSERT_EQ(sources[0].get_string(), "sshot1");
229+ ASSERT_EQ(sources[1].get_string(), "sshot2");
230+ ASSERT_EQ(sources[2].get_string(), "sshot3");
231+}
232+
233+class FakePreviewStrategy : public click::PreviewStrategy
234+{
235+public:
236+ FakePreviewStrategy(const unity::scopes::Result& result) : PreviewStrategy(result) {}
237+ using click::PreviewStrategy::pushPackagePreviewWidgets;
238+ std::vector<std::string> call_order;
239+ virtual void run(unity::scopes::PreviewReplyProxy const& /*reply*/)
240+ {
241+ }
242+
243+ virtual unity::scopes::PreviewWidgetList screenshotsWidgets (const click::PackageDetails &/*details*/) {
244+ call_order.push_back("screenshots");
245+ return {};
246+ }
247+ virtual unity::scopes::PreviewWidgetList headerWidgets (const click::PackageDetails &/*details*/) {
248+ call_order.push_back("header");
249+ return {};
250+ }
251+};
252+
253+TEST_F(PreviewStrategyTest, testScreenshotsPushedAfterHeader)
254+{
255+ FakeResult result{vm};
256+ unity::scopes::testing::MockPreviewReply reply;
257+ std::shared_ptr<unity::scopes::testing::MockPreviewReply> replyptr{&reply, [](unity::scopes::testing::MockPreviewReply*){}};
258+ click::PackageDetails details;
259+
260+ FakePreviewStrategy preview{result};
261+ preview.pushPackagePreviewWidgets(replyptr, details, {});
262+ std::vector<std::string> expected_order {"header", "screenshots"};
263+ ASSERT_EQ(expected_order, preview.call_order);
264+}

Subscribers

People subscribed via source and target branches

to all changes: