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
7b46b28e
Commit
7b46b28e
authored
Mar 19, 2021
by
Thomas Randolph
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a network action to fetch the MR Metadata from the API endpoint
parent
9a326fa7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
1 deletion
+68
-1
app/assets/javascripts/mr_notes/stores/actions.js
app/assets/javascripts/mr_notes/stores/actions.js
+19
-0
spec/frontend/mr_notes/stores/actions_spec.js
spec/frontend/mr_notes/stores/actions_spec.js
+49
-1
No files found.
app/assets/javascripts/mr_notes/stores/actions.js
View file @
7b46b28e
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
types
from
'
./mutation_types
'
;
export
function
setActiveTab
({
commit
},
tab
)
{
...
...
@@ -11,3 +13,20 @@ export function setEndpoints({ commit }, endpoints) {
export
function
setMrMetadata
({
commit
},
metadata
)
{
commit
(
types
.
SET_MR_METADATA
,
metadata
);
}
export
function
fetchMrMetadata
({
dispatch
,
state
})
{
if
(
state
.
endpoints
?.
metadata
)
{
axios
.
get
(
state
.
endpoints
.
metadata
)
.
then
((
response
)
=>
{
dispatch
(
'
setMrMetadata
'
,
response
.
data
);
})
.
catch
(()
=>
{
// https://gitlab.com/gitlab-org/gitlab/-/issues/324740
// We can't even do a simple console warning here because
// the pipeline will fail. However, the issue above will
// eventually handle errors appropriately.
// console.warn('Failed to load MR Metadata for the Overview tab.');
});
}
}
spec/frontend/mr_notes/stores/actions_spec.js
View file @
7b46b28e
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
testAction
from
'
helpers/vuex_action_helper
'
;
import
{
setEndpoints
,
setMrMetadata
}
from
'
~/mr_notes/stores/actions
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
{
setEndpoints
,
setMrMetadata
,
fetchMrMetadata
}
from
'
~/mr_notes/stores/actions
'
;
import
mutationTypes
from
'
~/mr_notes/stores/mutation_types
'
;
describe
(
'
MR Notes Mutator Actions
'
,
()
=>
{
...
...
@@ -42,4 +46,48 @@ describe('MR Notes Mutator Actions', () => {
);
});
});
describe
(
'
fetchMrMetadata
'
,
()
=>
{
const
mrMetadata
=
{
meta
:
true
,
data
:
'
foo
'
};
const
state
=
{
endpoints
:
{
metadata
:
'
metadata
'
,
},
};
let
getSpy
;
let
mock
;
beforeEach
(()
=>
{
getSpy
=
jest
.
spyOn
(
axios
,
'
get
'
);
mock
=
new
MockAdapter
(
axios
);
mock
.
onGet
(
state
.
endpoints
.
metadata
).
reply
(
200
,
mrMetadata
);
});
afterEach
(()
=>
{
getSpy
.
mockRestore
();
mock
.
restore
();
});
it
(
'
should fetch the data from the API
'
,
async
()
=>
{
await
fetchMrMetadata
({
state
,
dispatch
:
()
=>
{}
});
expect
(
axios
.
get
).
toHaveBeenCalledWith
(
state
.
endpoints
.
metadata
);
});
it
(
'
should set the fetched data into state
'
,
()
=>
{
return
testAction
(
fetchMrMetadata
,
{},
state
,
[],
[
{
type
:
'
setMrMetadata
'
,
payload
:
mrMetadata
,
},
],
);
});
});
});
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