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

« back to all changes in this revision

Viewing changes to tests/qmltests/Dash/tst_Card.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:
27
27
    height: units.gu(72)
28
28
    color: "#88FFFFFF"
29
29
 
30
 
    property string defaultLayout: '
31
 
    {
32
 
      "schema-version": 1,
33
 
      "template": {
34
 
        "category-layout": "grid",
35
 
        "card-layout": "vertical",
36
 
        "card-size": "medium",
37
 
        "overlay-mode": null,
38
 
        "collapsed-rows": 2
39
 
      },
40
 
      "components": {
41
 
        "title": null,
42
 
        "art": {
43
 
            "aspect-ratio": 1.0,
44
 
            "fill-mode": "crop"
45
 
        },
46
 
        "subtitle": null,
47
 
        "mascot": null,
48
 
        "emblem": null,
49
 
        "old-price": null,
50
 
        "price": null,
51
 
        "alt-price": null,
52
 
        "rating": {
53
 
          "type": "stars",
54
 
          "range": [0, 5],
55
 
          "full": "image://theme/rating-star-full",
56
 
          "half": "image://theme/rating-star-half",
57
 
          "empty": "image://theme/rating-star-empty"
58
 
        },
59
 
        "alt-rating": null,
60
 
        "summary": null
61
 
      },
62
 
      "resources": {}
63
 
    }'
64
 
 
65
30
    property string cardData: '
66
31
    {
67
32
      "art": "../../tests/qmltests/Dash/artwork/music-player-design.png",
71
36
      "summary": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
72
37
    }'
73
38
 
74
 
    property string fullMapping: '
75
 
    {
76
 
      "title": "title",
77
 
      "art": "art",
78
 
      "subtitle": "subtitle",
79
 
      "mascot": "mascot",
80
 
      "summary": "summary"
81
 
    }'
82
 
 
83
39
    property var cardsModel: [
84
40
        {
85
 
            "name": "Art, header, summary - vertical",
86
 
            "layout": { "components": JSON.parse(fullMapping) }
87
 
        },
88
 
        {
89
 
            "name": "Art, header, summary - vertical, small",
90
 
            "layout": { "template": { "card-size": "small" }, "components": JSON.parse(fullMapping) }
91
 
        },
92
 
        {
93
 
            "name": "Art, header, summary - vertical, large",
94
 
            "layout": { "template": { "card-size": "large" }, "components": JSON.parse(fullMapping) }
95
 
        },
96
 
        {
97
 
            "name": "Art, header, summary - vertical, wide",
98
 
            "layout": { "components": Helpers.update(JSON.parse(root.fullMapping), { "art": { "aspect-ratio": 2 } }) }
99
 
        },
100
 
        {
101
 
            "name": "Art, title - vertical, fitted",
102
 
            "layout": { "components": Helpers.update(JSON.parse(root.fullMapping), { "art": { "fill-mode": "fit" } }) }
 
41
            "name": "Art, header, summary",
 
42
            "layout": { "components": JSON.parse(Helpers.fullMapping) }
 
43
        },
 
44
        {
 
45
            "name": "Art, header, summary - small",
 
46
            "layout": { "template": { "card-size": "small" }, "components": JSON.parse(Helpers.fullMapping) }
 
47
        },
 
48
        {
 
49
            "name": "Art, header, summary - large",
 
50
            "layout": { "template": { "card-size": "large" }, "components": JSON.parse(Helpers.fullMapping) }
 
51
        },
 
52
        {
 
53
            "name": "Art, header, summary - wide",
 
54
            "layout": { "components": Helpers.update(JSON.parse(Helpers.fullMapping), { "art": { "aspect-ratio": 2 } }) }
 
55
        },
 
56
        {
 
57
            "name": "Art, title - fitted",
 
58
            "layout": { "components": Helpers.update(JSON.parse(Helpers.fullMapping), { "art": { "fill-mode": "fit" } }) }
103
59
        },
104
60
        {
105
61
            "name": "Art, header, summary - horizontal",
106
62
            "layout": { "template": { "card-layout": "horizontal" },
107
 
                        "components": JSON.parse(fullMapping) }
108
 
        },
109
 
        {
110
 
            "name": "Art, header - vertical",
111
 
            "layout": { "components": Helpers.update(JSON.parse(root.fullMapping), { "summary": undefined }) }
112
 
        },
113
 
        {
114
 
            "name": "Header title only - horizontal",
115
 
            "layout": { "template": { "card-layout": "horizontal" },
116
 
                        "components": { "title": "title" } }
 
63
                        "components": JSON.parse(Helpers.fullMapping) }
 
64
        },
 
