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
3df7cc30
Commit
3df7cc30
authored
Feb 09, 2021
by
Nicolò Maria Mezzopera
Committed by
Phil Hughes
Feb 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Packages and Registries settings: refactor to gl-alert
parent
8cbcd1cb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
29 deletions
+69
-29
app/assets/javascripts/packages_and_registries/settings/group/bundle.js
...ascripts/packages_and_registries/settings/group/bundle.js
+3
-0
app/assets/javascripts/packages_and_registries/settings/group/components/group_settings_app.vue
...gistries/settings/group/components/group_settings_app.vue
+14
-5
spec/frontend/packages_and_registries/settings/group/components/group_settings_app_spec.js
...ries/settings/group/components/group_settings_app_spec.js
+52
-24
No files found.
app/assets/javascripts/packages_and_registries/settings/group/bundle.js
View file @
3df7cc30
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
{
GlToast
}
from
'
@gitlab/ui
'
;
import
Translate
from
'
~/vue_shared/translate
'
;
import
Translate
from
'
~/vue_shared/translate
'
;
import
{
parseBoolean
}
from
'
~/lib/utils/common_utils
'
;
import
{
parseBoolean
}
from
'
~/lib/utils/common_utils
'
;
import
SettingsApp
from
'
./components/group_settings_app.vue
'
;
import
SettingsApp
from
'
./components/group_settings_app.vue
'
;
import
{
apolloProvider
}
from
'
./graphql
'
;
import
{
apolloProvider
}
from
'
./graphql
'
;
Vue
.
use
(
Translate
);
Vue
.
use
(
Translate
);
Vue
.
use
(
GlToast
);
export
default
()
=>
{
export
default
()
=>
{
const
el
=
document
.
getElementById
(
'
js-packages-and-registries-settings
'
);
const
el
=
document
.
getElementById
(
'
js-packages-and-registries-settings
'
);
...
...
app/assets/javascripts/packages_and_registries/settings/group/components/group_settings_app.vue
View file @
3df7cc30
<
script
>
<
script
>
import
{
GlSprintf
,
GlLink
}
from
'
@gitlab/ui
'
;
import
{
GlSprintf
,
GlLink
,
GlAlert
}
from
'
@gitlab/ui
'
;
import
createFlash
from
'
~/flash
'
;
import
SettingsBlock
from
'
~/vue_shared/components/settings/settings_block.vue
'
;
import
SettingsBlock
from
'
~/vue_shared/components/settings/settings_block.vue
'
;
import
MavenSettings
from
'
~/packages_and_registries/settings/group/components/maven_settings.vue
'
;
import
MavenSettings
from
'
~/packages_and_registries/settings/group/components/maven_settings.vue
'
;
...
@@ -26,6 +25,7 @@ export default {
...
@@ -26,6 +25,7 @@ export default {
PACKAGES_DOCS_PATH
,
PACKAGES_DOCS_PATH
,
},
},
components
:
{
components
:
{
GlAlert
,
GlSprintf
,
GlSprintf
,
GlLink
,
GlLink
,
SettingsBlock
,
SettingsBlock
,
...
@@ -49,6 +49,7 @@ export default {
...
@@ -49,6 +49,7 @@ export default {
return
{
return
{
packageSettings
:
{},
packageSettings
:
{},
errors
:
{},
errors
:
{},
alertMessage
:
null
,
};
};
},
},
computed
:
{
computed
:
{
...
@@ -57,6 +58,9 @@ export default {
...
@@ -57,6 +58,9 @@ export default {
},
},
},
},
methods
:
{
methods
:
{
dismissAlert
()
{
this
.
alertMessage
=
null
;
},
updateSettings
(
payload
)
{
updateSettings
(
payload
)
{
this
.
errors
=
{};
this
.
errors
=
{};
return
this
.
$apollo
return
this
.
$apollo
...
@@ -76,9 +80,10 @@ export default {
...
@@ -76,9 +80,10 @@ export default {
})
})
.
then
(({
data
})
=>
{
.
then
(({
data
})
=>
{
if
(
data
.
updateNamespacePackageSettings
?.
errors
?.
length
>
0
)
{
if
(
data
.
updateNamespacePackageSettings
?.
errors
?.
length
>
0
)
{
createFlash
({
message
:
ERROR_UPDATING_SETTINGS
,
type
:
'
warning
'
})
;
this
.
alertMessage
=
ERROR_UPDATING_SETTINGS
;
}
else
{
}
else
{
createFlash
({
message
:
SUCCESS_UPDATING_SETTINGS
,
type
:
'
success
'
});
this
.
dismissAlert
();
this
.
$toast
.
show
(
SUCCESS_UPDATING_SETTINGS
,
{
type
:
'
success
'
});
}
}
})
})
.
catch
((
e
)
=>
{
.
catch
((
e
)
=>
{
...
@@ -93,7 +98,7 @@ export default {
...
@@ -93,7 +98,7 @@ export default {
this
.
errors
=
{
...
this
.
errors
,
[
key
]:
message
};
this
.
errors
=
{
...
this
.
errors
,
[
key
]:
message
};
});
});
}
}
createFlash
({
message
:
ERROR_UPDATING_SETTINGS
,
type
:
'
warning
'
})
;
this
.
alertMessage
=
ERROR_UPDATING_SETTINGS
;
});
});
},
},
},
},
...
@@ -102,6 +107,10 @@ export default {
...
@@ -102,6 +107,10 @@ export default {
<
template
>
<
template
>
<div>
<div>
<gl-alert
v-if=
"alertMessage"
variant=
"warning"
class=
"gl-mt-4"
@
dismiss=
"dismissAlert"
>
{{
alertMessage
}}
</gl-alert>
<settings-block
:default-expanded=
"defaultExpanded"
>
<settings-block
:default-expanded=
"defaultExpanded"
>
<template
#title
>
{{
$options
.
i18n
.
PACKAGE_SETTINGS_HEADER
}}
</
template
>
<template
#title
>
{{
$options
.
i18n
.
PACKAGE_SETTINGS_HEADER
}}
</
template
>
<
template
#description
>
<
template
#description
>
...
...
spec/frontend/packages_and_registries/settings/group/components/group_settings_app_spec.js
View file @
3df7cc30
import
{
shallowMount
,
createLocalVue
}
from
'
@vue/test-utils
'
;
import
{
shallowMount
,
createLocalVue
}
from
'
@vue/test-utils
'
;
import
{
GlSprintf
,
GlLink
}
from
'
@gitlab/ui
'
;
import
{
GlSprintf
,
GlLink
,
GlAlert
}
from
'
@gitlab/ui
'
;
import
VueApollo
from
'
vue-apollo
'
;
import
VueApollo
from
'
vue-apollo
'
;
import
createMockApollo
from
'
helpers/mock_apollo_helper
'
;
import
createMockApollo
from
'
helpers/mock_apollo_helper
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
import
createFlash
from
'
~/flash
'
;
import
SettingsBlock
from
'
~/vue_shared/components/settings/settings_block.vue
'
;
import
SettingsBlock
from
'
~/vue_shared/components/settings/settings_block.vue
'
;
import
component
from
'
~/packages_and_registries/settings/group/components/group_settings_app.vue
'
;
import
component
from
'
~/packages_and_registries/settings/group/components/group_settings_app.vue
'
;
import
MavenSettings
from
'
~/packages_and_registries/settings/group/components/maven_settings.vue
'
;
import
MavenSettings
from
'
~/packages_and_registries/settings/group/components/maven_settings.vue
'
;
...
@@ -30,6 +29,7 @@ const localVue = createLocalVue();
...
@@ -30,6 +29,7 @@ const localVue = createLocalVue();
describe
(
'
Group Settings App
'
,
()
=>
{
describe
(
'
Group Settings App
'
,
()
=>
{
let
wrapper
;
let
wrapper
;
let
apolloProvider
;
let
apolloProvider
;
let
show
;
const
defaultProvide
=
{
const
defaultProvide
=
{
defaultExpanded
:
false
,
defaultExpanded
:
false
,
...
@@ -40,6 +40,7 @@ describe('Group Settings App', () => {
...
@@ -40,6 +40,7 @@ describe('Group Settings App', () => {
provide
=
defaultProvide
,
provide
=
defaultProvide
,
resolver
=
jest
.
fn
().
mockResolvedValue
(
groupPackageSettingsMock
),
resolver
=
jest
.
fn
().
mockResolvedValue
(
groupPackageSettingsMock
),
mutationResolver
=
jest
.
fn
().
mockResolvedValue
(
groupPackageSettingsMutationMock
()),
mutationResolver
=
jest
.
fn
().
mockResolvedValue
(
groupPackageSettingsMutationMock
()),
data
=
{},
}
=
{})
=>
{
}
=
{})
=>
{
localVue
.
use
(
VueApollo
);
localVue
.
use
(
VueApollo
);
...
@@ -54,13 +55,27 @@ describe('Group Settings App', () => {
...
@@ -54,13 +55,27 @@ describe('Group Settings App', () => {
localVue
,
localVue
,
apolloProvider
,
apolloProvider
,
provide
,
provide
,
data
()
{
return
{
...
data
,
};
},
stubs
:
{
stubs
:
{
GlSprintf
,
GlSprintf
,
SettingsBlock
,
SettingsBlock
,
},
},
mocks
:
{
$toast
:
{
show
,
},
},
});
});
};
};
beforeEach
(()
=>
{
show
=
jest
.
fn
();
});
afterEach
(()
=>
{
afterEach
(()
=>
{
wrapper
.
destroy
();
wrapper
.
destroy
();
wrapper
=
null
;
wrapper
=
null
;
...
@@ -70,6 +85,7 @@ describe('Group Settings App', () => {
...
@@ -70,6 +85,7 @@ describe('Group Settings App', () => {
const
findDescription
=
()
=>
wrapper
.
find
(
'
[data-testid="description"
'
);
const
findDescription
=
()
=>
wrapper
.
find
(
'
[data-testid="description"
'
);
const
findLink
=
()
=>
wrapper
.
find
(
GlLink
);
const
findLink
=
()
=>
wrapper
.
find
(
GlLink
);
const
findMavenSettings
=
()
=>
wrapper
.
find
(
MavenSettings
);
const
findMavenSettings
=
()
=>
wrapper
.
find
(
MavenSettings
);
const
findAlert
=
()
=>
wrapper
.
find
(
GlAlert
);
const
waitForApolloQueryAndRender
=
async
()
=>
{
const
waitForApolloQueryAndRender
=
async
()
=>
{
await
waitForPromises
();
await
waitForPromises
();
...
@@ -178,8 +194,7 @@ describe('Group Settings App', () => {
...
@@ -178,8 +194,7 @@ describe('Group Settings App', () => {
await
waitForPromises
();
await
waitForPromises
();
expect
(
createFlash
).
toHaveBeenCalledWith
({
expect
(
show
).
toHaveBeenCalledWith
(
SUCCESS_UPDATING_SETTINGS
,
{
message
:
SUCCESS_UPDATING_SETTINGS
,
type
:
'
success
'
,
type
:
'
success
'
,
});
});
});
});
...
@@ -211,6 +226,12 @@ describe('Group Settings App', () => {
...
@@ -211,6 +226,12 @@ describe('Group Settings App', () => {
});
});
describe
(
'
errors
'
,
()
=>
{
describe
(
'
errors
'
,
()
=>
{
const
verifyAlert
=
()
=>
{
expect
(
findAlert
().
exists
()).
toBe
(
true
);
expect
(
findAlert
().
text
()).
toBe
(
ERROR_UPDATING_SETTINGS
);
expect
(
findAlert
().
props
(
'
variant
'
)).
toBe
(
'
warning
'
);
};
it
(
'
mutation payload with root level errors
'
,
async
()
=>
{
it
(
'
mutation payload with root level errors
'
,
async
()
=>
{
// note this is a complex test that covers all the path around errors that are shown in the form
// note this is a complex test that covers all the path around errors that are shown in the form
// it's one single it case, due to the expensive preparation and execution
// it's one single it case, due to the expensive preparation and execution
...
@@ -229,10 +250,8 @@ describe('Group Settings App', () => {
...
@@ -229,10 +250,8 @@ describe('Group Settings App', () => {
);
);
// general error message is shown
// general error message is shown
expect
(
createFlash
).
toHaveBeenCalledWith
({
message
:
ERROR_UPDATING_SETTINGS
,
verifyAlert
();
type
:
'
warning
'
,
});
emitSettingsUpdate
();
emitSettingsUpdate
();
...
@@ -242,11 +261,11 @@ describe('Group Settings App', () => {
...
@@ -242,11 +261,11 @@ describe('Group Settings App', () => {
expect
(
findMavenSettings
().
props
(
'
mavenDuplicateExceptionRegexError
'
)).
toBe
(
''
);
expect
(
findMavenSettings
().
props
(
'
mavenDuplicateExceptionRegexError
'
)).
toBe
(
''
);
});
});
it
(
'
mutation payload with local errors
'
,
async
()
=>
{
it
.
each
`
const
mutationResolver
=
jest
type | mutationResolver
.
fn
()
${
'
local
'
}
|
${
jest
.
fn
().
mockResolvedValue
(
groupPackageSettingsMutationMock
({
errors
:
[
'
foo
'
]
}))}
.
mockResolvedValue
(
groupPackageSettingsMutationMock
({
errors
:
[
'
foo
'
]
}));
${
'
network
'
}
|
${
jest
.
fn
().
mockRejectedValue
()}
`
(
'
mutation payload with $type error
'
,
async
({
mutationResolver
})
=>
{
mountComponent
({
mutationResolver
});
mountComponent
({
mutationResolver
});
await
waitForApolloQueryAndRender
();
await
waitForApolloQueryAndRender
();
...
@@ -255,26 +274,35 @@ describe('Group Settings App', () => {
...
@@ -255,26 +274,35 @@ describe('Group Settings App', () => {
await
waitForPromises
();
await
waitForPromises
();
expect
(
createFlash
).
toHaveBeenCalledWith
({
verifyAlert
();
message
:
ERROR_UPDATING_SETTINGS
,
type
:
'
warning
'
,
});
});
});
it
(
'
shows an error in case of network error
'
,
async
()
=>
{
it
(
'
a successful request dismisses the alert
'
,
async
()
=>
{
const
mutationResolver
=
jest
.
fn
().
mockRejectedValue
();
mountComponent
({
data
:
{
alertMessage
:
'
foo
'
}
});
mountComponent
({
mutationResolver
});
await
waitForApolloQueryAndRender
();
await
waitForApolloQueryAndRender
();
expect
(
findAlert
().
exists
()).
toBe
(
true
);
emitSettingsUpdate
();
emitSettingsUpdate
();
await
waitForPromises
();
await
waitForPromises
();
expect
(
createFlash
).
toHaveBeenCalledWith
({
expect
(
findAlert
().
exists
()).
toBe
(
false
);
message
:
ERROR_UPDATING_SETTINGS
,
});
type
:
'
warning
'
,
});
it
(
'
dismiss event from alert dismiss it from the page
'
,
async
()
=>
{
mountComponent
({
data
:
{
alertMessage
:
'
foo
'
}
});
await
waitForApolloQueryAndRender
();
expect
(
findAlert
().
exists
()).
toBe
(
true
);
findAlert
().
vm
.
$emit
(
'
dismiss
'
);
await
wrapper
.
vm
.
$nextTick
();
expect
(
findAlert
().
exists
()).
toBe
(
false
);
});
});
});
});
});
});
...
...
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