deckar01-task_list 2.3.1 → 2.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,10 @@
1
+ import { assert } from '@esm-bundle/chai';
2
+
1
3
  window.$ = window.jQuery = require('jquery')
2
- window.TaskList = require('../../app/assets/javascripts/task_list')
4
+ window.TaskList = require('../../app/assets/javascripts/task_list.coffee')
3
5
 
4
- QUnit.module "TaskList updates",
5
- beforeEach: ->
6
+ describe "TaskList updates", ->
7
+ beforeEach ->
6
8
  @container = $ '<div>', class: 'js-task-list-container'
7
9
 
8
10
  @list = $ '<ul>', class: 'task-list'
@@ -257,439 +259,488 @@ QUnit.module "TaskList updates",
257
259
  @orderedCompleteItemSourcePos = '8:3-8:25'
258
260
  @orderedIncompleteItemSourcePos = '9:3-9:27'
259
261
 
260
- $('#qunit-fixture').append(@container)
262
+ $('body').append(@container)
261
263
  @container.taskList()
262
264
 
263
265
  @setSourcePosition = (item, pos) =>
264
266
  item.attr('data-sourcepos', pos)
267
+
268
+ @events = []
265
269
 
266
- @onChanged = (assert) =>
270
+ @onChanged = =>
267
271
  utils =
268
272
  test: (fn) =>
269
- done = assert.async()
270
- @field.on 'tasklist:changed', (event) =>
271
- fn event
272
- done()
273
+ @events.push new Promise (resolve) =>
274
+ @field.on 'tasklist:changed', (event) =>
275
+ fn event
276
+ resolve()
273
277
  eventHas: (name, value) =>
274
278
  utils.test (event) =>
275
279
  assert.equal event.detail[name], value
276
280
  fieldIs: (value) =>
277
281
  utils.test () =>
278
282
  assert.equal @field.val(), value
283
+
284
+ @allEvents = =>
285
+ for promise in @events
286
+ await promise
279
287
 
280
- afterEach: ->
288
+ afterEach ->
281
289
  $(document).off 'tasklist:changed'
