~nick-dedekind/unity8/indicators.hint-interval

« back to all changes in this revision

Viewing changes to tests/qmltests/Dash/Previews/tst_PreviewRatingDisplay.qml

  • Committer: Nick Dedekind
  • Date: 2014-03-07 15:54:57 UTC
  • mfrom: (638.1.118 unity8)
  • Revision ID: nicholas.dedekind@gmail.com-20140307155457-f0s1zu5ll2czt3rq
merged with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2014 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 "../../../../qml/Dash/Previews"
 
21
import Unity.Test 0.1 as UT
 
22
 
 
23
Rectangle {
 
24
    id: root
 
25
    width: units.gu(40)
 
26
    height: units.gu(80)
 
27
    color: Theme.palette.selected.background
 
28
 
 
29
    property var reviewsModel0: {
 
30
        "reviews": [ ]
 
31
    }
 
32
 
 
33
    property var reviewsModel1: {
 
34
        "reviews": [ { author: "Some dude", rating: 4.5, review: "Very cool app" },
 
35
                     { author: "Yet Another dude", rating: 5, review: "Very cool app" }, ]
 
36
    }
 
37
 
 
38
    property var reviewsModel2: {
 
39
        "reviews": [ { author: "Some dude", rating: 4.5, review: "Very cool app" },
 
40
                     { author: "Another dude", rating: 3, review: "Average app. Lorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus a mi vitae augue rhoncus lobortis ut rutrum metus.\nCurabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus a mi vitae augue rhoncus lobortis ut rutrum metus.\nCurabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh." },
 
41
                     { author: "Yet Another dude", rating: 5, review: "Very cool app" }, ]
 
42
    }
 
43
 
 
44
    property var reviewsModelMixed: {
 
45
        "reviews": [ { author: "Some dude", review: "Very cool app" },
 
46
                     { author: "" },
 
47
                     { rating: 3, review: "Average app. Lorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus a mi vitae augue rhoncus lobortis ut rutrum metus.\nCurabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus a mi vitae augue rhoncus lobortis ut rutrum metus.\nCurabitur tortor leo, tristique sed mollis quis, condimentum venenatis nibh." },
 
48
                     { author: "Yet Another dude", rating: 5 }, ]
 
49
    }
 
50
 
 
51
    PreviewRatingDisplay {
 
52
        id: previewRatingDisplay
 
53
        anchors.left: parent.left
 
54
        anchors.right: parent.right
 
55
        widgetData: reviewsModelMixed
 
56
    }
 
57
 
 
58
    UT.UnityTestCase {
 
59
        name: "PreviewRatingDisplayTest"
 
60
        when: windowShown
 
61
 
 
62
        function test_reviews_data() {
 
63
            return [
 
64
                    {tag: "0 reviews", reviewsModel: reviewsModel0},
 
65
                    {tag: "1 review", reviewsModel: reviewsModel1},
 
66
                    {tag: "3 reviews", reviewsModel: reviewsModel2},
 
67
                    {tag: "3 mixed reviews", reviewsModel: reviewsModelMixed}
 
68
            ];
 
69
        }
 
70
 
 
71
        function test_reviews(data) {
 
72
            previewRatingDisplay.widgetData = data.reviewsModel;
 
73
 
 
74
            var reviewsRepeater = findChild(previewRatingDisplay, "reviewsRepeater");
 
75
            compare(reviewsRepeater.count, data.reviewsModel["reviews"].length);
 
76
 
 
77
            for (var i = 0; i < data.reviewsModel["reviews"].length; ++i) {
 
78
                var reviewItem = findChild(previewRatingDisplay, "reviewItem" + i);
 
79
 
 
80
                var rating = findChild(reviewItem, "rating");
 
81
                if (data.reviewsModel["reviews"][i]["rating"] >= 0) {
 
82
                    compare(rating.visible, true);
 
83
                    compare(rating.value, data.reviewsModel["reviews"][i]["rating"]);
 
84
                } else {
 
85
                    compare(rating.visible, false);
 
86
                }
 
87
 
 
88
                var authorLabel = findChild(reviewItem, "authorLabel");
 
89
                if (data.reviewsModel["reviews"][i]["author"] &&
 
90
                    data.reviewsModel["reviews"][i]["author"] !== "") {
 
91
                    compare(authorLabel.visible, true);
 
92
                    compare(authorLabel.text, data.reviewsModel["reviews"][i]["author"]);
 
93
                } else {
 
94
                    compare(authorLabel.visible, false);
 
95
                }
 
96
 
 
97
                var reviewLabel = findChild(reviewItem, "reviewLabel");
 
98
                if (data.reviewsModel["reviews"][i]["review"] &&
 
99
                    data.reviewsModel["reviews"][i]["review"] !== "") {
 
100
                    compare(reviewLabel.visible, true);
 
101
                    compare(reviewLabel.text, data.reviewsModel["reviews"][i]["review"]);
 
102
                } else {
 
103
                    compare(reviewLabel.visible, false);
 
104
                }
 
105
 
 
106
                if (!rating.visible && !authorLabel.visible && !reviewLabel.visible) {
 
107
                    verify(reviewItem.height === 0);
 
108
                }
 
109
            }
 
110
        }
 
111
    }
 
112
}