@@ -0,0 +1,277 @@
2+ * Copyright (C) 2014 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"
22+import "CardHelpers.js" as Helpers
30+ property string defaultLayout: '
34+ "category-layout": "grid",
35+ "card-layout": "vertical",
36+ "card-size": "medium",
37+ "overlay-mode": null,
55+ "full": "image://theme/rating-star-full",
56+ "half": "image://theme/rating-star-half",
57+ "empty": "image://theme/rating-star-empty"
65+ property string fullMapping: '
69+ "subtitle": "subtitle",
74+ property var cardsModel: [
76+ "name": "Art, header, summary - vertical",
77+ "layout": { "components": JSON.parse(fullMapping) }
80+ "name": "Art, header, summary - vertical, small",
81+ "layout": { "template": { "card-size": "small" }, "components": JSON.parse(fullMapping) }
84+ "name": "Art, header, summary - vertical, large",
85+ "layout": { "template": { "card-size": "large" }, "components": JSON.parse(fullMapping) }
88+ "name": "Header title only - horizontal",
89+ "layout": { "template": { "card-layout": "horizontal" },
90+ "components": { "title": "title" } }
97+ template: Helpers.update(JSON.parse(root.defaultLayout), Helpers.tryParse(layoutArea.text, layoutError))['template'];
98+ components: Helpers.update(JSON.parse(root.defaultLayout), Helpers.tryParse(layoutArea.text, layoutError))['components'];
103+ anchors { left: parent.left; top: parent.top; margins: units.gu(1) }
107+ { label: "Card width", value: cardTool.cardWidth && cardTool.cardWidth / units.gu(1) },
108+ { label: "Card height", value: cardTool.cardHeight && cardTool.cardHeight / units.gu(1) },
112+ anchors { left: parent.left; right: parent.right; margins: units.gu(3) }
117+ text: modelData.label
118+ verticalAlignment: Text.AlignVCenter
123+ text: modelData.value || "undefined"
124+ verticalAlignment: Text.AlignVCenter
130+ template: cardTool.template;
131+ components: cardTool.components;
132+ cardData: Helpers.mapData(dataArea.text, components, dataError)
134+ width: cardTool.cardWidth || implicitWidth
135+ height: cardTool.cardHeight || implicitHeight
140+ anchors.fill: parent
141+ color: "transparent"
143+ border.color: "green"
149+ anchors { top: parent.top; bottom: parent.bottom; right: parent.right}
154+ anchors { fill: parent; margins: units.gu(1) }
155+ spacing: units.gu(1)
160+ delegate: OptionSelectorDelegate { text: modelData.name }
161+ onSelectedIndexChanged: updateAreas()
162+ Component.onCompleted: updateAreas()
164+ function updateAreas() {
165+ var element = cardsModel[selectedIndex];
167+ layoutArea.text = JSON.stringify(element.layout, undefined, 2) || "{}";
169+ layoutArea.text = "";
177+ { label: "Grid", layout: "grid" },
178+ { label: "Organic Grid", layout: "organic-grid" },
179+ { label: "Horizontal Journal", layout: "journal" },
180+ { label: "Vertical Journal", layout: "vertical-journal" },
182+ delegate: OptionSelectorDelegate { text: modelData.label }
183+ onSelectedIndexChanged: {
184+ var element = model[selectedIndex];
185+ if (element && cardTool.template["category-layout"] !== element.layout) {
186+ var current = JSON.parse(layoutArea.text);
187+ var update = { "template": { "category-layout": element.layout }}
188+ layoutArea.text = JSON.stringify(Helpers.update(current, update), undefined, 2) || "{}";
195+ anchors { left: parent.left; right: parent.right }
196+ height: units.gu(25)
201+ anchors { left: parent.left; right: parent.right }
208+ anchors { left: parent.left; right: parent.right }
209+ height: units.gu(25)
210+ text: JSON.stringify(cardTool.priv.card.cardData, undefined, 2)
215+ anchors { left: parent.left; right: parent.right }
223+ onTemplateChanged: {
224+ switch(cardTool.template["category-layout"]) {
225+ case "organic-grid": layoutSelector.selectedIndex = 1; break;
226+ case "journal": layoutSelector.selectedIndex = 2; break;
227+ case "vertical-journal": layoutSelector.selectedIndex = 3; break;
229+ default: layoutSelector.selectedIndex = 0; break;
241+ function cleanup() {
242+ selector.selectedIndex = -1;
243+ layoutSelector.selectedIndex = -1;
246+ function test_card_size_data() {
248+ { tag: "Medium", width: units.gu(18.5), height: undefined, index: 0 },
249+ { tag: "Small", width: units.gu(12), height: undefined, index: 1 },
250+ { tag: "Large", width: units.gu(38), height: undefined, index: 2 },
251+ { tag: "Horizontal", width: units.gu(38), height: undefined, index: 3 },
252+ { tag: "Journal", width: undefined, height: units.gu(20), size: 20, index: 0, layout_index: 2 },
253+ { tag: "OversizedJournal", width: undefined, height: units.gu(18.5), size: 40, index: 0, layout_index: 2 },
257+ function test_card_size(data) {
258+ selector.selectedIndex = data.index;
259+ if (data.hasOwnProperty("layout_index")) {
260+ layoutSelector.selectedIndex = data.layout_index;
263+ if (data.hasOwnProperty("size")) {
264+ cardTool.template['card-size'] = data.size;
265+ cardTool.templateChanged();
268+ if (data.hasOwnProperty("width")) {
269+ tryCompare(cardTool, "cardWidth", data.width);
272+ if (data.hasOwnProperty("height")) {
273+ tryCompare(cardTool, "cardHeight", data.height);