290
+ @container.remove()
291
+
292
+ it "updates the source, marking the incomplete item as complete", () ->
293
+ @onChanged().eventHas('checked', true)
294
+ @onChanged().eventHas('index', @incompleteItem.expectedIndex)
295
+ @onChanged().fieldIs(@changes.toIncomplete)
296
+
297
+ @incompleteCheckbox.click()
298
+
299
+ await @allEvents()
300
+
301
+ it "updates the source, marking the incomplete item as complete (sourcepos)", () ->
302
+ @setSourcePosition(@incompleteItem, @incompleteItemSourcePos)
303
+ @onChanged().eventHas('checked', true)
304
+ @onChanged().eventHas('index', @incompleteItem.expectedIndex)
305
+ @onChanged().fieldIs(@changes.toIncomplete)
306
+
307
+ @incompleteCheckbox.click()
308
+
309
+ await @allEvents()
310
+
311
+ it "updates the source, marking the complete item as incomplete", () ->
312
+ @onChanged().eventHas('checked', false)
313
+ @onChanged().eventHas('index', @completeItem.expectedIndex)
314
+ @onChanged().fieldIs(@changes.toComplete)
315
+
316
+ @completeCheckbox.click()
317
+
318
+ await @allEvents()
319
+
320
+ it "updates the source, marking the complete item as incomplete (sourcepos)", () ->
321
+ @setSourcePosition(@completeItem, @completeItemSourcePos)
322
+ @onChanged().eventHas('checked', false)
323
+ @onChanged().eventHas('index', @completeItem.expectedIndex)
324
+ @onChanged().fieldIs(@changes.toComplete)
325
+
326
+ @completeCheckbox.click()
327
+
328
+ await @allEvents()
329
+
330
+ # See: https://github.com/github/task-lists/pull/14
331
+ it "updates the source for items with non-breaking spaces", () ->
332
+ @onChanged().eventHas('checked', true)
333
+ @onChanged().eventHas('index', @incompleteNBSPItem.expectedIndex)
334
+ @onChanged().fieldIs(@changes.toIncompleteNBSP)
335
+
336
+ @incompleteNBSPCheckbox.click()
337
+
338
+ await @allEvents()
339
+
340
+ # See: https://github.com/github/task-lists/pull/14
341
+ it "updates the source for items with non-breaking spaces (sourcepos)", () ->
342
+ @setSourcePosition(@incompleteNBSPItem, @incompleteNBSPItemSourcePos)
343
+ @onChanged().eventHas('checked', true)
344
+ @onChanged().eventHas('index', @incompleteNBSPItem.expectedIndex)
345
+ @onChanged().fieldIs(@changes.toIncompleteNBSP)
346
+
347
+ @incompleteNBSPCheckbox.click()
348
+
349
+ await @allEvents()
350
+
351
+ it "updates the source of a quoted item, marking the incomplete item as complete", () ->
352
+ @onChanged().eventHas('checked', true)
353
+ @onChanged().eventHas('index', @quotedIncompleteItem.expectedIndex)
354
+ @onChanged().fieldIs(@changes.toQuotedIncomplete)
355
+
356
+ @quotedIncompleteCheckbox.click()
357
+
358
+ await @allEvents()
359
+
360
+ it "updates the source of a quoted item, marking the incomplete item as complete (sourcepos)", () ->
361
+ @setSourcePosition(@quotedIncompleteItem, @quotedIncompleteItemSourcePos)
362
+ @onChanged().eventHas('checked', true)
363
+ @onChanged().eventHas('index', @quotedIncompleteItem.expectedIndex)
364
+ @onChanged().fieldIs(@changes.toQuotedIncomplete)
365
+
366
+ @quotedIncompleteCheckbox.click()
367
+
368
+ await @allEvents()
369
+
370
+ it "updates the source of a quoted item, marking the complete item as incomplete", () ->
371
+ @onChanged().eventHas('checked', false)
372
+ @onChanged().eventHas('index', @quotedCompleteItem.expectedIndex)
373
+ @onChanged().fieldIs(@changes.toQuotedComplete)
374
+
375
+ @quotedCompleteCheckbox.click()
376
+
377
+ await @allEvents()
378
+
379
+ it "updates the source of a quoted item, marking the complete item as incomplete (sourcepos)", () ->
380
+ @setSourcePosition(@quotedCompleteItem, @quotedCompleteItemSourcePos)
381
+ @onChanged().eventHas('checked', false)
382
+ @onChanged().eventHas('index', @quotedCompleteItem.expectedIndex)
383
+ @onChanged().fieldIs(@changes.toQuotedComplete)
384
+
385
+ @quotedCompleteCheckbox.click()
386
+
387
+ await @allEvents()
388
+
389
+ it "updates the source of a quoted quoted item, marking the incomplete item as complete", () ->
390
+ @onChanged().eventHas('checked', true)
391
+ @onChanged().eventHas('index', @innerIncompleteItem.expectedIndex)
392
+ @onChanged().fieldIs(@changes.toInnerIncomplete)
393
+
394
+ @innerIncompleteCheckbox.click()
395
+
396
+ await @allEvents()
397
+
398
+ it "updates the source of a quoted quoted item, marking the incomplete item as complete (sourcepos)", () ->
399
+ @setSourcePosition(@innerIncompleteItem, @innerIncompleteItemSourcePos)
400
+ @onChanged().eventHas('checked', true)
401
+ @onChanged().eventHas('index', @innerIncompleteItem.expectedIndex)
402
+ @onChanged().fieldIs(@changes.toInnerIncomplete)
403
+
404
+ @innerIncompleteCheckbox.click()
405
+
406
+ await @allEvents()
407
+
408
+ it "updates the source of a quoted quoted item, marking the complete item as incomplete", () ->
409
+ @onChanged().eventHas('checked', false)
410
+ @onChanged().eventHas('index', @innerCompleteItem.expectedIndex)
411
+ @onChanged().fieldIs(@changes.toInnerComplete)
412
+
413
+ @innerCompleteCheckbox.click()
414
+
415
+ await @allEvents()
416
+
417
+ it "updates the source of a quoted quoted item, marking the complete item as incomplete (sourcepos)", () ->
418
+ @setSourcePosition(@innerCompleteItem, @innerCompleteItemSourcePos)
419
+ @onChanged().eventHas('checked', false)
420
+ @onChanged().eventHas('index', @innerCompleteItem.expectedIndex)
421
+ @onChanged().fieldIs(@changes.toInnerComplete)
422
+
423
+ @innerCompleteCheckbox.click()
424
+
425
+ await @allEvents()
426
+
427
+ it "updates the source of an ordered list item, marking the incomplete item as complete", () ->
428
+ @onChanged().eventHas('checked', true)
429
+ @onChanged().eventHas('index', @orderedIncompleteItem.expectedIndex)
430
+ @onChanged().fieldIs(@changes.toOrderedIncomplete)
431
+
432
+ @orderedIncompleteCheckbox.click()
433
+
434
+ await @allEvents()
435
+
436
+ it "updates the source of an ordered list item, marking the incomplete item as complete (sourcepos)", () ->
437
+ @setSourcePosition(@orderedIncompleteItem, @orderedIncompleteItemSourcePos)
438
+ @onChanged().eventHas('checked', true)
439
+ @onChanged().eventHas('index', @orderedIncompleteItem.expectedIndex)
440
+ @onChanged().fieldIs(@changes.toOrderedIncomplete)
441
+
442
+ @orderedIncompleteCheckbox.click()
443
+
444
+ await @allEvents()
445
+
446
+ it "updates the source of an ordered list item, marking the complete item as incomplete", () ->
447
+ @onChanged().eventHas('checked', false)
448
+ @onChanged().eventHas('index', @orderedCompleteItem.expectedIndex)
449
+ @onChanged().fieldIs(@changes.toOrderedComplete)
450
+
451
+ @orderedCompleteCheckbox.click()
452
+
453
+ await @allEvents()
454
+
455
+ it "updates the source of an ordered list item, marking the complete item as incomplete (sourcepos)", () ->
456
+ @setSourcePosition(@orderedCompleteItem, @orderedCompleteItemSourcePos)
457
+ @onChanged().eventHas('checked', false)
458
+ @onChanged().eventHas('index', @orderedCompleteItem.expectedIndex)
459
+ @onChanged().fieldIs(@changes.toOrderedComplete)
460
+
461
+ @orderedCompleteCheckbox.click()
462
+
463
+ await @allEvents()
464
+
465
+ setupListPrefix = ->
466
+ @container.remove()
467
+
468
+ @container = $ '<div>', class: 'js-task-list-container'
469
+
470
+ @list = $ '<ul>', class: 'task-list'
471
+
472
+ @item1 = $ '<li>', class: 'task-list-item'
473
+ @item1Checkbox = $ '<input>',
474
+ type: 'checkbox'
475
+ class: 'task-list-item-checkbox'
476
+ disabled: true
477
+ checked: false
478
+
479
+ @item2 = $ '<li>', class: 'task-list-item'
480
+ @item2Checkbox = $ '<input>',
481
+ type: 'checkbox'
482
+ class: 'task-list-item-checkbox'
483
+ disabled: true
484
+ checked: false
485
+
486
+ @field = $ '<textarea>', class: 'js-task-list-field', text: """
487
+ [ ] one
488
+ [ ] two
489
+ - [ ] three
490
+ - [ ] four
491
+ """
492
+
493
+ @changes = """
494
+ [ ] one
495
+ [ ] two
496
+ - [ ] three
497
+ - [x] four
498
+ """
282
499
 
