2
* Copyright (C) 2013 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; version 3.
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/>.
19
import Ubuntu.Components 0.1
20
import Unity.Test 0.1 as UT
21
import "../../../qml/Dash"
31
anchors { left: parent.left; right: parent.right }
35
anchors.fill: cardHeader
46
property Item mascot: findChild(cardHeader, "mascotShape")
47
property Item titleLabel: findChild(cardHeader, "titleLabel")
48
property Item subtitleLabel: findChild(cardHeader, "subtitleLabel")
49
property Item prices: findChild(cardHeader, "prices")
50
property Item oldPriceLabel: findChild(cardHeader, "oldPriceLabel")
51
property Item outerRow: findChild(cardHeader, "outerRow")
52
property Item column: findChild(cardHeader, "column")
54
function initTestCase() {
55
verify(typeof testCase.mascot === "object", "Couldn't find mascot object.");
56
verify(typeof testCase.titleLabel === "object", "Couldn't find titleLabel object.");
57
verify(typeof testCase.subtitleLabel === "object", "Couldn't find subtitleLabel object.");
58
verify(typeof testCase.prices === "object", "Couldn't find prices object.");
59
verify(typeof testCase.oldPriceLabel === "object", "Couldn't find oldPriceLabel object.");
63
cardHeader.mascot = "";
64
cardHeader.title = "";
65
cardHeader.subtitle = "";
66
cardHeader.price = "";
67
cardHeader.oldPrice = "";
68
cardHeader.altPrice = "";
71
function test_mascot_data() {
73
{ tag: "Empty", source: "", visible: false },
74
{ tag: "Invalid", source: "bad_path", visible: false },
75
{ tag: "Valid", source: Qt.resolvedUrl("artwork/avatar.png"), visible: true },
79
function test_mascot(data) {
80
cardHeader.mascot = data.source;
81
tryCompare(testCase.mascot, "visible", data.visible);
84
function test_labels_data() {
86
{ tag: "Empty", visible: false },
87
{ tag: "Title only", title: "Foo", visible: true },
88
{ tag: "Subtitle only", subtitle: "Bar", visible: false },
89
{ tag: "Both", title: "Foo", subtitle: "Bar", visible: true },
93
function test_labels(data) {
94
cardHeader.title = data.title !== undefined ? data.title : "";
95
cardHeader.subtitle = data.subtitle !== undefined ? data.subtitle : "";
96
tryCompare(cardHeader, "visible", data.visible);
99
function test_prices_data() {
101
{ tag: "Main", main: "$1.25", visible: true },
102
{ tag: "Alt", alt: "€1.00", visible: false },
103
{ tag: "Old", old: "€2.00", visible: false },
104
{ tag: "Main and Alt", main: "$1.25", alt: "€1.00", visible: true },
105
{ tag: "Main and Old", main: "$1.25", old: "$2.00", visible: true, oldAlign: Text.AlignRight },
106
{ tag: "Alt and Old", alt: "€1.00", old: "$2.00", visible: false },
107
{ tag: "All", main: "$1.25", alt: "€1.00", old: "$2.00", visible: true, oldAlign: Text.AlignHCenter },
111
function test_prices(data) {
112
cardHeader.price = data.main !== undefined ? data.main : "";
113
cardHeader.oldPrice = data.old !== undefined ? data.old : "";
114
cardHeader.altPrice = data.alt !== undefined ? data.alt : "";
115
tryCompare(cardHeader, "visible", data.visible);
116
if (data.hasOwnProperty("oldAlign")) {
117
compare(testCase.oldPriceLabel.horizontalAlignment, data.oldAlign, "Old price label is aligned wrong.")
121
function test_dimensions_data() {
123
{ tag: "Column width", object: column, width: cardHeader.width },
124
{ tag: "Column width with mascot", object: column, width: cardHeader.width - mascot.width - outerRow.margins * 3, mascot: "artwork/avatar.png" },
125
{ tag: "Header height", object: cardHeader, height: function() { return subtitleLabel.y + subtitleLabel.height + outerRow.margins * 2 } },
129
function test_dimensions(data) {
130
if (data.hasOwnProperty("mascot")) {
131
cardHeader.mascot = data.mascot;
134
if (data.hasOwnProperty("width")) {
135
tryCompare(data.object, "width", data.width);
138
if (data.hasOwnProperty("height")) {
139
tryCompareFunction(function() { return data.object.height === data.height() }, true);