~mterry/unity8/power-button-on-lock

« back to all changes in this revision

Viewing changes to tests/qmltests/Greeter/tst_Clock.qml

  • Committer: Michael Terry
  • Date: 2014-11-24 15:25:42 UTC
  • mfrom: (1368.1.82 unity8)
  • Revision ID: michael.terry@canonical.com-20141124152542-5cysva8ds3qfula6
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import ".."
20
20
import "../../../qml/Greeter"
21
21
import Ubuntu.Components 0.1
22
 
import QMenuModel 0.1
 
22
import Unity.Indicators 0.1 as Indicators
23
23
import Unity.Test 0.1 as UT
24
24
 
25
25
Rectangle {
36
36
        }
37
37
    }
38
38
 
39
 
    UnityMenuModel {
40
 
        id: menuModel
41
 
        modelData: [{
42
 
            "rowData": {
43
 
                "actionState": { "label": Qt.formatTime(new Date("October 13, 1975 11:13:00")) }
44
 
            }
45
 
        }]
 
39
    function updateDatetimeModelTime(label) {
 
40
        Indicators.UnityMenuModelCache.setCachedModelData("/com/canonical/indicator/datetime/phone",
 
41
            [{
 
42
                "rowData": {
 
43
                    "actionState": { "label": label }
 
44
                }
 
45
            }]);
46
46
    }
47
47
 
48
48
    UT.UnityTestCase {
49
49
        name: "Clock"
 
50
        when: windowShown
50
51
 
51
52
        function init() {
52
 
            var cachedModel = findChild(clock, "timeModel");
53
 
            verify(cachedModel !== undefined);
54
 
            cachedModel.model = menuModel;
55
 
        }
56
 
 
57
 
        function test_customDate() {
58
 
            var dateObj = new Date("October 13, 1975 11:13:00")
59
 
            var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)
60
 
            var timeString = Qt.formatTime(dateObj)
61
 
 
62
 
            clock.currentDate = dateObj
63
 
            var dateLabel = findChild(clock, "dateLabel")
64
 
            compare(dateLabel.text, dateString, "Not the expected date")
65
 
            var timeLabel = findChild(clock, "timeLabel")
66
 
            compare(timeLabel.text, timeString, "Not the expected time")
67
 
        }
68
 
 
69
 
        function test_dateUpdate() {
70
 
            var dateObj = new Date("October 13, 1975 11:13:00")
71
 
            var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)
72
 
            var timeString = Qt.formatTime(dateObj)
73
 
 
 
53
            updateDatetimeModelTime(Qt.formatTime(new Date("October 13, 1975 12:14:00")));
 
54
            clock.visible = true;
 
55
        }
 
56
 
 
57
        // Test that the date portion of the clock updates with custom value.
 
58
        // Time portion is controlled by indicators
 
59
        function test_updateDate() {
 
60
            var dateLabel = findChild(clock, "dateLabel");
 
61
            var timeLabel = findChild(clock, "timeLabel");
 
62
 
 
63
            var timeString = Qt.formatTime(new Date("October 13, 1975 12:14:00"));
 
64
 
 
65
            // initial date.
 
66
            var dateObj = new Date("October 13, 1975 11:13:00");
 
67
            var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate);
 
68
            clock.currentDate = dateObj;
 
69
 
 
70
            compare(dateLabel.text, dateString, "Not the expected date");
 
71
            compare(timeLabel.text, timeString, "Time should come from indicators");
 
72
 
 
73
            // update date.
 
74
            var dateObj2 = new Date("October 14, 1976 13:15:00");
 
75
            var dateString2 = Qt.formatDate(dateObj2, Qt.DefaultLocaleLongDate);
 
76
            clock.currentDate = dateObj2;
 
77
 
 
78
            compare(dateLabel.text, dateString2, "Not the expected date");
 
79
            compare(timeLabel.text,timeString, "Time should come from indicators");
 
80
        }
 
81
 
 
82
        // Test that the date portion of the clock updates with custom value.
 
83
        // Time portion is controlled by indicators
 
84
        function test_updateTime() {
 
85
            var timeLabel = findChild(clock, "timeLabel");
 
86
 
 
87
            var timeString1 = Qt.formatTime(new Date("October 13, 1975 11:15:00"));
 
88
            var timeString2 = Qt.formatTime(new Date("October 14, 1976 12:16:00"));
 
89
 
 
90
            updateDatetimeModelTime(timeString1);
 
91
            compare(timeLabel.text, timeString1, "Time should come from indicators");
 
92
 
 
93
            updateDatetimeModelTime(timeString2);
 
94
            compare(timeLabel.text, timeString2, "Time should come from indicators");
 
95
        }
 
96
 
 
97
        function test_indicatorDisconnect() {
74
98
            clock.visible = false
75
99
            var timeModel = findInvisibleChild(clock, "timeModel")
76
 
 
77
100
            compare(timeModel.menuObjectPath, "", "Clock shouldn't be connected to Indicators when not visible.")
78
101
 
79
 
            clock.currentDate = dateObj
80
 
 
81
 
            var dateLabel = findChild(clock, "dateLabel")
82
 
            compare(dateLabel.text, dateString, "Not the expected date")
83
 
            var timeLabel = findChild(clock, "timeLabel")
84
 
            compare(timeLabel.text, timeString, "Not the expected time")
85
 
 
86
102
            clock.visible = true
87
 
 
88
 
            verify(timeModel.menuObjectPath != "", "Should be connected to Indicators.")
 
103
            verify(timeModel.menuObjectPath !== "", "Should be connected to Indicators.")
89
104
        }
90
105
    }
91
106
}