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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
63cf88ba
Commit
63cf88ba
authored
Sep 23, 2019
by
Winnie Hellmann
Committed by
Fatih Acet
Sep 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor RecaptchaModal component to allow more than one instance
parent
3b7fd896
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
5 deletions
+81
-5
app/assets/javascripts/vue_shared/components/recaptcha_eventhub.js
...s/javascripts/vue_shared/components/recaptcha_eventhub.js
+21
-0
app/assets/javascripts/vue_shared/components/recaptcha_modal.vue
...ets/javascripts/vue_shared/components/recaptcha_modal.vue
+3
-5
spec/frontend/vue_shared/components/recaptcha_eventhub_spec.js
...frontend/vue_shared/components/recaptcha_eventhub_spec.js
+21
-0
spec/frontend/vue_shared/components/recaptcha_modal_spec.js
spec/frontend/vue_shared/components/recaptcha_modal_spec.js
+36
-0
No files found.
app/assets/javascripts/vue_shared/components/recaptcha_eventhub.js
0 → 100644
View file @
63cf88ba
import
Vue
from
'
vue
'
;
// see recaptcha_tags in app/views/shared/_recaptcha_form.html.haml
export
const
callbackName
=
'
recaptchaDialogCallback
'
;
export
const
eventHub
=
new
Vue
();
const
throwDuplicateCallbackError
=
()
=>
{
throw
new
Error
(
`
${
callbackName
}
is already defined!`
);
};
if
(
window
[
callbackName
])
{
throwDuplicateCallbackError
();
}
const
callback
=
()
=>
eventHub
.
$emit
(
'
submit
'
);
Object
.
defineProperty
(
window
,
callbackName
,
{
get
:
()
=>
callback
,
set
:
throwDuplicateCallbackError
,
});
app/assets/javascripts/vue_shared/components/recaptcha_modal.vue
View file @
63cf88ba
<
script
>
<
script
>
import
DeprecatedModal
from
'
./deprecated_modal.vue
'
;
import
DeprecatedModal
from
'
./deprecated_modal.vue
'
;
import
{
eventHub
}
from
'
./recaptcha_eventhub
'
;
export
default
{
export
default
{
name
:
'
RecaptchaModal
'
,
name
:
'
RecaptchaModal
'
,
...
@@ -30,14 +31,11 @@ export default {
...
@@ -30,14 +31,11 @@ export default {
},
},
mounted
()
{
mounted
()
{
if
(
window
.
recaptchaDialogCallback
)
{
eventHub
.
$on
(
'
submit
'
,
this
.
submit
);
throw
new
Error
(
'
recaptchaDialogCallback is already defined!
'
);
}
window
.
recaptchaDialogCallback
=
this
.
submit
.
bind
(
this
);
},
},
beforeDestroy
()
{
beforeDestroy
()
{
window
.
recaptchaDialogCallback
=
null
;
eventHub
.
$off
(
'
submit
'
,
this
.
submit
)
;
},
},
methods
:
{
methods
:
{
...
...
spec/frontend/vue_shared/components/recaptcha_eventhub_spec.js
0 → 100644
View file @
63cf88ba
import
{
eventHub
,
callbackName
}
from
'
~/vue_shared/components/recaptcha_eventhub
'
;
describe
(
'
reCAPTCHA event hub
'
,
()
=>
{
// the following test case currently crashes
// see https://gitlab.com/gitlab-org/gitlab/issues/29192#note_217840035
// eslint-disable-next-line jest/no-disabled-tests
it
.
skip
(
'
throws an error for overriding the callback
'
,
()
=>
{
expect
(()
=>
{
window
[
callbackName
]
=
'
something
'
;
}).
toThrow
();
});
it
(
'
triggering callback emits a submit event
'
,
()
=>
{
const
eventHandler
=
jest
.
fn
();
eventHub
.
$once
(
'
submit
'
,
eventHandler
);
window
[
callbackName
]();
expect
(
eventHandler
).
toHaveBeenCalled
();
});
});
spec/frontend/vue_shared/components/recaptcha_modal_spec.js
0 → 100644
View file @
63cf88ba
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
eventHub
}
from
'
~/vue_shared/components/recaptcha_eventhub
'
;
import
RecaptchaModal
from
'
~/vue_shared/components/recaptcha_modal
'
;
describe
(
'
RecaptchaModal
'
,
()
=>
{
const
recaptchaFormId
=
'
recaptcha-form
'
;
const
recaptchaHtml
=
`<form id="
${
recaptchaFormId
}
"></form>`
;
let
wrapper
;
const
findRecaptchaForm
=
()
=>
wrapper
.
find
(
`#
${
recaptchaFormId
}
`
).
element
;
beforeEach
(()
=>
{
wrapper
=
shallowMount
(
RecaptchaModal
,
{
sync
:
false
,
propsData
:
{
html
:
recaptchaHtml
,
},
});
});
afterEach
(()
=>
{
wrapper
.
destroy
();
});
it
(
'
submits the form if event hub emits submit event
'
,
()
=>
{
const
form
=
findRecaptchaForm
();
jest
.
spyOn
(
form
,
'
submit
'
).
mockImplementation
();
eventHub
.
$emit
(
'
submit
'
);
expect
(
form
.
submit
).
toHaveBeenCalled
();
});
});
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