283
- QUnit.test "updates the source, marking the incomplete item as complete", (assert) ->
284
- @onChanged(assert).eventHas('checked', true)
285
- @onChanged(assert).eventHas('index', @incompleteItem.expectedIndex)
286
- @onChanged(assert).fieldIs(@changes.toIncomplete)
500
+ @item1.append @item1Checkbox
501
+ @list.append @item1
502
+ @item1.expectedIndex = 1
287
503
 
288
- @incompleteCheckbox.click()
504
+ @item2.append @item2Checkbox
505
+ @list.append @item2
506
+ @item2.expectedIndex = 2
289
507
 
290
- QUnit.test "updates the source, marking the incomplete item as complete (sourcepos)", (assert) ->
291
- @setSourcePosition(@incompleteItem, @incompleteItemSourcePos)
292
- @onChanged(assert).eventHas('checked', true)
293
- @onChanged(assert).eventHas('index', @incompleteItem.expectedIndex)
294
- @onChanged(assert).fieldIs(@changes.toIncomplete)
508
+ @container.append @list
509
+ @container.append @field
510
+
511
+ $('body').append(@container)
512
+ @container.taskList()
513
+
514
+ @onChanged().eventHas('checked', true)
515
+ @onChanged().eventHas('index', @item2.expectedIndex)
516
+ @onChanged().fieldIs(@changes)
295
517
 
296
- @incompleteCheckbox.click()
518
+ it "update ignores items that look like Task List items but lack list prefix", () ->
519
+ setupListPrefix.call this
297
520
 
298
- QUnit.test "updates the source, marking the complete item as incomplete", (assert) ->
299
- @onChanged(assert).eventHas('checked', false)
300
- @onChanged(assert).eventHas('index', @completeItem.expectedIndex)
301
- @onChanged(assert).fieldIs(@changes.toComplete)
521
+ @item2Checkbox.click()
302
522
 
303
- @completeCheckbox.click()
523
+ await @allEvents()
304
524
 
305
- QUnit.test "updates the source, marking the complete item as incomplete (sourcepos)", (assert) ->
306
- @setSourcePosition(@completeItem, @completeItemSourcePos)
307
- @onChanged(assert).eventHas('checked', false)
308
- @onChanged(assert).eventHas('index', @completeItem.expectedIndex)
309
- @onChanged(assert).fieldIs(@changes.toComplete)
525
+ it "update ignores items that look like Task List items but lack list prefix (sourcepos)", () ->
526
+ setupListPrefix.call this
527
+ @item1.attr('data-sourcepos', '3:1-3:11')
528
+ @item2.attr('data-sourcepos', '4:1-4:10')
310
529
 
