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
bfa89103
Commit
bfa89103
authored
Apr 13, 2020
by
jboyson1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add head to target versions list
Add head to tests Streamlin target versiont tests with helper functions
parent
082e7bdb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
28 deletions
+97
-28
app/assets/javascripts/diffs/constants.js
app/assets/javascripts/diffs/constants.js
+1
-0
app/assets/javascripts/diffs/store/getters_versions_dropdowns.js
...ets/javascripts/diffs/store/getters_versions_dropdowns.js
+17
-3
changelogs/unreleased/jdb-display-head-base-dropwdowns.yml
changelogs/unreleased/jdb-display-head-base-dropwdowns.yml
+5
-0
spec/frontend/diffs/store/getters_versions_dropdowns_spec.js
spec/frontend/diffs/store/getters_versions_dropdowns_spec.js
+74
-25
No files found.
app/assets/javascripts/diffs/constants.js
View file @
bfa89103
...
@@ -60,3 +60,4 @@ export const PARALLEL_DIFF_LINES_KEY = 'parallel_diff_lines';
...
@@ -60,3 +60,4 @@ export const PARALLEL_DIFF_LINES_KEY = 'parallel_diff_lines';
export
const
DIFFS_PER_PAGE
=
20
;
export
const
DIFFS_PER_PAGE
=
20
;
export
const
DIFF_COMPARE_BASE_VERSION_INDEX
=
-
1
;
export
const
DIFF_COMPARE_BASE_VERSION_INDEX
=
-
1
;
export
const
DIFF_COMPARE_HEAD_VERSION_INDEX
=
-
2
;
app/assets/javascripts/diffs/store/getters_versions_dropdowns.js
View file @
bfa89103
import
{
__
,
n__
,
sprintf
}
from
'
~/locale
'
;
import
{
__
,
n__
,
sprintf
}
from
'
~/locale
'
;
import
{
DIFF_COMPARE_BASE_VERSION_INDEX
}
from
'
../constants
'
;
import
{
getParameterByName
,
parseBoolean
}
from
'
~/lib/utils/common_utils
'
;
import
{
DIFF_COMPARE_BASE_VERSION_INDEX
,
DIFF_COMPARE_HEAD_VERSION_INDEX
}
from
'
../constants
'
;
export
const
selectedTargetIndex
=
state
=>
export
const
selectedTargetIndex
=
state
=>
state
.
startVersion
?.
version_index
||
DIFF_COMPARE_BASE_VERSION_INDEX
;
state
.
startVersion
?.
version_index
||
DIFF_COMPARE_BASE_VERSION_INDEX
;
...
@@ -9,12 +10,25 @@ export const selectedSourceIndex = state => state.mergeRequestDiff.version_index
...
@@ -9,12 +10,25 @@ export const selectedSourceIndex = state => state.mergeRequestDiff.version_index
export
const
diffCompareDropdownTargetVersions
=
(
state
,
getters
)
=>
{
export
const
diffCompareDropdownTargetVersions
=
(
state
,
getters
)
=>
{
// startVersion only exists if the user has selected a version other
// startVersion only exists if the user has selected a version other
// than "base" so if startVersion is null then base must be selected
// than "base" so if startVersion is null then base must be selected
const
diffHead
=
parseBoolean
(
getParameterByName
(
'
diff_head
'
));
const
isBaseSelected
=
!
state
.
startVersion
&&
!
diffHead
;
const
isHeadSelected
=
!
state
.
startVersion
&&
diffHead
;
const
baseVersion
=
{
const
baseVersion
=
{
versionName
:
state
.
targetBranchName
,
versionName
:
state
.
targetBranchName
,
version_index
:
DIFF_COMPARE_BASE_VERSION_INDEX
,
version_index
:
DIFF_COMPARE_BASE_VERSION_INDEX
,
href
:
state
.
mergeRequestDiff
.
base_version_path
,
href
:
state
.
mergeRequestDiff
.
base_version_path
,
isBase
:
true
,
isBase
:
true
,
selected
:
!
state
.
startVersion
,
selected
:
isBaseSelected
,
};
const
headVersion
=
{
versionName
:
state
.
targetBranchName
,
version_index
:
DIFF_COMPARE_HEAD_VERSION_INDEX
,
href
:
state
.
mergeRequestDiff
.
head_version_path
,
isHead
:
true
,
selected
:
isHeadSelected
,
};
};
// Appended properties here are to make the compare_dropdown_layout easier to reason about
// Appended properties here are to make the compare_dropdown_layout easier to reason about
const
formatVersion
=
v
=>
{
const
formatVersion
=
v
=>
{
...
@@ -25,7 +39,7 @@ export const diffCompareDropdownTargetVersions = (state, getters) => {
...
@@ -25,7 +39,7 @@ export const diffCompareDropdownTargetVersions = (state, getters) => {
...
v
,
...
v
,
};
};
};
};
return
[...
state
.
mergeRequestDiffs
.
slice
(
1
).
map
(
formatVersion
),
baseVersion
];
return
[...
state
.
mergeRequestDiffs
.
slice
(
1
).
map
(
formatVersion
),
baseVersion
,
headVersion
];
};
};
export
const
diffCompareDropdownSourceVersions
=
(
state
,
getters
)
=>
{
export
const
diffCompareDropdownSourceVersions
=
(
state
,
getters
)
=>
{
...
...
changelogs/unreleased/jdb-display-head-base-dropwdowns.yml
0 → 100644
View file @
bfa89103
---
title
:
fix display head and base in version dropdowns
merge_request
:
29433
author
:
type
:
fixed
spec/frontend/diffs/store/getters_versions_dropdowns_spec.js
View file @
bfa89103
import
*
as
getters
from
'
~/diffs/store/getters
'
;
import
*
as
getters
from
'
~/diffs/store/getters
'
;
import
state
from
'
~/diffs/store/modules/diff_state
'
;
import
state
from
'
~/diffs/store/modules/diff_state
'
;
import
{
DIFF_COMPARE_BASE_VERSION_INDEX
}
from
'
~/diffs/constants
'
;
import
{
DIFF_COMPARE_BASE_VERSION_INDEX
,
DIFF_COMPARE_HEAD_VERSION_INDEX
,
}
from
'
~/diffs/constants
'
;
import
diffsMockData
from
'
../mock_data/merge_request_diffs
'
;
import
diffsMockData
from
'
../mock_data/merge_request_diffs
'
;
describe
(
'
Compare diff version dropdowns
'
,
()
=>
{
describe
(
'
Compare diff version dropdowns
'
,
()
=>
{
...
@@ -37,47 +40,93 @@ describe('Compare diff version dropdowns', () => {
...
@@ -37,47 +40,93 @@ describe('Compare diff version dropdowns', () => {
describe
(
'
diffCompareDropdownTargetVersions
'
,
()
=>
{
describe
(
'
diffCompareDropdownTargetVersions
'
,
()
=>
{
// diffCompareDropdownTargetVersions slices the array at the first position
// diffCompareDropdownTargetVersions slices the array at the first position
// and appends a "base" version which is why we use diffsMockData[1] below
// and appends a "base" and "head" version at the end of the list so that
// This is to display "base" at the end of the target dropdown
// "base" and "head" appear at the bottom of the dropdown
const
expectedFirstVersion
=
{
// this is also why we use diffsMockData[1] for the "first" version
...
diffsMockData
[
1
],
href
:
expect
.
any
(
String
),
let
expectedFirstVersion
;
versionName
:
expect
.
any
(
String
),
let
expectedBaseVersion
;
let
expectedHeadVersion
;
const
originalLocation
=
window
.
location
;
const
setupTest
=
includeDiffHeadParam
=>
{
const
diffHeadParam
=
includeDiffHeadParam
?
'
?diff_head=true
'
:
''
;
Object
.
defineProperty
(
window
,
'
location
'
,
{
writable
:
true
,
value
:
{
href
:
`https://example.gitlab.com
${
diffHeadParam
}
`
},
});
expectedFirstVersion
=
{
...
diffsMockData
[
1
],
href
:
expect
.
any
(
String
),
versionName
:
expect
.
any
(
String
),
selected
:
false
,
};
expectedBaseVersion
=
{
versionName
:
'
baseVersion
'
,
version_index
:
DIFF_COMPARE_BASE_VERSION_INDEX
,
href
:
'
basePath
'
,
isBase
:
true
,
selected
:
false
,
};
expectedHeadVersion
=
{
versionName
:
'
baseVersion
'
,
version_index
:
DIFF_COMPARE_HEAD_VERSION_INDEX
,
href
:
'
headPath
'
,
isHead
:
true
,
selected
:
false
,
};
};
};
const
expectedBaseVersion
=
{
const
assertVersions
=
targetVersions
=>
{
versionName
:
'
baseVersion
'
,
// base and head should be the last two versions in that order
version_index
:
DIFF_COMPARE_BASE_VERSION_INDEX
,
const
targetBaseVersion
=
targetVersions
[
targetVersions
.
length
-
2
];
href
:
'
basePath
'
,
const
targetHeadVersion
=
targetVersions
[
targetVersions
.
length
-
1
];
isBase
:
true
,
expect
(
targetVersions
[
0
]).
toEqual
(
expectedFirstVersion
);
expect
(
targetBaseVersion
).
toEqual
(
expectedBaseVersion
);
expect
(
targetHeadVersion
).
toEqual
(
expectedHeadVersion
);
};
};
afterEach
(()
=>
{
window
.
location
=
originalLocation
;
});
it
(
'
base version selected
'
,
()
=>
{
it
(
'
base version selected
'
,
()
=>
{
expectedFirstVersion
.
selected
=
false
;
setupTest
()
;
expectedBaseVersion
.
selected
=
true
;
expectedBaseVersion
.
selected
=
true
;
const
targetVersions
=
getters
.
diffCompareDropdownTargetVersions
(
localState
,
{
const
targetVersions
=
getters
.
diffCompareDropdownTargetVersions
(
localState
,
getters
);
selectedTargetIndex
:
DIFF_COMPARE_BASE_VERSION_INDEX
,
assertVersions
(
targetVersions
);
});
});
const
lastVersion
=
targetVersions
[
targetVersions
.
length
-
1
];
it
(
'
head version selected
'
,
()
=>
{
expect
(
targetVersions
[
0
]).
toEqual
(
expectedFirstVersion
);
setupTest
(
true
);
expect
(
lastVersion
).
toEqual
(
expectedBaseVersion
);
expectedHeadVersion
.
selected
=
true
;
const
targetVersions
=
getters
.
diffCompareDropdownTargetVersions
(
localState
,
getters
);
assertVersions
(
targetVersions
);
});
});
it
(
'
first version selected
'
,
()
=>
{
it
(
'
first version selected
'
,
()
=>
{
expectedFirstVersion
.
selected
=
true
;
// NOTE: It should not be possible to have both "diff_head=true" and
expectedBaseVersion
.
selected
=
false
;
// have anything other than the head version selected, but the user could
// manually add "?diff_head=true" to the url. In this instance we still
// want the actual selected version to display as "selected"
// Passing in "true" here asserts that first version is still selected
// even if "diff_head" is present in the url
setupTest
(
true
);
expectedFirstVersion
.
selected
=
true
;
localState
.
startVersion
=
expectedFirstVersion
;
localState
.
startVersion
=
expectedFirstVersion
;
const
targetVersions
=
getters
.
diffCompareDropdownTargetVersions
(
localState
,
{
const
targetVersions
=
getters
.
diffCompareDropdownTargetVersions
(
localState
,
{
selectedTargetIndex
:
expectedFirstVersion
.
version_index
,
selectedTargetIndex
:
expectedFirstVersion
.
version_index
,
});
});
assertVersions
(
targetVersions
);
const
lastVersion
=
targetVersions
[
targetVersions
.
length
-
1
];
expect
(
targetVersions
[
0
]).
toEqual
(
expectedFirstVersion
);
expect
(
lastVersion
).
toEqual
(
expectedBaseVersion
);
});
});
});
});
...
...
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