Skip to content
This repository was archived by the owner on Nov 1, 2017. It is now read-only.

Commit 7c8d7d1

Browse files
committed
Merge pull request #37 from github/list-item-prefix-requirement
Require list item prefix for task list update matching
2 parents 66ddf95 + fc0b015 commit 7c8d7d1

2 files changed

Lines changed: 68 additions & 7 deletions

File tree

app/assets/javascripts/task_list.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ completePattern = ///
115115
# Useful when you need iterate over all items.
116116
itemPattern = ///
117117
^
118-
(?: # optional prefix, consisting of
118+
(?: # prefix, consisting of
119119
\s* # optional leading whitespace
120120
(?:>\s*)* # zero or more blockquotes
121121
(?:[-+*]|(?:\d+\.)) # list item indicator
122-
)?
122+
)
123123
\s* # optional whitespace prefix
124124
( # checkbox
125125
#{escapePattern(complete)}|

test/unit/test_updates.coffee

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module "TaskList updates",
2828
class: 'task-list-item-checkbox'
2929
disabled: true
3030
checked: false
31-
31+
3232
@blockquote = $ '<blockquote>'
3333

3434
@quotedList = $ '<ul>', class: 'task-list'
@@ -46,7 +46,7 @@ module "TaskList updates",
4646
class: 'task-list-item-checkbox'
4747
disabled: true
4848
checked: false
49-
49+
5050
@innerBlockquote = $ '<blockquote>'
5151

5252
@innerList = $ '<ul>', class: 'task-list'
@@ -232,7 +232,7 @@ module "TaskList updates",
232232

233233
@blockquote.append @innerBlockquote
234234

235-
@container.append @blockquote
235+
@container.append @blockquote
236236

237237
@orderedCompleteItem.append @orderedCompleteCheckbox
238238
@orderedList.append @orderedCompleteItem
@@ -241,9 +241,9 @@ module "TaskList updates",
241241
@orderedIncompleteItem.append @orderedIncompleteCheckbox
242242
@orderedList.append @orderedIncompleteItem
243243
@orderedIncompleteItem.expectedIndex = 9
244-
244+
245245
@container.append @orderedList
246-
246+
247247
@blockquote.append @field
248248

249249
$('#qunit-fixture').append(@container)
@@ -379,3 +379,64 @@ asyncTest "updates the source of an ordered list item, marking the complete item
379379

380380
@orderedCompleteCheckbox.click()
381381

382+
asyncTest "update ignores items that look like Task List items but lack list prefix", ->
383+
expect 3
384+
385+
$('#qunit-fixture').empty()
386+
387+
container = $ '<div>', class: 'js-task-list-container'
388+
389+
list = $ '<ul>', class: 'task-list'
390+
391+
item1 = $ '<li>', class: 'task-list-item'
392+
item1Checkbox = $ '<input>',
393+
type: 'checkbox'
394+
class: 'task-list-item-checkbox'
395+
disabled: true
396+
checked: false
397+
398+
item2 = $ '<li>', class: 'task-list-item'
399+
item2Checkbox = $ '<input>',
400+
type: 'checkbox'
401+
class: 'task-list-item-checkbox'
402+
disabled: true
403+
checked: false
404+
405+
field = $ '<textarea>', class: 'js-task-list-field', text: """
406+
[ ] one
407+
[ ] two
408+
- [ ] three
409+
- [ ] four
410+
"""
411+
412+
changes = """
413+
[ ] one
414+
[ ] two
415+
- [ ] three
416+
- [x] four
417+
"""
418+
419+
item1.append item1Checkbox
420+
list.append item1
421+
item1.expectedIndex = 1
422+
423+
item2.append item2Checkbox
424+
list.append item2
425+
item2.expectedIndex = 2
426+
427+
container.append list
428+
container.append field
429+
430+
$('#qunit-fixture').append(container)
431+
container.taskList()
432+
433+
field.on 'tasklist:changed', (event, index, checked) =>
434+
ok checked
435+
equal index, item2.expectedIndex
436+
equal field.val(), changes
437+
438+
setTimeout ->
439+
start()
440+
, 20
441+
442+
item2Checkbox.click()

0 commit comments

Comments
 (0)