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
2e43bff4
Commit
2e43bff4
authored
Apr 23, 2020
by
Thomas Randolph
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an action that changes the Diffs app active commit
parent
b8c11c51
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
0 deletions
+82
-0
app/assets/javascripts/diffs/store/actions.js
app/assets/javascripts/diffs/store/actions.js
+23
-0
spec/frontend/diffs/store/actions_spec.js
spec/frontend/diffs/store/actions_spec.js
+59
-0
No files found.
app/assets/javascripts/diffs/store/actions.js
View file @
2e43bff4
...
@@ -642,5 +642,28 @@ export const setSuggestPopoverDismissed = ({ commit, state }) =>
...
@@ -642,5 +642,28 @@ export const setSuggestPopoverDismissed = ({ commit, state }) =>
createFlash
(
s__
(
'
MergeRequest|Error dismissing suggestion popover. Please try again.
'
));
createFlash
(
s__
(
'
MergeRequest|Error dismissing suggestion popover. Please try again.
'
));
});
});
export
function
changeCurrentCommit
({
dispatch
,
commit
,
state
},
{
commitId
})
{
/* eslint-disable @gitlab/require-i18n-strings */
if
(
!
commitId
)
{
return
Promise
.
reject
(
new
Error
(
'
`commitId` is a required argument
'
));
}
else
if
(
!
state
.
commit
)
{
return
Promise
.
reject
(
new
Error
(
'
`state` must already contain a valid `commit`
'
));
}
/* eslint-enable @gitlab/require-i18n-strings */
// this is less than ideal, see: https://gitlab.com/gitlab-org/gitlab/-/issues/215421
const
commitRE
=
new
RegExp
(
state
.
commit
.
id
,
'
g
'
);
commit
(
types
.
SET_DIFF_FILES
,
[]);
commit
(
types
.
SET_BASE_CONFIG
,
{
...
state
,
endpoint
:
state
.
endpoint
.
replace
(
commitRE
,
commitId
),
endpointBatch
:
state
.
endpointBatch
.
replace
(
commitRE
,
commitId
),
endpointMetadata
:
state
.
endpointMetadata
.
replace
(
commitRE
,
commitId
),
});
return
dispatch
(
'
fetchDiffFilesMeta
'
);
}
// prevent babel-plugin-rewire from generating an invalid default during karma tests
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export
default
()
=>
{};
export
default
()
=>
{};
spec/frontend/diffs/store/actions_spec.js
View file @
2e43bff4
...
@@ -43,6 +43,7 @@ import {
...
@@ -43,6 +43,7 @@ import {
setFileCollapsed
,
setFileCollapsed
,
setExpandedDiffLines
,
setExpandedDiffLines
,
setSuggestPopoverDismissed
,
setSuggestPopoverDismissed
,
changeCurrentCommit
,
}
from
'
~/diffs/store/actions
'
;
}
from
'
~/diffs/store/actions
'
;
import
eventHub
from
'
~/notes/event_hub
'
;
import
eventHub
from
'
~/notes/event_hub
'
;
import
*
as
types
from
'
~/diffs/store/mutation_types
'
;
import
*
as
types
from
'
~/diffs/store/mutation_types
'
;
...
@@ -1347,4 +1348,62 @@ describe('DiffsStoreActions', () => {
...
@@ -1347,4 +1348,62 @@ describe('DiffsStoreActions', () => {
);
);
});
});
});
});
describe
(
'
changeCurrentCommit
'
,
()
=>
{
it
(
'
commits the new commit information and re-requests the diff metadata for the commit
'
,
()
=>
{
return
testAction
(
changeCurrentCommit
,
{
commitId
:
'
NEW
'
},
{
commit
:
{
id
:
'
OLD
'
,
},
endpoint
:
'
URL/OLD
'
,
endpointBatch
:
'
URL/OLD
'
,
endpointMetadata
:
'
URL/OLD
'
,
},
[
{
type
:
types
.
SET_DIFF_FILES
,
payload
:
[]
},
{
type
:
types
.
SET_BASE_CONFIG
,
payload
:
{
commit
:
{
id
:
'
OLD
'
,
// Not a typo: the action fired next will overwrite all of the `commit` in state
},
endpoint
:
'
URL/NEW
'
,
endpointBatch
:
'
URL/NEW
'
,
endpointMetadata
:
'
URL/NEW
'
,
},
},
],
[{
type
:
'
fetchDiffFilesMeta
'
}],
);
});
it
.
each
`
commitId | commit | msg
${
undefined
}
|
${{
id
:
'
OLD
'
}
} |
${
'
`commitId` is a required argument
'
}
${
'
NEW
'
}
|
${
null
}
|
${
'
`state` must already contain a valid `commit`
'
}
${
undefined
}
|
${
null
}
|
${
'
`commitId` is a required argument
'
}
`
(
'
returns a rejected promise with the error message $msg given `{ "commitId": $commitId, "state.commit": $commit }`
'
,
({
commitId
,
commit
,
msg
})
=>
{
const
err
=
new
Error
(
msg
);
const
actionReturn
=
testAction
(
changeCurrentCommit
,
{
commitId
},
{
endpoint
:
'
URL/OLD
'
,
endpointBatch
:
'
URL/OLD
'
,
endpointMetadata
:
'
URL/OLD
'
,
commit
,
},
[],
[],
);
return
expect
(
actionReturn
).
rejects
.
toStrictEqual
(
err
);
},
);
});
});
});
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