~ubuntu-branches/ubuntu/trusty/unity8/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/qmltests/Dash/tst_CardHeader.qml

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Michael Terry, Ubuntu daily release, Michał Sawicz, Leo Arias, Michał Karnicki
  • Date: 2014-02-04 14:09:14 UTC
  • mfrom: (1.1.65)
  • Revision ID: package-import@ubuntu.com-20140204140914-twc0x02ooyb4uub1
Tags: 7.84+14.04.20140204-0ubuntu1
[ Michael Terry ]
* Disable NM integration test, jenkins has a problem with it because
  logind isn't configured

[ Ubuntu daily release ]
* New rebuild forced

[ Michał Sawicz ]
* Add ubuntu-settings-components to build script. Revert workaround
  for bug #1268578, got fixed upstream. Drop GenericName from
  unity8.desktop. (LP: #1268578)
* Improve Card and CardHeader layouts: anchor summary to art when no
  header. don't indent header when no mascot. reduce header and
  summary font sizes and weights. increase art shape radius .
* Add doxygen-based documentation generator.
* Add CardTool to determine category-wide card properties based on the
  category template. Clean up test configurations, too.
* Move upstart kill timeout to the unity8 job itself.
* Don't treat scope as active when preview open to inhibit model
  updates and reset processing on previewData changes. (LP: #1275832)

[ Leo Arias ]
* Added the DashPreview autopilot helper.

[ Michał Karnicki ]
* CardHeader mascot improvements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.0
 
18
import QtTest 1.0
 
19
import Ubuntu.Components 0.1
 
20
import Unity.Test 0.1 as UT
 
21
import "../../../qml/Dash"
 
22
 
 
23
 
 
24
Rectangle {
 
25
    width: units.gu(40)
 
26
    height: units.gu(72)
 
27
    color: "lightgrey"
 
28
 
 
29
    CardHeader {
 
30
        id: cardHeader
 
31
        anchors { left: parent.left; right: parent.right }
 
32
    }
 
33
 
 
34
    Rectangle {
 
35
        anchors.fill: cardHeader
 
36
        color: "lightblue"
 
37
        opacity: 0.5
 
38
    }
 
39
 
 
40
    UT.UnityTestCase {
 
41
        id: testCase
 
42
        name: "CardHeader"
 
43
 
 
44
        when: windowShown
 
45
 
 
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")
 
53
 
 
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.");
 
60
        }
 
61
 
 
62
        function cleanup() {
 
63
            cardHeader.mascot = "";
 
64
            cardHeader.title = "";
 
65
            cardHeader.subtitle = "";
 
66
            cardHeader.price = "";
 
67
            cardHeader.oldPrice = "";
 
68
            cardHeader.altPrice = "";
 
69
        }
 
70
 
 
71
        function test_mascot_data() {
 
72
            return [
 
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 },
 
76
            ]
 
77
        }
 
78
 
 
79
        function test_mascot(data) {
 
80
            cardHeader.mascot = data.source;
 
81
            tryCompare(testCase.mascot, "visible", data.visible);
 
82
        }
 
83
 
 
84
        function test_labels_data() {
 
85
            return [
 
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 },
 
90
            ]
 
91
        }
 
92
 
 
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);
 
97
        }
 
98
 
 
99
        function test_prices_data() {
 
100
            return [
 
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 },
 
108
            ]
 
109
        }
 
110
 
 
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.")
 
118
            }
 
119
        }
 
120
 
 
121
        function test_dimensions_data() {
 
122
            return [
 
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 } },
 
126
            ]
 
127
        }
 
128
 
 
129
        function test_dimensions(data) {
 
130
            if (data.hasOwnProperty("mascot")) {
 
131
                cardHeader.mascot = data.mascot;
 
132
            }
 
133
 
 
134
            if (data.hasOwnProperty("width")) {
 
135
                tryCompare(data.object, "width", data.width);
 
136
            }
 
137
 
 
138
            if (data.hasOwnProperty("height")) {
 
139
                tryCompareFunction(function() { return data.object.height === data.height() }, true);
 
140
            }
 
141
        }
 
142
    }
 
143
}