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

« back to all changes in this revision

Viewing changes to tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.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 "../../../../qml/Dash/Previews"
 
20
import Unity.Test 0.1 as UT
 
21
 
 
22
Rectangle {
 
23
    id: root
 
24
    width: units.gu(60)
 
25
    height: units.gu(80)
 
26
    color: Theme.palette.selected.background
 
27
 
 
28
    PreviewWidgetFactory {
 
29
        id: factory
 
30
        anchors {
 
31
            left: parent.left
 
32
            right: parent.right
 
33
        }
 
34
    }
 
35
 
 
36
    SignalSpy {
 
37
        id: triggeredSpy
 
38
        target: factory
 
39
        signalName: "triggered"
 
40
    }
 
41
 
 
42
    UT.UnityTestCase {
 
43
        name: "PreviewWidgetFactory"
 
44
        when: windowShown
 
45
 
 
46
        property Item mockWidget: findChild(factory, "mockPreviewWidget")
 
47
 
 
48
        function cleanup() {
 
49
            factory.source = Qt.binding(function() { return factory.widgetSource });
 
50
        }
 
51
 
 
52
        function test_previewData() {
 
53
            factory.source = Qt.resolvedUrl("MockPreviewWidget.qml");
 
54
 
 
55
            verify(typeof mockWidget === "object", "Could not find the mock preview widget.");
 
56
 
 
57
            tryCompare(mockWidget, "widgetData", factory.widgetData);
 
58
        }
 
59
 
 
60
        function test_triggered() {
 
61
            factory.source = Qt.resolvedUrl("MockPreviewWidget.qml");
 
62
 
 
63
            verify(typeof mockWidget === "object", "Could not find the mock preview widget.");
 
64
 
 
65
            mockWidget.trigger();
 
66
 
 
67
            triggeredSpy.wait();
 
68
 
 
69
            var args = triggeredSpy.signalArguments[0];
 
70
 
 
71
            compare(args[0], "mockWidget", "Widget id not passed correctly.");
 
72
            compare(args[1], "mockAction", "Action id not passed correctly.");
 
73
            compare(args[2]["mock"], "data", "Data not passed correctly.");
 
74
        }
 
75
 
 
76
        function test_mapping_data() {
 
77
            return [
 
78
                { tag: "Actions", type: "actions", source: "PreviewActions.qml" },
 
79
                { tag: "Audio", type: "audio", source: "PreviewAudioPlayback.qml" },
 
80
                { tag: "Gallery", type: "gallery", source: "PreviewImageGallery.qml" },
 
81
                { tag: "Header", type: "header", source: "PreviewHeader.qml" },
 
82
                { tag: "Image", type: "image", source: "PreviewZoomableImage.qml" },
 
83
                { tag: "Progress", type: "progress", source: "PreviewProgress.qml" },
 
84
                { tag: "Rating Input", type: "rating-input", source: "PreviewRatingInput.qml" },
 
85
                { tag: "Rating Display", type: "reviews", source: "PreviewRatingDisplay.qml" },
 
86
                { tag: "Text", type: "text", source: "PreviewTextSummary.qml" },
 
87
                { tag: "Video", type: "video", source: "PreviewVideoPlayback.qml" },
 
88
            ];
 
89
        }
 
90
 
 
91
        function test_mapping(data) {
 
92
            factory.widgetData = { type: data.type };
 
93
            factory.widgetType = data.type;
 
94
 
 
95
            verify(("" + factory.source).indexOf(data.source) != -1);
 
96
        }
 
97
    }
 
98
}