summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Schatz <jacobschatz@Jacobs-MBP.fios-router.home>2015-12-23 17:41:05 -0500
committerJacob Schatz <jacobschatz@Jacobs-MBP.fios-router.home>2015-12-23 17:41:05 -0500
commite11ee5ff01bf031cd4fda377a7444f2ba4d50f40 (patch)
tree2293d015f57afc311d3995866c95ac1a4180e870
parentb3e4bc5911737db82f2b296a0eed7fcb59fa28bb (diff)
downloadgitlab-ce-e11ee5ff01bf031cd4fda377a7444f2ba4d50f40.tar.gz
adds test for issue close/reopen failure
-rw-r--r--app/assets/javascripts/issue.js.coffee5
-rw-r--r--spec/javascripts/fixtures/issues_show.html.haml13
-rw-r--r--spec/javascripts/issue_spec.js.coffee51
3 files changed, 63 insertions, 6 deletions
diff --git a/app/assets/javascripts/issue.js.coffee b/app/assets/javascripts/issue.js.coffee
index 1a9e03e4ee3..3d9d514a9c7 100644
--- a/app/assets/javascripts/issue.js.coffee
+++ b/app/assets/javascripts/issue.js.coffee
@@ -15,6 +15,7 @@ class @Issue
$(document).on 'tasklist:changed', '.detail-page-description .js-task-list-container', @updateTaskList
initIssueBtnEventListeners: ->
+ issueFailMessage = 'Unable to update this issue at this time.'
$('a.btn-close, a.btn-reopen').on 'click', (e) ->
e.preventDefault()
e.stopImmediatePropagation()
@@ -27,7 +28,7 @@ class @Issue
url: url,
error: (jqXHR, textStatus, errorThrown) ->
issueStatus = if isClose then 'close' else 'open'
- new Flash('Issues update failed', 'alert')
+ new Flash(issueFailMessage, 'alert')
success: (data, textStatus, jqXHR) ->
if data.saved
$this.addClass('hidden')
@@ -40,7 +41,7 @@ class @Issue
$('div.status-box-closed').addClass('hidden')
$('div.status-box-open').removeClass('hidden')
else
- new Flash('Issues update failed', 'alert')
+ new Flash(issueFailMessage, 'alert')
$this.prop('disabled', false)
disableTaskList: ->
diff --git a/spec/javascripts/fixtures/issues_show.html.haml b/spec/javascripts/fixtures/issues_show.html.haml
index f67ea5a13c7..dd01b6378c5 100644
--- a/spec/javascripts/fixtures/issues_show.html.haml
+++ b/spec/javascripts/fixtures/issues_show.html.haml
@@ -1,10 +1,19 @@
:css
.hidden { display: none !important; }
+.flash-container
+ - if alert
+ .flash-alert
+ = alert
+
+ - elsif notice
+ .flash-notice
+ = notice
+
.status-box.status-box-open Open
.status-box.status-box-closed.hidden Closed
-%a.btn-close{"href" => "http://gitlab/issues/6/close"} Close
-%a.btn-reopen.hidden{"href" => "http://gitlab/issues/6/reopen"} Reopen
+%a.btn-close{"href" => "http://gitlab.com/issues/6/close"} Close
+%a.btn-reopen.hidden{"href" => "http://gitlab.com/issues/6/reopen"} Reopen
.detail-page-description
.description.js-task-list-container
diff --git a/spec/javascripts/issue_spec.js.coffee b/spec/javascripts/issue_spec.js.coffee
index 142eb05cc67..f0a57d99c56 100644
--- a/spec/javascripts/issue_spec.js.coffee
+++ b/spec/javascripts/issue_spec.js.coffee
@@ -1,3 +1,4 @@
+#= require flash
#= require issue
describe 'Issue', ->
@@ -28,7 +29,7 @@ describe 'reopen/close issue', ->
it 'closes an issue', ->
$.ajax = (obj) ->
expect(obj.type).toBe('PUT')
- expect(obj.url).toBe('http://gitlab/issues/6/close')
+ expect(obj.url).toBe('http://gitlab.com/issues/6/close')
obj.success saved: true
$btnClose = $('a.btn-close')
@@ -44,10 +45,56 @@ describe 'reopen/close issue', ->
expect($('div.status-box-closed')).toBeVisible()
expect($('div.status-box-open')).toBeHidden()
+ it 'fails to closes an issue with success:false', ->
+
+ $.ajax = (obj) ->
+ expect(obj.type).toBe('PUT')
+ expect(obj.url).toBe('http://goesnowhere.nothing/whereami')
+ obj.success saved: false
+
+ $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', ->
+
+ $.ajax = (obj) ->
+ expect(obj.type).toBe('PUT')
+ expect(obj.url).toBe('http://goesnowhere.nothing/whereami')
+ obj.error()
+
+ $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 'reopens an issue', ->
$.ajax = (obj) ->
expect(obj.type).toBe('PUT')
- expect(obj.url).toBe('http://gitlab/issues/6/reopen')
+ expect(obj.url).toBe('http://gitlab.com/issues/6/reopen')
obj.success saved: true
$btnClose = $('a.btn-close')