~elopio/ubuntu-ui-toolkit/textfield_emulators

« back to all changes in this revision

Viewing changes to tests/unit/tst_components/tst_modelsectioncounter.qml

  • Committer: Leo Arias
  • Date: 2014-01-10 02:59:19 UTC
  • mfrom: (789.1.118 trunk)
  • Revision ID: leo.arias@canonical.com-20140110025919-lq52fcyi3tvv2sn3
Merged with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2012 Canonical Ltd.
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU Lesser 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
 
 
21
 
TestCase {
22
 
    name: "ModelSectionCounterAPI"
23
 
 
24
 
    function initTestCase() {
25
 
        var component = Qt.createComponent(Qt.resolvedUrl("../../../modules/Ubuntu/Components/ModelSectionCounter.qml"));
26
 
        counter = component.createObject(parent);
27
 
    }
28
 
 
29
 
    function test_0_defaults() {
30
 
        compare(counter.view, null, "ModelSectionCounter does not have valid view set");
31
 
        compare(counter.count, 0, "ModelSectionCounter default sectionCount is 0");
32
 
        compare(counter.cacheSections, false, "ModelSectionCounter does not cache sections");
33
 
        compare(counter.cache, [], "ModelSectionCounter has empty section cache list");
34
 
    }
35
 
 
36
 
    function test_1_count_data() {
37
 
        return [
38
 
            {tag: "Empty model", model: emptyModel, sectionProperty: "label", expect: 0, expectFail: false},
39
 
            {tag: "ListModel", model: objectModel, sectionProperty: "label", expect: 8, expectFail: false},
40
 
            {tag: "StringList model", model: stringModel, sectionProperty: "modelData", expect: 8, expectFail: false},
41
 
            {tag: "VariantList model", model: variantModel, sectionProperty: "label", expect: 8, expectFail: false},
42
 
        ];
43
 
    }
44
 
 
45
 
    function test_1_count(data) {
46
 
        if (data.expectFail)
47
 
            expectFail("", data.tag);
48
 
        list.model = data.model;
49
 
        list.section.property = data.sectionProperty;
50
 
        list.section.criteria = ViewSection.FirstCharacter;
51
 
        counter.view = list;
52
 
        compare(counter.count, data.expect, "Section count is wrong");
53
 
    }
54
 
 
55
 
    function test_2_cache() {
56
 
        list.model = objectModel;
57
 
        list.section.property = "label";
58
 
        list.section.criteria = ViewSection.FirstCharacter;
59
 
        counter.view = list;
60
 
        counter.cacheSections = true;
61
 
        var cache = ["1", "2", "3", "4", "5", "6", "7", "8"];
62
 
        compare(counter.cache, cache, "Section cache is wrong");
63
 
 
64
 
        counter.cacheSections = false;
65
 
        cache = [];
66
 
        compare(counter.cache, cache, "Section cache is wrong");
67
 
    }
68
 
 
69
 
    Item {
70
 
        ListView {
71
 
            id: list
72
 
 
73
 
            delegate: Item{ height: 40 }
74
 
            section.delegate: Item{ height: 10 }
75
 
        }
76
 
    }
77
 
 
78
 
    property var counter
79
 
 
80
 
    property var emptyModel: ListModel {}
81
 
 
82
 
    property var objectModel: ListModel {
83
 
        ListElement {label: "1"}
84
 
        ListElement {label: "10"}
85
 
        ListElement {label: "100"}
86
 
        ListElement {label: "2"}
87
 
        ListElement {label: "3"}
88
 
        ListElement {label: "4"}
89
 
        ListElement {label: "5"}
90
 
        ListElement {label: "6"}
91
 
        ListElement {label: "7"}
92
 
        ListElement {label: "8"}
93
 
    }
94
 
 
95
 
    property var variantModel: [
96
 
        {"label": "1"},
97
 
        {"label": "10"},
98
 
        {"label": "100"},
99
 
        {"label": "2"},
100
 
        {"label": "3"},
101
 
        {"label": "4"},
102
 
        {"label": "5"},
103
 
        {"label": "6"},
104
 
        {"label": "7"},
105
 
        {"label": "8"}
106
 
    ]
107
 
 
108
 
    property var stringModel: ["1", "10", "100", "2", "3", "4", "5", "6", "7", "8"]
109
 
}