2
* Copyright 2016 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it under
5
* the terms of the GNU General Public License, version 3, as published by the
6
* Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
#include "libertine-scope/preview.h"
18
#include <unity/scopes/Variant.h>
19
#include <gtest/gtest.h>
20
#include <unity/scopes/ActionMetadata.h>
21
#include <unity/scopes/testing/Result.h>
22
#include <unity/scopes/testing/MockPreviewReply.h>
23
#include <unity/scopes/PreviewWidget.h>
28
TEST(TestPreview, pushesWidgetsWithAppInformation)
30
unity::scopes::testing::Result result;
31
result["desktop_file"] = unity::scopes::Variant(QString("%1/data/Full.desktop").arg(QDir::currentPath()).toStdString());
32
unity::scopes::ActionMetadata metadata("en_US", "phone");
34
std::unique_ptr<unity::scopes::PreviewWidgetList> list(new unity::scopes::PreviewWidgetList());
35
testing::NiceMock<unity::scopes::testing::MockPreviewReply> reply;
36
EXPECT_CALL(reply, push(testing::_)).WillOnce(testing::SaveArg<0>(list.get()));
37
unity::scopes::PreviewReplyProxy proxy(&reply, [](unity::scopes::PreviewReply*) {});
39
Preview preview(result, metadata);
42
ASSERT_NE(nullptr, list);
43
ASSERT_EQ(3, list->size());
45
auto header = list->front();
46
EXPECT_EQ("hdr", header.id());
47
EXPECT_EQ("header", header.widget_type());
48
EXPECT_EQ("title", header.attribute_mappings()["title"]);
49
EXPECT_EQ("art", header.attribute_mappings()["mascot"]);
52
auto desc = list->front();
53
EXPECT_EQ("desc", desc.id());
54
EXPECT_EQ("This session logs you into Matchbox", desc.attribute_values()["text"].get_string());
57
auto buttons = list->front();
58
EXPECT_EQ("buttons", buttons.id());
59
EXPECT_EQ("actions", buttons.widget_type());
60
auto buttons_actions = buttons.attribute_values()["actions"].get_array();
61
ASSERT_EQ(1, buttons_actions.size());
62
EXPECT_EQ("open", buttons_actions[0].get_dict()["id"].get_string());
63
EXPECT_EQ("Open", buttons_actions[0].get_dict()["label"].get_string());