311
- @completeCheckbox.click()
530
+ @item2Checkbox.click()
312
531
 
313
- # See: https://github.com/github/task-lists/pull/14
314
- QUnit.test "updates the source for items with non-breaking spaces", (assert) ->
315
- @onChanged(assert).eventHas('checked', true)
316
- @onChanged(assert).eventHas('index', @incompleteNBSPItem.expectedIndex)
317
- @onChanged(assert).fieldIs(@changes.toIncompleteNBSP)
532
+ await @allEvents()
318
533
 
319
- @incompleteNBSPCheckbox.click()
534
+ setupLinkItems = ->
535
+ @container.remove()
320
536
 
321
- # See: https://github.com/github/task-lists/pull/14
322
- QUnit.test "updates the source for items with non-breaking spaces (sourcepos)", (assert) ->
323
- @setSourcePosition(@incompleteNBSPItem, @incompleteNBSPItemSourcePos)
324
- @onChanged(assert).eventHas('checked', true)
325
- @onChanged(assert).eventHas('index', @incompleteNBSPItem.expectedIndex)
326
- @onChanged(assert).fieldIs(@changes.toIncompleteNBSP)
537
+ @container = $ '<div>', class: 'js-task-list-container'
327
538
 
328
- @incompleteNBSPCheckbox.click()
539
+ @list = $ '<ul>', class: 'task-list'
329
540
 
330
- QUnit.test "updates the source of a quoted item, marking the incomplete item as complete", (assert) ->
331
- @onChanged(assert).eventHas('checked', true)
332
- @onChanged(assert).eventHas('index', @quotedIncompleteItem.expectedIndex)
333
- @onChanged(assert).fieldIs(@changes.toQuotedIncomplete)
541
+ @item1 = $ '<li>', class: 'task-list-item'
542
+ @item1Checkbox = $ '<input>',
543
+ type: 'checkbox'
544
+ class: 'task-list-item-checkbox'
545
+ disabled: true
546
+ checked: false
547
+
548
+ @item2 = $ '<li>', class: 'task-list-item'
549
+ @item2Checkbox = $ '<input>',
550
+ type: 'checkbox'
551
+ class: 'task-list-item-checkbox'
552
+ disabled: true
553
+ checked: false
554
+
555
+ @field = $ '<textarea>', class: 'js-task-list-field', text: """
556
+ - [ ](link)
557
+ - [ ][reference]
558
+ - [ ]() collapsed
559
+ - [ ][] collapsed reference
560
+ - [ ] (no longer a link)
561
+ - [ ] item
562
+ """
334
563
 
335
- @quotedIncompleteCheckbox.click()
564
+ @changes = """
565
+ - [ ](link)
566
+ - [ ][reference]
567
+ - [ ]() collapsed
568
+ - [ ][] collapsed reference
569
+ - [ ] (no longer a link)
570
+ - [x] item
571
+ """
336
572
 
337
- QUnit.test "updates the source of a quoted item, marking the incomplete item as complete (sourcepos)", (assert) ->
338
- @setSourcePosition(@quotedIncompleteItem, @quotedIncompleteItemSourcePos)
339
- @onChanged(assert).eventHas('checked', true)
340
- @onChanged(assert).eventHas('index', @quotedIncompleteItem.expectedIndex)
341
- @onChanged(assert).fieldIs(@changes.toQuotedIncomplete)
573
+ @item1.append @item1Checkbox
574
+ @list.append @item1
575
+ @item1.expectedIndex = 1
342
576
 
343
- @quotedIncompleteCheckbox.click()
577
+ @item2.append @item2Checkbox
578
+ @list.append @item2
579
+ @item2.expectedIndex = 2
344
580
 
345
- QUnit.test "updates the source of a quoted item, marking the complete item as incomplete", (assert) ->
346
- @onChanged(assert).eventHas('checked', false)
347
- @onChanged(assert).eventHas('index', @quotedCompleteItem.expectedIndex)
348
- @onChanged(assert).fieldIs(@changes.toQuotedComplete)
581
+ @container.append @list
582
+ @container.append @field
349
583
 
350
- @quotedCompleteCheckbox.click()
584
+ $('body').append(@container)
585
+ @container.taskList()
351
586
 
