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
=== modified file 'libclickscope/click/preview.cpp'
--- libclickscope/click/preview.cpp 2014-07-16 21:49:11 +0000
+++ libclickscope/click/preview.cpp 2014-07-22 16:06:10 +0000
@@ -177,6 +177,16 @@
177{177{
178}178}
179179
180void PreviewStrategy::pushPackagePreviewWidgets(const unity::scopes::PreviewReplyProxy &reply,
181 const PackageDetails &details,
182 const scopes::PreviewWidgetList& button_area_widgets)
183{
184 reply->push(headerWidgets(details));
185 reply->push(button_area_widgets);
186 reply->push(screenshotsWidgets(details));
187 reply->push(descriptionWidgets(details));
188}
189
180PreviewStrategy::~PreviewStrategy()190PreviewStrategy::~PreviewStrategy()
181{191{
182}192}
@@ -235,10 +245,9 @@
235 }245 }
236}246}
237247
238scopes::PreviewWidgetList PreviewStrategy::headerWidgets(const click::PackageDetails& details)248scopes::PreviewWidgetList PreviewStrategy::screenshotsWidgets(const click::PackageDetails& details)
239{249{
240 scopes::PreviewWidgetList widgets;250 scopes::PreviewWidgetList widgets;
241
242 bool has_screenshots = !details.main_screenshot_url.empty() || !details.more_screenshots_urls.empty();251 bool has_screenshots = !details.main_screenshot_url.empty() || !details.more_screenshots_urls.empty();
243252
244 if (has_screenshots)253 if (has_screenshots)
@@ -259,6 +268,12 @@
259 gallery.add_attribute_value("sources", scopes::Variant(arr));268 gallery.add_attribute_value("sources", scopes::Variant(arr));
260 widgets.push_back(gallery);269 widgets.push_back(gallery);
261 }270 }
271 return widgets;
272}
273
274scopes::PreviewWidgetList PreviewStrategy::headerWidgets(const click::PackageDetails& details)
275{
276 scopes::PreviewWidgetList widgets;
262277
263 scopes::PreviewWidget header("hdr", "header");278 scopes::PreviewWidget header("hdr", "header");
264 header.add_attribute_value("title", scopes::Variant(details.package.title));279 header.add_attribute_value("title", scopes::Variant(details.package.title));
@@ -423,9 +438,7 @@
423 qDebug() << "Successfully created UDM Download.";438 qDebug() << "Successfully created UDM Download.";
424 populateDetails([this, reply, object_path](const PackageDetails &details) {439 populateDetails([this, reply, object_path](const PackageDetails &details) {
425 store_department(details);440 store_department(details);
426 reply->push(headerWidgets(details));441 pushPackagePreviewWidgets(reply, details, progressBarWidget(object_path));
427 reply->push(progressBarWidget(object_path));
428 reply->push(descriptionWidgets(details));
429 startLauncherAnimation(details);442 startLauncherAnimation(details);
430 },443 },
431 [this, reply](const ReviewList& reviewlist,444 [this, reply](const ReviewList& reviewlist,
@@ -526,9 +539,7 @@
526 getApplicationUri(manifest, [this, reply, manifest, app_name, &review](const std::string& uri) {539 getApplicationUri(manifest, [this, reply, manifest, app_name, &review](const std::string& uri) {
527 populateDetails([this, reply, uri, manifest, app_name, &review](const PackageDetails &details){540 populateDetails([this, reply, uri, manifest, app_name, &review](const PackageDetails &details){
528 store_department(details);541 store_department(details);
529 reply->push(headerWidgets(details));542 pushPackagePreviewWidgets(reply, details, createButtons(uri, manifest));
530 reply->push(createButtons(uri, manifest));
531 reply->push(descriptionWidgets(details));
532543
533 if (review.rating == 0 && manifest.removable) {544 if (review.rating == 0 && manifest.removable) {
534 scopes::PreviewWidgetList review_input;545 scopes::PreviewWidgetList review_input;
@@ -743,9 +754,7 @@
743754
744 populateDetails([this, reply](const PackageDetails &details){755 populateDetails([this, reply](const PackageDetails &details){
745 store_department(details);756 store_department(details);
746 reply->push(headerWidgets(details));757 pushPackagePreviewWidgets(reply, details, uninstalledActionButtonWidgets(details));
747 reply->push(uninstalledActionButtonWidgets(details));
748 reply->push(descriptionWidgets(details));
749 },758 },
750 [this, reply](const ReviewList& reviewlist,759 [this, reply](const ReviewList& reviewlist,
751 click::Reviews::Error error) {760 click::Reviews::Error error) {
752761
=== modified file 'libclickscope/click/preview.h'
--- libclickscope/click/preview.h 2014-07-14 15:35:10 +0000
+++ libclickscope/click/preview.h 2014-07-22 16:06:10 +0000
@@ -54,6 +54,7 @@
54class DepartmentUpdater54class DepartmentUpdater
55{55{
56protected:56protected:
57 DepartmentUpdater() = default;
57 DepartmentUpdater(const std::shared_ptr<click::DepartmentsDb>& depts);58 DepartmentUpdater(const std::shared_ptr<click::DepartmentsDb>& depts);
58 virtual ~DepartmentUpdater() = default;59 virtual ~DepartmentUpdater() = default;
59 void store_department(const PackageDetails& pkg);60 void store_department(const PackageDetails& pkg);
@@ -120,6 +121,7 @@
120 std::function<void(const click::ReviewList&,121 std::function<void(const click::ReviewList&,
121 click::Reviews::Error)> reviews_callback);122 click::Reviews::Error)> reviews_callback);
122 virtual scopes::PreviewWidgetList headerWidgets(const PackageDetails &details);123 virtual scopes::PreviewWidgetList headerWidgets(const PackageDetails &details);
124 virtual scopes::PreviewWidgetList screenshotsWidgets(const PackageDetails &details);
123 virtual scopes::PreviewWidgetList descriptionWidgets(const PackageDetails &details);125 virtual scopes::PreviewWidgetList descriptionWidgets(const PackageDetails &details);
124 virtual scopes::PreviewWidgetList reviewsWidgets(const click::ReviewList &reviewlist);126 virtual scopes::PreviewWidgetList reviewsWidgets(const click::ReviewList &reviewlist);
125 virtual scopes::PreviewWidgetList downloadErrorWidgets();127 virtual scopes::PreviewWidgetList downloadErrorWidgets();
@@ -129,6 +131,9 @@
129 const scopes::Variant& action_id,131 const scopes::Variant& action_id,
130 const scopes::Variant& action_label,132 const scopes::Variant& action_label,
131 const scopes::Variant& action_uri = scopes::Variant::null());133 const scopes::Variant& action_uri = scopes::Variant::null());
134 virtual void pushPackagePreviewWidgets(const unity::scopes::PreviewReplyProxy &reply,
135 const PackageDetails& details,
136 const scopes::PreviewWidgetList& button_area_widgets);
132 scopes::Result result;137 scopes::Result result;
133 QSharedPointer<click::web::Client> client;138 QSharedPointer<click::web::Client> client;
134 QSharedPointer<click::Index> index;139 QSharedPointer<click::Index> index;
@@ -151,6 +156,7 @@
151class InstallingPreview : public PreviewStrategy, public DepartmentUpdater156class InstallingPreview : public PreviewStrategy, public DepartmentUpdater
152{157{
153public:158public:
159 InstallingPreview(const unity::scopes::Result& result) : PreviewStrategy(result) {}
154 InstallingPreview(std::string const& download_url,160 InstallingPreview(std::string const& download_url,
155 const unity::scopes::Result& result,161 const unity::scopes::Result& result,
156 const QSharedPointer<click::web::Client>& client,162 const QSharedPointer<click::web::Client>& client,
157163
=== modified file 'libclickscope/tests/CMakeLists.txt'
--- libclickscope/tests/CMakeLists.txt 2014-07-14 08:49:19 +0000
+++ libclickscope/tests/CMakeLists.txt 2014-07-22 16:06:10 +0000
@@ -30,6 +30,7 @@
30 test_index.cpp30 test_index.cpp
31 test_interface.cpp31 test_interface.cpp
32 test_package.cpp32 test_package.cpp
33 test_preview.cpp
33 test_reviews.cpp34 test_reviews.cpp
34 test_smartconnect.cpp35 test_smartconnect.cpp
35 test_webclient.cpp36 test_webclient.cpp
3637
=== added file 'libclickscope/tests/test_preview.cpp'
--- libclickscope/tests/test_preview.cpp 1970-01-01 00:00:00 +0000
+++ libclickscope/tests/test_preview.cpp 2014-07-22 16:06:10 +0000
@@ -0,0 +1,131 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * In addition, as a special exception, the copyright holders give
17 * permission to link the code of portions of this program with the
18 * OpenSSL library under certain conditions as described in each
19 * individual source file, and distribute linked combinations
20 * including the two.
21 * You must obey the GNU General Public License in all respects
22 * for all of the code used other than OpenSSL. If you modify
23 * file(s) with this exception, you may extend this exception to your
24 * version of the file(s), but you are not obligated to do so. If you
25 * do not wish to do so, delete this exception statement from your
26 * version. If you delete this exception statement from all source
27 * files in the program, then also delete it here.
28 */
29
30#include <unity/scopes/testing/MockPreviewReply.h>
31
32#include <gtest/gtest.h>
33#include <click/preview.h>
34
35using namespace ::testing;
36using namespace unity::scopes;
37
38class FakeResult : public Result
39{
40public:
41 FakeResult(VariantMap& vm) : Result(vm)
42 {
43 }
44
45};
46
47class FakePreview : public click::PreviewStrategy
48{
49public:
50 FakePreview(Result& result) : click::PreviewStrategy::PreviewStrategy(result)
51 {
52
53 }
54
55 void run(const PreviewReplyProxy &/*reply*/)
56 {
57
58 }
59 using click::PreviewStrategy::screenshotsWidgets;
60};
61
62class PreviewsBaseTest : public Test
63{
64public:
65 VariantMap vm;
66 VariantMap internal;
67 VariantMap attrs;
68
69 PreviewsBaseTest()
70 {
71 attrs["uri"] = "fake://result";
72 vm["internal"] = internal;
73 vm["attrs"] = attrs;
74 }
75};
76
77class PreviewStrategyTest : public PreviewsBaseTest
78{
79
80};
81
82TEST_F(PreviewStrategyTest, testScreenshotsWidget)
83{
84 FakeResult result{vm};
85 FakePreview preview{result};
86 click::PackageDetails details;
87 details.main_screenshot_url = "sshot1";
88 details.more_screenshots_urls = {"sshot2", "sshot3"};
89
90 auto widgets = preview.screenshotsWidgets(details);
91 ASSERT_EQ(widgets.size(), 1);
92 auto first_widget = widgets.front();
93 auto attributes = first_widget.attribute_values();
94 auto sources = attributes["sources"].get_array();
95 ASSERT_EQ(sources[0].get_string(), "sshot1");
96 ASSERT_EQ(sources[1].get_string(), "sshot2");
97 ASSERT_EQ(sources[2].get_string(), "sshot3");
98}
99
100class FakePreviewStrategy : public click::PreviewStrategy
101{
102public:
103 FakePreviewStrategy(const unity::scopes::Result& result) : PreviewStrategy(result) {}
104 using click::PreviewStrategy::pushPackagePreviewWidgets;
105 std::vector<std::string> call_order;
106 virtual void run(unity::scopes::PreviewReplyProxy const& /*reply*/)
107 {
108 }
109
110 virtual unity::scopes::PreviewWidgetList screenshotsWidgets (const click::PackageDetails &/*details*/) {
111 call_order.push_back("screenshots");
112 return {};
113 }
114 virtual unity::scopes::PreviewWidgetList headerWidgets (const click::PackageDetails &/*details*/) {
115 call_order.push_back("header");
116 return {};
117 }
118};
119
120TEST_F(PreviewStrategyTest, testScreenshotsPushedAfterHeader)
121{
122 FakeResult result{vm};
123 unity::scopes::testing::MockPreviewReply reply;
124 std::shared_ptr<unity::scopes::testing::MockPreviewReply> replyptr{&reply, [](unity::scopes::testing::MockPreviewReply*){}};
125 click::PackageDetails details;
126
127 FakePreviewStrategy preview{result};
128 preview.pushPackagePreviewWidgets(replyptr, details, {});
129 std::vector<std::string> expected_order {"header", "screenshots"};
130 ASSERT_EQ(expected_order, preview.call_order);
131}

Subscribers

People subscribed via source and target branches

to all changes: