@@ -7,6 +7,7 @@ import destroyApp from '../helpers/destroy-app'
7
7
import { expect } from 'chai'
8
8
import startApp from '../helpers/start-app'
9
9
import moment from 'moment'
10
+ import formatDuration from 'timed/utils/format-duration'
10
11
11
12
describe ( 'Acceptance | index activities' , function ( ) {
12
13
let application
@@ -204,39 +205,43 @@ describe('Acceptance | index activities', function() {
204
205
expect ( currentURL ( ) ) . to . equal ( '/reports' )
205
206
} )
206
207
207
- it ( 'shows a warning when generating reports from active activities' , async function ( ) {
208
- server . create ( 'activity' , 'active' , { userId : this . user . id } )
208
+ it ( 'shows a warning when generating reports from overlapping activities' , async function ( ) {
209
+ let date = moment ( ) . subtract ( 1 , 'days' )
209
210
210
- await visit ( '/' )
211
+ server . create ( 'activity' , 'active' , { userId : this . user . id , date } )
212
+
213
+ await visit ( `/?day=${ date . format ( 'YYYY-MM-DD' ) } ` )
211
214
212
215
await click ( 'button:contains(Generate timesheet)' )
213
- await click ( '[data-test-active -warning] button:contains(Cancel)' )
216
+ await click ( '[data-test-overlapping -warning] button:contains(Cancel)' )
214
217
215
- expect ( currentURL ( ) ) . to . equal ( '/ ')
218
+ expect ( currentURL ( ) ) . to . not . contain ( 'reports ')
216
219
217
220
await click ( 'button:contains(Generate timesheet)' )
218
- await click ( '[data-test-active -warning] button:contains(fine)' )
221
+ await click ( '[data-test-overlapping -warning] button:contains(fine)' )
219
222
220
- expect ( currentURL ( ) ) . to . equal ( '/ reports')
223
+ expect ( currentURL ( ) ) . to . contain ( ' reports')
221
224
} )
222
225
223
226
it ( 'can handle both warnings' , async function ( ) {
224
- server . create ( 'activity' , 'unknown' , { userId : this . user . id } )
225
- server . create ( 'activity' , 'active' , { userId : this . user . id } )
227
+ let date = moment ( ) . subtract ( 1 , 'days' )
226
228
227
- await visit ( '/' )
229
+ server . create ( 'activity' , 'unknown' , { userId : this . user . id , date } )
230
+ server . create ( 'activity' , 'active' , { userId : this . user . id , date } )
231
+
232
+ await visit ( `/?day=${ date . format ( 'YYYY-MM-DD' ) } ` )
228
233
229
234
// both close if one clicks cancel
230
235
await click ( 'button:contains(Generate timesheet)' )
231
236
expect ( find ( '.modal--visible' ) ) . to . have . length ( 2 )
232
- await click ( '[data-test-active -warning] button:contains(Cancel)' )
237
+ await click ( '[data-test-overlapping -warning] button:contains(Cancel)' )
233
238
expect ( find ( '.modal--visible' ) ) . to . have . length ( 0 )
234
- expect ( currentURL ( ) ) . to . equal ( '/ ')
239
+ expect ( currentURL ( ) ) . to . not . contain ( 'reports ')
235
240
236
241
// both must be fine if it should continue
237
242
await click ( 'button:contains(Generate timesheet)' )
238
243
expect ( find ( '.modal--visible' ) ) . to . have . length ( 2 )
239
- await click ( '[data-test-active -warning] button:contains(fine)' )
244
+ await click ( '[data-test-overlapping -warning] button:contains(fine)' )
240
245
expect ( find ( '.modal--visible' ) ) . to . have . length ( 1 )
241
246
await click ( '[data-test-unknown-warning] button:contains(Cancel)' )
242
247
expect ( find ( '.modal--visible' ) ) . to . have . length ( 0 )
@@ -245,69 +250,120 @@ describe('Acceptance | index activities', function() {
245
250
expect ( find ( '.modal--visible' ) ) . to . have . length ( 2 )
246
251
await click ( '[data-test-unknown-warning] button:contains(fine)' )
247
252
expect ( find ( '.modal--visible' ) ) . to . have . length ( 1 )
248
- await click ( '[data-test-active -warning] button:contains(Cancel)' )
253
+ await click ( '[data-test-overlapping -warning] button:contains(Cancel)' )
249
254
expect ( find ( '.modal--visible' ) ) . to . have . length ( 0 )
250
- expect ( currentURL ( ) ) . to . equal ( '/ ')
255
+ expect ( currentURL ( ) ) . to . not . contain ( 'reports ')
251
256
252
257
// if both are fine continue
253
258
await click ( 'button:contains(Generate timesheet)' )
254
259
expect ( find ( '.modal--visible' ) ) . to . have . length ( 2 )
255
- await click ( '[data-test-active -warning] button:contains(fine)' )
260
+ await click ( '[data-test-overlapping -warning] button:contains(fine)' )
256
261
expect ( find ( '.modal--visible' ) ) . to . have . length ( 1 )
257
262
await click ( '[data-test-unknown-warning] button:contains(fine)' )
258
263
expect ( find ( '.modal--visible' ) ) . to . have . length ( 0 )
259
- expect ( currentURL ( ) ) . to . equal ( '/ reports')
264
+ expect ( currentURL ( ) ) . to . contain ( ' reports')
260
265
} )
261
266
262
- it ( 'splits overlapping activities when stopping' , async function ( ) {
267
+ it ( 'splits 1 day overlapping activities when stopping' , async function ( ) {
263
268
let activity = server . create ( 'activity' , 'active' , {
264
269
userId : this . user . id ,
265
- date : moment ( ) . subtract ( 2 , 'days' )
270
+ date : moment ( ) . subtract ( 1 , 'days' )
266
271
} )
267
272
268
273
await visit ( '/' )
269
274
270
275
await click ( '[data-test-record-stop]' )
271
276
272
- // todayday block should be from 00:00 to now
273
- expect ( find ( `[data-test-activity-row] td:contains(${ activity . comment } )` ) ) . to
274
- . be . ok
277
+ // today block should be from 00:00 to now
278
+ expect (
279
+ find ( `[data-test-activity-row] td:contains(${ activity . comment } )` )
280
+ ) . to . have . length ( 1 )
275
281
276
282
await click ( `[data-test-activity-row] td:contains(${ activity . comment } )` )
277
283
278
284
expect (
279
285
find ( '[data-test-activity-block-row] td:eq(1) input' ) . val ( )
280
286
) . to . equal ( '00:00' )
281
287
282
- // yesterday block should be from 00:00 to now
288
+ // yesterday block should be from old start time to 23:59
283
289
await visit ( '/' )
284
290
await click ( '[data-test-previous]' )
285
291
286
- expect ( find ( `[data-test-activity-row] td:contains(${ activity . comment } )` ) ) . to
287
- . be . ok
292
+ expect (
293
+ find ( `[data-test-activity-row] td:contains(${ activity . comment } )` )
294
+ ) . to . have . length ( 1 )
288
295
289
296
await click ( `[data-test-activity-row] td:contains(${ activity . comment } )` )
290
297
291
298
expect (
292
- find ( '[data-test-activity-block-row] td:eq(1) input' ) . val ( )
293
- ) . to . equal ( '00:00' )
299
+ find ( '[data-test-activity-block-row]:last td:eq(3) input' ) . val ( )
300
+ ) . to . equal ( '23:59' )
301
+ } )
294
302
303
+ it ( "doesn't split >1 days overlapping activities when stopping" , async function ( ) {
304
+ let activity = server . create ( 'activity' , 'active' , {
305
+ userId : this . user . id ,
306
+ date : moment ( ) . subtract ( 2 , 'days' )
307
+ } )
308
+
309
+ await visit ( '/' )
310
+
311
+ await click ( '[data-test-record-stop]' )
312
+
313
+ // today block should not exist
295
314
expect (
296
- find ( '[data-test-activity-block-row] td:eq(3) input' ) . val ( )
297
- ) . to . equal ( '23:59' )
315
+ find ( `[data-test-activity-row] td:contains(${ activity . comment } )` )
316
+ ) . to . have . length ( 0 )
317
+
318
+ // yesterday block should not exist
319
+ await visit ( '/' )
320
+ await click ( '[data-test-previous]' )
321
+
322
+ expect (
323
+ find ( `[data-test-activity-row] td:contains(${ activity . comment } )` )
324
+ ) . to . have . length ( 0 )
298
325
299
326
// day before yesterday block should be from old start time to 23:59
300
327
await visit ( '/' )
301
328
await click ( '[data-test-previous]' )
302
329
await click ( '[data-test-previous]' )
303
330
304
- expect ( find ( `[data-test-activity-row] td:contains(${ activity . comment } )` ) ) . to
305
- . be . ok
331
+ expect (
332
+ find ( `[data-test-activity-row] td:contains(${ activity . comment } )` )
333
+ ) . to . have . length ( 1 )
306
334
307
335
await click ( `[data-test-activity-row] td:contains(${ activity . comment } )` )
308
336
309
337
expect (
310
338
find ( '[data-test-activity-block-row]:last td:eq(3) input' ) . val ( )
311
339
) . to . equal ( '23:59' )
312
340
} )
341
+
342
+ it ( 'can generate active reports which do not overlap' , async function ( ) {
343
+ let activity = server . create ( 'activity' , 'active' , { userId : this . user . id } )
344
+ let { id, duration } = activity
345
+
346
+ duration = moment . duration ( duration , 'HH:mm:ss' ) . add (
347
+ moment ( ) . diff (
348
+ moment (
349
+ activity . blocks . models . find ( b => {
350
+ return ! b . toTime
351
+ } ) . fromTime ,
352
+ 'HH:mm:ss'
353
+ )
354
+ )
355
+ )
356
+
357
+ await visit ( '/' )
358
+
359
+ await click ( find ( 'button:contains(Generate timesheet)' ) )
360
+
361
+ expect ( currentURL ( ) ) . to . equal ( '/reports' )
362
+
363
+ expect ( find ( '[data-test-report-row]' ) ) . to . have . length ( 7 )
364
+
365
+ expect (
366
+ find ( `${ `[data-test-report-row-id="${ id } "]` } [name=duration]` ) . val ( )
367
+ ) . to . equal ( formatDuration ( duration , false ) )
368
+ } )
313
369
} )
0 commit comments