352
- QUnit.test "updates the source of a quoted item, marking the complete item as incomplete (sourcepos)", (assert) ->
353
- @setSourcePosition(@quotedCompleteItem, @quotedCompleteItemSourcePos)
354
- @onChanged(assert).eventHas('checked', false)
355
- @onChanged(assert).eventHas('index', @quotedCompleteItem.expectedIndex)
356
- @onChanged(assert).fieldIs(@changes.toQuotedComplete)
587
+ @onChanged().eventHas('checked', true)
588
+ @onChanged().eventHas('index', @item2.expectedIndex)
589
+ @onChanged().fieldIs(@changes)
357
590
 
358
- @quotedCompleteCheckbox.click()
591
+ it "update ignores items that look like Task List items but are links", ->
592
+ setupLinkItems.call this
359
593
 
360
- QUnit.test "updates the source of a quoted quoted item, marking the incomplete item as complete", (assert) ->
361
- @onChanged(assert).eventHas('checked', true)
362
- @onChanged(assert).eventHas('index', @innerIncompleteItem.expectedIndex)
363
- @onChanged(assert).fieldIs(@changes.toInnerIncomplete)
594
+ @item2Checkbox.click()
364
595
 
365
- @innerIncompleteCheckbox.click()
596
+ await @allEvents()
366
597
 
367
- QUnit.test "updates the source of a quoted quoted item, marking the incomplete item as complete (sourcepos)", (assert) ->
368
- @setSourcePosition(@innerIncompleteItem, @innerIncompleteItemSourcePos)
369
- @onChanged(assert).eventHas('checked', true)
370
- @onChanged(assert).eventHas('index', @innerIncompleteItem.expectedIndex)
371
- @onChanged(assert).fieldIs(@changes.toInnerIncomplete)
598
+ it "update ignores items that look like Task List items but are links (sourcepos)", ->
599
+ setupLinkItems.call this
600
+ @item1.attr 'data-sourcepos', '5:1-5:24'
601
+ @item2.attr 'data-sourcepos', '6:1-6:10'
372
602
 
373
- @innerIncompleteCheckbox.click()
603
+ @item2Checkbox.click()
374
604
 
375
- QUnit.test "updates the source of a quoted quoted item, marking the complete item as incomplete", (assert) ->
376
- @onChanged(assert).eventHas('checked', false)
377
- @onChanged(assert).eventHas('index', @innerCompleteItem.expectedIndex)
378
- @onChanged(assert).fieldIs(@changes.toInnerComplete)
605
+ await @allEvents()
379
606
 
380
- @innerCompleteCheckbox.click()
607
+ setupTrailingLinks = ->
608
+ @container.remove()
381
609
 
382
- QUnit.test "updates the source of a quoted quoted item, marking the complete item as incomplete (sourcepos)", (assert) ->
383
- @setSourcePosition(@innerCompleteItem, @innerCompleteItemSourcePos)
384
- @onChanged(assert).eventHas('checked', false)
385
- @onChanged(assert).eventHas('index', @innerCompleteItem.expectedIndex)
386
- @onChanged(assert).fieldIs(@changes.toInnerComplete)
610
+ @container = $ '<div>', class: 'js-task-list-container'
387
611
 
388
- @innerCompleteCheckbox.click()
612
+ @list = $ '<ul>', class: 'task-list'
389
613
 
390
- QUnit.test "updates the source of an ordered list item, marking the incomplete item as complete", (assert) ->
391
- @onChanged(assert).eventHas('checked', true)
392
- @onChanged(assert).eventHas('index', @orderedIncompleteItem.expectedIndex)
393
- @onChanged(assert).fieldIs(@changes.toOrderedIncomplete)
614
+ @item1 = $ '<li>', class: 'task-list-item'
615
+ @item1Checkbox = $ '<input>',
616
+ type: 'checkbox'
617
+ class: 'task-list-item-checkbox'
618
+ disabled: true
619
+ checked: false
394
620
 
395
- @orderedIncompleteCheckbox.click()
621
+ @item2 = $ '<li>', class: 'task-list-item'
622
+ @item2Checkbox = $ '<input>',
623
+ type: 'checkbox'
624
+ class: 'task-list-item-checkbox'
625
+ disabled: true
626
+ checked: false
396
627
 
397
- QUnit.test "updates the source of an ordered list item, marking the incomplete item as complete (sourcepos)", (assert) ->
398
- @setSourcePosition(@orderedIncompleteItem, @orderedIncompleteItemSourcePos)
399
- @onChanged(assert).eventHas('checked', true)
400
- @onChanged(assert).eventHas('index', @orderedIncompleteItem.expectedIndex)
401
- @onChanged(assert).fieldIs(@changes.toOrderedIncomplete)
628
+ @field = $ '<textarea>', class: 'js-task-list-field', text: """
629
+ - [ ] [link label](link)
630
+ - [ ] [reference label][reference]
631
+ """
402
632
 
