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
6ad31ac2
Commit
6ad31ac2
authored
Dec 07, 2021
by
Simon Knox
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ntepluhina-fix-labels-update' into 'master'
Fix updating labels See merge request gitlab-org/gitlab!76099
parents
81f06b6a
52e7bdbe
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
19 deletions
+88
-19
app/assets/javascripts/boards/graphql/issue_set_labels.mutation.graphql
...ascripts/boards/graphql/issue_set_labels.mutation.graphql
+5
-6
app/assets/javascripts/sidebar/queries/update_merge_request_labels.mutation.graphql
...ebar/queries/update_merge_request_labels.mutation.graphql
+2
-2
app/assets/javascripts/vue_shared/components/sidebar/labels_select_widget/graphql/epic_update_labels.mutation.graphql
...select_widget/graphql/epic_update_labels.mutation.graphql
+2
-2
app/assets/javascripts/vue_shared/components/sidebar/labels_select_widget/labels_select_root.vue
...nents/sidebar/labels_select_widget/labels_select_root.vue
+3
-6
spec/frontend/vue_shared/components/sidebar/labels_select_widget/labels_select_root_spec.js
...s/sidebar/labels_select_widget/labels_select_root_spec.js
+60
-3
spec/frontend/vue_shared/components/sidebar/labels_select_widget/mock_data.js
...ared/components/sidebar/labels_select_widget/mock_data.js
+16
-0
No files found.
app/assets/javascripts/boards/graphql/issue_set_labels.mutation.graphql
View file @
6ad31ac2
#import "~/graphql_shared/fragments/label.fragment.graphql"
mutation
issueSetLabels
(
$input
:
UpdateIssueInput
!)
{
mutation
issueSetLabels
(
$input
:
UpdateIssueInput
!)
{
updateIssue
(
input
:
$input
)
{
updateIssu
ableLabels
:
updateIssu
e
(
input
:
$input
)
{
issue
{
issu
able
:
issu
e
{
id
id
labels
{
labels
{
nodes
{
nodes
{
id
...
Label
title
color
description
}
}
}
}
}
}
...
...
app/assets/javascripts/sidebar/queries/update_merge_request_labels.mutation.graphql
View file @
6ad31ac2
mutation
mergeRequestSetLabels
(
$input
:
MergeRequestSetLabelsInput
!)
{
mutation
mergeRequestSetLabels
(
$input
:
MergeRequestSetLabelsInput
!)
{
mergeRequestSetLabels
(
input
:
$input
)
{
updateIssuableLabels
:
mergeRequestSetLabels
(
input
:
$input
)
{
errors
errors
mergeRequest
{
issuable
:
mergeRequest
{
id
id
labels
{
labels
{
nodes
{
nodes
{
...
...
app/assets/javascripts/vue_shared/components/sidebar/labels_select_widget/graphql/epic_update_labels.mutation.graphql
View file @
6ad31ac2
#import "~/graphql_shared/fragments/label.fragment.graphql"
#import "~/graphql_shared/fragments/label.fragment.graphql"
mutation
updateEpicLabels
(
$input
:
UpdateEpicInput
!)
{
mutation
updateEpicLabels
(
$input
:
UpdateEpicInput
!)
{
updateEpic
(
input
:
$input
)
{
update
IssuableLabels
:
update
Epic
(
input
:
$input
)
{
epic
{
issuable
:
epic
{
id
id
labels
{
labels
{
nodes
{
nodes
{
...
...
app/assets/javascripts/vue_shared/components/sidebar/labels_select_widget/labels_select_root.vue
View file @
6ad31ac2
...
@@ -225,16 +225,13 @@ export default {
...
@@ -225,16 +225,13 @@ export default {
variables
:
{
input
:
inputVariables
},
variables
:
{
input
:
inputVariables
},
})
})
.
then
(({
data
})
=>
{
.
then
(({
data
})
=>
{
const
{
mutationName
}
=
issuableLabelsQueries
[
this
.
issuableType
];
if
(
data
.
updateIssuableLabels
?.
errors
?.
length
)
{
if
(
data
[
mutationName
]?.
errors
?.
length
)
{
throw
new
Error
();
throw
new
Error
();
}
}
this
.
issuableLabels
=
data
[
mutationName
]?.[
this
.
issuableType
]?.
labels
?.
nodes
;
this
.
$emit
(
'
updateSelectedLabels
'
,
{
this
.
$emit
(
'
updateSelectedLabels
'
,
{
id
:
data
[
mutationName
]?.[
this
.
issuableType
]
?.
id
,
id
:
data
.
updateIssuableLabels
?.
issuable
?.
id
,
labels
:
this
.
issuableLabel
s
,
labels
:
data
.
updateIssuableLabels
?.
issuable
?.
labels
?.
node
s
,
});
});
})
})
.
catch
((
error
)
=>
.
catch
((
error
)
=>
...
...
spec/frontend/vue_shared/components/sidebar/labels_select_widget/labels_select_root_spec.js
View file @
6ad31ac2
...
@@ -10,16 +10,26 @@ import DropdownContents from '~/vue_shared/components/sidebar/labels_select_widg
...
@@ -10,16 +10,26 @@ import DropdownContents from '~/vue_shared/components/sidebar/labels_select_widg
import
DropdownValue
from
'
~/vue_shared/components/sidebar/labels_select_widget/dropdown_value.vue
'
;
import
DropdownValue
from
'
~/vue_shared/components/sidebar/labels_select_widget/dropdown_value.vue
'
;
import
DropdownValueCollapsed
from
'
~/vue_shared/components/sidebar/labels_select_widget/dropdown_value_collapsed.vue
'
;
import
DropdownValueCollapsed
from
'
~/vue_shared/components/sidebar/labels_select_widget/dropdown_value_collapsed.vue
'
;
import
issueLabelsQuery
from
'
~/vue_shared/components/sidebar/labels_select_widget/graphql/issue_labels.query.graphql
'
;
import
issueLabelsQuery
from
'
~/vue_shared/components/sidebar/labels_select_widget/graphql/issue_labels.query.graphql
'
;
import
updateIssueLabelsMutation
from
'
~/boards/graphql/issue_set_labels.mutation.graphql
'
;
import
updateMergeRequestLabelsMutation
from
'
~/sidebar/queries/update_merge_request_labels.mutation.graphql
'
;
import
updateEpicLabelsMutation
from
'
~/vue_shared/components/sidebar/labels_select_widget/graphql/epic_update_labels.mutation.graphql
'
;
import
LabelsSelectRoot
from
'
~/vue_shared/components/sidebar/labels_select_widget/labels_select_root.vue
'
;
import
LabelsSelectRoot
from
'
~/vue_shared/components/sidebar/labels_select_widget/labels_select_root.vue
'
;
import
{
mockConfig
,
issuableLabelsQueryResponse
}
from
'
./mock_data
'
;
import
{
mockConfig
,
issuableLabelsQueryResponse
,
updateLabelsMutationResponse
}
from
'
./mock_data
'
;
jest
.
mock
(
'
~/flash
'
);
jest
.
mock
(
'
~/flash
'
);
Vue
.
use
(
VueApollo
);
Vue
.
use
(
VueApollo
);
const
successfulQueryHandler
=
jest
.
fn
().
mockResolvedValue
(
issuableLabelsQueryResponse
);
const
successfulQueryHandler
=
jest
.
fn
().
mockResolvedValue
(
issuableLabelsQueryResponse
);
const
successfulMutationHandler
=
jest
.
fn
().
mockResolvedValue
(
updateLabelsMutationResponse
);
const
errorQueryHandler
=
jest
.
fn
().
mockRejectedValue
(
'
Houston, we have a problem
'
);
const
errorQueryHandler
=
jest
.
fn
().
mockRejectedValue
(
'
Houston, we have a problem
'
);
const
updateLabelsMutation
=
{
[
IssuableType
.
Issue
]:
updateIssueLabelsMutation
,
[
IssuableType
.
MergeRequest
]:
updateMergeRequestLabelsMutation
,
[
IssuableType
.
Epic
]:
updateEpicLabelsMutation
,
};
describe
(
'
LabelsSelectRoot
'
,
()
=>
{
describe
(
'
LabelsSelectRoot
'
,
()
=>
{
let
wrapper
;
let
wrapper
;
...
@@ -31,16 +41,21 @@ describe('LabelsSelectRoot', () => {
...
@@ -31,16 +41,21 @@ describe('LabelsSelectRoot', () => {
const
createComponent
=
({
const
createComponent
=
({
config
=
mockConfig
,
config
=
mockConfig
,
slots
=
{},
slots
=
{},
issuableType
=
IssuableType
.
Issue
,
queryHandler
=
successfulQueryHandler
,
queryHandler
=
successfulQueryHandler
,
mutationHandler
=
successfulMutationHandler
,
}
=
{})
=>
{
}
=
{})
=>
{
const
mockApollo
=
createMockApollo
([[
issueLabelsQuery
,
queryHandler
]]);
const
mockApollo
=
createMockApollo
([
[
issueLabelsQuery
,
queryHandler
],
[
updateLabelsMutation
[
issuableType
],
mutationHandler
],
]);
wrapper
=
shallowMount
(
LabelsSelectRoot
,
{
wrapper
=
shallowMount
(
LabelsSelectRoot
,
{
slots
,
slots
,
apolloProvider
:
mockApollo
,
apolloProvider
:
mockApollo
,
propsData
:
{
propsData
:
{
...
config
,
...
config
,
issuableType
:
IssuableType
.
Issue
,
issuableType
,
labelCreateType
:
'
project
'
,
labelCreateType
:
'
project
'
,
workspaceType
:
'
project
'
,
workspaceType
:
'
project
'
,
},
},
...
@@ -133,4 +148,46 @@ describe('LabelsSelectRoot', () => {
...
@@ -133,4 +148,46 @@ describe('LabelsSelectRoot', () => {
findDropdownContents
().
vm
.
$emit
(
'
setLabels
'
,
[
label
]);
findDropdownContents
().
vm
.
$emit
(
'
setLabels
'
,
[
label
]);
expect
(
wrapper
.
emitted
(
'
updateSelectedLabels
'
)).
toEqual
([[{
labels
:
[
label
]
}]]);
expect
(
wrapper
.
emitted
(
'
updateSelectedLabels
'
)).
toEqual
([[{
labels
:
[
label
]
}]]);
});
});
describe
.
each
`
issuableType
${
IssuableType
.
Issue
}
${
IssuableType
.
MergeRequest
}
${
IssuableType
.
Epic
}
`
(
'
when updating labels for $issuableType
'
,
({
issuableType
})
=>
{
const
label
=
{
id
:
'
gid://gitlab/ProjectLabel/2
'
};
it
(
'
sets the loading state
'
,
async
()
=>
{
createComponent
({
issuableType
});
await
nextTick
();
findDropdownContents
().
vm
.
$emit
(
'
setLabels
'
,
[
label
]);
await
nextTick
();
expect
(
findSidebarEditableItem
().
props
(
'
loading
'
)).
toBe
(
true
);
});
it
(
'
updates labels correctly after successful mutation
'
,
async
()
=>
{
createComponent
({
issuableType
});
await
nextTick
();
findDropdownContents
().
vm
.
$emit
(
'
setLabels
'
,
[
label
]);
await
waitForPromises
();
expect
(
findDropdownValue
().
props
(
'
selectedLabels
'
)).
toEqual
(
updateLabelsMutationResponse
.
data
.
updateIssuableLabels
.
issuable
.
labels
.
nodes
,
);
});
it
(
'
displays an error if mutation was rejected
'
,
async
()
=>
{
createComponent
({
issuableType
,
mutationHandler
:
errorQueryHandler
});
await
nextTick
();
findDropdownContents
().
vm
.
$emit
(
'
setLabels
'
,
[
label
]);
await
waitForPromises
();
expect
(
createFlash
).
toHaveBeenCalledWith
({
captureError
:
true
,
error
:
expect
.
anything
(),
message
:
'
An error occurred while updating labels.
'
,
});
});
});
});
});
spec/frontend/vue_shared/components/sidebar/labels_select_widget/mock_data.js
View file @
6ad31ac2
...
@@ -120,6 +120,7 @@ export const issuableLabelsQueryResponse = {
...
@@ -120,6 +120,7 @@ export const issuableLabelsQueryResponse = {
workspace
:
{
workspace
:
{
id
:
'
workspace-1
'
,
id
:
'
workspace-1
'
,
issuable
:
{
issuable
:
{
__typename
:
'
Issue
'
,
id
:
'
1
'
,
id
:
'
1
'
,
labels
:
{
labels
:
{
nodes
:
[
nodes
:
[
...
@@ -136,3 +137,18 @@ export const issuableLabelsQueryResponse = {
...
@@ -136,3 +137,18 @@ export const issuableLabelsQueryResponse = {
},
},
},
},
};
};
export
const
updateLabelsMutationResponse
=
{
data
:
{
updateIssuableLabels
:
{
errors
:
[],
issuable
:
{
__typename
:
'
Issue
'
,
id
:
'
1
'
,
labels
:
{
nodes
:
[],
},
},
},
},
};
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