@@ -34,6 +34,26 @@ module('Integration | Component | dashboard/week', function (hooks) {
34
34
35
35
return expectedTitle ;
36
36
} ;
37
+
38
+ this . setupEvents = function ( events ) {
39
+ class UserEvents extends Service {
40
+ async getEvents ( ) {
41
+ return events ;
42
+ }
43
+ }
44
+ this . owner . register ( 'service:user-events' , UserEvents ) ;
45
+ } ;
46
+
47
+ this . testTitleOnDate = async function ( assert , obj , expectedTitle ) {
48
+ const dt = DateTime . fromObject ( obj ) ;
49
+ freezeDateAt ( dt . toJSDate ( ) ) ;
50
+ await render ( hbs `<Dashboard::Week />` ) ;
51
+ assert . strictEqual (
52
+ component . weekGlance . title ,
53
+ expectedTitle ,
54
+ `correct title on ${ dt . toISODate ( ) } ` ,
55
+ ) ;
56
+ } ;
37
57
} ) ;
38
58
39
59
hooks . afterEach ( ( ) => {
@@ -75,12 +95,7 @@ module('Integration | Component | dashboard/week', function (hooks) {
75
95
} ) ;
76
96
77
97
const { userevents } = this . server . db ;
78
- class UserEvents extends Service {
79
- async getEvents ( ) {
80
- return userevents ;
81
- }
82
- }
83
- this . owner . register ( 'service:user-events' , UserEvents ) ;
98
+ this . setupEvents ( userevents ) ;
84
99
85
100
await render ( hbs `<Dashboard::Week />` ) ;
86
101
const expectedTitle = this . getTitle ( ) ;
@@ -92,14 +107,7 @@ module('Integration | Component | dashboard/week', function (hooks) {
92
107
} ) ;
93
108
94
109
test ( 'it renders blank' , async function ( assert ) {
95
- class UserEvents extends Service {
96
- async getEvents ( ) {
97
- return [ ] ;
98
- }
99
- }
100
- this . owner . register ( 'service:user-events' , UserEvents ) ;
101
- this . userEvents = this . owner . lookup ( 'service:user-events' ) ;
102
-
110
+ this . setupEvents ( [ ] ) ;
103
111
await render ( hbs `<Dashboard::Week />` ) ;
104
112
const expectedTitle = this . getTitle ( ) ;
105
113
assert . strictEqual ( component . weeklyLink , 'All Weeks' ) ;
@@ -108,95 +116,114 @@ module('Integration | Component | dashboard/week', function (hooks) {
108
116
} ) ;
109
117
110
118
test ( 'right week on sunday #5308' , async function ( assert ) {
111
- class UserEvents extends Service {
112
- async getEvents ( ) {
113
- return [ ] ;
114
- }
115
- }
116
- this . owner . register ( 'service:user-events' , UserEvents ) ;
117
- this . userEvents = this . owner . lookup ( 'service:user-events' ) ;
118
- freezeDateAt ( DateTime . fromObject ( { year : 2024 , month : 3 , day : 10 } ) . toJSDate ( ) ) ;
119
-
120
- await render ( hbs `<Dashboard::Week />` ) ;
121
- assert . strictEqual ( component . weekGlance . title , 'March 10-16 Week at a Glance' ) ;
119
+ assert . expect ( 1 ) ;
120
+ await this . testTitleOnDate (
121
+ assert ,
122
+ { year : 2024 , month : 3 , day : 10 } ,
123
+ 'March 10-16 Week at a Glance' ,
124
+ ) ;
122
125
} ) ;
123
126
124
127
test ( 'right week on monday #5308' , async function ( assert ) {
125
- class UserEvents extends Service {
126
- async getEvents ( ) {
127
- return [ ] ;
128
- }
129
- }
130
- this . owner . register ( 'service:user-events' , UserEvents ) ;
131
- this . userEvents = this . owner . lookup ( 'service:user-events' ) ;
132
- freezeDateAt ( DateTime . fromObject ( { year : 2023 , month : 8 , day : 7 } ) . toJSDate ( ) ) ;
133
-
134
- await render ( hbs `<Dashboard::Week />` ) ;
135
- assert . strictEqual ( component . weekGlance . title , 'August 6-12 Week at a Glance' ) ;
128
+ assert . expect ( 1 ) ;
129
+ await this . testTitleOnDate (
130
+ assert ,
131
+ { year : 2023 , month : 8 , day : 7 } ,
132
+ 'August 6-12 Week at a Glance' ,
133
+ ) ;
136
134
} ) ;
137
135
138
136
test ( 'right week on tuesday #5308' , async function ( assert ) {
139
- class UserEvents extends Service {
140
- async getEvents ( ) {
141
- return [ ] ;
142
- }
143
- }
144
- this . owner . register ( 'service:user-events' , UserEvents ) ;
145
- this . userEvents = this . owner . lookup ( 'service:user-events' ) ;
146
- freezeDateAt ( DateTime . fromObject ( { year : 2022 , month : 12 , day : 6 } ) . toJSDate ( ) ) ;
147
- await render ( hbs `<Dashboard::Week />` ) ;
148
- assert . strictEqual ( component . weekGlance . title , 'December 4-10 Week at a Glance' ) ;
137
+ assert . expect ( 1 ) ;
138
+ await this . testTitleOnDate (
139
+ assert ,
140
+ { year : 2022 , month : 12 , day : 6 } ,
141
+ 'December 4-10 Week at a Glance' ,
142
+ ) ;
149
143
} ) ;
150
144
151
145
test ( 'right week on wednesday #5308' , async function ( assert ) {
152
- class UserEvents extends Service {
153
- async getEvents ( ) {
154
- return [ ] ;
155
- }
156
- }
157
- this . owner . register ( 'service:user-events' , UserEvents ) ;
158
- this . userEvents = this . owner . lookup ( 'service:user-events' ) ;
159
- freezeDateAt ( DateTime . fromObject ( { year : 2022 , month : 7 , day : 13 } ) . toJSDate ( ) ) ;
160
- await render ( hbs `<Dashboard::Week />` ) ;
161
- assert . strictEqual ( component . weekGlance . title , 'July 10-16 Week at a Glance' ) ;
146
+ assert . expect ( 1 ) ;
147
+ await this . testTitleOnDate (
148
+ assert ,
149
+ { year : 2022 , month : 7 , day : 13 } ,
150
+ 'July 10-16 Week at a Glance' ,
151
+ ) ;
162
152
} ) ;
163
153
164
154
test ( 'right week on thursday #5308' , async function ( assert ) {
165
- class UserEvents extends Service {
166
- async getEvents ( ) {
167
- return [ ] ;
168
- }
169
- }
170
- this . owner . register ( 'service:user-events' , UserEvents ) ;
171
- this . userEvents = this . owner . lookup ( 'service:user-events' ) ;
172
- freezeDateAt ( DateTime . fromObject ( { year : 2021 , month : 5 , day : 13 } ) . toJSDate ( ) ) ;
173
- await render ( hbs `<Dashboard::Week />` ) ;
174
- assert . strictEqual ( component . weekGlance . title , 'May 9-15 Week at a Glance' ) ;
155
+ assert . expect ( 1 ) ;
156
+ await this . testTitleOnDate (
157
+ assert ,
158
+ { year : 2021 , month : 5 , day : 13 } ,
159
+ 'May 9-15 Week at a Glance' ,
160
+ ) ;
175
161
} ) ;
176
162
177
163
test ( 'right week on friday #5308' , async function ( assert ) {
178
- class UserEvents extends Service {
179
- async getEvents ( ) {
180
- return [ ] ;
181
- }
182
- }
183
- this . owner . register ( 'service:user-events' , UserEvents ) ;
184
- this . userEvents = this . owner . lookup ( 'service:user-events' ) ;
185
- freezeDateAt ( DateTime . fromObject ( { year : 2021 , month : 9 , day : 24 } ) . toJSDate ( ) ) ;
186
- await render ( hbs `<Dashboard::Week />` ) ;
187
- assert . strictEqual ( component . weekGlance . title , 'September 19-25 Week at a Glance' ) ;
164
+ assert . expect ( 1 ) ;
165
+ await this . testTitleOnDate (
166
+ assert ,
167
+ { year : 2021 , month : 9 , day : 24 } ,
168
+ 'September 19-25 Week at a Glance' ,
169
+ ) ;
188
170
} ) ;
189
171
190
172
test ( 'right week on saturday #5308' , async function ( assert ) {
191
- class UserEvents extends Service {
192
- async getEvents ( ) {
193
- return [ ] ;
194
- }
195
- }
196
- this . owner . register ( 'service:user-events' , UserEvents ) ;
197
- this . userEvents = this . owner . lookup ( 'service:user-events' ) ;
198
- freezeDateAt ( DateTime . fromObject ( { year : 2022 , month : 7 , day : 30 } ) . toJSDate ( ) ) ;
199
- await render ( hbs `<Dashboard::Week />` ) ;
200
- assert . strictEqual ( component . weekGlance . title , 'July 24-30 Week at a Glance' ) ;
173
+ assert . expect ( 1 ) ;
174
+ await this . testTitleOnDate (
175
+ assert ,
176
+ { year : 2022 , month : 7 , day : 30 } ,
177
+ 'July 24-30 Week at a Glance' ,
178
+ ) ;
179
+ } ) ;
180
+
181
+ test ( 'correct at the end of 2023 and the start of 2024' , async function ( assert ) {
182
+ assert . expect ( 7 ) ;
183
+ this . setupEvents ( [ ] ) ;
184
+ const title = 'December 31 - January 6 Week at a Glance' ;
185
+ await this . testTitleOnDate ( assert , { year : 2023 , month : 12 , day : 31 } , title ) ;
186
+ await this . testTitleOnDate ( assert , { year : 2024 , month : 1 , day : 1 } , title ) ;
187
+ await this . testTitleOnDate ( assert , { year : 2024 , month : 1 , day : 2 } , title ) ;
188
+ await this . testTitleOnDate ( assert , { year : 2024 , month : 1 , day : 3 } , title ) ;
189
+ await this . testTitleOnDate ( assert , { year : 2024 , month : 1 , day : 4 } , title ) ;
190
+ await this . testTitleOnDate ( assert , { year : 2024 , month : 1 , day : 5 } , title ) ;
191
+ await this . testTitleOnDate ( assert , { year : 2024 , month : 1 , day : 6 } , title ) ;
192
+ } ) ;
193
+
194
+ test ( 'correct at the end of 2024 and start of 2025' , async function ( assert ) {
195
+ assert . expect ( 7 ) ;
196
+ this . setupEvents ( [ ] ) ;
197
+ const title = 'December 29 - January 4 Week at a Glance' ;
198
+ await this . testTitleOnDate ( assert , { year : 2024 , month : 12 , day : 29 } , title ) ;
199
+ await this . testTitleOnDate ( assert , { year : 2024 , month : 12 , day : 30 } , title ) ;
200
+ await this . testTitleOnDate ( assert , { year : 2024 , month : 12 , day : 31 } , title ) ;
201
+ await this . testTitleOnDate ( assert , { year : 2025 , month : 1 , day : 1 } , title ) ;
202
+ await this . testTitleOnDate ( assert , { year : 2025 , month : 1 , day : 2 } , title ) ;
203
+ await this . testTitleOnDate ( assert , { year : 2025 , month : 1 , day : 3 } , title ) ;
204
+ await this . testTitleOnDate ( assert , { year : 2025 , month : 1 , day : 4 } , title ) ;
205
+ } ) ;
206
+
207
+ test ( 'correct at the end of 2025 and start of 2026' , async function ( assert ) {
208
+ assert . expect ( 7 ) ;
209
+ this . setupEvents ( [ ] ) ;
210
+ const title = 'December 28 - January 3 Week at a Glance' ;
211
+ await this . testTitleOnDate ( assert , { year : 2025 , month : 12 , day : 28 } , title ) ;
212
+ await this . testTitleOnDate ( assert , { year : 2025 , month : 12 , day : 29 } , title ) ;
213
+ await this . testTitleOnDate ( assert , { year : 2025 , month : 12 , day : 30 } , title ) ;
214
+ await this . testTitleOnDate ( assert , { year : 2025 , month : 12 , day : 31 } , title ) ;
215
+ await this . testTitleOnDate ( assert , { year : 2026 , month : 1 , day : 1 } , title ) ;
216
+ await this . testTitleOnDate ( assert , { year : 2026 , month : 1 , day : 2 } , title ) ;
217
+ await this . testTitleOnDate ( assert , { year : 2026 , month : 1 , day : 3 } , title ) ;
218
+ } ) ;
219
+
220
+ test ( 'correct on some random day' , async function ( assert ) {
221
+ assert . expect ( 1 ) ;
222
+ this . setupEvents ( [ ] ) ;
223
+ await this . testTitleOnDate (
224
+ assert ,
225
+ { year : 2005 , month : 6 , day : 24 } ,
226
+ 'June 19-25 Week at a Glance' ,
227
+ ) ;
201
228
} ) ;
202
229
} ) ;
0 commit comments