@@ -19,7 +19,7 @@ import QtTest 1.0
1919import ".."
2020import "../../../qml/Greeter"
2121import Ubuntu.Components 0.1
22−import QMenuModel 0.1
22+import Unity.Indicators 0.1 as Indicators
2323import Unity.Test 0.1 as UT
2424
2525Rectangle {
@@ -36,56 +36,73 @@ Rectangle {
3636 }
3737 }
3838
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",
41+ "/com/canonical/indicator/datetime/phone",
42+ "/com/canonical/indicator/datetime",
43+ [{
44+ "rowData": {
45+ "actionState": { "label": label }
46+ }
47+ }]);
4648 }
4749
4850 UT.UnityTestCase {
4951 name: "Clock"
52+ when: windowShown
5053
5154 function init() {
52− var cachedModel = findChild(clock, "timeModel");
53− verify(cachedModel !== undefined);
54− cachedModel.model = menuModel;
55+ updateDatetimeModelTime(Qt.formatTime(new Date("October 13, 1975 12:14:00")));
56+ clock.visible = true;
5557 }
5658
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)
59+ // Test that the date portion of the clock updates with custom value.
60+ // Time portion is controlled by indicators
61+ function test_updateDate() {
62+ var dateLabel = findChild(clock, "dateLabel");
63+ var timeLabel = findChild(clock, "timeLabel");
6164
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")
65+ var timeString = Qt.formatTime(new Date("October 13, 1975 12:14:00"));
66+
67+ // initial date.
68+ var dateObj = new Date("October 13, 1975 11:13:00");
69+ var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate);
70+ clock.currentDate = dateObj;
71+
72+ compare(dateLabel.text, dateString, "Not the expected date");
73+ compare(timeLabel.text, timeString, "Time should come from indicators");
74+
75+ // update date.
76+ var dateObj2 = new Date("October 14, 1976 13:15:00");
77+ var dateString2 = Qt.formatDate(dateObj2, Qt.DefaultLocaleLongDate);
78+ clock.currentDate = dateObj2;
79+
80+ compare(dateLabel.text, dateString2, "Not the expected date");
81+ compare(timeLabel.text,timeString, "Time should come from indicators");
6782 }
6883
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)
84+ // Test that the date portion of the clock updates with custom value.
85+ // Time portion is controlled by indicators
86+ function test_updateTime() {
87+ var timeLabel = findChild(clock, "timeLabel");
7388
74− clock.visible = false
75− var timeModel = findInvisibleChild(clock, "timeModel")
89+ var timeString1 = Qt.formatTime(new Date("October 13, 1975 11:15:00"));
90+ var timeString2 = Qt.formatTime(new Date("October 14, 1976 12:16:00"));
7691
77− compare(timeModel.menuObjectPath, "", "Clock shouldn't be connected to Indicators when not visible.")
92+ updateDatetimeModelTime(timeString1);
93+ compare(timeLabel.text, timeString1, "Time should come from indicators");
7894
79− clock.currentDate = dateObj
95+ updateDatetimeModelTime(timeString2);
96+ compare(timeLabel.text, timeString2, "Time should come from indicators");
97+ }
8098
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")
99+ function test_indicatorDisconnect() {
100+ clock.visible = false
101+ var timeModel = findInvisibleChild(clock, "timeModel")
102+ compare(timeModel.menuObjectPath, "", "Clock shouldn't be connected to Indicators when not visible.")
85103
86104 clock.visible = true
87−
88− verify(timeModel.menuObjectPath != "", "Should be connected to Indicators.")
105+ verify(timeModel.menuObjectPath !== "", "Should be connected to Indicators.")
89106 }
90107 }
91108}