Skip to content
This repository was archived by the owner on Nov 1, 2017. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/assets/javascripts/task_list.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ completePattern = ///
# Useful when you need iterate over all items.
itemPattern = ///
^
(?:\s*[-+*]|(?:\d+\.))? # optional list prefix
(?: # optional prefix, consisting of
\s* # optional leading whitespace
(?:>\s*)* # zero or more blockquotes
(?:[-+*]|(?:\d+\.)) # list item indicator
)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this stanza should be optional prefix; and item indicator would need to be clarified as list item indicator.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regexp looks solid! Thanks for the input, @aroben!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 looks good.

\s* # optional whitespace prefix
( # checkbox
#{escapePattern(complete)}|
Expand Down
264 changes: 264 additions & 0 deletions test/unit/test_updates.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,170 @@ module "TaskList updates",
class: 'task-list-item-checkbox'
disabled: true
checked: false

@blockquote = $ '<blockquote>'

@quotedList = $ '<ul>', class: 'task-list'

@quotedCompleteItem = $ '<li>', class: 'task-list-item'
@quotedCompleteCheckbox = $ '<input>',
type: 'checkbox'
class: 'task-list-item-checkbox'
disabled: true
checked: true

@quotedIncompleteItem = $ '<li>', class: 'task-list-item'
@quotedIncompleteCheckbox = $ '<input>',
type: 'checkbox'
class: 'task-list-item-checkbox'
disabled: true
checked: false

@innerBlockquote = $ '<blockquote>'

@innerList = $ '<ul>', class: 'task-list'

@innerCompleteItem = $ '<li>', class: 'task-list-item'
@innerCompleteCheckbox = $ '<input>',
type: 'checkbox'
class: 'task-list-item-checkbox'
disabled: true
checked: true

@innerIncompleteItem = $ '<li>', class: 'task-list-item'
@innerIncompleteCheckbox = $ '<input>',
type: 'checkbox'
class: 'task-list-item-checkbox'
disabled: true
checked: false

@orderedList = $ '<ol>', class: 'task-list'

@orderedCompleteItem = $ '<li>', class: 'task-list-item'
@orderedCompleteCheckbox = $ '<input>',
type: 'checkbox'
class: 'task-list-item-checkbox'
disabled: true
checked: true

@orderedIncompleteItem = $ '<li>', class: 'task-list-item'
@orderedIncompleteCheckbox = $ '<input>',
type: 'checkbox'
class: 'task-list-item-checkbox'
disabled: true
checked: false

@field = $ '<textarea>', class: 'js-task-list-field', text: """
- [x] complete
- [ ] incomplete
- [#{@nbsp}] incompleteNBSP
> - [x] quoted complete
> - [ ] quoted incomplete
>> - [x] inner complete
> > - [ ] inner incomplete
> 0. [x] ordered complete
> 0. [ ] ordered incomplete
"""

@changes =
toComplete: """
- [ ] complete
- [ ] incomplete
- [#{@nbsp}] incompleteNBSP
> - [x] quoted complete
> - [ ] quoted incomplete
>> - [x] inner complete
> > - [ ] inner incomplete
> 0. [x] ordered complete
> 0. [ ] ordered incomplete
"""
toQuotedComplete: """
- [x] complete
- [ ] incomplete
- [#{@nbsp}] incompleteNBSP
> - [ ] quoted complete
> - [ ] quoted incomplete
>> - [x] inner complete
> > - [ ] inner incomplete
> 0. [x] ordered complete
> 0. [ ] ordered incomplete
"""
toInnerComplete: """
- [x] complete
- [ ] incomplete
- [#{@nbsp}] incompleteNBSP
> - [x] quoted complete
> - [ ] quoted incomplete
>> - [ ] inner complete
> > - [ ] inner incomplete
> 0. [x] ordered complete
> 0. [ ] ordered incomplete
"""
toOrderedComplete: """
- [x] complete
- [ ] incomplete
- [#{@nbsp}] incompleteNBSP
> - [x] quoted complete
> - [ ] quoted incomplete
>> - [x] inner complete
> > - [ ] inner incomplete
> 0. [ ] ordered complete
> 0. [ ] ordered incomplete
"""
toIncomplete: """
- [x] complete
- [x] incomplete
- [#{@nbsp}] incompleteNBSP
> - [x] quoted complete
> - [ ] quoted incomplete
>> - [x] inner complete
> > - [ ] inner incomplete
> 0. [x] ordered complete
> 0. [ ] ordered incomplete
"""
toQuotedIncomplete: """
- [x] complete
- [ ] incomplete
- [#{@nbsp}] incompleteNBSP
> - [x] quoted complete
> - [x] quoted incomplete
>> - [x] inner complete
> > - [ ] inner incomplete
> 0. [x] ordered complete
> 0. [ ] ordered incomplete
"""
toInnerIncomplete: """
- [x] complete
- [ ] incomplete
- [#{@nbsp}] incompleteNBSP
> - [x] quoted complete
> - [ ] quoted incomplete
>> - [x] inner complete
> > - [x] inner incomplete
> 0. [x] ordered complete
> 0. [ ] ordered incomplete
"""
toOrderedIncomplete: """
- [x] complete
- [ ] incomplete
- [#{@nbsp}] incompleteNBSP
> - [x] quoted complete
> - [ ] quoted incomplete
>> - [x] inner complete
> > - [ ] inner incomplete
> 0. [x] ordered complete
> 0. [x] ordered incomplete
"""
toIncompleteNBSP: """
- [x] complete
- [ ] incomplete
- [x] incompleteNBSP
> - [x] quoted complete
> - [ ] quoted incomplete
>> - [x] inner complete
> > - [ ] inner incomplete
> 0. [x] ordered complete
> 0. [ ] ordered incomplete
"""

@completeItem.append @completeCheckbox
Expand All @@ -67,6 +209,43 @@ module "TaskList updates",
@container.append @list
@container.append @field

@quotedCompleteItem.append @quotedCompleteCheckbox
@quotedList.append @quotedCompleteItem
@quotedCompleteItem.expectedIndex = 4

@quotedIncompleteItem.append @quotedIncompleteCheckbox
@quotedList.append @quotedIncompleteItem
@quotedIncompleteItem.expectedIndex = 5

@blockquote.append @quotedList

@innerCompleteItem.append @innerCompleteCheckbox
@innerList.append @innerCompleteItem
@innerCompleteItem.expectedIndex = 6

@innerIncompleteItem.append @innerIncompleteCheckbox
@innerList.append @innerIncompleteItem
@innerIncompleteItem.expectedIndex = 7

@innerBlockquote.append @innerList
@innerBlockquote.append @innerField

@blockquote.append @innerBlockquote

@container.append @blockquote

@orderedCompleteItem.append @orderedCompleteCheckbox
@orderedList.append @orderedCompleteItem
@orderedCompleteItem.expectedIndex = 8

@orderedIncompleteItem.append @orderedIncompleteCheckbox
@orderedList.append @orderedIncompleteItem
@orderedIncompleteItem.expectedIndex = 9

@container.append @orderedList

@blockquote.append @field

$('#qunit-fixture').append(@container)
@container.taskList()

Expand Down Expand Up @@ -115,3 +294,88 @@ asyncTest "updates the source for items with non-breaking spaces", ->
, 20

@incompleteNBSPCheckbox.click()

asyncTest "updates the source of a quoted item, marking the incomplete item as complete", ->
expect 3

@field.on 'tasklist:changed', (event, index, checked) =>
ok checked
equal index, @quotedIncompleteItem.expectedIndex
equal @field.val(), @changes.toQuotedIncomplete

setTimeout ->
start()
, 20

@quotedIncompleteCheckbox.click()

asyncTest "updates the source of a quoted item, marking the complete item as incomplete", ->
expect 3

@field.on 'tasklist:changed', (event, index, checked) =>
ok !checked
equal index, @quotedCompleteItem.expectedIndex
equal @field.val(), @changes.toQuotedComplete

setTimeout ->
start()
, 20

@quotedCompleteCheckbox.click()

asyncTest "updates the source of a quoted quoted item, marking the incomplete item as complete", ->
expect 3

@field.on 'tasklist:changed', (event, index, checked) =>
ok checked
equal index, @innerIncompleteItem.expectedIndex
equal @field.val(), @changes.toInnerIncomplete

setTimeout ->
start()
, 20

@innerIncompleteCheckbox.click()

asyncTest "updates the source of a quoted quoted item, marking the complete item as incomplete", ->
expect 3

@field.on 'tasklist:changed', (event, index, checked) =>
ok !checked
equal index, @innerCompleteItem.expectedIndex
equal @field.val(), @changes.toInnerComplete

setTimeout ->
start()
, 20

@innerCompleteCheckbox.click()

asyncTest "updates the source of an ordered list item, marking the incomplete item as complete", ->
expect 3

@field.on 'tasklist:changed', (event, index, checked) =>
ok checked
equal index, @orderedIncompleteItem.expectedIndex
equal @field.val(), @changes.toOrderedIncomplete

setTimeout ->
start()
, 20

@orderedIncompleteCheckbox.click()

asyncTest "updates the source of an ordered list item, marking the complete item as incomplete", ->
expect 3

@field.on 'tasklist:changed', (event, index, checked) =>
ok !checked
equal index, @orderedCompleteItem.expectedIndex
equal @field.val(), @changes.toOrderedComplete

setTimeout ->
start()
, 20

@orderedCompleteCheckbox.click()