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
75c036f4
Commit
75c036f4
authored
May 04, 2021
by
Jacques Erasmus
Committed by
Phil Hughes
May 04, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability to swap revisions
parent
2c4abf28
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
242 additions
and
117 deletions
+242
-117
app/assets/javascripts/projects/compare/components/app.vue
app/assets/javascripts/projects/compare/components/app.vue
+53
-4
app/assets/javascripts/projects/compare/components/repo_dropdown.vue
...javascripts/projects/compare/components/repo_dropdown.vue
+23
-29
app/assets/javascripts/projects/compare/components/revision_card.vue
...javascripts/projects/compare/components/revision_card.vue
+13
-13
app/assets/javascripts/projects/compare/components/revision_dropdown.vue
...scripts/projects/compare/components/revision_dropdown.vue
+10
-3
app/assets/javascripts/projects/compare/index.js
app/assets/javascripts/projects/compare/index.js
+2
-4
changelogs/unreleased/225345-re-add-swap-revisions.yml
changelogs/unreleased/225345-re-add-swap-revisions.yml
+5
-0
spec/frontend/projects/compare/components/app_spec.js
spec/frontend/projects/compare/components/app_spec.js
+61
-16
spec/frontend/projects/compare/components/mock_data.js
spec/frontend/projects/compare/components/mock_data.js
+37
-0
spec/frontend/projects/compare/components/repo_dropdown_spec.js
...rontend/projects/compare/components/repo_dropdown_spec.js
+22
-34
spec/frontend/projects/compare/components/revision_card_spec.js
...rontend/projects/compare/components/revision_card_spec.js
+1
-7
spec/frontend/projects/compare/components/revision_dropdown_spec.js
...end/projects/compare/components/revision_dropdown_spec.js
+15
-7
No files found.
app/assets/javascripts/projects/compare/components/app.vue
View file @
75c036f4
<
script
>
<
script
>
import
{
GlButton
}
from
'
@gitlab/ui
'
;
import
{
GlButton
}
from
'
@gitlab/ui
'
;
import
csrf
from
'
~/lib/utils/csrf
'
;
import
csrf
from
'
~/lib/utils/csrf
'
;
import
{
joinPaths
}
from
'
~/lib/utils/url_utility
'
;
import
RevisionCard
from
'
./revision_card.vue
'
;
import
RevisionCard
from
'
./revision_card.vue
'
;
export
default
{
export
default
{
...
@@ -36,11 +37,46 @@ export default {
...
@@ -36,11 +37,46 @@ export default {
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
},
},
defaultProject
:
{
type
:
Object
,
required
:
true
,
},
projects
:
{
type
:
Array
,
required
:
true
,
},
},
data
()
{
return
{
from
:
{
projects
:
this
.
projects
,
selectedProject
:
this
.
defaultProject
,
revision
:
this
.
paramsFrom
,
refsProjectPath
:
this
.
refsProjectPath
,
},
to
:
{
selectedProject
:
this
.
defaultProject
,
revision
:
this
.
paramsTo
,
refsProjectPath
:
this
.
refsProjectPath
,
},
};
},
},
methods
:
{
methods
:
{
onSubmit
()
{
onSubmit
()
{
this
.
$refs
.
form
.
submit
();
this
.
$refs
.
form
.
submit
();
},
},
onSelectProject
({
direction
,
project
})
{
const
refsPath
=
joinPaths
(
gon
.
relative_url_root
||
''
,
`/
${
project
.
name
}
`
,
'
/refs
'
);
// direction is either 'from' or 'to'
this
[
direction
].
refsProjectPath
=
refsPath
;
this
[
direction
].
selectedProject
=
project
;
},
onSelectRevision
({
direction
,
revision
})
{
this
[
direction
].
revision
=
revision
;
// direction is either 'from' or 'to'
},
onSwapRevision
()
{
[
this
.
from
,
this
.
to
]
=
[
this
.
to
,
this
.
from
];
// swaps 'from' and 'to'
},
},
},
};
};
</
script
>
</
script
>
...
@@ -57,10 +93,15 @@ export default {
...
@@ -57,10 +93,15 @@ export default {
class=
"gl-lg-flex-direction-row gl-lg-display-flex gl-align-items-center compare-revision-cards"
class=
"gl-lg-flex-direction-row gl-lg-display-flex gl-align-items-center compare-revision-cards"
>
>
<revision-card
<revision-card
:refs-project-path=
"refsProjectPath"
data-testid=
"sourceRevisionCard"
:refs-project-path=
"to.refsProjectPath"
revision-text=
"Source"
revision-text=
"Source"
params-name=
"to"
params-name=
"to"
:params-branch=
"paramsTo"
:params-branch=
"to.revision"
:projects=
"to.projects"
:selected-project=
"to.selectedProject"
@
selectProject=
"onSelectProject"
@
selectRevision=
"onSelectRevision"
/>
/>
<div
<div
class=
"compare-ellipsis gl-display-flex gl-justify-content-center gl-align-items-center gl-my-4 gl-md-my-0"
class=
"compare-ellipsis gl-display-flex gl-justify-content-center gl-align-items-center gl-my-4 gl-md-my-0"
...
@@ -69,16 +110,24 @@ export default {
...
@@ -69,16 +110,24 @@ export default {
...
...
</div>
</div>
<revision-card
<revision-card
:refs-project-path=
"refsProjectPath"
data-testid=
"targetRevisionCard"
:refs-project-path=
"from.refsProjectPath"
revision-text=
"Target"
revision-text=
"Target"
params-name=
"from"
params-name=
"from"
:params-branch=
"paramsFrom"
:params-branch=
"from.revision"
:projects=
"from.projects"
:selected-project=
"from.selectedProject"
@
selectProject=
"onSelectProject"
@
selectRevision=
"onSelectRevision"
/>
/>
</div>
</div>
<div
class=
"gl-mt-4"
>
<div
class=
"gl-mt-4"
>
<gl-button
category=
"primary"
variant=
"success"
@
click=
"onSubmit"
>
<gl-button
category=
"primary"
variant=
"success"
@
click=
"onSubmit"
>
{{
s__
(
'
CompareRevisions|Compare
'
)
}}
{{
s__
(
'
CompareRevisions|Compare
'
)
}}
</gl-button>
</gl-button>
<gl-button
data-testid=
"swapRevisionsButton"
class=
"btn btn-default"
@
click=
"onSwapRevision"
>
{{
s__
(
'
CompareRevisions|Swap revisions
'
)
}}
</gl-button>
<gl-button
<gl-button
v-if=
"projectMergeRequestPath"
v-if=
"projectMergeRequestPath"
:href=
"projectMergeRequestPath"
:href=
"projectMergeRequestPath"
...
...
app/assets/javascripts/projects/compare/components/repo_dropdown.vue
View file @
75c036f4
<
script
>
<
script
>
import
{
GlDropdown
,
GlDropdownItem
,
GlSearchBoxByType
}
from
'
@gitlab/ui
'
;
import
{
GlDropdown
,
GlDropdownItem
,
GlSearchBoxByType
}
from
'
@gitlab/ui
'
;
const
SOURCE_PARAM_NAME
=
'
to
'
;
export
default
{
export
default
{
components
:
{
components
:
{
GlDropdown
,
GlDropdown
,
GlDropdownItem
,
GlDropdownItem
,
GlSearchBoxByType
,
GlSearchBoxByType
,
},
},
inject
:
[
'
projectTo
'
,
'
projectsFrom
'
],
props
:
{
props
:
{
paramsName
:
{
paramsName
:
{
type
:
String
,
type
:
String
,
required
:
true
,
required
:
true
,
},
},
projects
:
{
type
:
Array
,
required
:
false
,
default
:
null
,
},
selectedProject
:
{
type
:
Object
,
required
:
true
,
},
},
},
data
()
{
data
()
{
return
{
return
{
searchTerm
:
''
,
searchTerm
:
''
,
selectedRepo
:
{},
};
};
},
},
computed
:
{
computed
:
{
disableRepoDropdown
()
{
return
this
.
projects
===
null
;
},
filteredRepos
()
{
filteredRepos
()
{
const
lowerCaseSearchTerm
=
this
.
searchTerm
.
toLowerCase
();
const
lowerCaseSearchTerm
=
this
.
searchTerm
.
toLowerCase
();
return
this
?.
projectsFrom
.
filter
(({
name
})
=>
return
this
?.
projects
.
filter
(({
name
})
=>
name
.
toLowerCase
().
includes
(
lowerCaseSearchTerm
));
name
.
toLowerCase
().
includes
(
lowerCaseSearchTerm
),
);
},
isSourceRevision
()
{
return
this
.
paramsName
===
SOURCE_PARAM_NAME
;
},
},
inputName
()
{
inputName
()
{
return
`
${
this
.
paramsName
}
_project_id`
;
return
`
${
this
.
paramsName
}
_project_id`
;
},
},
},
},
mounted
()
{
this
.
setDefaultRepo
();
},
methods
:
{
methods
:
{
onClick
(
repo
)
{
onClick
(
project
)
{
this
.
selectedRepo
=
repo
;
this
.
emitTargetProject
(
project
);
this
.
emitTargetProject
(
repo
.
name
);
},
setDefaultRepo
()
{
this
.
selectedRepo
=
this
.
projectTo
;
},
},
emitTargetProject
(
name
)
{
emitTargetProject
(
project
)
{
if
(
!
this
.
isSourceRevision
)
{
this
.
$emit
(
'
selectProject
'
,
{
direction
:
this
.
paramsName
,
project
});
this
.
$emit
(
'
changeTargetProject
'
,
name
);
}
},
},
},
},
};
};
...
@@ -59,23 +53,23 @@ export default {
...
@@ -59,23 +53,23 @@ export default {
<
template
>
<
template
>
<div>
<div>
<input
type=
"hidden"
:name=
"inputName"
:value=
"selected
Repo
.id"
/>
<input
type=
"hidden"
:name=
"inputName"
:value=
"selected
Project
.id"
/>
<gl-dropdown
<gl-dropdown
:text=
"selected
Repo
.name"
:text=
"selected
Project
.name"
:header-text=
"s__(`CompareRevisions|Select target project`)"
:header-text=
"s__(`CompareRevisions|Select target project`)"
class=
"gl-w-full gl-font-monospace gl-sm-pr-3"
class=
"gl-w-full gl-font-monospace gl-sm-pr-3"
toggle-class=
"gl-min-w-0"
toggle-class=
"gl-min-w-0"
:disabled=
"
isSourceRevisio
n"
:disabled=
"
disableRepoDropdow
n"
>
>
<template
#header
>
<template
#header
>
<gl-search-box-by-type
v-if=
"!
isSourceRevisio
n"
v-model.trim=
"searchTerm"
/>
<gl-search-box-by-type
v-if=
"!
disableRepoDropdow
n"
v-model.trim=
"searchTerm"
/>
</
template
>
</
template
>
<
template
v-if=
"!
isSourceRevisio
n"
>
<
template
v-if=
"!
disableRepoDropdow
n"
>
<gl-dropdown-item
<gl-dropdown-item
v-for=
"repo in filteredRepos"
v-for=
"repo in filteredRepos"
:key=
"repo.id"
:key=
"repo.id"
is-check-item
is-check-item
:is-checked=
"selected
Repo
.id === repo.id"
:is-checked=
"selected
Project
.id === repo.id"
@
click=
"onClick(repo)"
@
click=
"onClick(repo)"
>
>
{{
repo
.
name
}}
{{
repo
.
name
}}
...
...
app/assets/javascripts/projects/compare/components/revision_card.vue
View file @
75c036f4
...
@@ -27,17 +27,14 @@ export default {
...
@@ -27,17 +27,14 @@ export default {
required
:
false
,
required
:
false
,
default
:
null
,
default
:
null
,
},
},
},
projects
:
{
data
()
{
type
:
Array
,
return
{
required
:
false
,
selectedRefsProjectPath
:
this
.
refsProjectPath
,
default
:
null
,
};
},
},
selectedProject
:
{
methods
:
{
type
:
Object
,
onChangeTargetProject
(
targetProjectName
)
{
required
:
true
,
if
(
this
.
paramsName
===
'
from
'
)
{
this
.
selectedRefsProjectPath
=
`/
${
targetProjectName
}
/refs`
;
}
},
},
},
},
};
};
...
@@ -52,13 +49,16 @@ export default {
...
@@ -52,13 +49,16 @@ export default {
<
repo
-
dropdown
<
repo
-
dropdown
class
=
"
gl-sm-w-half
"
class
=
"
gl-sm-w-half
"
:
params
-
name
=
"
paramsName
"
:
params
-
name
=
"
paramsName
"
@
changeTargetProject
=
"
onChangeTargetProject
"
:
projects
=
"
projects
"
:
selected
-
project
=
"
selectedProject
"
v
-
on
=
"
$listeners
"
/>
/>
<
revision
-
dropdown
<
revision
-
dropdown
class
=
"
gl-sm-w-half gl-mt-3 gl-sm-mt-0
"
class
=
"
gl-sm-w-half gl-mt-3 gl-sm-mt-0
"
:
refs
-
project
-
path
=
"
selectedR
efsProjectPath
"
:
refs
-
project
-
path
=
"
r
efsProjectPath
"
:
params
-
name
=
"
paramsName
"
:
params
-
name
=
"
paramsName
"
:
params
-
branch
=
"
paramsBranch
"
:
params
-
branch
=
"
paramsBranch
"
v
-
on
=
"
$listeners
"
/>
/>
<
/div
>
<
/div
>
<
/gl-card
>
<
/gl-card
>
...
...
app/assets/javascripts/projects/compare/components/revision_dropdown.vue
View file @
75c036f4
...
@@ -56,6 +56,9 @@ export default {
...
@@ -56,6 +56,9 @@ export default {
searchTerm
:
debounce
(
function
debounceSearch
()
{
searchTerm
:
debounce
(
function
debounceSearch
()
{
this
.
searchBranchesAndTags
();
this
.
searchBranchesAndTags
();
},
SEARCH_DEBOUNCE_MS
),
},
SEARCH_DEBOUNCE_MS
),
paramsBranch
(
newBranch
)
{
this
.
setSelectedRevision
(
newBranch
);
},
},
},
mounted
()
{
mounted
()
{
this
.
fetchBranchesAndTags
();
this
.
fetchBranchesAndTags
();
...
@@ -84,7 +87,7 @@ export default {
...
@@ -84,7 +87,7 @@ export default {
this
.
loading
=
true
;
this
.
loading
=
true
;
if
(
reset
)
{
if
(
reset
)
{
this
.
se
lectedRevision
=
this
.
getDefaultBranch
(
);
this
.
se
tSelectedRevision
(
this
.
paramsBranch
);
}
}
return
axios
return
axios
...
@@ -108,10 +111,14 @@ export default {
...
@@ -108,10 +111,14 @@ export default {
return
this
.
paramsBranch
||
EMPTY_DROPDOWN_TEXT
;
return
this
.
paramsBranch
||
EMPTY_DROPDOWN_TEXT
;
},
},
onClick
(
revision
)
{
onClick
(
revision
)
{
this
.
selectedRevision
=
revision
;
this
.
setSelectedRevision
(
revision
);
this
.
$emit
(
'
selectRevision
'
,
{
direction
:
this
.
paramsName
,
revision
});
},
},
onSearchEnter
()
{
onSearchEnter
()
{
this
.
selectedRevision
=
this
.
searchTerm
;
this
.
setSelectedRevision
(
this
.
searchTerm
);
},
setSelectedRevision
(
revision
)
{
this
.
selectedRevision
=
revision
||
EMPTY_DROPDOWN_TEXT
;
},
},
},
},
};
};
...
...
app/assets/javascripts/projects/compare/index.js
View file @
75c036f4
...
@@ -22,10 +22,6 @@ export default function init() {
...
@@ -22,10 +22,6 @@ export default function init() {
components
:
{
components
:
{
CompareApp
,
CompareApp
,
},
},
provide
:
{
projectTo
:
JSON
.
parse
(
projectTo
),
projectsFrom
:
JSON
.
parse
(
projectsFrom
),
},
render
(
createElement
)
{
render
(
createElement
)
{
return
createElement
(
CompareApp
,
{
return
createElement
(
CompareApp
,
{
props
:
{
props
:
{
...
@@ -35,6 +31,8 @@ export default function init() {
...
@@ -35,6 +31,8 @@ export default function init() {
projectCompareIndexPath
,
projectCompareIndexPath
,
projectMergeRequestPath
,
projectMergeRequestPath
,
createMrPath
,
createMrPath
,
defaultProject
:
JSON
.
parse
(
projectTo
),
projects
:
JSON
.
parse
(
projectsFrom
),
},
},
});
});
},
},
...
...
changelogs/unreleased/225345-re-add-swap-revisions.yml
0 → 100644
View file @
75c036f4
---
title
:
Add ability to swap revisions when comparing
merge_request
:
60491
author
:
type
:
added
spec/frontend/projects/compare/components/app_spec.js
View file @
75c036f4
...
@@ -2,26 +2,19 @@ import { GlButton } from '@gitlab/ui';
...
@@ -2,26 +2,19 @@ import { GlButton } from '@gitlab/ui';
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
CompareApp
from
'
~/projects/compare/components/app.vue
'
;
import
CompareApp
from
'
~/projects/compare/components/app.vue
'
;
import
RevisionCard
from
'
~/projects/compare/components/revision_card.vue
'
;
import
RevisionCard
from
'
~/projects/compare/components/revision_card.vue
'
;
import
{
appDefaultProps
as
defaultProps
}
from
'
./mock_data
'
;
jest
.
mock
(
'
~/lib/utils/csrf
'
,
()
=>
({
token
:
'
mock-csrf-token
'
}));
jest
.
mock
(
'
~/lib/utils/csrf
'
,
()
=>
({
token
:
'
mock-csrf-token
'
}));
const
projectCompareIndexPath
=
'
some/path
'
;
const
refsProjectPath
=
'
some/refs/path
'
;
const
paramsFrom
=
'
master
'
;
const
paramsTo
=
'
master
'
;
describe
(
'
CompareApp component
'
,
()
=>
{
describe
(
'
CompareApp component
'
,
()
=>
{
let
wrapper
;
let
wrapper
;
const
findSourceRevisionCard
=
()
=>
wrapper
.
find
(
'
[data-testid="sourceRevisionCard"]
'
);
const
findTargetRevisionCard
=
()
=>
wrapper
.
find
(
'
[data-testid="targetRevisionCard"]
'
);
const
createComponent
=
(
props
=
{})
=>
{
const
createComponent
=
(
props
=
{})
=>
{
wrapper
=
shallowMount
(
CompareApp
,
{
wrapper
=
shallowMount
(
CompareApp
,
{
propsData
:
{
propsData
:
{
projectCompareIndexPath
,
...
defaultProps
,
refsProjectPath
,
paramsFrom
,
paramsTo
,
projectMergeRequestPath
:
''
,
createMrPath
:
''
,
...
props
,
...
props
,
},
},
});
});
...
@@ -39,16 +32,16 @@ describe('CompareApp component', () => {
...
@@ -39,16 +32,16 @@ describe('CompareApp component', () => {
it
(
'
renders component with prop
'
,
()
=>
{
it
(
'
renders component with prop
'
,
()
=>
{
expect
(
wrapper
.
props
()).
toEqual
(
expect
(
wrapper
.
props
()).
toEqual
(
expect
.
objectContaining
({
expect
.
objectContaining
({
projectCompareIndexPath
,
projectCompareIndexPath
:
defaultProps
.
projectCompareIndexPath
,
refsProjectPath
,
refsProjectPath
:
defaultProps
.
refsProjectPath
,
paramsFrom
,
paramsFrom
:
defaultProps
.
paramsFrom
,
paramsTo
,
paramsTo
:
defaultProps
.
paramsTo
,
}),
}),
);
);
});
});
it
(
'
contains the correct form attributes
'
,
()
=>
{
it
(
'
contains the correct form attributes
'
,
()
=>
{
expect
(
wrapper
.
attributes
(
'
action
'
)).
toBe
(
projectCompareIndexPath
);
expect
(
wrapper
.
attributes
(
'
action
'
)).
toBe
(
defaultProps
.
projectCompareIndexPath
);
expect
(
wrapper
.
attributes
(
'
method
'
)).
toBe
(
'
POST
'
);
expect
(
wrapper
.
attributes
(
'
method
'
)).
toBe
(
'
POST
'
);
});
});
...
@@ -87,6 +80,58 @@ describe('CompareApp component', () => {
...
@@ -87,6 +80,58 @@ describe('CompareApp component', () => {
});
});
});
});
it
(
'
sets the selected project when the "selectProject" event is emitted
'
,
async
()
=>
{
const
project
=
{
name
:
'
some-to-name
'
,
id
:
'
1
'
,
};
findTargetRevisionCard
().
vm
.
$emit
(
'
selectProject
'
,
{
direction
:
'
to
'
,
project
,
});
await
wrapper
.
vm
.
$nextTick
();
expect
(
findTargetRevisionCard
().
props
(
'
selectedProject
'
)).
toEqual
(
expect
.
objectContaining
(
project
),
);
});
it
(
'
sets the selected revision when the "selectRevision" event is emitted
'
,
async
()
=>
{
const
revision
=
'
some-revision
'
;
findTargetRevisionCard
().
vm
.
$emit
(
'
selectRevision
'
,
{
direction
:
'
to
'
,
revision
,
});
await
wrapper
.
vm
.
$nextTick
();
expect
(
findSourceRevisionCard
().
props
(
'
paramsBranch
'
)).
toBe
(
revision
);
});
describe
(
'
swap revisions button
'
,
()
=>
{
const
findSwapRevisionsButton
=
()
=>
wrapper
.
find
(
'
[data-testid="swapRevisionsButton"]
'
);
it
(
'
renders the swap revisions button
'
,
()
=>
{
expect
(
findSwapRevisionsButton
().
exists
()).
toBe
(
true
);
});
it
(
'
has the correct text
'
,
()
=>
{
expect
(
findSwapRevisionsButton
().
text
()).
toBe
(
'
Swap revisions
'
);
});
it
(
'
swaps revisions when clicked
'
,
async
()
=>
{
findSwapRevisionsButton
().
vm
.
$emit
(
'
click
'
);
await
wrapper
.
vm
.
$nextTick
();
expect
(
findTargetRevisionCard
().
props
(
'
paramsBranch
'
)).
toBe
(
defaultProps
.
paramsTo
);
expect
(
findSourceRevisionCard
().
props
(
'
paramsBranch
'
)).
toBe
(
defaultProps
.
paramsFrom
);
});
});
describe
(
'
merge request buttons
'
,
()
=>
{
describe
(
'
merge request buttons
'
,
()
=>
{
const
findProjectMrButton
=
()
=>
wrapper
.
find
(
'
[data-testid="projectMrButton"]
'
);
const
findProjectMrButton
=
()
=>
wrapper
.
find
(
'
[data-testid="projectMrButton"]
'
);
const
findCreateMrButton
=
()
=>
wrapper
.
find
(
'
[data-testid="createMrButton"]
'
);
const
findCreateMrButton
=
()
=>
wrapper
.
find
(
'
[data-testid="createMrButton"]
'
);
...
...
spec/frontend/projects/compare/components/mock_data.js
0 → 100644
View file @
75c036f4
const
refsProjectPath
=
'
some/refs/path
'
;
const
paramsName
=
'
to
'
;
const
paramsBranch
=
'
main
'
;
const
defaultProject
=
{
name
:
'
some-to-name
'
,
id
:
'
1
'
,
};
export
const
appDefaultProps
=
{
projectCompareIndexPath
:
'
some/path
'
,
projectMergeRequestPath
:
''
,
projects
:
[
defaultProject
],
paramsFrom
:
'
main
'
,
paramsTo
:
'
target/branch
'
,
createMrPath
:
''
,
refsProjectPath
,
defaultProject
,
};
export
const
revisionCardDefaultProps
=
{
selectedProject
:
defaultProject
,
paramsBranch
,
revisionText
:
'
Source
'
,
refsProjectPath
,
paramsName
,
};
export
const
repoDropdownDefaultProps
=
{
selectedProject
:
defaultProject
,
paramsName
,
};
export
const
revisionDropdownDefaultProps
=
{
refsProjectPath
,
paramsBranch
,
paramsName
,
};
spec/frontend/projects/compare/components/repo_dropdown_spec.js
View file @
75c036f4
import
{
GlDropdown
,
GlDropdownItem
}
from
'
@gitlab/ui
'
;
import
{
GlDropdown
,
GlDropdownItem
}
from
'
@gitlab/ui
'
;
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
RepoDropdown
from
'
~/projects/compare/components/repo_dropdown.vue
'
;
import
RepoDropdown
from
'
~/projects/compare/components/repo_dropdown.vue
'
;
import
{
revisionCardDefaultProps
as
defaultProps
}
from
'
./mock_data
'
;
const
defaultProps
=
{
paramsName
:
'
to
'
,
};
const
projectToId
=
'
1
'
;
const
projectToName
=
'
some-to-name
'
;
const
projectFromId
=
'
2
'
;
const
projectFromName
=
'
some-from-name
'
;
const
defaultProvide
=
{
projectTo
:
{
id
:
projectToId
,
name
:
projectToName
},
projectsFrom
:
[
{
id
:
projectFromId
,
name
:
projectFromName
},
{
id
:
3
,
name
:
'
some-from-another-name
'
},
],
};
describe
(
'
RepoDropdown component
'
,
()
=>
{
describe
(
'
RepoDropdown component
'
,
()
=>
{
let
wrapper
;
let
wrapper
;
const
createComponent
=
(
props
=
{}
,
provide
=
{}
)
=>
{
const
createComponent
=
(
props
=
{})
=>
{
wrapper
=
shallowMount
(
RepoDropdown
,
{
wrapper
=
shallowMount
(
RepoDropdown
,
{
propsData
:
{
propsData
:
{
...
defaultProps
,
...
defaultProps
,
...
props
,
...
props
,
},
},
provide
:
{
...
defaultProvide
,
...
provide
,
},
});
});
};
};
...
@@ -49,11 +29,11 @@ describe('RepoDropdown component', () => {
...
@@ -49,11 +29,11 @@ describe('RepoDropdown component', () => {
});
});
it
(
'
set hidden input
'
,
()
=>
{
it
(
'
set hidden input
'
,
()
=>
{
expect
(
findHiddenInput
().
attributes
(
'
value
'
)).
toBe
(
projectToI
d
);
expect
(
findHiddenInput
().
attributes
(
'
value
'
)).
toBe
(
defaultProps
.
selectedProject
.
i
d
);
});
});
it
(
'
displays the project name in the disabled dropdown
'
,
()
=>
{
it
(
'
displays the project name in the disabled dropdown
'
,
()
=>
{
expect
(
findGlDropdown
().
props
(
'
text
'
)).
toBe
(
projectToN
ame
);
expect
(
findGlDropdown
().
props
(
'
text
'
)).
toBe
(
defaultProps
.
selectedProject
.
n
ame
);
expect
(
findGlDropdown
().
props
(
'
disabled
'
)).
toBe
(
true
);
expect
(
findGlDropdown
().
props
(
'
disabled
'
)).
toBe
(
true
);
});
});
...
@@ -66,31 +46,39 @@ describe('RepoDropdown component', () => {
...
@@ -66,31 +46,39 @@ describe('RepoDropdown component', () => {
describe
(
'
Target Revision
'
,
()
=>
{
describe
(
'
Target Revision
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
createComponent
({
paramsName
:
'
from
'
});
const
projects
=
[
{
name
:
'
some-to-name
'
,
id
:
'
1
'
,
},
];
createComponent
({
paramsName
:
'
from
'
,
projects
});
});
});
it
(
'
set hidden input of the selected project
'
,
()
=>
{
it
(
'
set hidden input of the selected project
'
,
()
=>
{
expect
(
findHiddenInput
().
attributes
(
'
value
'
)).
toBe
(
projectToI
d
);
expect
(
findHiddenInput
().
attributes
(
'
value
'
)).
toBe
(
defaultProps
.
selectedProject
.
i
d
);
});
});
it
(
'
displays matching project name of the source revision initially in the dropdown
'
,
()
=>
{
it
(
'
displays matching project name of the source revision initially in the dropdown
'
,
()
=>
{
expect
(
findGlDropdown
().
props
(
'
text
'
)).
toBe
(
projectToN
ame
);
expect
(
findGlDropdown
().
props
(
'
text
'
)).
toBe
(
defaultProps
.
selectedProject
.
n
ame
);
});
});
it
(
'
updates the hidd
i
n input value when onClick method is triggered
'
,
async
()
=>
{
it
(
'
updates the hidd
e
n input value when onClick method is triggered
'
,
async
()
=>
{
const
repoId
=
'
1
00
'
;
const
repoId
=
'
1
'
;
wrapper
.
vm
.
onClick
({
id
:
repoId
});
wrapper
.
vm
.
onClick
({
id
:
repoId
});
await
wrapper
.
vm
.
$nextTick
();
await
wrapper
.
vm
.
$nextTick
();
expect
(
findHiddenInput
().
attributes
(
'
value
'
)).
toBe
(
repoId
);
expect
(
findHiddenInput
().
attributes
(
'
value
'
)).
toBe
(
repoId
);
});
});
it
(
'
emits `changeTargetProject` event when another target project is selected
'
,
async
()
=>
{
it
(
'
emits `selectProject` event when another target project is selected
'
,
async
()
=>
{
const
index
=
1
;
findGlDropdown
().
findAll
(
GlDropdownItem
).
at
(
0
).
vm
.
$emit
(
'
click
'
);
const
{
projectsFrom
}
=
defaultProvide
;
findGlDropdown
().
findAll
(
GlDropdownItem
).
at
(
index
).
vm
.
$emit
(
'
click
'
);
await
wrapper
.
vm
.
$nextTick
();
await
wrapper
.
vm
.
$nextTick
();
expect
(
wrapper
.
emitted
(
'
changeTargetProject
'
)[
0
][
0
]).
toEqual
(
projectsFrom
[
index
].
name
);
expect
(
wrapper
.
emitted
(
'
selectProject
'
)[
0
][
0
]).
toEqual
({
direction
:
'
from
'
,
project
:
{
id
:
'
1
'
,
name
:
'
some-to-name
'
},
});
});
});
});
});
});
});
spec/frontend/projects/compare/components/revision_card_spec.js
View file @
75c036f4
...
@@ -3,13 +3,7 @@ import { shallowMount } from '@vue/test-utils';
...
@@ -3,13 +3,7 @@ import { shallowMount } from '@vue/test-utils';
import
RepoDropdown
from
'
~/projects/compare/components/repo_dropdown.vue
'
;
import
RepoDropdown
from
'
~/projects/compare/components/repo_dropdown.vue
'
;
import
RevisionCard
from
'
~/projects/compare/components/revision_card.vue
'
;
import
RevisionCard
from
'
~/projects/compare/components/revision_card.vue
'
;
import
RevisionDropdown
from
'
~/projects/compare/components/revision_dropdown.vue
'
;
import
RevisionDropdown
from
'
~/projects/compare/components/revision_dropdown.vue
'
;
import
{
revisionCardDefaultProps
as
defaultProps
}
from
'
./mock_data
'
;
const
defaultProps
=
{
refsProjectPath
:
'
some/refs/path
'
,
revisionText
:
'
Source
'
,
paramsName
:
'
to
'
,
paramsBranch
:
'
master
'
,
};
describe
(
'
RepoDropdown component
'
,
()
=>
{
describe
(
'
RepoDropdown component
'
,
()
=>
{
let
wrapper
;
let
wrapper
;
...
...
spec/frontend/projects/compare/components/revision_dropdown_spec.js
View file @
75c036f4
import
{
GlDropdown
,
GlSearchBoxByType
}
from
'
@gitlab/ui
'
;
import
{
GlDropdown
,
Gl
DropdownItem
,
Gl
SearchBoxByType
}
from
'
@gitlab/ui
'
;
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
AxiosMockAdapter
from
'
axios-mock-adapter
'
;
import
AxiosMockAdapter
from
'
axios-mock-adapter
'
;
import
createFlash
from
'
~/flash
'
;
import
createFlash
from
'
~/flash
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
RevisionDropdown
from
'
~/projects/compare/components/revision_dropdown.vue
'
;
import
RevisionDropdown
from
'
~/projects/compare/components/revision_dropdown.vue
'
;
import
{
revisionDropdownDefaultProps
as
defaultProps
}
from
'
./mock_data
'
;
const
defaultProps
=
{
refsProjectPath
:
'
some/refs/path
'
,
paramsName
:
'
from
'
,
paramsBranch
:
'
master
'
,
};
jest
.
mock
(
'
~/flash
'
);
jest
.
mock
(
'
~/flash
'
);
...
@@ -142,4 +137,17 @@ describe('RevisionDropdown component', () => {
...
@@ -142,4 +137,17 @@ describe('RevisionDropdown component', () => {
expect
(
findGlDropdown
().
props
(
'
text
'
)).
toBe
(
defaultProps
.
paramsBranch
);
expect
(
findGlDropdown
().
props
(
'
text
'
)).
toBe
(
defaultProps
.
paramsBranch
);
});
});
});
});
it
(
'
emits `selectRevision` event when another revision is selected
'
,
async
()
=>
{
createComponent
();
wrapper
.
vm
.
branches
=
[
'
some-branch
'
];
await
wrapper
.
vm
.
$nextTick
();
findGlDropdown
().
findAll
(
GlDropdownItem
).
at
(
0
).
vm
.
$emit
(
'
click
'
);
expect
(
wrapper
.
emitted
(
'
selectRevision
'
)[
0
][
0
]).
toEqual
({
direction
:
'
to
'
,
revision
:
'
some-branch
'
,
});
});
});
});
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