65
        {
 
66
            "name": "Art, header",
 
67
            "layout": { "components": Helpers.update(JSON.parse(Helpers.fullMapping), { "summary": undefined }) }
 
68
        },
 
69
        {
 
70
            "name": "Art, summary",
 
71
            "layout": { "components": { "art": "art", "summary": "summary" } }
 
72
        },
 
73
        {
 
74
            "name": "Header title only",
 
75
            "layout": { "components": { "title": "title" } }
 
76
        },
 
77
        {
 
78
            "name": "Art, header, summary - overlaid",
 
79
            "layout": { "template": { "overlay": true },
 
80
                        "components": JSON.parse(Helpers.fullMapping) }
 
81
        },
 
82
        {
 
83
            "name": "Art, header - grey background",
 
84
            "layout": { "template": { "card-background": { "type": "color", "elements": ["grey"] } },
 
85
                        "components": JSON.parse(Helpers.fullMapping) }
 
86
        },
 
87
        {
 
88
            "name": "Art, header - gradient background",
 
89
            "layout": { "template": { "card-background": { "type": "gradient", "elements": ["grey", "white"] } },
 
90
                        "components": JSON.parse(Helpers.fullMapping) }
 
91
        },
 
92
        {
 
93
            "name": "Art, header - image background",
 
94
            "layout": { "template": { "card-background": Qt.resolvedUrl("artwork/checkers.png") },
 
95
                        "components": JSON.parse(Helpers.fullMapping) }
117
96
        },
118
97
    ]
119
98
 
 
99
    CardTool {
 
100
        id: cardTool
 
101
        template: card.template
 
102
        components: card.components
 
103
        viewWidth: units.gu(48)
 
104
    }
 
105
 
120
106
    Card {
121
107
        id: card
122
108
        anchors { top: parent.top; left: parent.left; margins: units.gu(1) }
123
109
 
124
 
        template: Helpers.update(JSON.parse(root.defaultLayout), Helpers.tryParse(layoutArea.text, layoutError))['template'];
125
 
        components: Helpers.update(JSON.parse(root.defaultLayout), Helpers.tryParse(layoutArea.text, layoutError))['components'];
 
110
        width: cardTool.cardWidth || implicitWidth
 
111
        height: cardTool.cardHeight || implicitHeight
 
112
 
 
113
        template: Helpers.update(JSON.parse(Helpers.defaultLayout), Helpers.tryParse(layoutArea.text, layoutError))['template'];
 
114
        components: Helpers.update(JSON.parse(Helpers.defaultLayout), Helpers.tryParse(layoutArea.text, layoutError))['components'];
126
115
        cardData: Helpers.mapData(dataArea.text, components, dataError)
127
116
    }
128
117
 
193
182
        when: windowShown
194
183
 
195
184
        property Item header: findChild(card, "cardHeader")
 
185
        property Item title: findChild(header, "titleLabel")
196
186
        property Item art: findChild(card, "artShape")
197
187
        property Item artImage: findChild(card, "artImage")
198
188
        property Item summary: findChild(card, "summaryLabel")
 
189
        property Item background: findChild(card, "background")
 
190
        property Item backgroundImage: findChild(card, "backgroundImage")
199
191
 
200
192
        function initTestCase() {
201
193
            verify(typeof testCase.header === "object", "Couldn't find header object.");
202
194
            verify(typeof testCase.art === "object", "Couldn't find art object.");
203
195
            verify(typeof testCase.artImage === "object", "Couldn't find artImage object.");
204
196
            verify(typeof testCase.summary === "object", "Couldn't find summary object.");
 
197
            verify(typeof testCase.artImage === "object", "Couldn't find background object.");
 
198
            verify(typeof testCase.summary === "object", "Couldn't find backgroundImage object.");
205
199
        }
206
200
 
