~nick-dedekind/ubuntu-settings-components/bluetooth-menu

« back to all changes in this revision

Viewing changes to tests/qmltests/tst_Calendar.qml

  • Committer: Tarmac
  • Author(s): Nick Dedekind
  • Date: 2013-10-04 09:14:39 UTC
  • mfrom: (49.1.11 usc)
  • Revision ID: tarmac-20131004091439-bj4ts24iv1kmm7a7
Reworked directory, qml and resources into a more workable structure for release.

Approved by Andrea Cimitan, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import QtQuick 2.0
20
20
import QtTest 1.0
21
21
import Ubuntu.Components 0.1
22
 
import "../../SettingsComponents/Calendar"
 
22
import Ubuntu.Settings.Components 0.1
23
23
import "utils.js" as UtilsJS
24
24
 
25
25
Item {
26
26
    width: units.gu(42)
27
27
    height: units.gu(75)
28
28
 
29
 
    property var date1: new Date(2012, 3, 10)
30
 
    property var date2: new Date(2013, 3, 10)
31
 
    property var date3: new Date(2013, 4, 10)
32
 
    property var date4: new Date(2013, 4, 10)
33
 
    property var date5: new Date(2013, 5, 10)
34
 
    property var date6: new Date(2014, 5, 10)
35
 
 
36
29
    Label {
37
30
        id: label
38
31
        anchors {
54
47
            right: parent.right
55
48
            top: label.bottom
56
49
        }
57
 
        maximumDate: new Date(2013, 6, 10)
58
 
        minimumDate: new Date(2013, 2, 10)
59
 
        selectedDate: new Date(2013, 4, 10)
 
50
 
 
51
        selectedDate: new Date()
60
52
    }
61
53
 
62
54
    TestCase {
63
55
        name: "Calendar"
64
56
        when: windowShown
65
57
 
 
58
        function init() {
 
59
            calendar.selectedDate = new Date(2013, 4, 10);
 
60
            calendar.maximumDate = undefined;
 
61
            calendar.minimumDate = undefined;
 
62
        }
 
63
 
66
64
        function test_collapsed() {
67
 
            calendar.collapsed = true
68
 
            compare(calendar.interactive, false, "Calendar should not be interactive")
69
 
            var collapsedHeight = calendar.height
70
 
            calendar.collapsed = false
71
 
            verify(calendar.height > collapsedHeight * 4 && calendar.height < collapsedHeight * 6, "Height did not expand properly")
72
 
            compare(calendar.interactive, true, "Calendar should be interactive")
 
65
            calendar.collapsed = true;
 
66
            compare(calendar.interactive, false, "Calendar should not be interactive");
 
67
            var collapsedHeight = calendar.height;
 
68
            calendar.collapsed = false;
 
69
            verify(calendar.height > collapsedHeight * 4 && calendar.height < collapsedHeight * 6, "Height did not expand properly");
 
70
            compare(calendar.interactive, true, "Calendar should be interactive");
73
71
        }
74
72
 
75
 
        function test_currentDate_data() {
 
73
        function test_selectedDate_data() {
76
74
            return [
77
 
                {date: date4},
78
 
                {date: date3},
 
75
                { date: new Date(2010, 4, 10) },
 
76
                { date: new Date() },
 
77
                { date: new Date(2020, 10, 31)},
79
78
            ];
80
79
        }
81
80
 
82
 
        function test_currentDate(data) {
83
 
            calendar.currentDate = data.date
84
 
            compare(calendar.currentItem.monthStart.getMonth(), data.date.getMonth(), "currentItem did not change")
 
81
        function test_selectedDate(data) {
 
82
            calendar.selectedDate = data.date;
 
83
            compare(calendar.currentItem.monthStart.getYear(), data.date.getYear(), "Current year does no correspond to set date");
 
84
            compare(calendar.currentItem.monthStart.getMonth(), data.date.getMonth(), "Current month does no correspond to set date");
85
85
        }
86
86
 
87
87
        function test_firstDayOfWeek_data() {
88
88
            return [
89
 
                {tag: 'Thursday', firstDayOfWeek: 5, item1: 6},
90
 
                {tag: 'Sunday', firstDayOfWeek: 0, item1: 1},
 
89
                {tag: 'Thursday', firstDayOfWeek: 5},
 
90
                {tag: 'Sunday', firstDayOfWeek: 0},
91
91
            ];
92
92
        }
93
93
 
94
94
        function test_firstDayOfWeek(data) {
95
 
            var dayItem1 = UtilsJS.findChild(calendar, "dayItem1")
96
 
 
97
 
            calendar.firstDayOfWeek = data.firstDayOfWeek
98
 
            compare(dayItem1.dayStart.getDay(), data.item1, "Cannot set firstDayOfWeek")
99
 
        }
100
 
 
101
 
        function test_maximumDate_data() {
102
 
            return [
103
 
                {date: date6, count: 5},
104
 
                {date: date5, count: 4},
105
 
            ];
106
 
        }
107
 
 
108
 
        function test_maximumDate(data) {
109
 
            calendar.maximumDate = data.date
110
 
            compare(calendar.count, data.count, "The number of months should have changed")
111
 
        }
112
 
 
113
 
        function test_minimumDate_data() {
114
 
            return [
115
 
                {date: date1, count: 4},
116
 
                {date: date2, count: 3},
117
 
            ];
118
 
        }
119
 
 
120
 
        function test_minimumDate(data) {
121
 
            calendar.minimumDate = data.date
122
 
            compare(calendar.count, data.count, "The number of months should have changed")
123
 
        }
124
 
 
125
 
        function test_selectedDate_data() {
126
 
            return [
127
 
                {date: date4},
128
 
                {date: date3},
129
 
            ];
130
 
        }
131
 
 
132
 
        function test_selectedDate(data) {
133
 
            calendar.selectedDate = data.date
134
 
            compare(calendar.currentItem.monthStart.getMonth(), data.date.getMonth(), "currentItem did not change")
 
95
            calendar.firstDayOfWeek = data.firstDayOfWeek;
 
96
 
 
97
            for (var i = 0; i < (6*7); i++) {
 
98
                var dayColumn = UtilsJS.findChild(calendar, "dayItem" + i);
 
99
                verify(dayColumn);
 
100
 
 
101
                compare(dayColumn.dayStart.getDay(), (data.firstDayOfWeek + i)%7, "Day column does not match expected for firstDayOfWeek");
 
102
            }
 
103
        }
 
104
 
 
105
        function test_minMaxDate_data() {
 
106
            return [
 
107
                {tag: "undefined", date: new Date(), minDate: undefined, maxDate: undefined, count: 5}, // max out at +-2
 
108
                {tag: "Min=-0", date: new Date(), minDate: new Date(), maxDate: undefined, count: 3},
 
109
                {tag: "Min=-1", date: new Date(), minDate: new Date().addMonths(-1), maxDate: undefined, count: 4},
 
110
                {tag: "Min=-22", date: new Date(), minDate: new Date().addMonths(-22), maxDate: undefined, count: 5}, // max out at +-2
 
111
 
 
112
                {tag: "Max=+0", date: new Date(), minDate: undefined, maxDate: new Date(), count: 3},
 
113
                {tag: "Max=+1", date: new Date(), minDate: undefined, maxDate: new Date().addMonths(1), count: 4},
 
114
                {tag: "Max=+22", date: new Date(), minDate: undefined, maxDate: new Date().addMonths(22), count: 5}, // max out at +-2
 
115
 
 
116
                {tag: "Min=-0,Max=+0", date: new Date(), minDate: new Date(), maxDate: new Date(), count: 1},
 
117
                {tag: "Min=-1,Max=+1", date: new Date(), minDate: new Date().addMonths(-1), maxDate: new Date().addMonths(1), count: 3},
 
118
                {tag: "Min=-22,Max=+1", date: new Date(), minDate: new Date().addMonths(-22), maxDate: new Date().addMonths(1), count: 4}, // max out at +-2
 
119
                {tag: "Min=-1,Max=+22", date: new Date(), minDate: new Date().addMonths(-1), maxDate: new Date().addMonths(22), count: 4}, // max out at +-2
 
120
                {tag: "Min=-22,Max=+22", date: new Date(), minDate: new Date().addMonths(-22), maxDate: new Date().addMonths(22), count: 5}, // max out at +-2
 
121
            ];
 
122
        }
 
123
 
 
124
        function test_minMaxDate(data) {
 
125
            calendar.selectedDate = data.date;
 
126
            calendar.minimumDate = data.minDate;
 
127
            calendar.maximumDate = data.maxDate;
 
128
            compare(calendar.count, data.count, "The number of months should have changed");
135
129
        }
136
130
    }
137
131
}