403
- @orderedIncompleteCheckbox.click()
633
+ @changes = """
634
+ - [ ] [link label](link)
635
+ - [x] [reference label][reference]
636
+ """
404
637
 
405
- QUnit.test "updates the source of an ordered list item, marking the complete item as incomplete", (assert) ->
406
- @onChanged(assert).eventHas('checked', false)
407
- @onChanged(assert).eventHas('index', @orderedCompleteItem.expectedIndex)
408
- @onChanged(assert).fieldIs(@changes.toOrderedComplete)
638
+ @item1.append @item1Checkbox
639
+ @list.append @item1
640
+ @item1.expectedIndex = 1
409
641
 
410
- @orderedCompleteCheckbox.click()
642
+ @item2.append @item2Checkbox
643
+ @list.append @item2
644
+ @item2.expectedIndex = 2
411
645
 
412
- QUnit.test "updates the source of an ordered list item, marking the complete item as incomplete (sourcepos)", (assert) ->
413
- @setSourcePosition(@orderedCompleteItem, @orderedCompleteItemSourcePos)
414
- @onChanged(assert).eventHas('checked', false)
415
- @onChanged(assert).eventHas('index', @orderedCompleteItem.expectedIndex)
416
- @onChanged(assert).fieldIs(@changes.toOrderedComplete)
646
+ @container.append @list
647
+ @container.append @field
417
648
 
418
- @orderedCompleteCheckbox.click()
649
+ $('body').append(@container)
650
+ @container.taskList()
651
+
652
+ @onChanged().eventHas('checked', true)
653
+ @onChanged().eventHas('index', @item2.expectedIndex)
654
+ @onChanged().fieldIs(@changes)
655
+
656
+ it "updates items followed by links", ->
657
+ setupTrailingLinks.call this
658
+
659
+ @item2Checkbox.click()
660
+
661
+ await @allEvents()
662
+
663
+ it "updates items followed by links (sourcepos)", ->
664
+ setupTrailingLinks.call this
665
+ @item1.attr 'data-sourcepos', '1:1-1:24'
666
+ @item2.attr 'data-sourcepos', '2:1-3:0'
667
+
668
+ @item2Checkbox.click()
669
+
670
+ await @allEvents()
671
+
672
+ setupCodeBlocks = ->
673
+ @container.remove()
674
+
675
+ @container = $ '<div>', class: 'js-task-list-container'
676
+
677
+ @list = $ '<ul>', class: 'task-list'
678
+
679
+ @item1 = $ '<li>', class: 'task-list-item'
680
+ @item1Checkbox = $ '<input>',
681
+ type: 'checkbox'
682
+ class: 'task-list-item-checkbox'
683
+ disabled: true
684
+ checked: false
685
+
686
+ @item2 = $ '<li>', class: 'task-list-item'
687
+ @item2Checkbox = $ '<input>',
688
+ type: 'checkbox'
689
+ class: 'task-list-item-checkbox'
690
+ disabled: true
691
+ checked: false
692
+
693
+ @field = $ '<textarea>', class: 'js-task-list-field', text: """
694
+ ```
695
+ - [ ] test1
696
+ - [ ] test2
697
+ ```
698
+
699
+ - [ ] test1
700
+ - [ ] test2
701
+ """
702
+
703
+ @changes = """
704
+ ```
705
+ - [ ] test1
706
+ - [ ] test2
707
+ ```
708
+
709
+ - [ ] test1
710
+ - [x] test2
711
+ """
712
+
713
+ @item1.append @item1Checkbox
714
+ @list.append @item1
715
+ @item1.expectedIndex = 1
716
+
717
+ @item2.append @item2Checkbox
718
+ @list.append @item2
719
+ @item2.expectedIndex = 2
720
+
721
+ @container.append @list
722
+ @container.append @field
723
+
724
+ $('body').append(@container)
725
+ @container.taskList()
419
726
 
420
- QUnit.test "update ignores items that look like Task List items but lack list prefix", (assert) ->
421
- assertItemsLackListPrefix(assert, null, null)
727
+ @onChanged().eventHas('checked', true)
728
+ @onChanged().eventHas('index', @item2.expectedIndex)
729
+ @onChanged().fieldIs(@changes)
422
730
 
423
- QUnit.test "update ignores items that look like Task List items but lack list prefix (sourcepos)", (assert) ->
424
- assertItemsLackListPrefix(assert, '3:1-3:11', '4:1-4:10')
731
+ # See https://github.com/deckar01/task_list/issues/3
732
+ it "doesn't update items inside code blocks", ->
733
+ setupCodeBlocks.call this
425
734
 
426
- assertItemsLackListPrefix =(assert, sourcepos1, sourcepos2) ->
427
- done = assert.async()
428
- assert.expect 3
735
+ @item2Checkbox.click()
429
736
 