207
201
        function cleanup() {
245
239
        function test_card_size_data() {
246
240
            return [
247
241
                { tag: "Medium", width: units.gu(18.5), index: 0 },
248
 
                { tag: "Small", width: units.gu(12), size: "small", index: 0 },
249
 
                { tag: "Large", width: units.gu(38), size: "large", index: 0 },
 
242
                { tag: "Small", width: units.gu(12), index: 1 },
 
243
                { tag: "Large", width: units.gu(38), index: 2 },
250
244
                { tag: "Wide", width: units.gu(18.5), aspect: 0.5, index: 0 },
251
245
                { tag: "Horizontal", width: units.gu(38), index: 5 },
252
246
                // Make sure card ends with header when there's no summary
256
250
        }
257
251
 
258
252
        function test_card_size(data) {
 
253
            waitForRendering(card);
259
254
            selector.selectedIndex = data.index;
260
255
 
261
256
            if (data.hasOwnProperty("size")) {
346
341
                  left: function() { return art.x }, index: 0 },
347
342
                { tag: "Horizontal", top: function() { return art.y },
348
343
                  left: function() { return art.x + art.width }, index: 5 },
 
344
                { tag: "Overlay", top: function() { return art.y + art.height - header.height },
 
345
                  left: function() { return art.x }, index: 9 },
349
346
            ]
350
347
        }
351
348
 
356
353
            tryCompareFunction(function() { return testCase.header.x === data.left() }, true);
357
354
        }
358
355
 
 
356
        function test_summary_layout_data() {
 
357
            return [
 
358
                { tag: "With header", top: function() { return header.y + header.height }, index: 0 },
 
359
                { tag: "Without header", top: function() { return art.y + art.height }, index: 7 },
 
360
            ]
 
361
        }
 
362
 
 
363
        function test_summary_layout(data) {
 
364
            selector.selectedIndex = data.index;
 
365
 
 
366
            tryCompareFunction(function() { return testCase.summary.y === data.top() }, true);
 
367
        }
 
368
 
359
369
        function test_art_visibility() {
360
 
            selector.selectedIndex = 7
361
 
 
362
 
            tryCompare(testCase.artImage, "source", "")
363
 
            compare(testCase.art.visible, false)
364
 
            compare(testCase.art.height, 0)
365
 
            compare(testCase.art.width, 0)
 
370
            selector.selectedIndex = 8;
 
371
 
 
372
            tryCompare(testCase.artImage, "source", "");
 
373
            compare(testCase.art.visible, false);
 
374
            compare(testCase.art.height, 0);
 
375
            compare(testCase.art.width, 0);
 
376
        }
 
377
 
 
378
        function test_background_data() {
 
379
            return [
 
380
                { tag: "Art and summary", visible: true, color: "#ffffff", index: 0 },
 
381
                { tag: "No Summary", visible: false, index: 6 },
 
382
                { tag: "Horizontal", visible: false, index: 5 },
 
383
                { tag: "Grey background", visible: true, color: "#808080", index: 10 },
 
384
                { tag: "Overriden Gradient background", visible: true, color: "#808080", gradientColor: "#ffffff",
 
385
                  background: {type: "color", elements: ["grey", "white"]}, index: 10 },
 
386
                { tag: "Overriden Image background", visible: true, image: Qt.resolvedUrl("artwork/checkers.png"),
 
387
                  background: Qt.resolvedUrl("artwork/checkers.png"), index: 10 },
 
388
                { tag: "Gradient background", visible: true, color: "#808080", gradientColor: "#ffffff", index: 11 },
 
389
                { tag: "Image background", visible: true, image: Qt.resolvedUrl("artwork/checkers.png"), index: 12 },
 
390
            ];
 
391
        }
 
392
 
 
393
        function test_background(data) {
 
394
            selector.selectedIndex = data.index;
 
395
 
 
396
            if (data.hasOwnProperty("background")) {
 
397
                card.cardData["background"] = data.background;
 
398
                card.cardDataChanged();
 
399
            }
 
400
 
 
401
            waitForRendering(card);
 
402
 
 
403
            tryCompare(background, "visible", data.visible);
 
404
 
 
405
            if (data.hasOwnProperty("color")) {
 
406
                tryCompare(background, "color", data.color);
 
407
            }
 
408
 
 
409
            if (data.hasOwnProperty("gradientColor")) {
 
410
                tryCompare(background, "gradientColor", data.gradientColor);
 
411
            }
 
412
 
 
413
            if (data.hasOwnProperty("image")) {
 
414
                tryCompare(backgroundImage, "source", data.image);
 
415
            }
 
416
        }
 
417
 
 
418
        function test_font_weights_data() {
 
419
            return [
 
420
                { tag: "Title only", index: 8, weight: Font.Normal },
 
421
                { tag: "Title, subtitle", index: 0, weight: Font.DemiBold },
 
422
            ]
 
423
        }
 
424
 
 
425
        function test_font_weights(data) {
 
426
            selector.selectedIndex = data.index;
 
427
 
 
428
            tryCompare(testCase.title.font, "weight", data.weight);
366
429
        }
367
430
    }
368
431
}