|
| 1 | +#= require task_lists |
| 2 | + |
| 3 | +module "TaskList updates", |
| 4 | + setup: -> |
| 5 | + window.linkActivated = false |
| 6 | + |
| 7 | + @container = $ '<div>', class: 'js-task-list-container' |
| 8 | + |
| 9 | + @list = $ '<ul>', class: 'task-list' |
| 10 | + |
| 11 | + @completeItem = $ '<li>', class: 'task-list-item' |
| 12 | + @completeCheckbox = $ '<input>', |
| 13 | + type: 'checkbox' |
| 14 | + class: 'task-list-item-checkbox' |
| 15 | + disabled: true |
| 16 | + checked: true # yup |
| 17 | + "data-item-index": 1 |
| 18 | + |
| 19 | + @incompleteItem = $ '<li>', class: 'task-list-item' |
| 20 | + @incompleteCheckbox = $ '<input>', |
| 21 | + type: 'checkbox' |
| 22 | + class: 'task-list-item-checkbox' |
| 23 | + disabled: true |
| 24 | + checked: false |
| 25 | + "data-item-index": 2 |
| 26 | + |
| 27 | + @field = $ '<textarea>', class: 'js-task-list-field', text: """ |
| 28 | + - [x] complete |
| 29 | + - [ ] incomplete |
| 30 | + """ |
| 31 | + |
| 32 | + @changes = |
| 33 | + toComplete: """ |
| 34 | + - [ ] complete |
| 35 | + - [ ] incomplete |
| 36 | + """ |
| 37 | + toIncomplete: """ |
| 38 | + - [x] complete |
| 39 | + - [x] incomplete |
| 40 | + """ |
| 41 | + |
| 42 | + @completeItem.append @completeCheckbox |
| 43 | + @list.append @completeItem |
| 44 | + |
| 45 | + @incompleteItem.append @incompleteCheckbox |
| 46 | + @list.append @incompleteItem |
| 47 | + |
| 48 | + @container.append @list |
| 49 | + @container.append @field |
| 50 | + |
| 51 | + $('#qunit-fixture').append(@container).pageUpdate() |
| 52 | + |
| 53 | + teardown: -> |
| 54 | + $(document).off 'tasklist:change' |
| 55 | + |
| 56 | +asyncTest "updates the source, marking the incomplete item as complete", -> |
| 57 | + expect 3 |
| 58 | + |
| 59 | + @field.on 'tasklist:change', (event, index, checked) => |
| 60 | + equal parseInt(@incompleteCheckbox.attr('data-item-index')), index |
| 61 | + ok checked |
| 62 | + equal @field.val(), @changes.toIncomplete |
| 63 | + |
| 64 | + setTimeout -> |
| 65 | + start() |
| 66 | + , 20 |
| 67 | + |
| 68 | + @incompleteCheckbox.click() |
| 69 | + |
| 70 | +asyncTest "updates the source, marking the complete item as incomplete", -> |
| 71 | + expect 3 |
| 72 | + |
| 73 | + @field.on 'tasklist:change', (event, index, checked) => |
| 74 | + equal parseInt(@completeCheckbox.attr('data-item-index')), index |
| 75 | + ok !checked |
| 76 | + equal @field.val(), @changes.toComplete |
| 77 | + |
| 78 | + setTimeout -> |
| 79 | + start() |
| 80 | + , 20 |
| 81 | + |
| 82 | + @completeCheckbox.click() |
0 commit comments