Commit 8cc69ea9 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch '321666-improve-unit-tests-for-assignees-widget-component' into 'master'

Resolve "Improve unit tests for assignees widget component"

See merge request gitlab-org/gitlab!55504
parents 15a3481e 9056505a
...@@ -107,8 +107,8 @@ export default Vue.extend({ ...@@ -107,8 +107,8 @@ export default Vue.extend({
closeSidebar() { closeSidebar() {
this.detail.issue = {}; this.detail.issue = {};
}, },
setAssignees(data) { setAssignees(assignees) {
boardsStore.detail.issue.setAssignees(data.issueSetAssignees.issue.assignees.nodes); boardsStore.detail.issue.setAssignees(assignees);
}, },
showScopedLabels(label) { showScopedLabels(label) {
return boardsStore.scopedLabels.enabled && isScopedLabel(label); return boardsStore.scopedLabels.enabled && isScopedLabel(label);
......
#import "../fragments/user.fragment.graphql" #import "../fragments/user.fragment.graphql"
query usersSearch($search: String!, $fullPath: ID!) { query usersSearch($search: String!, $fullPath: ID!) {
issuable: project(fullPath: $fullPath) { workspace: project(fullPath: $fullPath) {
users: projectMembers(search: $search) { users: projectMembers(search: $search) {
nodes { nodes {
user { user {
......
...@@ -15,13 +15,12 @@ import { IssuableType } from '~/issue_show/constants'; ...@@ -15,13 +15,12 @@ import { IssuableType } from '~/issue_show/constants';
import { __, n__ } from '~/locale'; import { __, n__ } from '~/locale';
import IssuableAssignees from '~/sidebar/components/assignees/issuable_assignees.vue'; import IssuableAssignees from '~/sidebar/components/assignees/issuable_assignees.vue';
import SidebarEditableItem from '~/sidebar/components/sidebar_editable_item.vue'; import SidebarEditableItem from '~/sidebar/components/sidebar_editable_item.vue';
import { assigneesQueries } from '~/sidebar/constants'; import { assigneesQueries, ASSIGNEES_DEBOUNCE_DELAY } from '~/sidebar/constants';
import MultiSelectDropdown from '~/vue_shared/components/sidebar/multiselect_dropdown.vue'; import MultiSelectDropdown from '~/vue_shared/components/sidebar/multiselect_dropdown.vue';
export const assigneesWidget = Vue.observable({ export const assigneesWidget = Vue.observable({
updateAssignees: null, updateAssignees: null,
}); });
export default { export default {
i18n: { i18n: {
unassigned: __('Unassigned'), unassigned: __('Unassigned'),
...@@ -88,10 +87,10 @@ export default { ...@@ -88,10 +87,10 @@ export default {
return this.queryVariables; return this.queryVariables;
}, },
update(data) { update(data) {
return data.issuable || data.project?.issuable; return data.workspace?.issuable;
}, },
result({ data }) { result({ data }) {
const issuable = data.issuable || data.project?.issuable; const issuable = data.workspace?.issuable;
if (issuable) { if (issuable) {
this.selected = this.moveCurrentUserToStart(cloneDeep(issuable.assignees.nodes)); this.selected = this.moveCurrentUserToStart(cloneDeep(issuable.assignees.nodes));
} }
...@@ -109,7 +108,7 @@ export default { ...@@ -109,7 +108,7 @@ export default {
}; };
}, },
update(data) { update(data) {
const searchResults = data.issuable?.users?.nodes.map(({ user }) => user) || []; const searchResults = data.workspace?.users?.nodes.map(({ user }) => user) || [];
const mergedSearchResults = this.participants.reduce((acc, current) => { const mergedSearchResults = this.participants.reduce((acc, current) => {
if ( if (
!acc.some((user) => current.username === user.username) && !acc.some((user) => current.username === user.username) &&
...@@ -121,7 +120,7 @@ export default { ...@@ -121,7 +120,7 @@ export default {
}, searchResults); }, searchResults);
return mergedSearchResults; return mergedSearchResults;
}, },
debounce: 250, debounce: ASSIGNEES_DEBOUNCE_DELAY,
skip() { skip() {
return this.isSearchEmpty; return this.isSearchEmpty;
}, },
...@@ -229,7 +228,7 @@ export default { ...@@ -229,7 +228,7 @@ export default {
}, },
}) })
.then(({ data }) => { .then(({ data }) => {
this.$emit('assignees-updated', data); this.$emit('assignees-updated', data.issuableSetAssignees.issuable.assignees.nodes);
return data; return data;
}) })
.catch(() => { .catch(() => {
...@@ -378,7 +377,7 @@ export default { ...@@ -378,7 +377,7 @@ export default {
<template v-if="showCurrentUser"> <template v-if="showCurrentUser">
<gl-dropdown-divider /> <gl-dropdown-divider />
<gl-dropdown-item <gl-dropdown-item
data-testid="unselected-participant" data-testid="current-user"
@click.stop="selectAssignee(currentUser)" @click.stop="selectAssignee(currentUser)"
> >
<gl-avatar-link> <gl-avatar-link>
...@@ -409,7 +408,7 @@ export default { ...@@ -409,7 +408,7 @@ export default {
/> />
</gl-avatar-link> </gl-avatar-link>
</gl-dropdown-item> </gl-dropdown-item>
<gl-dropdown-item v-if="noUsersFound && !isSearching"> <gl-dropdown-item v-if="noUsersFound && !isSearching" data-testid="empty-results">
{{ __('No matching results') }} {{ __('No matching results') }}
</gl-dropdown-item> </gl-dropdown-item>
</template> </template>
......
...@@ -6,6 +6,8 @@ import getMergeRequestParticipants from '~/vue_shared/components/sidebar/queries ...@@ -6,6 +6,8 @@ import getMergeRequestParticipants from '~/vue_shared/components/sidebar/queries
import updateAssigneesMutation from '~/vue_shared/components/sidebar/queries/update_issue_assignees.mutation.graphql'; import updateAssigneesMutation from '~/vue_shared/components/sidebar/queries/update_issue_assignees.mutation.graphql';
import updateMergeRequestParticipantsMutation from '~/vue_shared/components/sidebar/queries/update_mr_assignees.mutation.graphql'; import updateMergeRequestParticipantsMutation from '~/vue_shared/components/sidebar/queries/update_mr_assignees.mutation.graphql';
export const ASSIGNEES_DEBOUNCE_DELAY = 250;
export const assigneesQueries = { export const assigneesQueries = {
[IssuableType.Issue]: { [IssuableType.Issue]: {
query: getIssueParticipants, query: getIssueParticipants,
......
#import "~/graphql_shared/fragments/user.fragment.graphql" #import "~/graphql_shared/fragments/user.fragment.graphql"
query issueParticipants($fullPath: ID!, $iid: String!) { query issueParticipants($fullPath: ID!, $iid: String!) {
project(fullPath: $fullPath) { workspace: project(fullPath: $fullPath) {
__typename
issuable: issue(iid: $iid) { issuable: issue(iid: $iid) {
__typename
id id
participants { participants {
nodes { nodes {
......
#import "~/graphql_shared/fragments/user.fragment.graphql" #import "~/graphql_shared/fragments/user.fragment.graphql"
query getMrParticipants($fullPath: ID!, $iid: String!) { query getMrParticipants($fullPath: ID!, $iid: String!) {
project(fullPath: $fullPath) { workspace: project(fullPath: $fullPath) {
issuable: mergeRequest(iid: $iid) { issuable: mergeRequest(iid: $iid) {
id id
participants { participants {
......
#import "~/graphql_shared/fragments/user.fragment.graphql" #import "~/graphql_shared/fragments/user.fragment.graphql"
mutation issueSetAssignees($iid: String!, $assigneeUsernames: [String!]!, $fullPath: ID!) { mutation issueSetAssignees($iid: String!, $assigneeUsernames: [String!]!, $fullPath: ID!) {
issueSetAssignees( issuableSetAssignees: issueSetAssignees(
input: { iid: $iid, assigneeUsernames: $assigneeUsernames, projectPath: $fullPath } input: { iid: $iid, assigneeUsernames: $assigneeUsernames, projectPath: $fullPath }
) { ) {
issue { issuable: issue {
id id
assignees { assignees {
nodes { nodes {
......
...@@ -86,7 +86,8 @@ export const mockMutationResponse = { ...@@ -86,7 +86,8 @@ export const mockMutationResponse = {
export const issuableQueryResponse = { export const issuableQueryResponse = {
data: { data: {
project: { workspace: {
__typename: 'Project',
issuable: { issuable: {
__typename: 'Issue', __typename: 'Issue',
id: 'gid://gitlab/Issue/1', id: 'gid://gitlab/Issue/1',
...@@ -109,6 +110,13 @@ export const issuableQueryResponse = { ...@@ -109,6 +110,13 @@ export const issuableQueryResponse = {
username: 'francina.skiles', username: 'francina.skiles',
webUrl: '/franc', webUrl: '/franc',
}, },
{
id: 'gid://gitlab/User/3',
avatarUrl: '/avatar',
name: 'John Doe',
username: 'johndoe',
webUrl: '/john',
},
], ],
}, },
assignees: { assignees: {
...@@ -130,7 +138,8 @@ export const issuableQueryResponse = { ...@@ -130,7 +138,8 @@ export const issuableQueryResponse = {
export const searchQueryResponse = { export const searchQueryResponse = {
data: { data: {
issuable: { workspace: {
__typename: 'Project',
users: { users: {
nodes: [ nodes: [
{ {
...@@ -144,8 +153,8 @@ export const searchQueryResponse = { ...@@ -144,8 +153,8 @@ export const searchQueryResponse = {
}, },
{ {
user: { user: {
id: '3', id: '2',
avatarUrl: '/avatar', avatarUrl: '/avatar2',
name: 'rookie', name: 'rookie',
username: 'rookie', username: 'rookie',
webUrl: 'rookie', webUrl: 'rookie',
...@@ -159,8 +168,8 @@ export const searchQueryResponse = { ...@@ -159,8 +168,8 @@ export const searchQueryResponse = {
export const updateIssueAssigneesMutationResponse = { export const updateIssueAssigneesMutationResponse = {
data: { data: {
issueSetAssignees: { issuableSetAssignees: {
issue: { issuable: {
id: 'gid://gitlab/Issue/1', id: 'gid://gitlab/Issue/1',
iid: '1', iid: '1',
assignees: { assignees: {
...@@ -202,7 +211,6 @@ export const updateIssueAssigneesMutationResponse = { ...@@ -202,7 +211,6 @@ export const updateIssueAssigneesMutationResponse = {
}, },
__typename: 'Issue', __typename: 'Issue',
}, },
__typename: 'IssueSetAssigneesPayload',
}, },
}, },
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment