issue_spec.js.coffee 3.7 KB
Newer Older
R
Robert Speicher 已提交
1 2 3 4
#= require issue

describe 'Issue', ->
  describe 'task lists', ->
5
    fixture.preload('issues_show.html')
R
Robert Speicher 已提交
6 7

    beforeEach ->
8
      fixture.load('issues_show.html')
R
Robert Speicher 已提交
9 10
      @issue = new Issue()

11
    it 'modifies the Markdown field', ->
R
Robert Speicher 已提交
12
      spyOn(jQuery, 'ajax').and.stub()
13 14 15
      $('input[type=checkbox]').attr('checked', true).trigger('change')
      expect($('.js-task-list-field').val()).toBe('- [x] Task List Item')

R
Robert Speicher 已提交
16
    it 'submits an ajax request on tasklist:changed', ->
R
Robert Speicher 已提交
17
      spyOn(jQuery, 'ajax').and.callFake (req) ->
R
Robert Speicher 已提交
18 19 20 21 22
        expect(req.type).toBe('PATCH')
        expect(req.url).toBe('/foo')
        expect(req.data.issue.description).not.toBe(null)

      $('.js-task-list-field').trigger('tasklist:changed')
23 24 25 26 27 28
describe 'reopen/close issue', ->
  fixture.preload('issues_show.html')
  beforeEach ->
    fixture.load('issues_show.html')
    @issue = new Issue()
  it 'closes an issue', ->
J
Jacob Schatz 已提交
29 30 31 32
    spyOn(jQuery, 'ajax').and.callFake (req) ->
      expect(req.type).toBe('PUT')
      expect(req.url).toBe('http://gitlab.com/issues/6/close')
      req.success saved: true
33
    
34 35
    $btnClose = $('a.btn-close')
    $btnReopen = $('a.btn-reopen')
36
    expect($btnReopen).toBeHidden()
37 38
    expect($btnClose.text()).toBe('Close')
    expect(typeof $btnClose.prop('disabled')).toBe('undefined')
39

40
    $btnClose.trigger('click')
41
    
42 43 44 45
    expect($btnReopen).toBeVisible()
    expect($btnClose).toBeHidden()
    expect($('div.status-box-closed')).toBeVisible()
    expect($('div.status-box-open')).toBeHidden()
46

47 48
  it 'fails to closes an issue with success:false', ->

J
Jacob Schatz 已提交
49 50 51 52
    spyOn(jQuery, 'ajax').and.callFake (req) ->
      expect(req.type).toBe('PUT')
      expect(req.url).toBe('http://goesnowhere.nothing/whereami')
      req.success saved: false
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    
    $btnClose = $('a.btn-close')
    $btnReopen = $('a.btn-reopen')
    $btnClose.attr('href','http://goesnowhere.nothing/whereami')
    expect($btnReopen).toBeHidden()
    expect($btnClose.text()).toBe('Close')
    expect(typeof $btnClose.prop('disabled')).toBe('undefined')

    $btnClose.trigger('click')
    
    expect($btnReopen).toBeHidden()
    expect($btnClose).toBeVisible()
    expect($('div.status-box-closed')).toBeHidden()
    expect($('div.status-box-open')).toBeVisible()
    expect($('div.flash-alert')).toBeVisible()
    expect($('div.flash-alert').text()).toBe('Unable to update this issue at this time.')

  it 'fails to closes an issue with HTTP error', ->

J
Jacob Schatz 已提交
72 73 74 75
    spyOn(jQuery, 'ajax').and.callFake (req) ->
      expect(req.type).toBe('PUT')
      expect(req.url).toBe('http://goesnowhere.nothing/whereami')
      req.error()
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    
    $btnClose = $('a.btn-close')
    $btnReopen = $('a.btn-reopen')
    $btnClose.attr('href','http://goesnowhere.nothing/whereami')
    expect($btnReopen).toBeHidden()
    expect($btnClose.text()).toBe('Close')
    expect(typeof $btnClose.prop('disabled')).toBe('undefined')

    $btnClose.trigger('click')
    
    expect($btnReopen).toBeHidden()
    expect($btnClose).toBeVisible()
    expect($('div.status-box-closed')).toBeHidden()
    expect($('div.status-box-open')).toBeVisible()
    expect($('div.flash-alert')).toBeVisible()
    expect($('div.flash-alert').text()).toBe('Unable to update this issue at this time.')

93
  it 'reopens an issue', ->
J
Jacob Schatz 已提交
94 95 96 97
    spyOn(jQuery, 'ajax').and.callFake (req) ->
      expect(req.type).toBe('PUT')
      expect(req.url).toBe('http://gitlab.com/issues/6/reopen')
      req.success saved: true
98

99 100 101
    $btnClose = $('a.btn-close')
    $btnReopen = $('a.btn-reopen')
    expect($btnReopen.text()).toBe('Reopen')
102

103
    $btnReopen.trigger('click')
104

105 106 107 108
    expect($btnReopen).toBeHidden()
    expect($btnClose).toBeVisible()
    expect($('div.status-box-open')).toBeVisible()
    expect($('div.status-box-closed')).toBeHidden()