Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
1a3b292d
Commit
1a3b292d
authored
Dec 08, 2017
by
Luke Bennett
Committed by
Sean McGivern
Dec 08, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "No feedback when checking on checklist if potential spam was detected"
parent
9429e8ac
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
363 additions
and
68 deletions
+363
-68
app/assets/javascripts/issue.js
app/assets/javascripts/issue.js
+1
-12
app/assets/javascripts/issue_show/components/app.vue
app/assets/javascripts/issue_show/components/app.vue
+58
-30
app/assets/javascripts/issue_show/components/description.vue
app/assets/javascripts/issue_show/components/description.vue
+23
-1
app/assets/javascripts/vue_shared/components/popup_dialog.vue
...assets/javascripts/vue_shared/components/popup_dialog.vue
+4
-2
app/assets/javascripts/vue_shared/components/recaptcha_dialog.vue
...ts/javascripts/vue_shared/components/recaptcha_dialog.vue
+85
-0
app/assets/javascripts/vue_shared/mixins/recaptcha_dialog_implementor.js
...scripts/vue_shared/mixins/recaptcha_dialog_implementor.js
+36
-0
app/assets/stylesheets/framework/modal.scss
app/assets/stylesheets/framework/modal.scss
+7
-0
app/controllers/concerns/issuable_actions.rb
app/controllers/concerns/issuable_actions.rb
+1
-1
app/controllers/concerns/spammable_actions.rb
app/controllers/concerns/spammable_actions.rb
+14
-3
app/views/layouts/_recaptcha_verification.html.haml
app/views/layouts/_recaptcha_verification.html.haml
+1
-14
app/views/shared/_recaptcha_form.html.haml
app/views/shared/_recaptcha_form.html.haml
+19
-0
changelogs/unreleased/29483-no-feedback-when-checking-on-checklist-if-potential-spam-was-detected.yml
...-checking-on-checklist-if-potential-spam-was-detected.yml
+5
-0
spec/controllers/projects/issues_controller_spec.rb
spec/controllers/projects/issues_controller_spec.rb
+18
-5
spec/javascripts/issue_show/components/app_spec.js
spec/javascripts/issue_show/components/app_spec.js
+49
-0
spec/javascripts/issue_show/components/description_spec.js
spec/javascripts/issue_show/components/description_spec.js
+30
-0
spec/javascripts/vue_shared/components/popup_dialog_spec.js
spec/javascripts/vue_shared/components/popup_dialog_spec.js
+12
-0
No files found.
app/assets/javascripts/issue.js
View file @
1a3b292d
...
@@ -8,18 +8,7 @@ import IssuablesHelper from './helpers/issuables_helper';
...
@@ -8,18 +8,7 @@ import IssuablesHelper from './helpers/issuables_helper';
export
default
class
Issue
{
export
default
class
Issue
{
constructor
()
{
constructor
()
{
if
(
$
(
'
a.btn-close
'
).
length
)
{
if
(
$
(
'
a.btn-close
'
).
length
)
this
.
initIssueBtnEventListeners
();
this
.
taskList
=
new
TaskList
({
dataType
:
'
issue
'
,
fieldName
:
'
description
'
,
selector
:
'
.detail-page-description
'
,
onSuccess
:
(
result
)
=>
{
document
.
querySelector
(
'
#task_status
'
).
innerText
=
result
.
task_status
;
document
.
querySelector
(
'
#task_status_short
'
).
innerText
=
result
.
task_status_short
;
}
});
this
.
initIssueBtnEventListeners
();
}
Issue
.
$btnNewBranch
=
$
(
'
#new-branch
'
);
Issue
.
$btnNewBranch
=
$
(
'
#new-branch
'
);
Issue
.
createMrDropdownWrap
=
document
.
querySelector
(
'
.create-mr-dropdown-wrap
'
);
Issue
.
createMrDropdownWrap
=
document
.
querySelector
(
'
.create-mr-dropdown-wrap
'
);
...
...
app/assets/javascripts/issue_show/components/app.vue
View file @
1a3b292d
...
@@ -9,6 +9,7 @@ import descriptionComponent from './description.vue';
...
@@ -9,6 +9,7 @@ import descriptionComponent from './description.vue';
import
editedComponent
from
'
./edited.vue
'
;
import
editedComponent
from
'
./edited.vue
'
;
import
formComponent
from
'
./form.vue
'
;
import
formComponent
from
'
./form.vue
'
;
import
'
../../lib/utils/url_utility
'
;
import
'
../../lib/utils/url_utility
'
;
import
RecaptchaDialogImplementor
from
'
../../vue_shared/mixins/recaptcha_dialog_implementor
'
;
export
default
{
export
default
{
props
:
{
props
:
{
...
@@ -149,6 +150,11 @@ export default {
...
@@ -149,6 +150,11 @@ export default {
editedComponent
,
editedComponent
,
formComponent
,
formComponent
,
},
},
mixins
:
[
RecaptchaDialogImplementor
,
],
methods
:
{
methods
:
{
openForm
()
{
openForm
()
{
if
(
!
this
.
showForm
)
{
if
(
!
this
.
showForm
)
{
...
@@ -164,9 +170,11 @@ export default {
...
@@ -164,9 +170,11 @@ export default {
closeForm
()
{
closeForm
()
{
this
.
showForm
=
false
;
this
.
showForm
=
false
;
},
},
updateIssuable
()
{
updateIssuable
()
{
this
.
service
.
updateIssuable
(
this
.
store
.
formState
)
this
.
service
.
updateIssuable
(
this
.
store
.
formState
)
.
then
(
res
=>
res
.
json
())
.
then
(
res
=>
res
.
json
())
.
then
(
data
=>
this
.
checkForSpam
(
data
))
.
then
((
data
)
=>
{
.
then
((
data
)
=>
{
if
(
location
.
pathname
!==
data
.
web_url
)
{
if
(
location
.
pathname
!==
data
.
web_url
)
{
gl
.
utils
.
visitUrl
(
data
.
web_url
);
gl
.
utils
.
visitUrl
(
data
.
web_url
);
...
@@ -179,11 +187,24 @@ export default {
...
@@ -179,11 +187,24 @@ export default {
this
.
store
.
updateState
(
data
);
this
.
store
.
updateState
(
data
);
eventHub
.
$emit
(
'
close.form
'
);
eventHub
.
$emit
(
'
close.form
'
);
})
})
.
catch
(()
=>
{
.
catch
((
error
)
=>
{
eventHub
.
$emit
(
'
close.form
'
);
if
(
error
&&
error
.
name
===
'
SpamError
'
)
{
window
.
Flash
(
`Error updating
${
this
.
issuableType
}
`
);
this
.
openRecaptcha
();
}
else
{
eventHub
.
$emit
(
'
close.form
'
);
window
.
Flash
(
`Error updating
${
this
.
issuableType
}
`
);
}
});
});
},
},
closeRecaptchaDialog
()
{
this
.
store
.
setFormState
({
updateLoading
:
false
,
});
this
.
closeRecaptcha
();
},
deleteIssuable
()
{
deleteIssuable
()
{
this
.
service
.
deleteIssuable
()
this
.
service
.
deleteIssuable
()
.
then
(
res
=>
res
.
json
())
.
then
(
res
=>
res
.
json
())
...
@@ -237,9 +258,9 @@ export default {
...
@@ -237,9 +258,9 @@ export default {
</
script
>
</
script
>
<
template
>
<
template
>
<div>
<div>
<div
v-if=
"canUpdate && showForm"
>
<form-component
<form-component
v-if=
"canUpdate && showForm"
:form-state=
"formState"
:form-state=
"formState"
:can-destroy=
"canDestroy"
:can-destroy=
"canDestroy"
:issuable-templates=
"issuableTemplates"
:issuable-templates=
"issuableTemplates"
...
@@ -251,30 +272,37 @@ export default {
...
@@ -251,30 +272,37 @@ export default {
:can-attach-file=
"canAttachFile"
:can-attach-file=
"canAttachFile"
:enable-autocomplete=
"enableAutocomplete"
:enable-autocomplete=
"enableAutocomplete"
/>
/>
<div
v-else
>
<title-component
<recaptcha-dialog
:issuable-ref=
"issuableRef"
v-show=
"showRecaptcha"
:can-update=
"canUpdate"
:html=
"recaptchaHTML"
:title-html=
"state.titleHtml"
@
close=
"closeRecaptchaDialog"
:title-text=
"state.titleText"
/>
:show-inline-edit-button=
"showInlineEditButton"
</div>
/>
<div
v-else
>
<description-component
<title-component
v-if=
"state.descriptionHtml"
:issuable-ref=
"issuableRef"
:can-update=
"canUpdate"
:can-update=
"canUpdate"
:description-html=
"state.descriptionHtml"
:title-html=
"state.titleHtml"
:description-text=
"state.descriptionText"
:title-text=
"state.titleText"
:updated-at=
"state.updatedAt"
:show-inline-edit-button=
"showInlineEditButton"
:task-status=
"state.taskStatus"
/>
:issuable-type=
"issuableType"
<description-component
:update-url=
"updateEndpoint"
v-if=
"state.descriptionHtml"
/>
:can-update=
"canUpdate"
<edited-component
:description-html=
"state.descriptionHtml"
v-if=
"hasUpdated"
:description-text=
"state.descriptionText"
:updated-at=
"state.updatedAt"
:updated-at=
"state.updatedAt"
:updated-by-name=
"state.updatedByName"
:task-status=
"state.taskStatus"
:updated-by-path=
"state.updatedByPath"
:issuable-type=
"issuableType"
/>
:update-url=
"updateEndpoint"
</div>
/>
<edited-component
v-if=
"hasUpdated"
:updated-at=
"state.updatedAt"
:updated-by-name=
"state.updatedByName"
:updated-by-path=
"state.updatedByPath"
/>
</div>
</div>
</div>
</
template
>
</
template
>
app/assets/javascripts/issue_show/components/description.vue
View file @
1a3b292d
<
script
>
<
script
>
import
animateMixin
from
'
../mixins/animate
'
;
import
animateMixin
from
'
../mixins/animate
'
;
import
TaskList
from
'
../../task_list
'
;
import
TaskList
from
'
../../task_list
'
;
import
RecaptchaDialogImplementor
from
'
../../vue_shared/mixins/recaptcha_dialog_implementor
'
;
export
default
{
export
default
{
mixins
:
[
animateMixin
],
mixins
:
[
animateMixin
,
RecaptchaDialogImplementor
,
],
props
:
{
props
:
{
canUpdate
:
{
canUpdate
:
{
type
:
Boolean
,
type
:
Boolean
,
...
@@ -51,6 +56,7 @@
...
@@ -51,6 +56,7 @@
this
.
updateTaskStatusText
();
this
.
updateTaskStatusText
();
},
},
},
},
methods
:
{
methods
:
{
renderGFM
()
{
renderGFM
()
{
$
(
this
.
$refs
[
'
gfm-content
'
]).
renderGFM
();
$
(
this
.
$refs
[
'
gfm-content
'
]).
renderGFM
();
...
@@ -61,9 +67,19 @@
...
@@ -61,9 +67,19 @@
dataType
:
this
.
issuableType
,
dataType
:
this
.
issuableType
,
fieldName
:
'
description
'
,
fieldName
:
'
description
'
,
selector
:
'
.detail-page-description
'
,
selector
:
'
.detail-page-description
'
,
onSuccess
:
this
.
taskListUpdateSuccess
.
bind
(
this
),
});
});
}
}
},
},
taskListUpdateSuccess
(
data
)
{
try
{
this
.
checkForSpam
(
data
);
}
catch
(
error
)
{
if
(
error
&&
error
.
name
===
'
SpamError
'
)
this
.
openRecaptcha
();
}
},
updateTaskStatusText
()
{
updateTaskStatusText
()
{
const
taskRegexMatches
=
this
.
taskStatus
.
match
(
/
(\d
+
)
of
((?!
0
)\d
+
)
/
);
const
taskRegexMatches
=
this
.
taskStatus
.
match
(
/
(\d
+
)
of
((?!
0
)\d
+
)
/
);
const
$issuableHeader
=
$
(
'
.issuable-meta
'
);
const
$issuableHeader
=
$
(
'
.issuable-meta
'
);
...
@@ -109,5 +125,11 @@
...
@@ -109,5 +125,11 @@
:data-update-url=
"updateUrl"
:data-update-url=
"updateUrl"
>
>
</textarea>
</textarea>
<recaptcha-dialog
v-show=
"showRecaptcha"
:html=
"recaptchaHTML"
@
close=
"closeRecaptcha"
/>
</div>
</div>
</
template
>
</
template
>
app/assets/javascripts/vue_shared/components/popup_dialog.vue
View file @
1a3b292d
...
@@ -38,7 +38,8 @@ export default {
...
@@ -38,7 +38,8 @@ export default {
},
},
primaryButtonLabel
:
{
primaryButtonLabel
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
false
,
default
:
''
,
},
},
submitDisabled
:
{
submitDisabled
:
{
type
:
Boolean
,
type
:
Boolean
,
...
@@ -113,8 +114,9 @@ export default {
...
@@ -113,8 +114,9 @@ export default {
{{
closeButtonLabel
}}
{{
closeButtonLabel
}}
</button>
</button>
<button
<button
v-if=
"primaryButtonLabel"
type=
"button"
type=
"button"
class=
"btn pull-right"
class=
"btn pull-right
js-primary-button
"
:disabled=
"submitDisabled"
:disabled=
"submitDisabled"
:class=
"btnKindClass"
:class=
"btnKindClass"
@
click=
"emitSubmit(true)"
>
@
click=
"emitSubmit(true)"
>
...
...
app/assets/javascripts/vue_shared/components/recaptcha_dialog.vue
0 → 100644
View file @
1a3b292d
<
script
>
import
PopupDialog
from
'
./popup_dialog.vue
'
;
export
default
{
name
:
'
recaptcha-dialog
'
,
props
:
{
html
:
{
type
:
String
,
required
:
false
,
default
:
''
,
},
},
data
()
{
return
{
script
:
{},
scriptSrc
:
'
https://www.google.com/recaptcha/api.js
'
,
};
},
components
:
{
PopupDialog
,
},
methods
:
{
appendRecaptchaScript
()
{
this
.
removeRecaptchaScript
();
const
script
=
document
.
createElement
(
'
script
'
);
script
.
src
=
this
.
scriptSrc
;
script
.
classList
.
add
(
'
js-recaptcha-script
'
);
script
.
async
=
true
;
script
.
defer
=
true
;
this
.
script
=
script
;
document
.
body
.
appendChild
(
script
);
},
removeRecaptchaScript
()
{
if
(
this
.
script
instanceof
Element
)
this
.
script
.
remove
();
},
close
()
{
this
.
removeRecaptchaScript
();
this
.
$emit
(
'
close
'
);
},
submit
()
{
this
.
$el
.
querySelector
(
'
form
'
).
submit
();
},
},
watch
:
{
html
()
{
this
.
appendRecaptchaScript
();
},
},
mounted
()
{
window
.
recaptchaDialogCallback
=
this
.
submit
.
bind
(
this
);
},
};
</
script
>
<
template
>
<popup-dialog
kind=
"warning"
class=
"recaptcha-dialog js-recaptcha-dialog"
:hide-footer=
"true"
:title=
"__('Please solve the reCAPTCHA')"
@
toggle=
"close"
>
<div
slot=
"body"
>
<p>
{{
__
(
'
We want to be sure it is you, please confirm you are not a robot.
'
)
}}
</p>
<div
ref=
"recaptcha"
v-html=
"html"
></div>
</div>
</popup-dialog>
</
template
>
app/assets/javascripts/vue_shared/mixins/recaptcha_dialog_implementor.js
0 → 100644
View file @
1a3b292d
import
RecaptchaDialog
from
'
../components/recaptcha_dialog.vue
'
;
export
default
{
data
()
{
return
{
showRecaptcha
:
false
,
recaptchaHTML
:
''
,
};
},
components
:
{
RecaptchaDialog
,
},
methods
:
{
openRecaptcha
()
{
this
.
showRecaptcha
=
true
;
},
closeRecaptcha
()
{
this
.
showRecaptcha
=
false
;
},
checkForSpam
(
data
)
{
if
(
!
data
.
recaptcha_html
)
return
data
;
this
.
recaptchaHTML
=
data
.
recaptcha_html
;
const
spamError
=
new
Error
(
data
.
error_message
);
spamError
.
name
=
'
SpamError
'
;
spamError
.
message
=
'
SpamError
'
;
throw
spamError
;
},
},
};
app/assets/stylesheets/framework/modal.scss
View file @
1a3b292d
...
@@ -48,3 +48,10 @@ body.modal-open {
...
@@ -48,3 +48,10 @@ body.modal-open {
display
:
block
;
display
:
block
;
}
}
.recaptcha-dialog
.recaptcha-form
{
display
:
inline-block
;
.recaptcha
{
margin
:
0
;
}
}
app/controllers/concerns/issuable_actions.rb
View file @
1a3b292d
...
@@ -25,7 +25,7 @@ module IssuableActions
...
@@ -25,7 +25,7 @@ module IssuableActions
end
end
format
.
json
do
format
.
json
do
re
nder_entity_json
re
captcha_check_with_fallback
(
false
)
{
render_entity_json
}
end
end
end
end
...
...
app/controllers/concerns/spammable_actions.rb
View file @
1a3b292d
...
@@ -23,8 +23,8 @@ module SpammableActions
...
@@ -23,8 +23,8 @@ module SpammableActions
@spam_config_loaded
=
Gitlab
::
Recaptcha
.
load_configurations!
@spam_config_loaded
=
Gitlab
::
Recaptcha
.
load_configurations!
end
end
def
recaptcha_check_with_fallback
(
&
fallback
)
def
recaptcha_check_with_fallback
(
should_redirect
=
true
,
&
fallback
)
if
spammable
.
valid?
if
s
hould_redirect
&&
s
pammable
.
valid?
redirect_to
spammable_path
redirect_to
spammable_path
elsif
render_recaptcha?
elsif
render_recaptcha?
ensure_spam_config_loaded!
ensure_spam_config_loaded!
...
@@ -33,7 +33,18 @@ module SpammableActions
...
@@ -33,7 +33,18 @@ module SpammableActions
flash
[
:alert
]
=
'There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.'
flash
[
:alert
]
=
'There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.'
end
end
render
:verify
respond_to
do
|
format
|
format
.
html
do
render
:verify
end
format
.
json
do
locals
=
{
spammable:
spammable
,
script:
false
,
has_submit:
false
}
recaptcha_html
=
render_to_string
(
partial:
'shared/recaptcha_form'
,
formats: :html
,
locals:
locals
)
render
json:
{
recaptcha_html:
recaptcha_html
}
end
end
else
else
yield
yield
end
end
...
...
app/views/layouts/_recaptcha_verification.html.haml
View file @
1a3b292d
-
humanized_resource_name
=
spammable
.
class
.
model_name
.
human
.
downcase
-
humanized_resource_name
=
spammable
.
class
.
model_name
.
human
.
downcase
-
resource_name
=
spammable
.
class
.
model_name
.
singular
%h3
.page-title
%h3
.page-title
Anti-spam verification
Anti-spam verification
...
@@ -8,16 +7,4 @@
...
@@ -8,16 +7,4 @@
%p
%p
#{
"We detected potential spam in the #{humanized_resource_name}. Please solve the reCAPTCHA to proceed."
}
#{
"We detected potential spam in the #{humanized_resource_name}. Please solve the reCAPTCHA to proceed."
}
=
form_for
form
do
|
f
|
=
render
'shared/recaptcha_form'
,
spammable:
spammable
.recaptcha
-
params
[
resource_name
].
each
do
|
field
,
value
|
=
hidden_field
(
resource_name
,
field
,
value:
value
)
=
hidden_field_tag
(
:spam_log_id
,
spammable
.
spam_log
.
id
)
=
hidden_field_tag
(
:recaptcha_verification
,
true
)
=
recaptcha_tags
-# Yields a block with given extra params.
=
yield
.row-content-block.footer-block
=
f
.
submit
"Submit
#{
humanized_resource_name
}
"
,
class:
'btn btn-create'
app/views/shared/_recaptcha_form.html.haml
0 → 100644
View file @
1a3b292d
-
resource_name
=
spammable
.
class
.
model_name
.
singular
-
humanized_resource_name
=
spammable
.
class
.
model_name
.
human
.
downcase
-
script
=
local_assigns
.
fetch
(
:script
,
true
)
-
has_submit
=
local_assigns
.
fetch
(
:has_submit
,
true
)
=
form_for
resource_name
,
method: :post
,
html:
{
class:
'recaptcha-form js-recaptcha-form'
}
do
|
f
|
.recaptcha
-
params
[
resource_name
].
each
do
|
field
,
value
|
=
hidden_field
(
resource_name
,
field
,
value:
value
)
=
hidden_field_tag
(
:spam_log_id
,
spammable
.
spam_log
.
id
)
=
hidden_field_tag
(
:recaptcha_verification
,
true
)
=
recaptcha_tags
script:
script
,
callback:
'recaptchaDialogCallback'
-# Yields a block with given extra params.
=
yield
-
if
has_submit
.row-content-block.footer-block
=
f
.
submit
"Submit
#{
humanized_resource_name
}
"
,
class:
'btn btn-create'
changelogs/unreleased/29483-no-feedback-when-checking-on-checklist-if-potential-spam-was-detected.yml
0 → 100644
View file @
1a3b292d
---
title
:
Add recaptcha modal to issue updates detected as spam
merge_request
:
15408
author
:
type
:
fixed
spec/controllers/projects/issues_controller_spec.rb
View file @
1a3b292d
...
@@ -272,6 +272,20 @@ describe Projects::IssuesController do
...
@@ -272,6 +272,20 @@ describe Projects::IssuesController do
expect
(
response
).
to
have_http_status
(
:ok
)
expect
(
response
).
to
have_http_status
(
:ok
)
expect
(
issue
.
reload
.
title
).
to
eq
(
'New title'
)
expect
(
issue
.
reload
.
title
).
to
eq
(
'New title'
)
end
end
context
'when Akismet is enabled and the issue is identified as spam'
do
before
do
stub_application_setting
(
recaptcha_enabled:
true
)
allow_any_instance_of
(
SpamService
).
to
receive
(
:check_for_spam?
).
and_return
(
true
)
allow_any_instance_of
(
AkismetService
).
to
receive
(
:spam?
).
and_return
(
true
)
end
it
'renders json with recaptcha_html'
do
subject
expect
(
JSON
.
parse
(
response
.
body
)).
to
have_key
(
'recaptcha_html'
)
end
end
end
end
context
'when user does not have access to update issue'
do
context
'when user does not have access to update issue'
do
...
@@ -504,17 +518,16 @@ describe Projects::IssuesController do
...
@@ -504,17 +518,16 @@ describe Projects::IssuesController do
expect
(
spam_logs
.
first
.
recaptcha_verified
).
to
be_falsey
expect
(
spam_logs
.
first
.
recaptcha_verified
).
to
be_falsey
end
end
it
'renders
json errors
'
do
it
'renders
recaptcha_html json response
'
do
update_issue
update_issue
expect
(
json_response
)
expect
(
json_response
).
to
have_key
(
'recaptcha_html'
)
.
to
eql
(
"errors"
=>
[
"Your issue has been recognized as spam. Please, change the content or solve the reCAPTCHA to proceed."
])
end
end
it
'returns
422
status'
do
it
'returns
200
status'
do
update_issue
update_issue
expect
(
response
).
to
have_gitlab_http_status
(
422
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
end
end
...
...
spec/javascripts/issue_show/components/app_spec.js
View file @
1a3b292d
...
@@ -4,6 +4,7 @@ import '~/render_gfm';
...
@@ -4,6 +4,7 @@ import '~/render_gfm';
import
issuableApp
from
'
~/issue_show/components/app.vue
'
;
import
issuableApp
from
'
~/issue_show/components/app.vue
'
;
import
eventHub
from
'
~/issue_show/event_hub
'
;
import
eventHub
from
'
~/issue_show/event_hub
'
;
import
issueShowData
from
'
../mock_data
'
;
import
issueShowData
from
'
../mock_data
'
;
import
setTimeoutPromise
from
'
../../helpers/set_timeout_promise_helper
'
;
function
formatText
(
text
)
{
function
formatText
(
text
)
{
return
text
.
trim
().
replace
(
/
\s\s
+/g
,
'
'
);
return
text
.
trim
().
replace
(
/
\s\s
+/g
,
'
'
);
...
@@ -55,6 +56,8 @@ describe('Issuable output', () => {
...
@@ -55,6 +56,8 @@ describe('Issuable output', () => {
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
interceptor
);
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
interceptor
);
vm
.
poll
.
stop
();
vm
.
poll
.
stop
();
vm
.
$destroy
();
});
});
it
(
'
should render a title/description/edited and update title/description/edited on update
'
,
(
done
)
=>
{
it
(
'
should render a title/description/edited and update title/description/edited on update
'
,
(
done
)
=>
{
...
@@ -268,6 +271,52 @@ describe('Issuable output', () => {
...
@@ -268,6 +271,52 @@ describe('Issuable output', () => {
});
});
});
});
it
(
'
opens recaptcha dialog if update rejected as spam
'
,
(
done
)
=>
{
function
mockScriptSrc
()
{
const
recaptchaChild
=
vm
.
$children
.
find
(
child
=>
child
.
$options
.
_componentTag
===
'
recaptcha-dialog
'
);
// eslint-disable-line no-underscore-dangle
recaptchaChild
.
scriptSrc
=
'
//scriptsrc
'
;
}
let
modal
;
const
promise
=
new
Promise
((
resolve
)
=>
{
resolve
({
json
()
{
return
{
recaptcha_html
:
'
<div class="g-recaptcha">recaptcha_html</div>
'
,
};
},
});
});
spyOn
(
vm
.
service
,
'
updateIssuable
'
).
and
.
returnValue
(
promise
);
vm
.
canUpdate
=
true
;
vm
.
showForm
=
true
;
vm
.
$nextTick
()
.
then
(()
=>
mockScriptSrc
())
.
then
(()
=>
vm
.
updateIssuable
())
.
then
(
promise
)
.
then
(()
=>
setTimeoutPromise
())
.
then
(()
=>
{
modal
=
vm
.
$el
.
querySelector
(
'
.js-recaptcha-dialog
'
);
expect
(
modal
.
style
.
display
).
not
.
toEqual
(
'
none
'
);
expect
(
modal
.
querySelector
(
'
.g-recaptcha
'
).
textContent
).
toEqual
(
'
recaptcha_html
'
);
expect
(
document
.
body
.
querySelector
(
'
.js-recaptcha-script
'
).
src
).
toMatch
(
'
//scriptsrc
'
);
})
.
then
(()
=>
modal
.
querySelector
(
'
.close
'
).
click
())
.
then
(()
=>
vm
.
$nextTick
())
.
then
(()
=>
{
expect
(
modal
.
style
.
display
).
toEqual
(
'
none
'
);
expect
(
document
.
body
.
querySelector
(
'
.js-recaptcha-script
'
)).
toBeNull
();
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
describe
(
'
deleteIssuable
'
,
()
=>
{
describe
(
'
deleteIssuable
'
,
()
=>
{
it
(
'
changes URL when deleted
'
,
(
done
)
=>
{
it
(
'
changes URL when deleted
'
,
(
done
)
=>
{
spyOn
(
gl
.
utils
,
'
visitUrl
'
);
spyOn
(
gl
.
utils
,
'
visitUrl
'
);
...
...
spec/javascripts/issue_show/components/description_spec.js
View file @
1a3b292d
...
@@ -51,6 +51,35 @@ describe('Description component', () => {
...
@@ -51,6 +51,35 @@ describe('Description component', () => {
});
});
});
});
it
(
'
opens recaptcha dialog if update rejected as spam
'
,
(
done
)
=>
{
let
modal
;
const
recaptchaChild
=
vm
.
$children
.
find
(
child
=>
child
.
$options
.
_componentTag
===
'
recaptcha-dialog
'
);
// eslint-disable-line no-underscore-dangle
recaptchaChild
.
scriptSrc
=
'
//scriptsrc
'
;
vm
.
taskListUpdateSuccess
({
recaptcha_html
:
'
<div class="g-recaptcha">recaptcha_html</div>
'
,
});
vm
.
$nextTick
()
.
then
(()
=>
{
modal
=
vm
.
$el
.
querySelector
(
'
.js-recaptcha-dialog
'
);
expect
(
modal
.
style
.
display
).
not
.
toEqual
(
'
none
'
);
expect
(
modal
.
querySelector
(
'
.g-recaptcha
'
).
textContent
).
toEqual
(
'
recaptcha_html
'
);
expect
(
document
.
body
.
querySelector
(
'
.js-recaptcha-script
'
).
src
).
toMatch
(
'
//scriptsrc
'
);
})
.
then
(()
=>
modal
.
querySelector
(
'
.close
'
).
click
())
.
then
(()
=>
vm
.
$nextTick
())
.
then
(()
=>
{
expect
(
modal
.
style
.
display
).
toEqual
(
'
none
'
);
expect
(
document
.
body
.
querySelector
(
'
.js-recaptcha-script
'
)).
toBeNull
();
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
describe
(
'
TaskList
'
,
()
=>
{
describe
(
'
TaskList
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
vm
=
mountComponent
(
DescriptionComponent
,
Object
.
assign
({},
props
,
{
vm
=
mountComponent
(
DescriptionComponent
,
Object
.
assign
({},
props
,
{
...
@@ -86,6 +115,7 @@ describe('Description component', () => {
...
@@ -86,6 +115,7 @@ describe('Description component', () => {
dataType
:
'
issuableType
'
,
dataType
:
'
issuableType
'
,
fieldName
:
'
description
'
,
fieldName
:
'
description
'
,
selector
:
'
.detail-page-description
'
,
selector
:
'
.detail-page-description
'
,
onSuccess
:
jasmine
.
any
(
Function
),
});
});
done
();
done
();
});
});
...
...
spec/javascripts/vue_shared/components/popup_dialog_spec.js
0 → 100644
View file @
1a3b292d
import
Vue
from
'
vue
'
;
import
PopupDialog
from
'
~/vue_shared/components/popup_dialog.vue
'
;
import
mountComponent
from
'
../../helpers/vue_mount_component_helper
'
;
describe
(
'
PopupDialog
'
,
()
=>
{
it
(
'
does not render a primary button if no primaryButtonLabel
'
,
()
=>
{
const
popupDialog
=
Vue
.
extend
(
PopupDialog
);
const
vm
=
mountComponent
(
popupDialog
);
expect
(
vm
.
$el
.
querySelector
(
'
.js-primary-button
'
)).
toBeNull
();
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment