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
925655ed
Commit
925655ed
authored
Jul 22, 2021
by
Robert Hunt
Committed by
Savas Vedova
Jul 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add loading icon and form hiding on error to group-level merge request settings
parent
c83cf1f8
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
358 additions
and
181 deletions
+358
-181
ee/app/assets/javascripts/approvals/components/approval_settings.vue
...ts/javascripts/approvals/components/approval_settings.vue
+85
-49
ee/app/assets/javascripts/approvals/constants.js
ee/app/assets/javascripts/approvals/constants.js
+16
-7
ee/app/assets/javascripts/approvals/stores/modules/group_settings/actions.js
...cripts/approvals/stores/modules/group_settings/actions.js
+17
-22
ee/app/assets/javascripts/approvals/stores/modules/group_settings/mutation_types.js
...approvals/stores/modules/group_settings/mutation_types.js
+2
-0
ee/app/assets/javascripts/approvals/stores/modules/group_settings/mutations.js
...ipts/approvals/stores/modules/group_settings/mutations.js
+13
-0
ee/app/assets/javascripts/approvals/stores/modules/group_settings/state.js
...ascripts/approvals/stores/modules/group_settings/state.js
+2
-0
ee/spec/frontend/approvals/components/approval_settings_spec.js
...c/frontend/approvals/components/approval_settings_spec.js
+145
-57
ee/spec/frontend/approvals/stores/modules/group_settings/actions_spec.js
...d/approvals/stores/modules/group_settings/actions_spec.js
+31
-28
ee/spec/frontend/approvals/stores/modules/group_settings/mutations_spec.js
...approvals/stores/modules/group_settings/mutations_spec.js
+23
-0
locale/gitlab.pot
locale/gitlab.pot
+24
-18
No files found.
ee/app/assets/javascripts/approvals/components/approval_settings.vue
View file @
925655ed
<
script
>
<
script
>
import
{
GlButton
,
GlForm
,
GlFormGroup
}
from
'
@gitlab/ui
'
;
import
{
GlAlert
,
GlButton
,
GlForm
,
GlFormGroup
,
GlLoadingIcon
}
from
'
@gitlab/ui
'
;
import
{
isEmpty
}
from
'
lodash
'
;
import
{
mapActions
,
mapState
}
from
'
vuex
'
;
import
{
mapActions
,
mapState
}
from
'
vuex
'
;
import
{
mapComputed
}
from
'
~/vuex_shared/bindings
'
;
import
{
mapComputed
}
from
'
~/vuex_shared/bindings
'
;
import
{
APPROVAL_SETTINGS_I18N
}
from
'
../constants
'
;
import
{
APPROVAL_SETTINGS_I18N
}
from
'
../constants
'
;
...
@@ -8,9 +9,11 @@ import ApprovalSettingsCheckbox from './approval_settings_checkbox.vue';
...
@@ -8,9 +9,11 @@ import ApprovalSettingsCheckbox from './approval_settings_checkbox.vue';
export
default
{
export
default
{
components
:
{
components
:
{
ApprovalSettingsCheckbox
,
ApprovalSettingsCheckbox
,
GlAlert
,
GlButton
,
GlButton
,
GlForm
,
GlForm
,
GlFormGroup
,
GlFormGroup
,
GlLoadingIcon
,
},
},
props
:
{
props
:
{
approvalSettingsPath
:
{
approvalSettingsPath
:
{
...
@@ -18,14 +21,12 @@ export default {
...
@@ -18,14 +21,12 @@ export default {
required
:
true
,
required
:
true
,
},
},
},
},
data
()
{
return
{
hasFormLoaded
:
false
,
};
},
computed
:
{
computed
:
{
...
mapState
({
...
mapState
({
isLoading
:
(
state
)
=>
state
.
approvals
.
isLoading
,
isLoading
:
(
state
)
=>
state
.
approvals
.
isLoading
,
isUpdated
:
(
state
)
=>
state
.
approvals
.
isUpdated
,
settings
:
(
state
)
=>
state
.
approvals
.
settings
,
errorMessage
:
(
state
)
=>
state
.
approvals
.
errorMessage
,
}),
}),
...
mapComputed
(
...
mapComputed
(
[
[
...
@@ -38,15 +39,25 @@ export default {
...
@@ -38,15 +39,25 @@ export default {
undefined
,
undefined
,
(
state
)
=>
state
.
approvals
.
settings
,
(
state
)
=>
state
.
approvals
.
settings
,
),
),
hasSettings
()
{
return
!
isEmpty
(
this
.
settings
);
},
isLoaded
()
{
return
this
.
hasSettings
||
this
.
errorMessage
;
},
},
},
async
created
()
{
created
()
{
await
this
.
fetchSettings
(
this
.
approvalSettingsPath
);
this
.
fetchSettings
(
this
.
approvalSettingsPath
);
this
.
hasFormLoaded
=
true
;
},
},
methods
:
{
methods
:
{
...
mapActions
([
'
fetchSettings
'
,
'
updateSettings
'
]),
...
mapActions
([
onSubmit
()
{
'
fetchSettings
'
,
this
.
updateSettings
(
this
.
approvalSettingsPath
);
'
updateSettings
'
,
'
dismissErrorMessage
'
,
'
dismissSuccessMessage
'
,
]),
async
onSubmit
()
{
await
this
.
updateSettings
(
this
.
approvalSettingsPath
);
},
},
},
},
links
:
{
links
:
{
...
@@ -62,7 +73,31 @@ export default {
...
@@ -62,7 +73,31 @@ export default {
</
script
>
</
script
>
<
template
>
<
template
>
<gl-form
v-if=
"hasFormLoaded"
@
submit.prevent=
"onSubmit"
>
<div>
<gl-loading-icon
v-if=
"!isLoaded"
size=
"lg"
/>
<gl-alert
v-if=
"errorMessage"
variant=
"danger"
:dismissible=
"hasSettings"
:contained=
"true"
:class=
"
{ 'gl-mb-6': hasSettings }"
data-testid="error-alert"
@dismiss="dismissErrorMessage"
>
{{
errorMessage
}}
</gl-alert>
<gl-alert
v-if=
"isUpdated"
variant=
"success"
:dismissible=
"true"
:contained=
"true"
class=
"gl-mb-6"
data-testid=
"success-alert"
@
dismiss=
"dismissSuccessMessage"
>
{{
$options
.
i18n
.
savingSuccessMessage
}}
</gl-alert>
<gl-form
v-if=
"hasSettings"
@
submit.prevent=
"onSubmit"
>
<gl-form-group>
<gl-form-group>
<approval-settings-checkbox
<approval-settings-checkbox
v-model=
"preventAuthorApproval"
v-model=
"preventAuthorApproval"
...
@@ -95,8 +130,9 @@ export default {
...
@@ -95,8 +130,9 @@ export default {
data-testid=
"prevent-committers-approval"
data-testid=
"prevent-committers-approval"
/>
/>
</gl-form-group>
</gl-form-group>
<gl-button
type=
"submit"
variant=
"success"
category=
"primary"
:disabled
=
"isLoading"
>
<gl-button
type=
"submit"
variant=
"confirm"
category=
"primary"
:loading
=
"isLoading"
>
{{
$options
.
i18n
.
saveChanges
}}
{{
$options
.
i18n
.
saveChanges
}}
</gl-button>
</gl-button>
</gl-form>
</gl-form>
</div>
</
template
>
</
template
>
ee/app/assets/javascripts/approvals/constants.js
View file @
925655ed
...
@@ -50,14 +50,23 @@ export const APPROVAL_RULE_CONFIGS = {
...
@@ -50,14 +50,23 @@ export const APPROVAL_RULE_CONFIGS = {
export
const
APPROVALS_HELP_PATH
=
'
user/project/merge_requests/merge_request_approvals
'
;
export
const
APPROVALS_HELP_PATH
=
'
user/project/merge_requests/merge_request_approvals
'
;
export
const
APPROVAL_SETTINGS_I18N
=
{
export
const
APPROVAL_SETTINGS_I18N
=
{
authorApprovalLabel
:
__
(
'
Prevent MR approvals by the author.
'
),
authorApprovalLabel
:
s__
(
'
ApprovalSettings|Prevent MR approvals by the author.
'
),
preventMrApprovalRuleEditLabel
:
__
(
'
Prevent users from modifying MR approval rules.
'
),
preventMrApprovalRuleEditLabel
:
s__
(
preventCommittersApprovalLabel
:
__
(
'
ApprovalSettings|Prevent users from modifying MR approval rules.
'
,
'
Prevent approval of merge requests by merge request committers.
'
,
),
),
requireUserPasswordLabel
:
__
(
'
Require user password for approvals.
'
),
preventCommittersApprovalLabel
:
s__
(
removeApprovalsOnPushLabel
:
__
(
'
ApprovalSettings|Prevent approval of merge requests by merge request committers.
'
,
'
Remove all approvals in a merge request when new commits are pushed to its source branch.
'
,
),
requireUserPasswordLabel
:
s__
(
'
ApprovalSettings|Require user password for approvals.
'
),
removeApprovalsOnPushLabel
:
s__
(
'
ApprovalSettings|Remove all approvals in a merge request when new commits are pushed to its source branch.
'
,
),
),
saveChanges
:
__
(
'
Save changes
'
),
saveChanges
:
__
(
'
Save changes
'
),
loadingErrorMessage
:
s__
(
'
ApprovalSettings|There was an error loading merge request approval settings.
'
,
),
savingErrorMessage
:
s__
(
'
ApprovalSettings|There was an error updating merge request approval settings.
'
,
),
savingSuccessMessage
:
s__
(
'
ApprovalSettings|Merge request approval settings have been updated.
'
),
};
};
ee/app/assets/javascripts/approvals/stores/modules/group_settings/actions.js
View file @
925655ed
import
createFlash
from
'
~/flash
'
;
import
*
as
Sentry
from
'
@sentry/browser
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
{
__
}
from
'
~/locale
'
;
import
*
as
types
from
'
./mutation_types
'
;
import
*
as
types
from
'
./mutation_types
'
;
const
mapStateToPayload
=
(
state
)
=>
({
const
mapStateToPayload
=
(
state
)
=>
({
...
@@ -19,15 +18,11 @@ export const fetchSettings = ({ commit }, endpoint) => {
...
@@ -19,15 +18,11 @@ export const fetchSettings = ({ commit }, endpoint) => {
.
then
(({
data
})
=>
{
.
then
(({
data
})
=>
{
commit
(
types
.
RECEIVE_SETTINGS_SUCCESS
,
data
);
commit
(
types
.
RECEIVE_SETTINGS_SUCCESS
,
data
);
})
})
.
catch
((
{
response
}
)
=>
{
.
catch
((
e
)
=>
{
const
error
=
response
?.
data
?.
messag
e
;
const
error
=
e
?.
response
?.
data
?.
message
||
e
;
commit
(
types
.
RECEIVE_SETTINGS_ERROR
,
error
);
Sentry
.
captureException
(
error
);
createFlash
({
commit
(
types
.
RECEIVE_SETTINGS_ERROR
);
message
:
__
(
'
There was an error loading merge request approval settings.
'
),
captureError
:
true
,
error
,
});
});
});
};
};
...
@@ -38,23 +33,23 @@ export const updateSettings = ({ commit, state }, endpoint) => {
...
@@ -38,23 +33,23 @@ export const updateSettings = ({ commit, state }, endpoint) => {
.
put
(
endpoint
,
{
...
mapStateToPayload
(
state
)
})
.
put
(
endpoint
,
{
...
mapStateToPayload
(
state
)
})
.
then
(({
data
})
=>
{
.
then
(({
data
})
=>
{
commit
(
types
.
UPDATE_SETTINGS_SUCCESS
,
data
);
commit
(
types
.
UPDATE_SETTINGS_SUCCESS
,
data
);
createFlash
({
message
:
__
(
'
Merge request approval settings have been updated.
'
),
type
:
'
notice
'
,
});
})
})
.
catch
((
{
response
}
)
=>
{
.
catch
((
e
)
=>
{
const
error
=
response
?.
data
?.
messag
e
;
const
error
=
e
?.
response
?.
data
?.
message
||
e
;
commit
(
types
.
UPDATE_SETTINGS_ERROR
,
error
);
Sentry
.
captureException
(
error
);
createFlash
({
commit
(
types
.
UPDATE_SETTINGS_ERROR
);
message
:
__
(
'
There was an error updating merge request approval settings.
'
),
captureError
:
true
,
error
,
});
});
});
};
};
export
const
dismissSuccessMessage
=
({
commit
})
=>
{
commit
(
types
.
DISMISS_SUCCESS_MESSAGE
);
};
export
const
dismissErrorMessage
=
({
commit
})
=>
{
commit
(
types
.
DISMISS_ERROR_MESSAGE
);
};
export
const
setPreventAuthorApproval
=
({
commit
},
{
preventAuthorApproval
})
=>
{
export
const
setPreventAuthorApproval
=
({
commit
},
{
preventAuthorApproval
})
=>
{
commit
(
types
.
SET_PREVENT_AUTHOR_APPROVAL
,
preventAuthorApproval
);
commit
(
types
.
SET_PREVENT_AUTHOR_APPROVAL
,
preventAuthorApproval
);
};
};
...
...
ee/app/assets/javascripts/approvals/stores/modules/group_settings/mutation_types.js
View file @
925655ed
...
@@ -6,6 +6,8 @@ export const RECEIVE_SETTINGS_ERROR = 'RECEIVE_SETTINGS_ERROR';
...
@@ -6,6 +6,8 @@ export const RECEIVE_SETTINGS_ERROR = 'RECEIVE_SETTINGS_ERROR';
export
const
REQUEST_UPDATE_SETTINGS
=
'
REQUEST_UPDATE_SETTINGS
'
;
export
const
REQUEST_UPDATE_SETTINGS
=
'
REQUEST_UPDATE_SETTINGS
'
;
export
const
UPDATE_SETTINGS_SUCCESS
=
'
UPDATE_SETTINGS_SUCCESS
'
;
export
const
UPDATE_SETTINGS_SUCCESS
=
'
UPDATE_SETTINGS_SUCCESS
'
;
export
const
UPDATE_SETTINGS_ERROR
=
'
UPDATE_SETTINGS_ERROR
'
;
export
const
UPDATE_SETTINGS_ERROR
=
'
UPDATE_SETTINGS_ERROR
'
;
export
const
DISMISS_SUCCESS_MESSAGE
=
'
DISMISS_SUCCESS_MESSAGE
'
;
export
const
DISMISS_ERROR_MESSAGE
=
'
DISMISS_ERROR_MESSAGE
'
;
export
const
SET_PREVENT_AUTHOR_APPROVAL
=
'
SET_PREVENT_AUTHOR_APPROVAL
'
;
export
const
SET_PREVENT_AUTHOR_APPROVAL
=
'
SET_PREVENT_AUTHOR_APPROVAL
'
;
export
const
SET_PREVENT_COMMITTERS_APPROVAL
=
'
SET_PREVENT_COMMITTERS_APPROVAL
'
;
export
const
SET_PREVENT_COMMITTERS_APPROVAL
=
'
SET_PREVENT_COMMITTERS_APPROVAL
'
;
...
...
ee/app/assets/javascripts/approvals/stores/modules/group_settings/mutations.js
View file @
925655ed
import
{
APPROVAL_SETTINGS_I18N
}
from
'
../../../constants
'
;
import
*
as
types
from
'
./mutation_types
'
;
import
*
as
types
from
'
./mutation_types
'
;
const
mapDataToState
=
(
data
)
=>
({
const
mapDataToState
=
(
data
)
=>
({
...
@@ -11,6 +12,7 @@ const mapDataToState = (data) => ({
...
@@ -11,6 +12,7 @@ const mapDataToState = (data) => ({
export
default
{
export
default
{
[
types
.
REQUEST_SETTINGS
](
state
)
{
[
types
.
REQUEST_SETTINGS
](
state
)
{
state
.
isLoading
=
true
;
state
.
isLoading
=
true
;
state
.
errorMessage
=
''
;
},
},
[
types
.
RECEIVE_SETTINGS_SUCCESS
](
state
,
data
)
{
[
types
.
RECEIVE_SETTINGS_SUCCESS
](
state
,
data
)
{
state
.
settings
=
{
...
mapDataToState
(
data
)
};
state
.
settings
=
{
...
mapDataToState
(
data
)
};
...
@@ -18,16 +20,27 @@ export default {
...
@@ -18,16 +20,27 @@ export default {
},
},
[
types
.
RECEIVE_SETTINGS_ERROR
](
state
)
{
[
types
.
RECEIVE_SETTINGS_ERROR
](
state
)
{
state
.
isLoading
=
false
;
state
.
isLoading
=
false
;
state
.
errorMessage
=
APPROVAL_SETTINGS_I18N
.
loadingErrorMessage
;
},
},
[
types
.
REQUEST_UPDATE_SETTINGS
](
state
)
{
[
types
.
REQUEST_UPDATE_SETTINGS
](
state
)
{
state
.
isLoading
=
true
;
state
.
isLoading
=
true
;
state
.
isUpdated
=
false
;
state
.
errorMessage
=
''
;
},
},
[
types
.
UPDATE_SETTINGS_SUCCESS
](
state
,
data
)
{
[
types
.
UPDATE_SETTINGS_SUCCESS
](
state
,
data
)
{
state
.
settings
=
{
...
mapDataToState
(
data
)
};
state
.
settings
=
{
...
mapDataToState
(
data
)
};
state
.
isLoading
=
false
;
state
.
isLoading
=
false
;
state
.
isUpdated
=
true
;
},
},
[
types
.
UPDATE_SETTINGS_ERROR
](
state
)
{
[
types
.
UPDATE_SETTINGS_ERROR
](
state
)
{
state
.
isLoading
=
false
;
state
.
isLoading
=
false
;
state
.
errorMessage
=
APPROVAL_SETTINGS_I18N
.
savingErrorMessage
;
},
[
types
.
DISMISS_SUCCESS_MESSAGE
](
state
)
{
state
.
isUpdated
=
false
;
},
[
types
.
DISMISS_ERROR_MESSAGE
](
state
)
{
state
.
errorMessage
=
''
;
},
},
[
types
.
SET_PREVENT_AUTHOR_APPROVAL
](
state
,
preventAuthorApproval
)
{
[
types
.
SET_PREVENT_AUTHOR_APPROVAL
](
state
,
preventAuthorApproval
)
{
state
.
settings
.
preventAuthorApproval
=
preventAuthorApproval
;
state
.
settings
.
preventAuthorApproval
=
preventAuthorApproval
;
...
...
ee/app/assets/javascripts/approvals/stores/modules/group_settings/state.js
View file @
925655ed
export
default
()
=>
({
export
default
()
=>
({
settings
:
{},
settings
:
{},
isLoading
:
false
,
isLoading
:
false
,
isUpdated
:
false
,
errorMessage
:
''
,
});
});
ee/spec/frontend/approvals/components/approval_settings_spec.js
View file @
925655ed
import
{
GlButton
,
GlForm
}
from
'
@gitlab/ui
'
;
import
{
GlButton
,
GlForm
,
GlLoadingIcon
}
from
'
@gitlab/ui
'
;
import
{
createLocalVue
,
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
createLocalVue
,
shallowMount
}
from
'
@vue/test-utils
'
;
import
Vuex
from
'
vuex
'
;
import
Vuex
from
'
vuex
'
;
import
ApprovalSettings
from
'
ee/approvals/components/approval_settings.vue
'
;
import
ApprovalSettings
from
'
ee/approvals/components/approval_settings.vue
'
;
import
{
APPROVAL_SETTINGS_I18N
}
from
'
ee/approvals/constants
'
;
import
{
APPROVAL_SETTINGS_I18N
}
from
'
ee/approvals/constants
'
;
import
{
createStoreOptions
}
from
'
ee/approvals/stores
'
;
import
createStore
from
'
ee/approvals/stores
'
;
import
groupSettingsModule
from
'
ee/approvals/stores/modules/group_settings
'
;
import
groupSettingsModule
from
'
ee/approvals/stores/modules/group_settings
'
;
import
{
extendedWrapper
}
from
'
helpers/vue_test_utils_helper
'
;
import
{
extendedWrapper
}
from
'
helpers/vue_test_utils_helper
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
...
@@ -19,50 +19,122 @@ describe('ApprovalSettings', () => {
...
@@ -19,50 +19,122 @@ describe('ApprovalSettings', () => {
const
approvalSettingsPath
=
'
groups/22/merge_request_approval_settings
'
;
const
approvalSettingsPath
=
'
groups/22/merge_request_approval_settings
'
;
const
setupStore
=
(
data
=
{})
=>
{
const
module
=
groupSettingsModule
();
module
.
state
.
settings
=
data
;
actions
=
module
.
actions
;
jest
.
spyOn
(
actions
,
'
fetchSettings
'
).
mockImplementation
();
jest
.
spyOn
(
actions
,
'
updateSettings
'
).
mockImplementation
();
jest
.
spyOn
(
actions
,
'
dismissErrorMessage
'
).
mockImplementation
();
jest
.
spyOn
(
actions
,
'
dismissSuccessMessage
'
).
mockImplementation
();
store
=
createStore
(
module
);
};
const
createWrapper
=
()
=>
{
const
createWrapper
=
()
=>
{
wrapper
=
extendedWrapper
(
wrapper
=
extendedWrapper
(
shallowMount
(
ApprovalSettings
,
{
shallowMount
(
ApprovalSettings
,
{
localVue
,
localVue
,
store
:
new
Vuex
.
Store
(
store
)
,
store
,
propsData
:
{
approvalSettingsPath
},
propsData
:
{
approvalSettingsPath
},
}),
}),
);
);
};
};
const
findLoadingIcon
=
()
=>
wrapper
.
findComponent
(
GlLoadingIcon
);
const
findErrorAlert
=
()
=>
wrapper
.
findByTestId
(
'
error-alert
'
);
const
findSuccessAlert
=
()
=>
wrapper
.
findByTestId
(
'
success-alert
'
);
const
findForm
=
()
=>
wrapper
.
findComponent
(
GlForm
);
const
findForm
=
()
=>
wrapper
.
findComponent
(
GlForm
);
const
findSaveButton
=
()
=>
wrapper
.
findComponent
(
GlButton
);
const
findSaveButton
=
()
=>
wrapper
.
findComponent
(
GlButton
);
beforeEach
(()
=>
{
store
=
createStoreOptions
(
groupSettingsModule
());
actions
=
store
.
modules
.
approvals
.
actions
;
jest
.
spyOn
(
actions
,
'
fetchSettings
'
).
mockImplementation
();
jest
.
spyOn
(
actions
,
'
updateSettings
'
).
mockImplementation
();
});
afterEach
(()
=>
{
afterEach
(()
=>
{
wrapper
.
destroy
();
wrapper
.
destroy
();
store
=
null
;
store
=
null
;
});
});
it
(
'
fetches settings from API
'
,
()
=>
{
it
(
'
fetches settings from API
'
,
()
=>
{
setupStore
();
createWrapper
();
createWrapper
();
expect
(
actions
.
fetchSettings
).
toHaveBeenCalledWith
(
expect
.
any
(
Object
),
approvalSettingsPath
);
expect
(
actions
.
fetchSettings
).
toHaveBeenCalledWith
(
expect
.
any
(
Object
),
approvalSettingsPath
);
});
});
describe
(
'
before loaded
'
,
()
=>
{
beforeEach
(()
=>
{
setupStore
();
});
it
(
'
renders the loading icon and not the form if the settings are not there yet
'
,
()
=>
{
createWrapper
();
expect
(
findLoadingIcon
().
exists
()).
toBe
(
true
);
expect
(
findErrorAlert
().
exists
()).
toBe
(
false
);
expect
(
findSuccessAlert
().
exists
()).
toBe
(
false
);
expect
(
findForm
().
exists
()).
toBe
(
false
);
});
it
(
'
renders the alert and not the form if an initial error occurs
'
,
async
()
=>
{
createWrapper
();
await
store
.
commit
(
'
RECEIVE_SETTINGS_ERROR
'
);
await
waitForPromises
();
expect
(
findLoadingIcon
().
exists
()).
toBe
(
false
);
expect
(
findErrorAlert
().
text
()).
toBe
(
APPROVAL_SETTINGS_I18N
.
loadingErrorMessage
);
expect
(
findErrorAlert
().
classes
(
'
gl-mb-6
'
)).
toBe
(
false
);
expect
(
findForm
().
exists
()).
toBe
(
false
);
});
});
describe
(
'
with settings
'
,
()
=>
{
beforeEach
(()
=>
{
setupStore
({
allow_author_approval
:
false
,
allow_committer_approval
:
false
,
allow_overrides_to_approver_list_per_merge_request
:
false
,
require_password_to_approve
:
false
,
retain_approvals_on_push
:
false
,
});
});
it
(
'
renders the form once successfully loaded
'
,
async
()
=>
{
createWrapper
();
await
waitForPromises
();
expect
(
findLoadingIcon
().
exists
()).
toBe
(
false
);
expect
(
findErrorAlert
().
exists
()).
toBe
(
false
);
expect
(
findSuccessAlert
().
exists
()).
toBe
(
false
);
expect
(
findForm
().
exists
()).
toBe
(
true
);
});
it
(
'
renders enabled button when not loading
'
,
async
()
=>
{
createWrapper
();
await
waitForPromises
();
expect
(
findSaveButton
().
props
(
'
loading
'
)).
toBe
(
false
);
});
it
(
'
renders loading button when loading
'
,
async
()
=>
{
createWrapper
();
await
waitForPromises
();
await
store
.
commit
(
'
REQUEST_UPDATE_SETTINGS
'
);
expect
(
findSaveButton
().
props
(
'
loading
'
)).
toBe
(
true
);
});
describe
.
each
`
describe
.
each
`
testid
| setting | labelKey | anchor
testid | action
| setting | labelKey | anchor
${
'
prevent-author-approval
'
}
|
${
'
preventAuthorApproval
'
}
|
${
'
authorApprovalLabel
'
}
|
${
'
allowing-merge-request-authors-to-approve-their-own-merge-requests
'
}
${
'
prevent-author-approval
'
}
|
${
'
setPreventAuthorApproval
'
}
|
${
'
preventAuthorApproval
'
}
|
${
'
authorApprovalLabel
'
}
|
${
'
allowing-merge-request-authors-to-approve-their-own-merge-requests
'
}
${
'
prevent-committers-approval
'
}
|
${
'
preventCommittersApproval
'
}
|
${
'
preventCommittersApprovalLabel
'
}
|
${
'
prevent-approval-of-merge-requests-by-their-committers
'
}
${
'
prevent-committers-approval
'
}
|
${
'
setPreventCommittersApproval
'
}
|
${
'
preventCommittersApproval
'
}
|
${
'
preventCommittersApprovalLabel
'
}
|
${
'
prevent-approval-of-merge-requests-by-their-committers
'
}
${
'
prevent-mr-approval-rule-e
dit
'
}
|
${
'
preventMrApprovalRuleEdit
'
}
|
${
'
preventMrApprovalRuleEditLabel
'
}
|
${
'
editing--overriding-approval-rules-per-merge-request
'
}
${
'
prevent-mr-approval-rule-edit
'
}
|
${
'
setPreventMrApprovalRuleE
dit
'
}
|
${
'
preventMrApprovalRuleEdit
'
}
|
${
'
preventMrApprovalRuleEditLabel
'
}
|
${
'
editing--overriding-approval-rules-per-merge-request
'
}
${
'
require-user-password
'
}
|
${
'
requireUserPassword
'
}
|
${
'
requireUserPasswordLabel
'
}
|
${
'
require-authentication-when-approving-a-merge-request
'
}
${
'
require-user-password
'
}
|
${
'
setRequireUserPassword
'
}
|
${
'
requireUserPassword
'
}
|
${
'
requireUserPasswordLabel
'
}
|
${
'
require-authentication-when-approving-a-merge-request
'
}
${
'
remove-approvals-on-push
'
}
|
${
'
removeApprovalsOnPush
'
}
|
${
'
removeApprovalsOnPushLabel
'
}
|
${
'
resetting-approvals-on-push
'
}
${
'
remove-approvals-on-push
'
}
|
${
'
setRemoveApprovalsOnPush
'
}
|
${
'
removeApprovalsOnPush
'
}
|
${
'
removeApprovalsOnPushLabel
'
}
|
${
'
resetting-approvals-on-push
'
}
`
(
'
with $testid checkbox
'
,
({
testid
,
setting
,
labelKey
,
anchor
})
=>
{
`
(
'
with the $testid checkbox
'
,
({
testid
,
action
,
setting
,
labelKey
,
anchor
})
=>
{
let
checkbox
=
null
;
let
checkbox
=
null
;
beforeEach
(
async
()
=>
{
beforeEach
(
async
()
=>
{
store
.
modules
.
approvals
.
state
.
settings
[
setting
]
=
false
;
jest
.
spyOn
(
store
,
'
dispatch
'
).
mockImplementation
()
;
createWrapper
();
createWrapper
();
await
waitForPromises
();
await
waitForPromises
();
checkbox
=
wrapper
.
findByTestId
(
testid
);
checkbox
=
wrapper
.
findByTestId
(
testid
);
...
@@ -83,47 +155,63 @@ describe('ApprovalSettings', () => {
...
@@ -83,47 +155,63 @@ describe('ApprovalSettings', () => {
});
});
});
});
it
(
'
updates the store when the value is changed
'
,
async
()
=>
{
it
(
`triggers the action
${
action
}
when the value is changed`
,
async
()
=>
{
await
checkbox
.
vm
.
$emit
(
'
input
'
,
true
);
await
checkbox
.
vm
.
$emit
(
'
input
'
,
true
);
await
waitForPromises
();
await
waitForPromises
();
expect
(
store
.
modules
.
approvals
.
state
.
settings
[
setting
]).
toBe
(
true
);
expect
(
store
.
dispatch
).
toHaveBeenLastCalledWith
(
action
,
{
[
setting
]:
true
}
);
});
});
});
});
describe
(
'
loading
'
,
()
=>
{
describe
(
'
form submission
'
,
()
=>
{
it
(
'
does not render the form if the settings are not there yet
'
,
()
=>
{
describe
(
'
if an error occurs while updating
'
,
()
=>
{
beforeEach
(
async
()
=>
{
createWrapper
();
createWrapper
();
expect
(
findForm
().
exists
()).
toBe
(
false
);
await
waitForPromises
();
await
store
.
commit
(
'
UPDATE_SETTINGS_ERROR
'
);
});
});
it
(
'
renders enabled button when not loading
'
,
async
()
=>
{
it
(
'
renders the alert
'
,
()
=>
{
store
.
modules
.
approvals
.
state
.
isLoading
=
false
;
expect
(
findErrorAlert
().
text
()).
toBe
(
APPROVAL_SETTINGS_I18N
.
savingErrorMessage
);
expect
(
findErrorAlert
().
classes
(
'
gl-mb-6
'
)).
toBe
(
true
);
expect
(
findSuccessAlert
().
exists
()).
toBe
(
false
);
});
createWrapper
();
it
(
'
dismisses the alert
'
,
async
()
=>
{
await
waitForPromises
(
);
await
findErrorAlert
().
vm
.
$emit
(
'
dismiss
'
);
expect
(
findSaveButton
().
props
(
'
disabled
'
)).
toBe
(
false
);
expect
(
actions
.
dismissErrorMessage
).
toHaveBeenCalled
();
});
});
});
it
(
'
renders disabled button when loading
'
,
async
()
=>
{
describe
(
'
if the form updates
'
,
()
=>
{
store
.
modules
.
approvals
.
state
.
isLoading
=
true
;
beforeEach
(
async
()
=>
{
createWrapper
();
createWrapper
();
await
waitForPromises
();
await
waitForPromises
();
await
findForm
().
vm
.
$emit
(
'
submit
'
,
{
preventDefault
:
()
=>
{}
});
await
store
.
commit
(
'
UPDATE_SETTINGS_SUCCESS
'
,
{});
});
expect
(
findSaveButton
().
props
(
'
disabled
'
)).
toBe
(
true
);
it
(
'
update the settings
'
,
()
=>
{
expect
(
actions
.
updateSettings
).
toHaveBeenCalledWith
(
expect
.
any
(
Object
),
approvalSettingsPath
,
);
});
});
it
(
'
renders the alert
'
,
()
=>
{
expect
(
findErrorAlert
().
exists
()).
toBe
(
false
);
expect
(
findSuccessAlert
().
text
()).
toBe
(
APPROVAL_SETTINGS_I18N
.
savingSuccessMessage
);
});
});
describe
(
'
form submission
'
,
()
=>
{
it
(
'
dismisses the alert
'
,
async
()
=>
{
it
(
'
update settings via API
'
,
async
()
=>
{
await
findSuccessAlert
().
vm
.
$emit
(
'
dismiss
'
);
createWrapper
();
await
waitForPromises
();
await
findForm
().
vm
.
$emit
(
'
submit
'
,
{
preventDefault
:
()
=>
{}
});
expect
(
actions
.
updateSettings
).
toHaveBeenCalledWith
(
expect
.
any
(
Object
),
approvalSettingsPath
);
expect
(
actions
.
dismissSuccessMessage
).
toHaveBeenCalled
();
});
});
});
});
});
});
});
});
ee/spec/frontend/approvals/stores/modules/group_settings/actions_spec.js
View file @
925655ed
import
*
as
Sentry
from
'
@sentry/browser
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
*
as
actions
from
'
ee/approvals/stores/modules/group_settings/actions
'
;
import
*
as
actions
from
'
ee/approvals/stores/modules/group_settings/actions
'
;
import
*
as
types
from
'
ee/approvals/stores/modules/group_settings/mutation_types
'
;
import
*
as
types
from
'
ee/approvals/stores/modules/group_settings/mutation_types
'
;
import
getInitialState
from
'
ee/approvals/stores/modules/group_settings/state
'
;
import
getInitialState
from
'
ee/approvals/stores/modules/group_settings/state
'
;
import
testAction
from
'
helpers/vuex_action_helper
'
;
import
testAction
from
'
helpers/vuex_action_helper
'
;
import
createFlash
from
'
~/flash
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
httpStatus
from
'
~/lib/utils/http_status
'
;
import
httpStatus
from
'
~/lib/utils/http_status
'
;
jest
.
mock
(
'
~/flash
'
);
describe
(
'
EE approvals group settings module actions
'
,
()
=>
{
describe
(
'
EE approvals group settings module actions
'
,
()
=>
{
let
state
;
let
state
;
let
mock
;
let
mock
;
...
@@ -18,10 +16,10 @@ describe('EE approvals group settings module actions', () => {
...
@@ -18,10 +16,10 @@ describe('EE approvals group settings module actions', () => {
beforeEach
(()
=>
{
beforeEach
(()
=>
{
state
=
getInitialState
();
state
=
getInitialState
();
mock
=
new
MockAdapter
(
axios
);
mock
=
new
MockAdapter
(
axios
);
jest
.
spyOn
(
Sentry
,
'
captureException
'
);
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
createFlash
.
mockClear
();
mock
.
restore
();
mock
.
restore
();
});
});
...
@@ -53,17 +51,10 @@ describe('EE approvals group settings module actions', () => {
...
@@ -53,17 +51,10 @@ describe('EE approvals group settings module actions', () => {
actions
.
fetchSettings
,
actions
.
fetchSettings
,
approvalSettingsPath
,
approvalSettingsPath
,
state
,
state
,
[
[{
type
:
types
.
REQUEST_SETTINGS
},
{
type
:
types
.
RECEIVE_SETTINGS_ERROR
}],
{
type
:
types
.
REQUEST_SETTINGS
},
{
type
:
types
.
RECEIVE_SETTINGS_ERROR
,
payload
:
data
.
message
},
],
[],
[],
).
then
(()
=>
{
).
then
(()
=>
{
expect
(
createFlash
).
toHaveBeenCalledWith
({
expect
(
Sentry
.
captureException
.
mock
.
calls
[
0
][
0
]).
toBe
(
data
.
message
);
message
:
'
There was an error loading merge request approval settings.
'
,
captureError
:
true
,
error
:
'
Internal Server Error
'
,
});
});
});
});
});
});
});
...
@@ -102,12 +93,7 @@ describe('EE approvals group settings module actions', () => {
...
@@ -102,12 +93,7 @@ describe('EE approvals group settings module actions', () => {
{
type
:
types
.
UPDATE_SETTINGS_SUCCESS
,
payload
:
data
},
{
type
:
types
.
UPDATE_SETTINGS_SUCCESS
,
payload
:
data
},
],
],
[],
[],
).
then
(()
=>
{
);
expect
(
createFlash
).
toHaveBeenCalledWith
({
message
:
'
Merge request approval settings have been updated.
'
,
type
:
'
notice
'
,
});
});
});
});
});
});
...
@@ -120,19 +106,36 @@ describe('EE approvals group settings module actions', () => {
...
@@ -120,19 +106,36 @@ describe('EE approvals group settings module actions', () => {
actions
.
updateSettings
,
actions
.
updateSettings
,
approvalSettingsPath
,
approvalSettingsPath
,
state
,
state
,
[
[{
type
:
types
.
REQUEST_UPDATE_SETTINGS
},
{
type
:
types
.
UPDATE_SETTINGS_ERROR
}],
{
type
:
types
.
REQUEST_UPDATE_SETTINGS
},
{
type
:
types
.
UPDATE_SETTINGS_ERROR
,
payload
:
data
.
message
},
],
[],
[],
).
then
(()
=>
{
).
then
(()
=>
{
expect
(
createFlash
).
toHaveBeenCalledWith
({
expect
(
Sentry
.
captureException
.
mock
.
calls
[
0
][
0
]).
toBe
(
data
.
message
);
message
:
'
There was an error updating merge request approval settings.
'
,
});
captureError
:
true
,
error
:
'
Internal Server Error
'
,
});
});
});
});
});
});
describe
(
'
dismissSuccessMessage
'
,
()
=>
{
it
(
'
commits DISMISS_SUCCESS_MESSAGE
'
,
()
=>
{
return
testAction
(
actions
.
dismissSuccessMessage
,
{},
state
,
[{
type
:
types
.
DISMISS_SUCCESS_MESSAGE
}],
[],
);
});
});
describe
(
'
dismissErrorMessage
'
,
()
=>
{
it
(
'
commits DISMISS_ERROR_MESSAGE
'
,
()
=>
{
return
testAction
(
actions
.
dismissErrorMessage
,
{},
state
,
[{
type
:
types
.
DISMISS_ERROR_MESSAGE
}],
[],
);
});
});
});
});
...
...
ee/spec/frontend/approvals/stores/modules/group_settings/mutations_spec.js
View file @
925655ed
import
{
APPROVAL_SETTINGS_I18N
}
from
'
ee/approvals/constants
'
;
import
mutations
from
'
ee/approvals/stores/modules/group_settings/mutations
'
;
import
mutations
from
'
ee/approvals/stores/modules/group_settings/mutations
'
;
import
getInitialState
from
'
ee/approvals/stores/modules/group_settings/state
'
;
import
getInitialState
from
'
ee/approvals/stores/modules/group_settings/state
'
;
...
@@ -13,6 +14,7 @@ describe('Group settings store mutations', () => {
...
@@ -13,6 +14,7 @@ describe('Group settings store mutations', () => {
mutations
.
REQUEST_SETTINGS
(
state
);
mutations
.
REQUEST_SETTINGS
(
state
);
expect
(
state
.
isLoading
).
toBe
(
true
);
expect
(
state
.
isLoading
).
toBe
(
true
);
expect
(
state
.
errorMessage
).
toBe
(
''
);
});
});
});
});
...
@@ -40,6 +42,7 @@ describe('Group settings store mutations', () => {
...
@@ -40,6 +42,7 @@ describe('Group settings store mutations', () => {
mutations
.
RECEIVE_SETTINGS_ERROR
(
state
);
mutations
.
RECEIVE_SETTINGS_ERROR
(
state
);
expect
(
state
.
isLoading
).
toBe
(
false
);
expect
(
state
.
isLoading
).
toBe
(
false
);
expect
(
state
.
errorMessage
).
toBe
(
APPROVAL_SETTINGS_I18N
.
loadingErrorMessage
);
});
});
});
});
...
@@ -48,6 +51,8 @@ describe('Group settings store mutations', () => {
...
@@ -48,6 +51,8 @@ describe('Group settings store mutations', () => {
mutations
.
REQUEST_UPDATE_SETTINGS
(
state
);
mutations
.
REQUEST_UPDATE_SETTINGS
(
state
);
expect
(
state
.
isLoading
).
toBe
(
true
);
expect
(
state
.
isLoading
).
toBe
(
true
);
expect
(
state
.
isUpdated
).
toBe
(
false
);
expect
(
state
.
errorMessage
).
toBe
(
''
);
});
});
});
});
...
@@ -65,6 +70,7 @@ describe('Group settings store mutations', () => {
...
@@ -65,6 +70,7 @@ describe('Group settings store mutations', () => {
expect
(
state
.
settings
.
requireUserPassword
).
toBe
(
true
);
expect
(
state
.
settings
.
requireUserPassword
).
toBe
(
true
);
expect
(
state
.
settings
.
removeApprovalsOnPush
).
toBe
(
false
);
expect
(
state
.
settings
.
removeApprovalsOnPush
).
toBe
(
false
);
expect
(
state
.
isLoading
).
toBe
(
false
);
expect
(
state
.
isLoading
).
toBe
(
false
);
expect
(
state
.
isUpdated
).
toBe
(
true
);
});
});
});
});
...
@@ -73,6 +79,23 @@ describe('Group settings store mutations', () => {
...
@@ -73,6 +79,23 @@ describe('Group settings store mutations', () => {
mutations
.
UPDATE_SETTINGS_ERROR
(
state
);
mutations
.
UPDATE_SETTINGS_ERROR
(
state
);
expect
(
state
.
isLoading
).
toBe
(
false
);
expect
(
state
.
isLoading
).
toBe
(
false
);
expect
(
state
.
errorMessage
).
toBe
(
APPROVAL_SETTINGS_I18N
.
savingErrorMessage
);
});
});
describe
(
'
DISMISS_SUCCESS_MESSAGE
'
,
()
=>
{
it
(
'
resets isUpdated
'
,
()
=>
{
mutations
.
DISMISS_SUCCESS_MESSAGE
(
state
);
expect
(
state
.
isUpdated
).
toBe
(
false
);
});
});
describe
(
'
DISMISS_ERROR_MESSAGE
'
,
()
=>
{
it
(
'
resets errorMessage
'
,
()
=>
{
mutations
.
DISMISS_ERROR_MESSAGE
(
state
);
expect
(
state
.
errorMessage
).
toBe
(
''
);
});
});
});
});
...
...
locale/gitlab.pot
View file @
925655ed
...
@@ -4160,6 +4160,30 @@ msgstr ""
...
@@ -4160,6 +4160,30 @@ msgstr ""
msgid "ApprovalRule|Target branch"
msgid "ApprovalRule|Target branch"
msgstr ""
msgstr ""
msgid "ApprovalSettings|Merge request approval settings have been updated."
msgstr ""
msgid "ApprovalSettings|Prevent MR approvals by the author."
msgstr ""
msgid "ApprovalSettings|Prevent approval of merge requests by merge request committers."
msgstr ""
msgid "ApprovalSettings|Prevent users from modifying MR approval rules."
msgstr ""
msgid "ApprovalSettings|Remove all approvals in a merge request when new commits are pushed to its source branch."
msgstr ""
msgid "ApprovalSettings|Require user password for approvals."
msgstr ""
msgid "ApprovalSettings|There was an error loading merge request approval settings."
msgstr ""
msgid "ApprovalSettings|There was an error updating merge request approval settings."
msgstr ""
msgid "ApprovalStatusTooltip|Adheres to separation of duties"
msgid "ApprovalStatusTooltip|Adheres to separation of duties"
msgstr ""
msgstr ""
...
@@ -20486,9 +20510,6 @@ msgstr ""
...
@@ -20486,9 +20510,6 @@ msgstr ""
msgid "Merge request analytics"
msgid "Merge request analytics"
msgstr ""
msgstr ""
msgid "Merge request approval settings have been updated."
msgstr ""
msgid "Merge request approvals"
msgid "Merge request approvals"
msgstr ""
msgstr ""
...
@@ -24764,9 +24785,6 @@ msgstr ""
...
@@ -24764,9 +24785,6 @@ msgstr ""
msgid "Prevent adding new members to project membership within this group"
msgid "Prevent adding new members to project membership within this group"
msgstr ""
msgstr ""
msgid "Prevent approval of merge requests by merge request committers."
msgstr ""
msgid "Prevent environment from auto-stopping"
msgid "Prevent environment from auto-stopping"
msgstr ""
msgstr ""
...
@@ -24782,9 +24800,6 @@ msgstr ""
...
@@ -24782,9 +24800,6 @@ msgstr ""
msgid "Prevent users from modifying MR approval rules in projects and merge requests."
msgid "Prevent users from modifying MR approval rules in projects and merge requests."
msgstr ""
msgstr ""
msgid "Prevent users from modifying MR approval rules."
msgstr ""
msgid "Prevent users from performing write operations on GitLab while performing maintenance."
msgid "Prevent users from performing write operations on GitLab while performing maintenance."
msgstr ""
msgstr ""
...
@@ -27123,9 +27138,6 @@ msgstr ""
...
@@ -27123,9 +27138,6 @@ msgstr ""
msgid "Remove access"
msgid "Remove access"
msgstr ""
msgstr ""
msgid "Remove all approvals in a merge request when new commits are pushed to its source branch."
msgstr ""
msgid "Remove all or specific assignee(s)"
msgid "Remove all or specific assignee(s)"
msgstr ""
msgstr ""
...
@@ -33123,9 +33135,6 @@ msgstr ""
...
@@ -33123,9 +33135,6 @@ msgstr ""
msgid "There was an error importing the Jira project."
msgid "There was an error importing the Jira project."
msgstr ""
msgstr ""
msgid "There was an error loading merge request approval settings."
msgstr ""
msgid "There was an error loading related feature flags"
msgid "There was an error loading related feature flags"
msgstr ""
msgstr ""
...
@@ -33165,9 +33174,6 @@ msgstr ""
...
@@ -33165,9 +33174,6 @@ msgstr ""
msgid "There was an error trying to validate your query"
msgid "There was an error trying to validate your query"
msgstr ""
msgstr ""
msgid "There was an error updating merge request approval settings."
msgstr ""
msgid "There was an error updating the Geo Settings"
msgid "There was an error updating the Geo Settings"
msgstr ""
msgstr ""
...
...
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