File: test_events.coffee

package info (click to toggle)
ruby-task-list 2.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 256 kB
  • sloc: ruby: 308; javascript: 58; sh: 14; makefile: 8
file content (98 lines) | stat: -rw-r--r-- 2,331 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
window.$ = window.jQuery = require('jquery')
window.TaskList = require('../../app/assets/javascripts/task_list')

QUnit.module "TaskList events",
  beforeEach: ->
    @container = $ '<div>', class: 'js-task-list-container'

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

    @field = $ '<textarea>', class: 'js-task-list-field', "- [ ] text"

    @item.append @checkbox
    @list.append @item
    @container.append @list

    @container.append @field

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

  afterEach: ->
    $(document).off 'tasklist:enabled'
    $(document).off 'tasklist:disabled'
    $(document).off 'tasklist:change'
    $(document).off 'tasklist:changed'

QUnit.test "triggers a tasklist:change event before making task list item changes", (assert) ->
  done = assert.async()
  assert.expect 1

  @field.on 'tasklist:change', (event, index, checked) ->
    assert.ok true
    done()

  @checkbox.click()

QUnit.test "triggers a tasklist:changed event once a task list item changes", (assert) ->
  done = assert.async()
  assert.expect 1

  @field.on 'tasklist:changed', (event, index, checked) ->
    assert.ok true
    done()

  @checkbox.click()

QUnit.test "can cancel a tasklist:changed event", (assert) ->
  done = assert.async()
  done2 = assert.async()
  assert.expect 2

  @field.on 'tasklist:change', (event, index, checked) ->
    assert.ok true
    event.preventDefault()
    done2()

  @field.on 'tasklist:changed', (event, index, checked) ->
    assert.ok false

  before = @checkbox.val()
  setTimeout =>
    assert.ok true
    done()
  , 20

  @checkbox.click()

QUnit.test "enables task list items when a .js-task-list-field is present", (assert) ->
  done = assert.async()
  assert.expect 1

  $(document).on 'tasklist:enabled', (event) ->
    assert.ok true
    done()
  
  @container.taskList()

QUnit.test "doesn't enable task list items when a .js-task-list-field is absent", (assert) ->
  done = assert.async()
  assert.expect 1

  $(document).on 'tasklist:enabled', (event) ->
    assert.ok false

  @field.remove()

  @container.taskList()

  setTimeout =>
    assert.ok true
    done()
  , 20