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
3bd5b7d1
Commit
3bd5b7d1
authored
Jan 29, 2020
by
Nicolò Maria Mezzopera
Committed by
Natalia Tepluhina
Jan 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tracking for submit and reset events
- tracking - unit tests update
parent
7d47ea84
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
9 deletions
+42
-9
app/assets/javascripts/registry/settings/components/settings_form.vue
...avascripts/registry/settings/components/settings_form.vue
+15
-1
spec/frontend/registry/settings/components/settings_form_spec.js
...ontend/registry/settings/components/settings_form_spec.js
+27
-8
No files found.
app/assets/javascripts/registry/settings/components/settings_form.vue
View file @
3bd5b7d1
...
...
@@ -10,6 +10,7 @@ import {
GlLoadingIcon
,
}
from
'
@gitlab/ui
'
;
import
{
s__
,
__
,
sprintf
}
from
'
~/locale
'
;
import
Tracking
from
'
~/tracking
'
;
import
{
NAME_REGEX_LENGTH
,
UPDATE_SETTINGS_ERROR_MESSAGE
,
...
...
@@ -27,10 +28,18 @@ export default {
GlCard
,
GlLoadingIcon
,
},
mixins
:
[
Tracking
.
mixin
()],
labelsConfig
:
{
cols
:
3
,
align
:
'
right
'
,
},
data
()
{
return
{
tracking
:
{
label
:
'
docker_container_retention_and_expiration_policies
'
,
},
};
},
computed
:
{
...
mapState
([
'
formOptions
'
,
'
isLoading
'
]),
...
mapComputed
(
...
...
@@ -86,7 +95,12 @@ export default {
},
methods
:
{
...
mapActions
([
'
resetSettings
'
,
'
saveSettings
'
]),
reset
()
{
this
.
track
(
'
reset_form
'
);
this
.
resetSettings
();
},
submit
()
{
this
.
track
(
'
submit_form
'
);
this
.
saveSettings
()
.
then
(()
=>
this
.
$toast
.
show
(
UPDATE_SETTINGS_SUCCESS_MESSAGE
,
{
type
:
'
success
'
}))
.
catch
(()
=>
this
.
$toast
.
show
(
UPDATE_SETTINGS_ERROR_MESSAGE
,
{
type
:
'
error
'
}));
...
...
@@ -96,7 +110,7 @@ export default {
</
script
>
<
template
>
<form
ref=
"form-element"
@
submit.prevent=
"submit"
@
reset.prevent=
"reset
Settings
"
>
<form
ref=
"form-element"
@
submit.prevent=
"submit"
@
reset.prevent=
"reset"
>
<gl-card>
<template
#header
>
{{
s__
(
'
ContainerRegistry|Tag expiration policy
'
)
}}
...
...
spec/frontend/registry/settings/components/settings_form_spec.js
View file @
3bd5b7d1
import
{
mount
}
from
'
@vue/test-utils
'
;
import
Tracking
from
'
~/tracking
'
;
import
stubChildren
from
'
helpers/stub_children
'
;
import
component
from
'
~/registry/settings/components/settings_form.vue
'
;
import
{
createStore
}
from
'
~/registry/settings/store/
'
;
...
...
@@ -15,6 +16,9 @@ describe('Settings Form', () => {
let
dispatchSpy
;
const
FORM_ELEMENTS_ID_PREFIX
=
'
#expiration-policy
'
;
const
trackingPayload
=
{
label
:
'
docker_container_retention_and_expiration_policies
'
,
};
const
GlLoadingIcon
=
{
name
:
'
gl-loading-icon-stub
'
,
template
:
'
<svg></svg>
'
};
...
...
@@ -48,6 +52,7 @@ describe('Settings Form', () => {
store
.
dispatch
(
'
setInitialState
'
,
stringifiedFormOptions
);
dispatchSpy
=
jest
.
spyOn
(
store
,
'
dispatch
'
);
mountComponent
();
jest
.
spyOn
(
Tracking
,
'
event
'
);
});
afterEach
(()
=>
{
...
...
@@ -118,15 +123,23 @@ describe('Settings Form', () => {
beforeEach
(()
=>
{
form
=
findForm
();
});
it
(
'
cancel has type reset
'
,
()
=>
{
expect
(
findCancelButton
().
attributes
(
'
type
'
)).
toBe
(
'
reset
'
);
});
it
(
'
form reset event call the appropriate function
'
,
()
=>
{
dispatchSpy
.
mockReturnValue
();
form
.
trigger
(
'
reset
'
);
// expect.any(Object) is necessary because the event payload is passed to the function
expect
(
dispatchSpy
).
toHaveBeenCalledWith
(
'
resetSettings
'
,
expect
.
any
(
Object
));
describe
(
'
form cancel event
'
,
()
=>
{
it
(
'
has type reset
'
,
()
=>
{
expect
(
findCancelButton
().
attributes
(
'
type
'
)).
toBe
(
'
reset
'
);
});
it
(
'
calls the appropriate function
'
,
()
=>
{
dispatchSpy
.
mockReturnValue
();
form
.
trigger
(
'
reset
'
);
expect
(
dispatchSpy
).
toHaveBeenCalledWith
(
'
resetSettings
'
);
});
it
(
'
tracks the reset event
'
,
()
=>
{
dispatchSpy
.
mockReturnValue
();
form
.
trigger
(
'
reset
'
);
expect
(
Tracking
.
event
).
toHaveBeenCalledWith
(
undefined
,
'
reset_form
'
,
trackingPayload
);
});
});
it
(
'
save has type submit
'
,
()
=>
{
...
...
@@ -177,6 +190,12 @@ describe('Settings Form', () => {
expect
(
dispatchSpy
).
toHaveBeenCalledWith
(
'
saveSettings
'
);
});
it
(
'
tracks the submit event
'
,
()
=>
{
dispatchSpy
.
mockResolvedValue
();
form
.
trigger
(
'
submit
'
);
expect
(
Tracking
.
event
).
toHaveBeenCalledWith
(
undefined
,
'
submit_form
'
,
trackingPayload
);
});
it
(
'
show a success toast when submit succeed
'
,
()
=>
{
dispatchSpy
.
mockResolvedValue
();
form
.
trigger
(
'
submit
'
);
...
...
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