430
- $('#qunit-fixture').empty()
431
-
432
- container = $ '<div>', class: 'js-task-list-container'
433
-
434
- list = $ '<ul>', class: 'task-list'
435
-
436
- item1 = $ '<li>', class: 'task-list-item'
437
- item1.attr('data-sourcepos', sourcepos1) if sourcepos1
438
- item1Checkbox = $ '<input>',
439
- type: 'checkbox'
440
- class: 'task-list-item-checkbox'
441
- disabled: true
442
- checked: false
443
-
444
- item2 = $ '<li>', class: 'task-list-item'
445
- item2.attr('data-sourcepos', sourcepos2) if sourcepos2
446
- item2Checkbox = $ '<input>',
447
- type: 'checkbox'
448
- class: 'task-list-item-checkbox'
449
- disabled: true
450
- checked: false
451
-
452
- field = $ '<textarea>', class: 'js-task-list-field', text: """
453
- [ ] one
454
- [ ] two
455
- - [ ] three
456
- - [ ] four
457
- """
458
-
459
- changes = """
460
- [ ] one
461
- [ ] two
462
- - [ ] three
463
- - [x] four
464
- """
465
-
466
- item1.append item1Checkbox
467
- list.append item1
468
- item1.expectedIndex = 1
469
-
470
- item2.append item2Checkbox
471
- list.append item2
472
- item2.expectedIndex = 2
737
+ await @allEvents()
473
738
 
474
- container.append list
475
- container.append field
739
+ it "doesn't update items inside code blocks (sourcepos)", ->
740
+ setupCodeBlocks.call this
741
+ @item1.attr 'data-sourcepos', '6:1-6:11'
742
+ @item2.attr 'data-sourcepos', '7:1-7:11'
476
743
 
477
- $('#qunit-fixture').append(container)
478
- container.taskList()
744
+ @item2Checkbox.click()
479
745
 
