|
1 | | -describe('TzDate', function() { |
| 1 | +describe('mocks', function(){ |
| 2 | + describe('TzDate', function() { |
2 | 3 |
|
3 | | - function minutes(min) { |
4 | | - return min*60*1000; |
5 | | - } |
| 4 | + function minutes(min) { |
| 5 | + return min*60*1000; |
| 6 | + } |
6 | 7 |
|
7 | | - it('should take millis as constructor argument', function() { |
8 | | - expect(new TzDate(0, 0).getTime()).toBe(0); |
9 | | - expect(new TzDate(0, 1283555108000).getTime()).toBe(1283555108000); |
10 | | - }); |
11 | | - |
12 | | - it('should take dateString as constructor argument', function() { |
13 | | - expect(new TzDate(0, '1970-01-01T00:00:00.000Z').getTime()).toBe(0); |
14 | | - expect(new TzDate(0, '2010-09-03T23:05:08.023Z').getTime()).toBe(1283555108023); |
15 | | - }); |
16 | | - |
17 | | - |
18 | | - it('should fake getLocalDateString method', function() { |
19 | | - //0 in -3h |
20 | | - var t0 = new TzDate(-3, 0); |
21 | | - expect(t0.toLocaleDateString()).toMatch('1970'); |
22 | | - |
23 | | - //0 in +0h |
24 | | - var t1 = new TzDate(0, 0); |
25 | | - expect(t1.toLocaleDateString()).toMatch('1970'); |
26 | | - |
27 | | - //0 in +3h |
28 | | - var t2 = new TzDate(3, 0); |
29 | | - expect(t2.toLocaleDateString()).toMatch('1969'); |
30 | | - }); |
31 | | - |
32 | | - |
33 | | - it('should fake getHours method', function() { |
34 | | - //0 in -3h |
35 | | - var t0 = new TzDate(-3, 0); |
36 | | - expect(t0.getHours()).toBe(3); |
37 | | - |
38 | | - //0 in +0h |
39 | | - var t1 = new TzDate(0, 0); |
40 | | - expect(t1.getHours()).toBe(0); |
41 | | - |
42 | | - //0 in +3h |
43 | | - var t2 = new TzDate(3, 0); |
44 | | - expect(t2.getHours()).toMatch(21); |
45 | | - }); |
46 | | - |
47 | | - |
48 | | - it('should fake getMinutes method', function() { |
49 | | - //0:15 in -3h |
50 | | - var t0 = new TzDate(-3, minutes(15)); |
51 | | - expect(t0.getMinutes()).toBe(15); |
52 | | - |
53 | | - //0:15 in -3.25h |
54 | | - var t0a = new TzDate(-3.25, minutes(15)); |
55 | | - expect(t0a.getMinutes()).toBe(30); |
56 | | - |
57 | | - //0 in +0h |
58 | | - var t1 = new TzDate(0, minutes(0)); |
59 | | - expect(t1.getMinutes()).toBe(0); |
60 | | - |
61 | | - //0:15 in +0h |
62 | | - var t1a = new TzDate(0, minutes(15)); |
63 | | - expect(t1a.getMinutes()).toBe(15); |
| 8 | + it('should take millis as constructor argument', function() { |
| 9 | + expect(new TzDate(0, 0).getTime()).toBe(0); |
| 10 | + expect(new TzDate(0, 1283555108000).getTime()).toBe(1283555108000); |
| 11 | + }); |
64 | 12 |
|
65 | | - //0:15 in +3h |
66 | | - var t2 = new TzDate(3, minutes(15)); |
67 | | - expect(t2.getMinutes()).toMatch(15); |
| 13 | + it('should take dateString as constructor argument', function() { |
| 14 | + expect(new TzDate(0, '1970-01-01T00:00:00.000Z').getTime()).toBe(0); |
| 15 | + expect(new TzDate(0, '2010-09-03T23:05:08.023Z').getTime()).toBe(1283555108023); |
| 16 | + }); |
| 17 | + |
| 18 | + |
| 19 | + it('should fake getLocalDateString method', function() { |
| 20 | + //0 in -3h |
| 21 | + var t0 = new TzDate(-3, 0); |
| 22 | + expect(t0.toLocaleDateString()).toMatch('1970'); |
68 | 23 |
|
69 | | - //0:15 in +3.25h |
70 | | - var t2a = new TzDate(3.25, minutes(15)); |
71 | | - expect(t2a.getMinutes()).toMatch(0); |
| 24 | + //0 in +0h |
| 25 | + var t1 = new TzDate(0, 0); |
| 26 | + expect(t1.toLocaleDateString()).toMatch('1970'); |
| 27 | + |
| 28 | + //0 in +3h |
| 29 | + var t2 = new TzDate(3, 0); |
| 30 | + expect(t2.toLocaleDateString()).toMatch('1969'); |
| 31 | + }); |
| 32 | + |
| 33 | + |
| 34 | + it('should fake getHours method', function() { |
| 35 | + //0 in -3h |
| 36 | + var t0 = new TzDate(-3, 0); |
| 37 | + expect(t0.getHours()).toBe(3); |
| 38 | + |
| 39 | + //0 in +0h |
| 40 | + var t1 = new TzDate(0, 0); |
| 41 | + expect(t1.getHours()).toBe(0); |
| 42 | + |
| 43 | + //0 in +3h |
| 44 | + var t2 = new TzDate(3, 0); |
| 45 | + expect(t2.getHours()).toMatch(21); |
| 46 | + }); |
| 47 | + |
| 48 | + |
| 49 | + it('should fake getMinutes method', function() { |
| 50 | + //0:15 in -3h |
| 51 | + var t0 = new TzDate(-3, minutes(15)); |
| 52 | + expect(t0.getMinutes()).toBe(15); |
| 53 | + |
| 54 | + //0:15 in -3.25h |
| 55 | + var t0a = new TzDate(-3.25, minutes(15)); |
| 56 | + expect(t0a.getMinutes()).toBe(30); |
| 57 | + |
| 58 | + //0 in +0h |
| 59 | + var t1 = new TzDate(0, minutes(0)); |
| 60 | + expect(t1.getMinutes()).toBe(0); |
| 61 | + |
| 62 | + //0:15 in +0h |
| 63 | + var t1a = new TzDate(0, minutes(15)); |
| 64 | + expect(t1a.getMinutes()).toBe(15); |
| 65 | + |
| 66 | + //0:15 in +3h |
| 67 | + var t2 = new TzDate(3, minutes(15)); |
| 68 | + expect(t2.getMinutes()).toMatch(15); |
| 69 | + |
| 70 | + //0:15 in +3.25h |
| 71 | + var t2a = new TzDate(3.25, minutes(15)); |
| 72 | + expect(t2a.getMinutes()).toMatch(0); |
| 73 | + }); |
| 74 | + |
| 75 | + |
| 76 | + it('should fake getSeconds method', function() { |
| 77 | + //0 in -3h |
| 78 | + var t0 = new TzDate(-3, 0); |
| 79 | + expect(t0.getSeconds()).toBe(0); |
| 80 | + |
| 81 | + //0 in +0h |
| 82 | + var t1 = new TzDate(0, 0); |
| 83 | + expect(t1.getSeconds()).toBe(0); |
| 84 | + |
| 85 | + //0 in +3h |
| 86 | + var t2 = new TzDate(3, 0); |
| 87 | + expect(t2.getSeconds()).toMatch(0); |
| 88 | + }); |
| 89 | + |
| 90 | + |
| 91 | + it('should create a date representing new year in Bratislava', function() { |
| 92 | + var newYearInBratislava = new TzDate(-1, '2009-12-31T23:00:00.000Z'); |
| 93 | + expect(newYearInBratislava.getTimezoneOffset()).toBe(-60); |
| 94 | + expect(newYearInBratislava.getFullYear()).toBe(2010); |
| 95 | + expect(newYearInBratislava.getMonth()).toBe(0); |
| 96 | + expect(newYearInBratislava.getDate()).toBe(1); |
| 97 | + expect(newYearInBratislava.getHours()).toBe(0); |
| 98 | + expect(newYearInBratislava.getMinutes()).toBe(0); |
| 99 | + }); |
| 100 | + |
| 101 | + |
| 102 | + it('should delegate all the UTC methods to the original UTC Date object', function() { |
| 103 | + //from when created from string |
| 104 | + var date1 = new TzDate(-1, '2009-12-31T23:00:00.000Z'); |
| 105 | + expect(date1.getUTCFullYear()).toBe(2009); |
| 106 | + expect(date1.getUTCMonth()).toBe(11); |
| 107 | + expect(date1.getUTCDate()).toBe(31); |
| 108 | + expect(date1.getUTCHours()).toBe(23); |
| 109 | + expect(date1.getUTCMinutes()).toBe(0); |
| 110 | + expect(date1.getUTCSeconds()).toBe(0); |
| 111 | + |
| 112 | + |
| 113 | + //from when created from millis |
| 114 | + var date2 = new TzDate(-1, angular.String.toDate('2009-12-31T23:00:00.000Z').getTime()); |
| 115 | + expect(date2.getUTCFullYear()).toBe(2009); |
| 116 | + expect(date2.getUTCMonth()).toBe(11); |
| 117 | + expect(date2.getUTCDate()).toBe(31); |
| 118 | + expect(date2.getUTCHours()).toBe(23); |
| 119 | + expect(date2.getUTCMinutes()).toBe(0); |
| 120 | + expect(date2.getUTCSeconds()).toBe(0); |
| 121 | + }); |
| 122 | + }); |
| 123 | + |
| 124 | + describe('$log mock', function() { |
| 125 | + var $log; |
| 126 | + beforeEach(function() { |
| 127 | + $log = MockLogFactory(); |
| 128 | + }); |
| 129 | + |
| 130 | + it('should provide log method', function() { |
| 131 | + expect(function() { $log.log(''); }).not.toThrow(); |
| 132 | + }); |
| 133 | + |
| 134 | + it('should provide info method', function() { |
| 135 | + expect(function() { $log.info(''); }).not.toThrow(); |
| 136 | + }); |
| 137 | + |
| 138 | + it('should provide warn method', function() { |
| 139 | + expect(function() { $log.warn(''); }).not.toThrow(); |
| 140 | + }); |
| 141 | + |
| 142 | + it('should provide error method', function() { |
| 143 | + expect(function() { $log.error(''); }).not.toThrow(); |
| 144 | + }); |
| 145 | + |
| 146 | + it('should store log messages', function() { |
| 147 | + $log.log('fake log'); |
| 148 | + expect($log.log.logs).toContain(['fake log']); |
| 149 | + }); |
| 150 | + |
| 151 | + it('should store info messages', function() { |
| 152 | + $log.info('fake log'); |
| 153 | + expect($log.info.logs).toContain(['fake log']); |
| 154 | + }); |
| 155 | + |
| 156 | + it('should store warn messages', function() { |
| 157 | + $log.warn('fake log'); |
| 158 | + expect($log.warn.logs).toContain(['fake log']); |
| 159 | + }); |
| 160 | + |
| 161 | + it('should store error messages', function() { |
| 162 | + $log.error('fake log'); |
| 163 | + expect($log.error.logs).toContain(['fake log']); |
| 164 | + }); |
| 165 | + }); |
| 166 | + |
| 167 | + describe('defer', function(){ |
| 168 | + var browser, log; |
| 169 | + beforeEach(function(){ |
| 170 | + browser = new MockBrowser(); |
| 171 | + log = ''; |
| 172 | + }); |
| 173 | + |
| 174 | + function logFn(text){ return function(){ |
| 175 | + log += text +';'; |
| 176 | + }; |
| 177 | + } |
| 178 | + |
| 179 | + it('should flush', function(){ |
| 180 | + browser.defer(logFn('A')); |
| 181 | + expect(log).toEqual(''); |
| 182 | + browser.defer.flush(); |
| 183 | + expect(log).toEqual('A;'); |
| 184 | + }); |
| 185 | + |
| 186 | + it('should flush delayed', function(){ |
| 187 | + browser.defer(logFn('A')); |
| 188 | + browser.defer(logFn('B'), 10); |
| 189 | + browser.defer(logFn('C'), 20); |
| 190 | + expect(log).toEqual(''); |
| 191 | + |
| 192 | + expect(browser.defer.now).toEqual(0); |
| 193 | + browser.defer.flush(); |
| 194 | + browser.defer.flush(); |
| 195 | + expect(log).toEqual('A;'); |
| 196 | + |
| 197 | + browser.defer.flush(10); |
| 198 | + expect(browser.defer.now).toEqual(10); |
| 199 | + expect(log).toEqual('A;B;'); |
| 200 | + |
| 201 | + browser.defer.flush(10); |
| 202 | + expect(browser.defer.now).toEqual(20); |
| 203 | + expect(log).toEqual('A;B;C;'); |
| 204 | + |
| 205 | + }); |
72 | 206 | }); |
73 | 207 |
|
74 | | - |
75 | | - it('should fake getSeconds method', function() { |
76 | | - //0 in -3h |
77 | | - var t0 = new TzDate(-3, 0); |
78 | | - expect(t0.getSeconds()).toBe(0); |
79 | | - |
80 | | - //0 in +0h |
81 | | - var t1 = new TzDate(0, 0); |
82 | | - expect(t1.getSeconds()).toBe(0); |
83 | | - |
84 | | - //0 in +3h |
85 | | - var t2 = new TzDate(3, 0); |
86 | | - expect(t2.getSeconds()).toMatch(0); |
87 | | - }); |
88 | | - |
89 | | - |
90 | | - it('should create a date representing new year in Bratislava', function() { |
91 | | - var newYearInBratislava = new TzDate(-1, '2009-12-31T23:00:00.000Z'); |
92 | | - expect(newYearInBratislava.getTimezoneOffset()).toBe(-60); |
93 | | - expect(newYearInBratislava.getFullYear()).toBe(2010); |
94 | | - expect(newYearInBratislava.getMonth()).toBe(0); |
95 | | - expect(newYearInBratislava.getDate()).toBe(1); |
96 | | - expect(newYearInBratislava.getHours()).toBe(0); |
97 | | - expect(newYearInBratislava.getMinutes()).toBe(0); |
98 | | - }); |
99 | | - |
100 | | - |
101 | | - it('should delegate all the UTC methods to the original UTC Date object', function() { |
102 | | - //from when created from string |
103 | | - var date1 = new TzDate(-1, '2009-12-31T23:00:00.000Z'); |
104 | | - expect(date1.getUTCFullYear()).toBe(2009); |
105 | | - expect(date1.getUTCMonth()).toBe(11); |
106 | | - expect(date1.getUTCDate()).toBe(31); |
107 | | - expect(date1.getUTCHours()).toBe(23); |
108 | | - expect(date1.getUTCMinutes()).toBe(0); |
109 | | - expect(date1.getUTCSeconds()).toBe(0); |
110 | | - |
111 | | - |
112 | | - //from when created from millis |
113 | | - var date2 = new TzDate(-1, angular.String.toDate('2009-12-31T23:00:00.000Z').getTime()); |
114 | | - expect(date2.getUTCFullYear()).toBe(2009); |
115 | | - expect(date2.getUTCMonth()).toBe(11); |
116 | | - expect(date2.getUTCDate()).toBe(31); |
117 | | - expect(date2.getUTCHours()).toBe(23); |
118 | | - expect(date2.getUTCMinutes()).toBe(0); |
119 | | - expect(date2.getUTCSeconds()).toBe(0); |
120 | | - }); |
121 | | -}); |
122 | | - |
123 | | -describe('$log mock', function() { |
124 | | - var $log; |
125 | | - beforeEach(function() { |
126 | | - $log = MockLogFactory(); |
127 | | - }); |
128 | | - |
129 | | - it('should provide log method', function() { |
130 | | - expect(function() { $log.log(''); }).not.toThrow(); |
131 | | - }); |
132 | | - |
133 | | - it('should provide info method', function() { |
134 | | - expect(function() { $log.info(''); }).not.toThrow(); |
135 | | - }); |
136 | | - |
137 | | - it('should provide warn method', function() { |
138 | | - expect(function() { $log.warn(''); }).not.toThrow(); |
139 | | - }); |
140 | | - |
141 | | - it('should provide error method', function() { |
142 | | - expect(function() { $log.error(''); }).not.toThrow(); |
143 | | - }); |
144 | | - |
145 | | - it('should store log messages', function() { |
146 | | - $log.log('fake log'); |
147 | | - expect($log.log.logs).toContain(['fake log']); |
148 | | - }); |
149 | | - |
150 | | - it('should store info messages', function() { |
151 | | - $log.info('fake log'); |
152 | | - expect($log.info.logs).toContain(['fake log']); |
153 | | - }); |
154 | | - |
155 | | - it('should store warn messages', function() { |
156 | | - $log.warn('fake log'); |
157 | | - expect($log.warn.logs).toContain(['fake log']); |
158 | | - }); |
159 | | - |
160 | | - it('should store error messages', function() { |
161 | | - $log.error('fake log'); |
162 | | - expect($log.error.logs).toContain(['fake log']); |
163 | | - }); |
164 | 208 | }); |
0 commit comments