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