480
- field.on 'tasklist:changed', (event) =>
481
- assert.ok event.detail.checked
482
- assert.equal event.detail.index, item2.expectedIndex
483
- assert.equal field.val(), changes
484
- done()
485
-
486
- item2Checkbox.click()
487
-
488
- QUnit.test "update ignores items that look like Task List items but are links", (assert) ->
489
- assertItemsButAreLinks(assert, null, null)
490
-
491
- QUnit.test "update ignores items that look like Task List items but are links (sourcepos)", (assert) ->
492
- assertItemsButAreLinks(assert, '5:1-5:24', '6:1-6:10')
493
-
494
- assertItemsButAreLinks =(assert, sourcepos1, sourcepos2) ->
495
- done = assert.async()
496
- assert.expect 3
497
-
498
- $('#qunit-fixture').empty()
499
-
500
- container = $ '<div>', class: 'js-task-list-container'
501
-
502
- list = $ '<ul>', class: 'task-list'
503
-
504
- item1 = $ '<li>', class: 'task-list-item'
505
- item1.attr('data-sourcepos', sourcepos1) if sourcepos1
506
- item1Checkbox = $ '<input>',
507
- type: 'checkbox'
508
- class: 'task-list-item-checkbox'
509
- disabled: true
510
- checked: false
511
-
512
- item2 = $ '<li>', class: 'task-list-item'
513
- item2.attr('data-sourcepos', sourcepos2) if sourcepos2
514
- item2Checkbox = $ '<input>',
515
- type: 'checkbox'
516
- class: 'task-list-item-checkbox'
517
- disabled: true
518
- checked: false
519
-
520
- field = $ '<textarea>', class: 'js-task-list-field', text: """
521
- - [ ](link)
522
- - [ ][reference]
523
- - [ ]() collapsed
524
- - [ ][] collapsed reference
525
- - [ ] (no longer a link)
526
- - [ ] item
527
- """
528
-
529
- changes = """
530
- - [ ](link)
531
- - [ ][reference]
532
- - [ ]() collapsed
533
- - [ ][] collapsed reference
534
- - [ ] (no longer a link)
535
- - [x] item
536
- """
537
-
538
- item1.append item1Checkbox
539
- list.append item1
540
- item1.expectedIndex = 1
541
-
542
- item2.append item2Checkbox
543
- list.append item2
544
- item2.expectedIndex = 2
545
-
546
- container.append list
547
- container.append field
548
-
549
- $('#qunit-fixture').append(container)
550
- container.taskList()
551
-
552
- field.on 'tasklist:changed', (event) =>
553
- assert.ok event.detail.checked
554
- assert.equal event.detail.index, item2.expectedIndex
555
- assert.equal field.val(), changes
556
- done()
557
-
558
- item2Checkbox.click()
559
-
560
- QUnit.test "updates items followed by links", (assert) ->
561
- assertItemsFollowedByLinks(assert, null, null)
562
-
563
- QUnit.test "updates items followed by links (sourcepos)", (assert) ->
564
- assertItemsFollowedByLinks(assert, '1:1-1:24', '2:1-3:0')
565
-
566
- assertItemsFollowedByLinks =(assert, sourcepos1, sourcepos2) ->
567
- done = assert.async()
568
- assert.expect 3
569
-
570
- $('#qunit-fixture').empty()
571
-
572
- container = $ '<div>', class: 'js-task-list-container'
573
-
574
- list = $ '<ul>', class: 'task-list'
575
-
576
- item1 = $ '<li>', class: 'task-list-item'
577
- item1.attr('data-sourcepos', sourcepos1) if sourcepos1
578
- item1Checkbox = $ '<input>',
579
- type: 'checkbox'
580
- class: 'task-list-item-checkbox'
581
- disabled: true
582
- checked: false
583
-
584
- item2 = $ '<li>', class: 'task-list-item'
585
- item2.attr('data-sourcepos', sourcepos2) if sourcepos2
586
- item2Checkbox = $ '<input>',
587
- type: 'checkbox'
588
- class: 'task-list-item-checkbox'
589
- disabled: true
590
- checked: false
591
-
592
- field = $ '<textarea>', class: 'js-task-list-field', text: """
593
- - [ ] [link label](link)
594
- - [ ] [reference label][reference]
595
- """
596
-
597
- changes = """
598
- - [ ] [link label](link)
599
- - [x] [reference label][reference]
600
- """
601
-
602
- item1.append item1Checkbox
603
- list.append item1
604
- item1.expectedIndex = 1
605
-
606
- item2.append item2Checkbox
607
- list.append item2
608
- item2.expectedIndex = 2
609
-
610
- container.append list
611
- container.append field
612
-
613
- $('#qunit-fixture').append(container)
614
- container.taskList()
615
-
616
- field.on 'tasklist:changed', (event) =>
617
- assert.ok event.detail.checked
618
- assert.equal event.detail.index, item2.expectedIndex
619
- assert.equal field.val(), changes
620
- done()
621
-
622
- item2Checkbox.click()
623
-
624
- # See https://github.com/deckar01/task_list/issues/3
625
- QUnit.test "doesn't update items inside code blocks", (assert) ->
626
- assertItemsInsideCodeBlocks(assert, null, null)
627
-
628
- QUnit.test "doesn't update items inside code blocks (sourcepos)", (assert) ->
629
- assertItemsInsideCodeBlocks(assert, '6:1-6:11', '7:1-7:11')
630
-
631
- assertItemsInsideCodeBlocks =(assert, sourcepos1, sourcepos2) ->
632
- done = assert.async()
633
- assert.expect 3
634
-
635
- container = $ '<div>', class: 'js-task-list-container'
636
-
637
- list = $ '<ul>', class: 'task-list'
638
-
639
- item1 = $ '<li>', class: 'task-list-item'
640
- item1.attr('data-sourcepos', sourcepos1) if sourcepos1
641
- item1Checkbox = $ '<input>',
642
- type: 'checkbox'
643
- class: 'task-list-item-checkbox'
644
- disabled: true
645
- checked: false
646
-
647
- item2 = $ '<li>', class: 'task-list-item'
648
- item2.attr('data-sourcepos', sourcepos2) if sourcepos2
649
- item2Checkbox = $ '<input>',
650
- type: 'checkbox'
651
- class: 'task-list-item-checkbox'
652
- disabled: true
653
- checked: false
654
-
655
- field = $ '<textarea>', class: 'js-task-list-field', text: """
656
- ```
657
- - [ ] test1
658
- - [ ] test2
659
- ```
660
-
661
- - [ ] test1
662
- - [ ] test2
663
- """
664
-
665
- changes = """
666
- ```
667
- - [ ] test1
668
- - [ ] test2
669
- ```
670
-
671
- - [ ] test1
672
- - [x] test2
673
- """
674
-
675
- item1.append item1Checkbox
676
- list.append item1
677
- item1.expectedIndex = 1
678
-
679
- item2.append item2Checkbox
680
- list.append item2
681
- item2.expectedIndex = 2
682
-
683
- container.append list
684
- container.append field
685
-
686
- $('#qunit-fixture').append(container)
687
- container.taskList()
688
-
689
- field.on 'tasklist:changed', (event) =>
690
- assert.ok event.detail.checked
691
- assert.equal event.detail.index, item2.expectedIndex
692
- assert.equal field.val(), changes
693
- done()
694
-
695
- item2Checkbox.click()
746
+ await @allEvents()